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

[FEATURE] integrate browsersync again and add default task

parent b5646188
......@@ -27,7 +27,7 @@ class Run {
* Returns the name of the triggered task
*/
static _getTaskName() {
return cliArguments._[0];
return cliArguments._[0] ? cliArguments._[0] : 'default';
}
}
......
......@@ -21,7 +21,9 @@ class Settings {
this._tasks = {
css: () => {return require('./tasks/css')},
js: () => {return require('./tasks/js')},
watch: () => {return require('./tasks/watch')}
watch: () => {return require('./tasks/watch')},
server: () => {return require('./tasks/server')},
default: () => {return require('./tasks/default')}
};
}
......
const Task = require('../task');
/**
* The default task will be executed if you don't pass a task argument to the runner
*/
module.exports = class Default extends Task {
/**
* Runner function
*/
async run() {
let serverTask = this._settings.tasks.server();
new serverTask().run();
let watchTask = this._settings.tasks.watch();
new watchTask().run();
}
}
......@@ -7,6 +7,7 @@ const browserify = require('browserify');
const babelify = require('babelify');
const CLIEngine = require("eslint").CLIEngine;
const exorcist = require('exorcist');
const browserSync = require('browser-sync');
/**
* The JS task takes care of compiling JavaScript and running qa on it
......@@ -105,6 +106,7 @@ module.exports = class Js extends Task {
))
.pipe(fs.createWriteStream(_output));
browserSync.reload('*.js');
this._logger.success(`Written ${chalk.white(path.basename(_output))}`);
} catch(_error) {
this._logger.error(_error.stack);
......
const Task = require('../task');
const browserSync = require('browser-sync');
const argv = require('yargs').argv;
/**
* The JS task takes care of compiling JavaScript and running qa on it
*/
module.exports = class Server extends Task {
/**
* Start the server
*/
async run(_subTask = null) {
browserSync({
proxy: this.getUrl(),
middleware: (req, res, next) => {
var conjunction;
if (req.url.match(/\?/)) {
conjunction = '&';
} else {
conjunction = '?';
}
req.url = req.url + conjunction + this._config.browsersync.urlparams;
next();
},
open: typeof argv.s === 'undefined' ? 'local' : false
});
}
/**
* Determines the URL to open
*/
getUrl() {
const configuredUrl = this._config.browsersync.url;
let desiredDomain = argv.d;
if (typeof configuredUrl === 'string') {
return configuredUrl;
} else if (typeof configuredUrl === 'object') {
if (typeof desiredDomain === 'undefined') {
for (let key in configuredUrl) {
if (configuredUrl.hasOwnProperty(key)) {
return configuredUrl[key];
}
}
} else {
if (configuredUrl.hasOwnProperty(desiredDomain)) {
return configuredUrl[desiredDomain];
} else {
throw new Error(plugins.util.colors.red('The key "' + desiredDomain + '" could not be resolved ' +
'to any domain. Please check your SGC configuration.'));
}
}
}
}
}
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