Skip to content

Commit

Permalink
fix: ignore __transpiled folder in watch mode (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
magicmatatjahu authored Jan 7, 2021
1 parent a3a47e1 commit e216b8f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,18 @@ xfs.mkdirp(program.output, async err => {
let watcher;
const watchDir = path.resolve(template);
const outputPath = path.resolve(watchDir, program.output);
const transpiledTemplatePath = path.resolve(watchDir, Generator.TRANSPILED_TEMPLATE_LOCATION);
const ignorePaths = [outputPath, transpiledTemplatePath];
// Template name is needed as it is not always a part of the cli commad
// There is a use case that you run generator from a root of the template with `./` path
const templateName = require(path.resolve(watchDir,'package.json')).name;

if (isAsyncapiDocLocal) {
console.log(`[WATCHER] Watching for changes in the template directory ${magenta(watchDir)} and in the AsyncAPI file ${magenta(asyncapiDocPath)}`);
watcher = new Watcher([asyncapiDocPath, watchDir], outputPath);
watcher = new Watcher([asyncapiDocPath, watchDir], ignorePaths);
} else {
console.log(`[WATCHER] Watching for changes in the template directory ${magenta(watchDir)}`);
watcher = new Watcher(watchDir, outputPath);
watcher = new Watcher(watchDir, ignorePaths);
}
// Must check template in its installation path in generator to use isLocalTemplate function
if (!await isLocalTemplate(path.resolve(Generator.DEFAULT_TEMPLATES_DIR, templateName))) {
Expand Down
1 change: 1 addition & 0 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -830,5 +830,6 @@ class Generator {
}

Generator.DEFAULT_TEMPLATES_DIR = DEFAULT_TEMPLATES_DIR;
Generator.TRANSPILED_TEMPLATE_LOCATION = TRANSPILED_TEMPLATE_LOCATION;

module.exports = Generator;
6 changes: 3 additions & 3 deletions lib/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const chokidar = require('chokidar');
* Class to watch for change in certain file(s)
*/
class Watcher {
constructor(paths, ignorePath) {
constructor(paths, ignorePaths) {
if (Array.isArray(paths)) {
this.paths = paths;
} else {
Expand All @@ -19,7 +19,7 @@ class Watcher {
this.fsWait = false;
this.watchers = {};
this.filesChanged = {};
this.ignorePath = ignorePath;
this.ignorePaths = ignorePaths;
}

/**
Expand All @@ -29,7 +29,7 @@ class Watcher {
* @param {*} errorCallback Calback to call when it is no longer possible to watch a file.
*/
initiateWatchOnPath(path, changeCallback, errorCallback) {
const watcher = chokidar.watch(path, {ignoreInitial: true, ignored: this.ignorePath});
const watcher = chokidar.watch(path, {ignoreInitial: true, ignored: this.ignorePaths});
watcher.on('all', (eventType, changedPath) => this.fileChanged(path, changedPath, eventType, changeCallback, errorCallback));
this.watchers[path] = watcher;
}
Expand Down

0 comments on commit e216b8f

Please sign in to comment.