Commit 2e4dc4e9 authored by Philipp Nowinski's avatar Philipp Nowinski
Browse files

[BUGFIX] swap watcher library to support triggers for new files

parent 6f96f5dd
......@@ -54,7 +54,7 @@ module.exports = class task {
}
/**
* Returns the full path (relative to the project dit) for _path
* Returns the full path (relative to the project dir) for _path
*
* @param {String} _path The path the full path shall be found for
*/
......
const Task = require('../task');
const watch = require('node-watch');
const globby = require('globby');
const gaze = require('gaze');
const chalk = require('chalk');
const path = require('path');
const settings = require('../settings');
......@@ -11,7 +11,7 @@ module.exports = class Watch extends Task {
/**
* Runner function
*
*
* @override
*/
async run() {
......@@ -26,7 +26,7 @@ module.exports = class Watch extends Task {
*/
async _watchCss() {
let globs = [];
// get a glob for each extension that shall be watched
this._config.extensions.forEach(_extension => {
globs.push(this._getGlobFor(_extension, `${this._config.directories.sass}/**/*.scss`));
......@@ -34,21 +34,23 @@ module.exports = class Watch extends Task {
});
// assemble information about which files need to be watched
const ignoredFiles = ['!**/*_svg.scss'].concat(this._config.css.excludeFromQa);
const files = await globby(globs.concat(ignoredFiles));
const ignoredFiles = ['!**/*_svg.scss'];
// watch those files
files.forEach(file => {
watch(file, { recursive: true }, this._onCssChange.bind(this));
gaze(globs.concat(ignoredFiles), (error, watcher) => {
if (error) {
this._logger.error(error.stack);
}
watcher.on('changed', this._onCssChange.bind(this));
watcher.on('added', this._onNewFile.bind(this));
});
}
/**
* Watch for JS-related files
*/
async _watchJs() {
let globs = [];
// get a glob for each extension that shall be watched
this._config.extensions.forEach(_extension => {
globs.push(this._getGlobFor(_extension, `${this._config.directories.javascriptSrc}/**/*.js`));
......@@ -56,17 +58,19 @@ module.exports = class Watch extends Task {
// assemble information about which files need to be watched
const ignoredFiles = ['!**/*.min.js'].concat(this._config.js.excludeFromQa);
const files = await globby(globs.concat(ignoredFiles));
// watch those files
files.forEach(file => {
watch(file, { recursive: true }, this._onJsChange.bind(this));
gaze(globs.concat(ignoredFiles), (error, watcher) => {
if (error) {
this._logger.error(error.stack);
}
watcher.on('changed', this._onJsChange.bind(this));
watcher.on('added', this._onNewFile.bind(this));
});
}
/**
* Generates the glob for files in _path in _extension
*
*
* @param {String} _extension Name of the extension
* @param {String} _path The path to the files inside the extension
*/
......@@ -81,7 +85,7 @@ module.exports = class Watch extends Task {
let task = this._settings.tasks.css();
new task().run();
}
/**
* Trigger JS-compilation
*/
......@@ -92,34 +96,42 @@ module.exports = class Watch extends Task {
/**
* This function will execute on file changes
*
* @param {Event} _event The change event
*
* @param {String} _fileName The path to the file that changed
*/
_onCssChange(_event, _fileName) {
_onCssChange(_fileName) {
this._setCurrentExtensionName(_fileName);
this._logger.info(`${_fileName} changed`);
this._logger.info(`Change in ${chalk.white(path.basename(_fileName))}`);
this._triggerCss();
}
/**
* This function will execute on file changes
*
* @param {Event} _event The change event
*
* @param {String} _fileName The path to the file that changed
*/
_onJsChange(_event, _fileName) {
this._logger.info(`${_fileName} changed`);
_onJsChange(_fileName) {
this._logger.info(`Change in ${chalk.white(path.basename(_fileName))}`);
this._triggerJs();
}
/**
* Prints a notification about the creation of new files
*
* @param _fileName
* @private
*/
_onNewFile(_fileName) {
this._logger.info(`New file ${chalk.white(path.basename(_fileName))}`);
}
/**
* Tells our settings object which extension shall be used for the following build steps
*
*
* @param {String} _file The changed file
*/
_setCurrentExtensionName(_file) {
// the filepath will contain backslashes instead of slashes on windows. we need to normalize this.
// the file path will contain backslashes instead of slashes on windows. we need to normalize this.
let file = _file.replace(/\\/g, '/');
settings.setExtension(file.split(this._config.directories.basePath)[1].split('/')[0]);
}
......
{
"name": "sgc",
"version": "3.0.5",
"version": "3.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......@@ -1826,97 +1826,6 @@
"resolved": "https://registry.npmjs.org/ansi-wrap/-/ansi-wrap-0.1.0.tgz",
"integrity": "sha1-qCJQ3bABXponyoLoLqYDu/pF768="
},
"anymatch": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-1.3.2.tgz",
"integrity": "sha512-0XNayC8lTHQ2OI8aljNCN3sSx6hsr/1+rlcDAotXJR7C1oZZHCNsfpbKwMjRA3Uqb5tF1Rae2oloTr4xpq+WjA==",
"requires": {
"micromatch": "^2.1.5",
"normalize-path": "^2.0.0"
},
"dependencies": {
"arr-diff": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-2.0.0.tgz",
"integrity": "sha1-jzuCf5Vai9ZpaX5KQlasPOrjVs8=",
"requires": {
"arr-flatten": "^1.0.1"
}
},
"array-unique": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.2.1.tgz",
"integrity": "sha1-odl8yvy8JiXMcPrc6zalDFiwGlM="
},
"braces": {
"version": "1.8.5",
"resolved": "https://registry.npmjs.org/braces/-/braces-1.8.5.tgz",
"integrity": "sha1-uneWLhLf+WnWt2cR6RS3N4V79qc=",
"requires": {
"expand-range": "^1.8.1",
"preserve": "^0.2.0",
"repeat-element": "^1.1.2"
}
},
"expand-brackets": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/expand-brackets/-/expand-brackets-0.1.5.tgz",
"integrity": "sha1-3wcoTjQqgHzXM6xa9yQR5YHRF3s=",
"requires": {
"is-posix-bracket": "^0.1.0"
}
},
"extglob": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/extglob/-/extglob-0.3.2.tgz",
"integrity": "sha1-Lhj/PS9JqydlzskCPwEdqo2DSaE=",
"requires": {
"is-extglob": "^1.0.0"
}
},
"is-extglob": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-1.0.0.tgz",
"integrity": "sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA="
},
"is-glob": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz",
"integrity": "sha1-0Jb5JqPe1WAPP9/ZEZjLCIjC2GM=",
"requires": {
"is-extglob": "^1.0.0"
}
},
"kind-of": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
"integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=",
"requires": {
"is-buffer": "^1.1.5"
}
},
"micromatch": {
"version": "2.3.11",
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz",
"integrity": "sha1-hmd8l9FyCzY0MdBNDRUpO9OMFWU=",
"requires": {
"arr-diff": "^2.0.0",
"array-unique": "^0.2.1",
"braces": "^1.8.2",
"expand-brackets": "^0.1.4",
"extglob": "^0.3.1",
"filename-regex": "^2.0.0",
"is-extglob": "^1.0.0",
"is-glob": "^2.0.1",
"kind-of": "^3.0.2",
"normalize-path": "^2.0.1",
"object.omit": "^2.0.0",
"parse-glob": "^3.0.4",
"regex-cache": "^0.4.2"
}
}
}
},
"aproba": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
......@@ -2382,9 +2291,9 @@
}
},
"binary-extensions": {
"version": "1.11.0",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.11.0.tgz",
"integrity": "sha1-RqoXUftqL5PuXmibsQh9SxTGwgU="
"version": "1.12.0",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.12.0.tgz",
"integrity": "sha512-DYWGk01lDcxeS/K9IHPGWfT8PsJmbXRtRd2Sx72Tnb8pcYZQFF1oSDb8hJtS1vhp212q1Rzi5dUf9+nq0o9UIg=="
},
"bindings": {
"version": "1.3.0",
......@@ -2604,6 +2513,15 @@
"yargs": "6.4.0"
},
"dependencies": {
"anymatch": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-1.3.2.tgz",
"integrity": "sha512-0XNayC8lTHQ2OI8aljNCN3sSx6hsr/1+rlcDAotXJR7C1oZZHCNsfpbKwMjRA3Uqb5tF1Rae2oloTr4xpq+WjA==",
"requires": {
"micromatch": "^2.1.5",
"normalize-path": "^2.0.0"
}
},
"arr-diff": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-2.0.0.tgz",
......@@ -2632,6 +2550,22 @@
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-3.0.0.tgz",
"integrity": "sha1-MvxLn82vhF/N9+c7uXysImHwqwo="
},
"chokidar": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-1.7.0.tgz",
"integrity": "sha1-eY5ol3gVHIB2tLNg5e3SjNortGg=",
"requires": {
"anymatch": "^1.3.0",
"async-each": "^1.0.0",
"fsevents": "^1.0.0",
"glob-parent": "^2.0.0",
"inherits": "^2.0.1",
"is-binary-path": "^1.0.0",
"is-glob": "^2.0.0",
"path-is-absolute": "^1.0.0",
"readdirp": "^2.0.0"
}
},
"cliui": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz",
......@@ -2658,6 +2592,14 @@
"is-extglob": "^1.0.0"
}
},
"glob-parent": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-2.0.0.tgz",
"integrity": "sha1-gTg9ctsFT8zPUzbaqQLxgvbtuyg=",
"requires": {
"is-glob": "^2.0.0"
}
},
"is-extglob": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-1.0.0.tgz",
......@@ -3351,45 +3293,6 @@
"resolved": "https://registry.npmjs.org/chardet/-/chardet-0.5.0.tgz",
"integrity": "sha512-9ZTaoBaePSCFvNlNGrsyI8ZVACP2svUtq0DkM7t4K2ClAa96sqOIRjAzDTc8zXzFt1cZR46rRzLTiHFSJ+Qw0g=="
},
"chokidar": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-1.7.0.tgz",
"integrity": "sha1-eY5ol3gVHIB2tLNg5e3SjNortGg=",
"requires": {
"anymatch": "^1.3.0",
"async-each": "^1.0.0",
"fsevents": "^1.0.0",
"glob-parent": "^2.0.0",
"inherits": "^2.0.1",
"is-binary-path": "^1.0.0",
"is-glob": "^2.0.0",
"path-is-absolute": "^1.0.0",
"readdirp": "^2.0.0"
},
"dependencies": {
"glob-parent": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-2.0.0.tgz",
"integrity": "sha1-gTg9ctsFT8zPUzbaqQLxgvbtuyg=",
"requires": {
"is-glob": "^2.0.0"
}
},
"is-extglob": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-1.0.0.tgz",
"integrity": "sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA="
},
"is-glob": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz",
"integrity": "sha1-0Jb5JqPe1WAPP9/ZEZjLCIjC2GM=",
"requires": {
"is-extglob": "^1.0.0"
}
}
}
},
"cipher-base": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz",
......@@ -9298,11 +9201,6 @@
"resolved": "https://registry.npmjs.org/node-status-codes/-/node-status-codes-1.0.0.tgz",
"integrity": "sha1-WuVUHQJGRdMqWPzdyc7s6nrjrC8="
},
"node-watch": {
"version": "0.5.8",
"resolved": "https://registry.npmjs.org/node-watch/-/node-watch-0.5.8.tgz",
"integrity": "sha512-HXiCg9YS3IAzEJ4O3CNlUjsoYCxg4hVbo9oAEBQoiJV7p/R7PT6/ekXM9S3D2K3jUjSQOOjtuW/LgcSiwh/btQ=="
},
"nopt": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz",
......@@ -10689,14 +10587,13 @@
}
},
"readdirp": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-2.1.0.tgz",
"integrity": "sha1-TtCtBg3zBzMAxIRANz9y0cxkLXg=",
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-2.2.1.tgz",
"integrity": "sha512-1JU/8q+VgFZyxwrJ+SVIOsh+KywWGpds3NTqikiKpDMZWScmAYyKIgqkO+ARvNWJfXeXR1zxz7aHF4u4CyH6vQ==",
"requires": {
"graceful-fs": "^4.1.2",
"minimatch": "^3.0.2",
"readable-stream": "^2.0.2",
"set-immediate-shim": "^1.0.1"
"graceful-fs": "^4.1.11",
"micromatch": "^3.1.10",
"readable-stream": "^2.0.2"
}
},
"redent": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment