Commit 7515cc02 authored by Stefan Galinski's avatar Stefan Galinski 🎮
Browse files

[BUGFIX] Create some output directories to prevent crashes

parent 520aeec9
......@@ -263,4 +263,4 @@ module.exports = class Css extends Task {
resolve();
});
}
}
};
......@@ -18,7 +18,7 @@ module.exports = class Js extends Task {
/**
* Start the build process
*
*
* @override
*/
async run(_subTask = null) {
......@@ -29,7 +29,7 @@ module.exports = class Js extends Task {
// if _subTask is set, just execute that one task
if (_subTask === 'qa') {
steps.push(this._runQa());
} else if(_subTask === 'compile') {
} else if (_subTask === 'compile') {
steps.push(this._runCompile());
} else {
this._logTaskNotDefined(`js:${_subTask}`);
......@@ -58,9 +58,9 @@ module.exports = class Js extends Task {
const compilations = [];
files.forEach(file => {
compilations.push(this._compile(file, this._getOutputPath(file)));
});
await Promise.all(compilations);
resolve();
});
await Promise.all(compilations);
resolve();
});
}
......@@ -80,10 +80,10 @@ module.exports = class Js extends Task {
/**
* Returns the name of the output file
*
*
* @param {String} _fileName The name of the input file
*/
_getOutputPath(_fileName) {
_getOutputPath(_fileName) {
let newSuffix = this._config.jsPipeline.renameToDotMin
? '.bundled.min.js'
: '.bundled.js';
......@@ -93,7 +93,7 @@ module.exports = class Js extends Task {
/**
* Returns the path to the sourceMap associated with _fileName
*
*
* @param {String} _fileName The name of the JS-file the sourceMap is associated with
*/
_getSourceMapsPath(_fileName) {
......@@ -103,7 +103,7 @@ module.exports = class Js extends Task {
/**
* Compiles and bundles the JS
*
*
* @param {String} _input The path to the input file
* @param {String} _output The path to the output file
*/
......@@ -115,12 +115,19 @@ module.exports = class Js extends Task {
},
useBuiltIns: 'usage'
} : undefined;
try {
this._logger.displayBrowserSyncNotification('Compiling JS – hang in there...');
let relativeSourceMapPath
let relativeSourceMapPath;
if (this._config.jsPipeline.sourceMaps) {
let sourceMapPath = this._getSourceMapsPath(_output);
let sourceMapDirectory = path.dirname(sourceMapPath);
fs.access(sourceMapDirectory, fs.constants.F_OK, (error) => {
if (error) {
console.log(`${sourceMapDirectory} 'does not exist. Create now!'`);
fs.mkdirSync(sourceMapDirectory);
}
});
relativeSourceMapPath = path.join(path.dirname(sourceMapPath), path.basename(sourceMapPath));
}
let bundler = browserify(_input, {
......@@ -131,23 +138,30 @@ module.exports = class Js extends Task {
[require('@babel/preset-env'), presetEnvConfiguration],
]
});
if (this._config.jsPipeline.uglify) {
bundler.plugin(tinyify, {flat: false});
}
bundler = bundler.bundle();
if (this._config.jsPipeline.sourceMaps) {
bundler.pipe(exorcist(
this._getSourceMapsPath(_output),
path.relative(path.dirname(_output), relativeSourceMapPath)
));
}
// create the stream for writing the outFile
let distDirectory = path.dirname(_output);
  • Ah, dann. Überall sonst nutze ich meine eigene writeFile Funktion, die legt ggf. fehlende Verzeichnisse an. Ging natürlich mit dem Stream nicht. Danke, das war exakt der Fehler.

Please register or sign in to reply
fs.access(distDirectory, fs.constants.F_OK, (error) => {
if (error) {
console.log(`${distDirectory} 'does not exist. Create now!'`);
fs.mkdirSync(distDirectory);
}
});
let outFile = fs.createWriteStream(_output, 'utf-8');
// wait for the stream to finish writing before calling success
outFile.on('finish', () => {
browserSync.reload('*.js');
......@@ -157,7 +171,7 @@ module.exports = class Js extends Task {
// announce the write stream as a build step
bundler.pipe(outFile);
} catch(_error) {
} catch (_error) {
this._logger.error(_error.stack);
resolve();
}
......@@ -166,7 +180,7 @@ module.exports = class Js extends Task {
/**
* Runs qa tasks against all JS source files
*
*
* @param {Array} _files The array containing all src files
*/
async _qa(_files) {
......@@ -185,4 +199,4 @@ module.exports = class Js extends Task {
});
}
}
};
Supports Markdown
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