Skip to content

Commit

Permalink
fix(handelbars): fix watch-observer in hb task for empty changes (docs)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorn Walli committed Feb 15, 2021
1 parent 12cfdc8 commit 943d08f
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions env/engine/lib/tasks/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = function (name, config, watch) {
});

let watcherInitialized = false;
let watcherObserver;

return taskGenerator(
name,
Expand All @@ -40,7 +41,7 @@ module.exports = function (name, config, watch) {
if (!watcherInitialized) {
if (task.partialRendering && options.watchers) {
// Register WatcherHelper for partial file rendering
var watcherObserver = new WatcherObserver();
watcherObserver = new WatcherObserver();
options.watchers.forEach(function (watcher) {
if (watcher.options.partialRendering) {
watcherObserver.register(watcher);
Expand Down Expand Up @@ -71,7 +72,7 @@ module.exports = function (name, config, watch) {
/**
* PartialRendering
*/

let hasChanges = true;
if (task.partialRendering && watcherObserver && watcherObserver.hasChanges()) {
const src = watcherObserver.watchers.reduce(function (result, watcher) {
const src = micromatch(
Expand All @@ -82,37 +83,33 @@ module.exports = function (name, config, watch) {
).map(function (file) {
return upath.relative(upath.join(task.partialRendering.options.cwd), file);
});
watcher.resetChangedFiles();
return result.concat(src);
}, []);

// var src = micromatch(
// watcherHelper.changedFiles.map(function(file) {
// return './' + upath.relative(process.cwd(), file);
// }),
// task.files.src
// ).map(function(file) {
// return upath.relative(upath.join(task.partialRendering.options.cwd), file);
// });
// watcherHelper.resetChangedFiles();
app[task.name](src, {
base: task.partialRendering.options.base || task.partialRendering.options.cwd || '',
cwd: task.partialRendering.options.cwd,
ignore: task.files.ignore
});
if (src.length > 0) {
app[task.name](src, {
base: task.partialRendering.options.base || task.partialRendering.options.cwd || '',
cwd: task.partialRendering.options.cwd,
ignore: task.files.ignore
});
} else {
hasChanges = false;
}
} else {
app[task.name](task.files.src, {
base: task.files.base,
ignore: task.files.ignore
});
}

const stream = app
.toStream(task.name)
.pipe(app.renderFile(getData(watch, config.resources, config.fonts)))
.on('error', errorHandler)
.pipe(extname())
.on('error', errorHandler);
let stream = app
.toStream(task.name);
if (hasChanges) {
stream = stream
.pipe(app.renderFile(getData(watch, config.resources, config.fonts)))
.on('error', errorHandler)
.pipe(extname())
.on('error', errorHandler);
}

return stream.pipe(app.dest(task.files.dest)).on('error', errorHandler);
});
Expand Down

0 comments on commit 943d08f

Please sign in to comment.