Skip to content

Commit 448b239

Browse files
committed
In build mode prevent data from being read more than once
1 parent 9d91934 commit 448b239

File tree

4 files changed

+50
-21
lines changed

4 files changed

+50
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.5.2] - 2022-06-17
8+
### Updated
9+
- In build mode prevent data from being read more than once
10+
711
## [1.5.1] - 2022-04-14
812
### Fixed
913
- Dependency update

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@videinfra/static-website-builder",
3-
"version": "1.5.1",
3+
"version": "1.5.2",
44
"description": "Customizable static site project builder",
55
"license": "MIT",
66
"engines": {

tasks/data/get-data.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const getFileNamesSync = require('../../lib/get-file-names');
1010
const camelizeFileName = require('../../lib/camelize-file-name');
1111

1212

13-
module.exports = function getData () {
13+
function getData () {
1414
const folders = getPaths.getSourcePaths('data');
1515
const extensions = getConfig.getTaskConfig('data', 'extensions');
1616
const loaders = getConfig.getTaskConfig('data', 'loaders');
@@ -63,3 +63,25 @@ module.exports = function getData () {
6363

6464
return data;
6565
}
66+
67+
68+
let cache = null;
69+
70+
module.exports = function (options) {
71+
const build = options && !!options.build;
72+
73+
return function () {
74+
if (build) {
75+
// Cache during full build
76+
if (!cache) {
77+
cache = getData();
78+
}
79+
80+
return cache;
81+
} else {
82+
// Don't cache during watch build
83+
cache = null;
84+
return getData();
85+
}
86+
}
87+
}

tasks/html/task.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,39 @@ const getEngine = memoize(function () {
5353
return engine ? engine() : (() => {});
5454
});
5555

56+
function html (options) {
57+
const build = options && !!options.build;
5658

57-
function html () {
58-
return gulp.src(getGlobPaths())
59-
.pipe(taskStart())
59+
return function html () {
60+
return gulp.src(getGlobPaths())
61+
.pipe(taskStart())
6062

61-
// Faster incremental builds, skip files which didn't changed or their dependencies didn't changed
62-
.pipe(gulpif(!!getConfig.getTaskConfig('html', 'dependents'), cached('html')))
63-
.pipe(gulpif(!!getConfig.getTaskConfig('html', 'dependents'), dependents(getConfig.getTaskConfig('dependents'))))
63+
// Faster incremental builds, skip files which didn't changed or their dependencies didn't changed
64+
.pipe(gulpif(!!getConfig.getTaskConfig('html', 'dependents'), cached('html')))
65+
.pipe(gulpif(!!getConfig.getTaskConfig('html', 'dependents'), dependents(getConfig.getTaskConfig('dependents'))))
6466

65-
// Prevent file from being rendered if it's in the ignore list
66-
.pipe(ignore.exclude(getGlobIgnorePaths(), {}))
67+
// Prevent file from being rendered if it's in the ignore list
68+
.pipe(ignore.exclude(getGlobIgnorePaths(), {}))
6769

68-
// Preprocess using TWIG
69-
.pipe(gulpif(!!getConfig.getTaskConfig('html', 'engine'), data(getData)))
70-
.pipe(gulpif(!!getConfig.getTaskConfig('html', 'engine'), getEngine()))
70+
// Preprocess using TWIG
71+
.pipe(gulpif(!!getConfig.getTaskConfig('html', 'engine'), data(getData({ build: build }))))
72+
.pipe(gulpif(!!getConfig.getTaskConfig('html', 'engine'), getEngine()))
7173

72-
// Minify
73-
.pipe(gulpif(!!getConfig.getTaskConfig('html', 'htmlmin'), htmlmin(getConfig.getTaskConfig('html', 'htmlmin'))))
74+
// Minify
75+
.pipe(gulpif(!!getConfig.getTaskConfig('html', 'htmlmin'), htmlmin(getConfig.getTaskConfig('html', 'htmlmin'))))
7476

75-
.pipe(taskBeforeDest())
76-
.pipe(gulp.dest(getPaths.getDestPath('html')))
77+
.pipe(taskBeforeDest())
78+
.pipe(gulp.dest(getPaths.getDestPath('html')))
7779

78-
// Reload on change
79-
.pipe(taskEnd());
80+
// Reload on change
81+
.pipe(taskEnd());
82+
};
8083
}
8184

8285
function htmlWatch () {
83-
return taskWatch(getWatchGlobPaths(), html);
86+
return taskWatch(getWatchGlobPaths(), html({ build: false }));
8487
}
8588

8689

87-
exports.build = html;
90+
exports.build = html({ build: true });
8891
exports.watch = htmlWatch;

0 commit comments

Comments
 (0)