Commit 442da3a3 authored by Philipp Nowinski's avatar Philipp Nowinski
Browse files

[FEATURE] add build task + massive cleanup

parent f3ccedc8
#!/bin/bash
params="$(echo $@ | sed 's/build//')"
if [[ "${@#--ext}" = "$@" ]]
then
extensions="$(node ./sgc-core/core/getExtensions.js)"
for extension in $extensions
do
sgc execBuild --ext $extension $params
done
else
# do the regular call
sgc execBuild $params
fi
'use strict';
const settings = require('../gulp/settings');
const config = settings.getConfig();
let extensions = config.extensions.reduce((accumulator, currentValue) => accumulator + ' ' + currentValue);
// intended as an information output
// eslint-disable-next-line
console.log(extensions);
'use strict'; /* eslint-disable class-methods-use-this */
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const {argv} = require('yargs'); const {argv} = require('yargs');
let extension;
/** /**
* This module is a global settings singleton * This module is a global settings singleton
...@@ -17,7 +18,7 @@ class Settings { ...@@ -17,7 +18,7 @@ class Settings {
this._config = Settings.parseConfig(); this._config = Settings.parseConfig();
this._extensionPath = this._config.directories.basePath; this._extensionPath = this._config.directories.basePath;
this._webPath = this._config.directories.webPath; this._webPath = this._config.directories.webPath;
[this._extension] = this._config.extensions; [extension] = this._config.extensions;
this._tasks = { this._tasks = {
css: () => require('./tasks/css'), css: () => require('./tasks/css'),
js: () => require('./tasks/js'), js: () => require('./tasks/js'),
...@@ -26,7 +27,8 @@ class Settings { ...@@ -26,7 +27,8 @@ class Settings {
images: () => require('./tasks/images'), images: () => require('./tasks/images'),
open: () => require('./tasks/open'), open: () => require('./tasks/open'),
releaseExtension: () => require('./tasks/releaseExtension'), releaseExtension: () => require('./tasks/releaseExtension'),
default: () => require('./tasks/default') default: () => require('./tasks/default'),
build: () => require('./tasks/build')
}; };
} }
...@@ -37,7 +39,7 @@ class Settings { ...@@ -37,7 +39,7 @@ class Settings {
*/ */
getPath(_isWebPath) { getPath(_isWebPath) {
let extensionName = (typeof argv.ext === 'undefined') let extensionName = (typeof argv.ext === 'undefined')
? this._extension ? extension
: argv.ext; : argv.ext;
return typeof _isWebPath === 'undefined' return typeof _isWebPath === 'undefined'
? path.join(this._extensionPath, extensionName) ? path.join(this._extensionPath, extensionName)
...@@ -49,8 +51,8 @@ class Settings { ...@@ -49,8 +51,8 @@ class Settings {
* *
* @param {String} _extensionName The name of the extension which path should be used * @param {String} _extensionName The name of the extension which path should be used
*/ */
setPath(_extensionName) { setExtension(_extensionName) {
this._extension = _extensionName; extension = _extensionName;
} }
/** /**
......
const Task = require('../task');
const settings = require('../settings');
/**
* The main build step – basically a combination of the most important tasks
*/
module.exports = class Build extends Task {
/**
* Run all important tasks
*
* @override
*/
async run() {
let images = this._settings.tasks.images();
let css = this._settings.tasks.css();
let js = this._settings.tasks.js();
this._config.extensions.forEach(_extension => {
settings.setExtension(_extension);
new images().run();
new css().run();
new js().run();
});
}
};
...@@ -104,9 +104,10 @@ module.exports = class Css extends Task { ...@@ -104,9 +104,10 @@ module.exports = class Css extends Task {
this._logger.displayBrowserSyncNotification('Compiling Sass – hang in there...'); this._logger.displayBrowserSyncNotification('Compiling Sass – hang in there...');
const render = util.promisify(sass.render); const render = util.promisify(sass.render);
const sourceMapPath = this._getSourceMapsPath(_output); const sourceMapPath = this._getSourceMapsPath(_output);
let compiledSass;
try { try {
let compiledSass = await render({ compiledSass = await render({
file: _input, file: _input,
outFile: _output, outFile: _output,
outputStyle: 'expanded', outputStyle: 'expanded',
......
const Task = require('../task'); const Task = require('../task');
const watch = require('node-watch'); const watch = require('node-watch');
const globby = require('globby'); const globby = require('globby');
const path = require('path');
const settings = require('../settings');
/** /**
* The watch-task observes changes in source files and triggers compilation * The watch-task observes changes in source files and triggers compilation
...@@ -21,11 +23,18 @@ module.exports = class Watch extends Task { ...@@ -21,11 +23,18 @@ module.exports = class Watch extends Task {
* Watch for CSS-related files * Watch for CSS-related files
*/ */
async _watchCss() { async _watchCss() {
const files = await globby([ let globs = [];
`${this._path}/${this._config.directories.sass}/**/*.scss`,
'!**/*_svg.scss' // get a glob for each extension that shall be watched
].concat(this._config.css.excludeFromQa)); this._config.extensions.forEach(_extension => {
globs.push(this._getGlobFor(_extension, `${this._config.directories.sass}/**/*.scss`));
});
// 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));
// watch those files
files.forEach(file => { files.forEach(file => {
watch(file, { recursive: true }, this._onCssChange.bind(this)); watch(file, { recursive: true }, this._onCssChange.bind(this));
}); });
...@@ -35,16 +44,33 @@ module.exports = class Watch extends Task { ...@@ -35,16 +44,33 @@ module.exports = class Watch extends Task {
* Watch for JS-related files * Watch for JS-related files
*/ */
async _watchJs() { async _watchJs() {
const files = await globby([ let globs = [];
`${this._path}/${this._config.directories.javascriptSrc}/**/*.js`,
'!**/*.min.js' // get a glob for each extension that shall be watched
].concat(this._config.js.excludeFromQa)); this._config.extensions.forEach(_extension => {
globs.push(this._getGlobFor(_extension, `${this._config.directories.javascriptSrc}/**/*.js`));
});
// 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 => { files.forEach(file => {
watch(file, { recursive: true }, this._onJsChange.bind(this)); watch(file, { recursive: true }, this._onJsChange.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
*/
_getGlobFor(_extension, _path) {
return path.join(this._config.directories.basePath, _extension, _path);
}
/** /**
* Trigger CSS-compilation * Trigger CSS-compilation
*/ */
...@@ -68,6 +94,7 @@ module.exports = class Watch extends Task { ...@@ -68,6 +94,7 @@ module.exports = class Watch extends Task {
* @param {String} _fileName The path to the file that changed * @param {String} _fileName The path to the file that changed
*/ */
_onCssChange(_event, _fileName) { _onCssChange(_event, _fileName) {
this._setCurrentExtensionName(_fileName);
this._logger.info(`${_fileName} changed`); this._logger.info(`${_fileName} changed`);
this._triggerCss(); this._triggerCss();
} }
...@@ -82,4 +109,15 @@ module.exports = class Watch extends Task { ...@@ -82,4 +109,15 @@ module.exports = class Watch extends Task {
this._logger.info(`${_fileName} changed`); this._logger.info(`${_fileName} changed`);
this._triggerJs(); this._triggerJs();
} }
/**
* 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.
let file = _file.replace(/\\/g, '/');
settings.setExtension(file.split(this._config.directories.basePath)[1].split('/')[0]);
}
} }
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