doomjs
Version:
A bunch of modular gulp tasks
156 lines (109 loc) • 4.31 kB
JavaScript
var doom = process.doom;
var config = require('./config');
var $ = require('./lib');
// ---------------------------------------------
// @module core
// ---------------------------------------------
var Module = (function () {
// Private Vars
// ---------------------------------------------
// Private Methods
// ---------------------------------------------
// Public Methods
// ---------------------------------------------
var launcher = function (name, tasks, callback) {
$.gulp.task(name, tasks, callback);
};
var errors = function () {
var args = Array.prototype.slice.call(arguments);
// Send error to notification center with gulp-notify
$.notify.onError({
title: "Compile Error",
message: "<%= error %>"
}).apply(this, args);
// Keep gulp from hanging on this task
this.emit('end');
};
var delete_files = function (target, type, context) {
$.del(config.static + doom.dist + '/**' + target + context + type);
};
var delete_path = function (target) {
$.del(target);
};
var generate_core_dist = function (task_sequence) {
// @create or @delete static into common
// ---------------------------------------------
config.static = doom.static + doom.core;
config.templates = doom.templates + doom.core;
config.context = '';
task_sequence();
};
var generate_wraith_dist = function (wraith, is_wraith, task_sequence) {
// @create or @delete static into specific wraith
// ---------------------------------------------
for (var i = 0; i < Object.keys(wraith.paths).length; i++) {
var path = Object.keys(wraith.paths)[i];
if ($.argv[path] === true) {
var wraith_active = wraith.active[path] = wraith.paths[path];
config.static = doom.static + wraith_active;
config.templates = doom.templates + wraith_active;
context_manager(wraith, task_sequence);
is_wraith = true;
return;
}
}
};
var generate_all_dist = function (wraith, task_sequence) {
// @create or @delete static into all wraiths
// ---------------------------------------------
wraith.active = wraith.paths;
for (var i = 0; i < Object.keys(wraith.active).length; i++) {
var path = Object.keys(wraith.active)[i];
var wraith_active = wraith.active[path];
config.static = doom.static + wraith_active;
config.templates = doom.templates + wraith_active;
context_manager(wraith, task_sequence);
}
};
var context_manager = function (wraith, task_sequence) {
// @create or @delete static into wraith context
// ---------------------------------------------
var static = config.static;
var templates = config.templates;
for (var k = 0; k < Object.keys(wraith.context).length; k++) {
var context_path = Object.keys(wraith.context)[k];
var context = wraith.context[context_path];
config.static = static + context;
config.templates = templates + context;
config.context = '-' + context_path;
task_sequence();
}
};
var wraith_manager = function (task_sequence) {
process.wraith.active = {};
var wraith = process.wraith;
if ($.argv['all'] || $.argv['a'] === true) {
generate_all_dist(wraith, task_sequence);
generate_core_dist(task_sequence);
return;
} else {
var is_wraith = false;
generate_wraith_dist(wraith, is_wraith, task_sequence);
if (is_wraith === false) {
generate_core_dist(task_sequence);
}
}
};
// Module API
// ---------------------------------------------
return {
launcher: launcher,
errors: errors,
delete_files: delete_files,
delete_path: delete_path,
wraith_manager: wraith_manager
};
})();
// Module Export
// ---------------------------------------------
module.exports = Module;