Commit 9cb2fdbe authored by Philipp Nowinski's avatar Philipp Nowinski
Browse files

[FEATURE] add css:qa as subtask

parent deec1bd3
......@@ -15,12 +15,13 @@ class Run {
*/
constructor() {
process.chdir('..');
let taskName = Run._getTaskName();
if (tasks.hasOwnProperty(taskName)) {
let task = new tasks[taskName]();
task.run();
let taskArgument = Run._getTaskName();
let taskNames = taskArgument.split(':');
if (tasks.hasOwnProperty(taskNames[0])) {
let task = new tasks[taskNames[0]]();
task.run(taskNames[1] || null);
} else {
logger.error(`Task ${chalk.bold(taskName)} is not defined`);
logger.error(`Task ${chalk.bold(taskNames[0])} is not defined`);
}
}
......
module.exports = class task {
constructor(_configuration = {}) {
constructor() {
const settings = require('./settings');
this._configuration = _configuration;
this._settings = settings.getConfig();
this._path = settings.getPath();
this._logger = require('./logger');
}
run() {
run(_subTask = null) {
this._logger.error('Task is not implemented');
}
_logTaskNotDefined(_task) {
logger.error(`Task ${chalk.bold(_task)} is not defined`);
}
}
......@@ -7,6 +7,9 @@ const postcss = require('postcss');
const autoprefixer = require('autoprefixer');
const util = require('util');
const chalk = require('chalk');
const stylelint = require('stylelint');
const reporter = require('postcss-reporter');
const scss = require('postcss-scss');
/**
* The CSS task takes care of compiling Sass and running the CSS QA tasks
......@@ -16,14 +19,27 @@ 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));
});
async run(_subTask = null) {
if (_subTask) {
const files = await globby([
`${this._path}/${this._settings.directories.sass}/**/*.scss`
].concat(this._settings.css.excludeFromQa));
if (_subTask === 'qa') {
files.forEach(file => {
this._qa(file);
});
} else {
this._logTaskNotDefined(`css:${_subTask}`);
}
} else {
const files = await globby([
`${this._path}/${this._settings.directories.sass}/*.scss`,
'!**/_*.scss'
]);
files.forEach(file => {
this._compile(file, this._getOutputPath(file));
});
}
}
/**
......@@ -54,7 +70,7 @@ module.exports = class Css extends Task {
this._logger.error(_error);
}
let css = await postcss([autoprefixer]).process(result.css);
let css = await postcss([autoprefixer]).process(result.css, {from: _input});
fs.writeFile(_output, css, _error => {
if (_error) {
......@@ -64,4 +80,26 @@ 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) {
let file = fs.readFileSync(_input, "utf8");
postcss([
stylelint({
configBasedir: `${process.cwd()}/sgc-core/`
}),
reporter({
clearReportedMessages: true
})
]).process(file, {
from: _input,
syntax: scss
}).catch(error => {
this._logger.error(error.stack)
});
}
}
This diff is collapsed.
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