Commit c7275ba4 authored by Philipp Nowinski's avatar Philipp Nowinski
Browse files

[FEATURE] heavy refactoring + proper log module

parent 50dec668
......@@ -63,5 +63,5 @@ elif [ -e "./sgc-core/core/modules/$COMMAND.js" ]; then
else
setNodeVersion
cd sgc-core
node ./node_modules/gulp/bin/gulp.js $@
node ./core/run.js $@
fi
const logSymbols = require('log-symbols');
const timestamp = require('time-stamp');
const chalk = require('chalk');
/**
* Logging-Module for the SGC
*/
module.exports = class Logger {
/**
* Logs an info message
*
* @param {String} _message The message to log
*/
static info(_message) {
console.log(Logger._getTimestamp(), logSymbols.info, chalk.blue(_message));
}
/**
* Logs a warning message
*
* @param {String} _message The message to log
*/
static warning(_message) {
console.log(Logger._getTimestamp(), logSymbols.warning, chalk.yellow(_message));
}
/**
* Logs an error message
*
* @param {String} _message The message to log
*/
static error(_message) {
console.log(Logger._getTimestamp(), logSymbols.error, chalk.red(_message));
}
/**
* Logs a success message
*
* @param {String} _message The message to log
*/
static success(_message) {
console.log(Logger._getTimestamp(), logSymbols.success, chalk.green(_message));
}
/**
* Generates the output for the current timestamp
*
* @private
*/
static _getTimestamp() {
return chalk.dim(chalk.white(`[${timestamp('HH:mm:ss')}]`));
}
}
const SassTask = require('./tasks/sass');
const cliArguments = require('yargs').argv;
const logger = require('./logger');
const chalk = require('chalk');
const tasks = {
css: require('./tasks/css')
};
const arguments = require('yargs').argv;
/**
* Task Runner
*/
class Run {
if (arguments._.indexOf('css') >= 0) {
new SassTask('../web/typo3conf/ext/project_theme/Resources/Public/Sass/main.scss', './res.css').run();
/**
* Kick things off
*/
constructor() {
process.chdir('..');
let taskName = Run._getTaskName();
if (tasks.hasOwnProperty(taskName)) {
let task = new tasks[taskName]();
task.run();
} else {
logger.error(`Task ${chalk.bold(taskName)} is not defined`);
}
}
/**
* Returns the name of the triggered task
*/
static _getTaskName() {
return cliArguments._[0];
}
}
new Run();
module.exports = class task {
constructor(_input, _output, _configuration = {}) {
this._input = _input;
this._output = _output;
constructor(_configuration = {}) {
const settings = require('./settings');
this._configuration = _configuration;
this._settings = settings.getConfig();
this._path = settings.getPath();
this._logger = require('./logger');
}
run() {
this.logError('Task is not implemented');
}
logError(_error) {
console.log(_error);
this._logger.error('Task is not implemented');
}
}
const Task = require('../task');
const sass = require('node-sass');
const fs = require('fs');
const path = require('path');
const globby = require('globby');
/**
* The CSS task takes care of compiling Sass and running the CSS QA tasks
*/
module.exports = class Css extends Task {
/**
* Start the build process
*/
async run() {
const files = await globby([
`${this._path}/${this._settings.directories.sass}/*.scss`,
'!**/_*.scss'
]);
files.forEach(file => {
this._compile(file, this._getOutputPath(file));
});
}
/**
* Returns the name of the output file
*
* @param {String} _fileName The name of the input file
*/
_getOutputPath(_fileName) {
let fileName = path.basename(_fileName).replace('.scss', '.css');
return `${this._path}/${this._settings.directories.css}/${fileName}`;
}
/**
* Compiles Sass to Css
*
* @param {String} _input The path to the input file
* @param {String} _output The path to the output file
*/
_compile(_input, _output) {
sass.render({
file: _input,
outputStyle: 'compressed'
}, (_error, _result) => {
if (!_error) {
fs.writeFile(_output, _result.css, _error => {
if (_error) {
return this.logError(_error);
}
console.log(`Compiled ${path.basename(_input)}`);
});
} else {
this.logError(_error);
}
});
}
}
const Task = require('../task');
const sass = require('node-sass');
const fs = require('fs');
module.exports = class Sass extends Task {
run() {
sass.render({
file: this._input,
outputStyle: 'compressed'
}, (_error, _result) => {
if (!_error) {
fs.writeFile(this._output, _result.css, _error => {
if (_error) {
return this.logError(_error);
}
console.log('done');
});
} else {
this.logError(_error);
}
});
}
}
This diff is collapsed.
......@@ -15,7 +15,11 @@
"node": "~10.9.0"
},
"dependencies": {
"chalk": "^2.4.1",
"globby": "^8.0.1",
"log-symbols": "^2.2.0",
"node-sass": "^4.9.3",
"time-stamp": "^2.1.0",
"yargs": "^12.0.1"
}
}
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