Commit a7a227ac authored by Stefan Galinski's avatar Stefan Galinski 🎮
Browse files

[BUGFIX] Some more checks regarding the existence of directories

parent 40e9c791
......@@ -62,7 +62,7 @@ class Settings {
try {
fs.statSync('./sgc-core/gulp/config.json');
return require('./config.json');
} catch(exception) {
} catch (exception) {
return require('../../.sgc-config.json');
}
}
......
......@@ -34,10 +34,10 @@ module.exports = class task {
/**
* Runs the task. A subTask can be triggered by apending it with a colon
*
*
* E.g: sgc css – triggers the main Css Task
* sgc css:qa – triggers the subTask qa
*
*
* @param {String} _subTask Name of the subtask
*/
run(_subTask = null) {
......@@ -46,7 +46,7 @@ module.exports = class task {
/**
* Logs the error message that _task could not be found
*
*
* @param {String} _task The task that could not be found
*/
_logTaskNotDefined(_task) {
......@@ -55,7 +55,7 @@ module.exports = class task {
/**
* Returns the full path (relative to the project dit) for _path
*
*
* @param {String} _path The path the full path shall be found for
*/
_getFullPath(_path) {
......@@ -64,8 +64,8 @@ module.exports = class task {
/**
* Writes _content to _filePath.
* It will create all necessary folders in _filePath if they don't exist already
*
* It will create all necessary folders in _filePath if they don't exist already
*
* @param {String} _filePath The path that shall be written to
* @param {Buffer} _content The file contents
*/
......@@ -78,4 +78,4 @@ module.exports = class task {
let writeFile = util.promisify(fs.writeFile);
return writeFile(_filePath, _content);
}
}
};
......@@ -16,7 +16,7 @@ const globImporter = require('node-sass-glob-importer');
const browserSync = require('browser-sync');
const InlineSvg = require('@sgalinski/inline-svg');
const ImageDimensions = require('@sgalinski/image-dimensions');
const { inlineSource } = require('inline-source');
const {inlineSource} = require('inline-source');
/**
* The CSS task takes care of compiling Sass and running the CSS QA tasks
......@@ -99,7 +99,7 @@ module.exports = class Css extends Task {
/**
* Returns the name of the output file
*
*
* @param {String} _fileName The name of the input file
*/
_getOutputPath(_fileName) {
......@@ -107,22 +107,36 @@ module.exports = class Css extends Task {
? '.min.css'
: '.css';
let fileName = path.basename(_fileName).replace('.scss', newSuffix);
return this._getFullPath(`${this._config.directories.css}/${fileName}`);
let distDirectory = this._getFullPath(this._config.directories.css);
if (!fs.existsSync(distDirectory)) {
console.log(`${distDirectory} 'does not exist. Create now!'`);
  • Hier sollte auch this._logger genutzt werden, dann ist der output einheitlich + lässt sich auch mit -q unterdrücken.

Please register or sign in to reply
fs.mkdirSync(distDirectory);
}
return `${distDirectory}/${fileName}`;
}
/**
* Returns the path to the sourceMap associated with _fileName
*
*
* @param {String} _fileName The name of the CSS-file the sourceMap is associated with
*/
_getSourceMapsPath(_fileName) {
let fileName = path.basename(_fileName).replace('.css', '.css.map');
return this._getFullPath(`${this._config.directories.cssSourceMaps}/${fileName}`);
let sourceMapDirectory = this._getFullPath(this._config.directories.cssSourceMaps);
if (!fs.existsSync(sourceMapDirectory)) {
console.log(`${sourceMapDirectory} 'does not exist. Create now!'`);
fs.mkdirSync(sourceMapDirectory);
}
return `${sourceMapDirectory}/${fileName}`;
}
/**
* Compiles Sass to Css
*
*
* @param {String} _input The path to the input file
* @param {String} _output The path to the output file
*/
......@@ -186,7 +200,7 @@ module.exports = class Css extends Task {
/**
* Runs qa tasks against all Sass source files
*
*
* @param {String} _input The path to the input file
*/
async _qa(_input) {
......@@ -235,7 +249,7 @@ module.exports = class Css extends Task {
/**
* Runs the whole CSS through the image dimensions module
*
*
* @param {String} _source The CSS as a string
*/
_imageDimensions(_source) {
......@@ -255,8 +269,15 @@ module.exports = class Css extends Task {
let html = await inlineSource(this._config.abovethefold.template, {
compress: false
});
await this._writeFile(path.join(this._config.abovethefold.dest, filename), html);
} catch(_error) {
let distDirectory = this._getFullPath(this._config.abovethefold.dest);
if (!fs.existsSync(distDirectory)) {
console.log(`${distDirectory} 'does not exist. Create now!'`);
fs.mkdirSync(distDirectory);
}
await this._writeFile(path.join(distDirectory, filename), html);
} catch (_error) {
this._logger.error(_error);
}
this._logger.success(`Written ${chalk.white(path.basename(filename))}`);
......
......@@ -88,7 +88,14 @@ module.exports = class Js extends Task {
? '.bundled.min.js'
: '.bundled.js';
let fileName = path.basename(_fileName).replace('.js', newSuffix);
return this._getFullPath(`${this._config.directories.javascriptDest}/${fileName}`);
let distDirectory = this._getFullPath(this._config.directories.javascriptDest);
if (!fs.existsSync(distDirectory)) {
console.log(`${distDirectory} 'does not exist. Create now!'`);
  • Sind die ganzen Checks wirklich notwendig? Eigentlich müsste this._writeFile das selbst regeln. Ansonsten muss das vereinheitlicht werden, so ist das viel Code-Dopplung. Lasse das mal als todo für mich hier, funktioniert ja erstmal.

  • Alles notwendig. Ich bin in allesamt diese Fehler reingelaufen.

Please register or sign in to reply
fs.mkdirSync(distDirectory);
}
return `${distDirectory}/${fileName}`;
}
/**
......@@ -98,7 +105,14 @@ module.exports = class Js extends Task {
*/
_getSourceMapsPath(_fileName) {
let fileName = path.basename(_fileName).replace('.js', '.js.map');
return this._getFullPath(`${this._config.directories.javascriptSourceMaps}/${fileName}`);
let sourceMapDirectory = this._getFullPath(this._config.directories.javascriptSourceMaps);
if (!fs.existsSync(sourceMapDirectory)) {
console.log(`${sourceMapDirectory} 'does not exist. Create now!'`);
fs.mkdirSync(sourceMapDirectory);
}
return `${sourceMapDirectory}/${fileName}`;
}
/**
......@@ -121,13 +135,6 @@ module.exports = class Js extends Task {
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, {
......@@ -153,13 +160,6 @@ module.exports = class Js extends Task {
}
// create the stream for writing the outFile
let distDirectory = path.dirname(_output);
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
......
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