adgile
Version:
An easy-to-use automated front-end setup.
250 lines (205 loc) • 5.9 kB
JavaScript
;
// Requires & Variables -----------------------------------------------------
//
const settings = require('./settings.default'),
bsTask = require('./tasks/task-browsersync'),
initTask = require('./tasks/task-init'),
inlineTask = require('./tasks/task-inline'),
psiTask = require('./tasks/task-psi'),
buildTask = require('./tasks/task-build'),
cleanTask = require('./tasks/task-clean'),
sassTask = require('./tasks/task-sass'),
uncssTask = require('./tasks/task-uncss'),
jsTask = require('./tasks/task-js'),
imagesTask = require('./tasks/task-images'),
otherTask = require('./tasks/task-other'),
templatesTask = require('./tasks/task-templates'),
serverTask = require('./tasks/task-server'),
helpers = require('./helpers/index'),
chalk = require('chalk'),
_ = require('lodash'),
gulp = require('gulp');
global.config = null;
// LOGGING --------------------------------------------------------------------
//
if (!settings.isVerbose) {
// To get a better grip on logging by either console.log or direct writing to process.stdout,
// a hook is applied to stdout when not running in --vebose mode
require('./lib/hook.js')(process.stdout).hook('write', function (msg, encoding, fd, write) {
// Validate message
msg = helpers.validForWrite(msg);
// If the message is not suited for output, block it
if (!msg) {
return;
}
if (msg.length === 1) return;
// There is no progress bar, so just write
if (_.isNull(settings.bar)) {
write(msg);
return;
}
// There is a progress bar, but it hasn't completed yet, so buffer
if (!settings.bar.complete) {
settings.stdoutBuffer.push(msg);
return;
}
// There is a buffer, prepend a newline to the array
// if(settings.stdoutBuffer.length) {
// settings.stdoutBuffer.unshift('\n');
// }
// Write out the buffer until it's empty
// shift() removes the first line from the array and prints it out
while (settings.stdoutBuffer.length) {
write(settings.stdoutBuffer.shift());
}
// Finally, just write out
write(msg);
});
// Map console.warn to console.log to make sure gulp-sassgraph errors
// get validated by the code above
/*console.warn = console.log; /*function () {
var args = Array.prototype.slice.call(arguments);
console.error('passing this to console.log: ', args);
console.log.apply(console, args);
}*/
}
// INITIALIZE -----------------------------------------------------------------
/**
* Run the `gulp init` task
* @param {cb} callback
*/
gulp.task('init', function (cb) {
initTask.runtask(cb);
});
// INLINE ---------------------------------------------------------------------
/**
* Run the `gulp inline` task
* @param {cb} callback
*/
gulp.task('inline', function(cb){
inlineTask.runTask(cb);
});
// BUILD ----------------------------------------------------------------------
/**
* Run the `gulp build` task
* @param {cb} callback
*/
gulp.task('build', function(cb) {
buildTask.runtask(cb);
});
// CLEAN ----------------------------------------------------------------------
/**
* Run the `gulp clean:export` task
*/
gulp.task('clean:export', function () {
helpers.updateBar('Cleaning export directories');
return cleanTask.runTask();
});
// SASS -----------------------------------------------------------------------
//
/**
* Run the `gulp sass` task
*/
gulp.task('sass', function () {
return sassTask.runTask();
});
// UNCSS ----------------------------------------------------------------------
//
/**
* Run the `gulp uncss` task
* @param {cb} callback
*/
gulp.task('uncss', function (cb) {
if (!settings.isProduction || !config.useUncss) {
helpers.updateBar('Done');
cb(null);
return;
}
return uncssTask.runTask();
});
// SCRIPTS --------------------------------------------------------------------
//
/**
* Run the `gulp hint:scripts` task
* @param {cb} callback
*/
gulp.task('hint:scripts', function (cb) {
if (!config.hint_js) {
cb(null);
return;
}
return jsTask.runHints();
});
/**
* Run the `gulp scripts:view` task
*/
gulp.task('scripts:view', function () {
return jsTask.runScriptsView();
});
/**
* Run the `gulp scripts` task
*/
gulp.task('scripts', gulp.series(['hint:scripts', 'scripts:view'], function () {
return jsTask.runScriptsMain();
}));
// IMAGES ---------------------------------------------------------------------
//
/**
* Run the `gulp images` task
*/
gulp.task('images', function () {
return imagesTask.runTask();
});
// MISC -----------------------------------------------------------------------
//
/**
* Run the `gulp misc` task (only in production)
* @param {cb} callback
*/
gulp.task('misc', function (cb) {
if (settings.isProduction) {
const miscTask = require('./tasks/task-misc');
miscTask.runTask();
}
cb(null);
});
// OTHER ----------------------------------------------------------------------
//
/**
* Run the `gulp other` task
*/
gulp.task('other', gulp.series(['misc'], function () {
return otherTask.runTask();
}));
// TEMPLATES ------------------------------------------------------------------
//
/**
* Run the `gulp templates` task
* @param {cb} callback
*/
gulp.task('templates', function () {
return templatesTask.runTask();
});
// SERVER ---------------------------------------------------------------------
//
/**
* Run the `gulp browsersync` task
* @param {cb} callback
*/
gulp.task('browsersync', function (cb) {
bsTask.runtask(cb);
});
/**
* Run the `gulp server` task
* @param {cb} callback
*/
gulp.task('server', gulp.series(['browsersync'], function (cb) {
serverTask.runTask(cb)
}));
/**
* Run the `gulp psi` task (Page Speed Insights)
* @param {cb} callback
*/
gulp.task('psi', function (cb) {
psiTask.runtask(cb);
});