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 path = require('path');
const {argv} = require('yargs');
let extension;
/**
* This module is a global settings singleton
......@@ -17,7 +18,7 @@ class Settings {
this._config = Settings.parseConfig();
this._extensionPath = this._config.directories.basePath;
this._webPath = this._config.directories.webPath;
[this._extension] = this._config.extensions;
[extension] = this._config.extensions;
this._tasks = {
css: () => require('./tasks/css'),
js: () => require('./tasks/js'),
......@@ -26,7 +27,8 @@ class Settings {
images: () => require('./tasks/images'),
open: () => require('./tasks/open'),
releaseExtension: () => require('./tasks/releaseExtension'),
default: () => require('./tasks/default')
default: () => require('./tasks/default'),
build: () => require('./tasks/build')
};
}
......@@ -37,7 +39,7 @@ class Settings {
*/
getPath(_isWebPath) {
let extensionName = (typeof argv.ext === 'undefined')
? this._extension
? extension
: argv.ext;
return typeof _isWebPath === 'undefined'
? path.join(this._extensionPath, extensionName)
......@@ -49,8 +51,8 @@ class Settings {
*
* @param {String} _extensionName The name of the extension which path should be used
*/
setPath(_extensionName) {
this._extension = _extensionName;
setExtension(_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 {
this._logger.displayBrowserSyncNotification('Compiling Sass – hang in there...');
const render = util.promisify(sass.render);
const sourceMapPath = this._getSourceMapsPath(_output);
let compiledSass;
try {
let compiledSass = await render({
compiledSass = await render({
file: _input,
outFile: _output,
outputStyle: 'expanded',
......
const Task = require('../task');
const watch = require('node-watch');
const globby = require('globby');
const path = require('path');
const settings = require('../settings');
/**
* The watch-task observes changes in source files and triggers compilation
......@@ -21,11 +23,18 @@ module.exports = class Watch extends Task {
* Watch for CSS-related files
*/
async _watchCss() {
const files = await globby([
`${this._path}/${this._config.directories.sass}/**/*.scss`,
'!**/*_svg.scss'
].concat(this._config.css.excludeFromQa));
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`));
});
// 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 => {
watch(file, { recursive: true }, this._onCssChange.bind(this));
});
......@@ -35,16 +44,33 @@ module.exports = class Watch extends Task {
* Watch for JS-related files
*/
async _watchJs() {
const files = await globby([
`${this._path}/${this._config.directories.javascriptSrc}/**/*.js`,
'!**/*.min.js'
].concat(this._config.js.excludeFromQa));
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`));
});
// 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));
});
}
/**
* 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
*/
......@@ -68,6 +94,7 @@ module.exports = class Watch extends Task {
* @param {String} _fileName The path to the file that changed
*/
_onCssChange(_event, _fileName) {
this._setCurrentExtensionName(_fileName);
this._logger.info(`${_fileName} changed`);
this._triggerCss();
}
......@@ -82,4 +109,15 @@ module.exports = class Watch extends Task {
this._logger.info(`${_fileName} changed`);
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