Commit 70e1c25b authored by Philipp Nowinski's avatar Philipp Nowinski
Browse files

[BUGFIX] stop execution on error when watcher is not running + print

more helpful error messages
parent f13ae5da
......@@ -4,6 +4,7 @@ const fs = require('fs');
const path = require('path');
const {argv} = require('yargs');
let extension;
let watcherActive = false;
/**
* This module is a global settings singleton
......@@ -55,6 +56,10 @@ class Settings {
extension = _extensionName;
}
setWatcherActive(_value) {
watcherActive = _value;
}
/**
* Returns the sgc-config object
*/
......@@ -80,6 +85,10 @@ class Settings {
get config() {
return this._config;
}
get watcherActive() {
return watcherActive;
}
}
const instance = new Settings();
......
......@@ -62,6 +62,13 @@ module.exports = class task {
return `${this._path}/${_path}`;
}
_handleError(_errorMessage) {
this._logger.error(_errorMessage);
if (!settings.watcherActive) {
process.exit(1);
}
}
/**
* Writes _content to _filePath.
* It will create all necessary folders in _filePath if they don't exist already
......
......@@ -162,7 +162,7 @@ module.exports = class Css extends Task {
importer: globImporter()
});
} catch (_error) {
return this._logger.error(_error.stack);
return this._handleError(`${_error.message} in ${_error.file}`);
}
let cssString = this._imageDimensions(compiledSass.css.toString());
......@@ -293,7 +293,7 @@ module.exports = class Css extends Task {
await this._writeFile(path.join(distDirectory, filename), html);
} catch (_error) {
this._logger.error(_error);
this._handleError(_error.stack);
}
this._logger.success(`Written ${chalk.white(path.basename(filename))}`);
resolve();
......
......@@ -150,7 +150,9 @@ module.exports = class Js extends Task {
bundler.plugin(tinyify, {flat: false});
}
bundler = bundler.bundle();
bundler = bundler.bundle().on('error', (_error) => {
this._handleError(_error.message);
});
if (this._config.jsPipeline.sourceMaps) {
bundler.pipe(exorcist(
......@@ -172,7 +174,7 @@ module.exports = class Js extends Task {
// announce the write stream as a build step
bundler.pipe(outFile);
} catch (_error) {
this._logger.error(_error.stack);
this._handleError(_error.stack);
resolve();
}
});
......
......@@ -15,6 +15,7 @@ module.exports = class Watch extends Task {
* @override
*/
async run() {
settings.setWatcherActive(true);
return new Promise(resolve => {
this._watchCss();
this._watchJs();
......@@ -38,7 +39,7 @@ module.exports = class Watch extends Task {
gaze(globs.concat(ignoredFiles), (error, watcher) => {
if (error) {
this._logger.error(error.stack);
this._handleError(error.stack);
}
watcher.on('changed', this._onCssChange.bind(this));
watcher.on('added', this._onNewFile.bind(this));
......
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