UNPKG

gulp-io

Version:

iio's front-end build tools.

170 lines (142 loc) 4.66 kB
var clc = require('cli-color'); var load = require('gulp-load-plugins'); var Log = require("./helpers/log"); var error = new Log("red"); var success = new Log("green"); var info = new Log("blue"); var debug = new Log("purple"); var warning = new Log("orange"); var notice = new Log("gray"); var text = new Log(); var private = {}; private.projecter = function() { return process.env.INIT_CWD; }; private.moder = function() { //TO WORK WITH NPM START --env-dev or any other env // console.log(process); var env = false; if (process.argv) { if (JSON.stringify(process.argv).split("--env-")[1]) { env = JSON.stringify(process.argv).split("--env-")[1].split("\"")[0]; } if (env) { success.log("Environment", env); env = env; } else { notice.log("Environment", "NONE"); env = false; } } if (process.env.npm_config_argv) { if (JSON.stringify(process.env.npm_config_argv).split("--env-")[1]) { env = JSON.stringify(process.env.npm_config_argv).split("--env-")[1].split("\\\"")[0]; } if (env) { success.log("Environment", env); env = env; } else { notice.log("Environment", "NONE"); env = false; } } return env; // if (process.argv[3] && process.argv[3].split("--")[1]) { // var env = process.argv[3].split("--")[1]; // success.log("Environment", env); // return env; // } else if (process.argv[2] && process.argv[2].split("--")[1]) { // var env = process.argv[2].split("--")[1]; // success.log("Environment", env); // return env; // } else { // notice.log("Environment", "NONE"); // return false; // } }; private.scope = function(mode) { if (mode === false) { return ['dependencies']; } else { return ['dependencies', mode + 'Dependencies']; } }; var public = module.exports = function(CONFIG) { this.gulp = require('gulp'); }; public.prototype.init = function(CONFIG) { private.debuging = CONFIG.debuging; private.logging = CONFIG.logging; this.mode = {}; this.mode.name = private.moder(); this.mode.ext = this.mode.name ? '.' + this.mode.name : ''; this.mode.scope = private.scope(this.mode.name); this.mode.config = ""; this.project = {}; this.project.address = private.projecter(this.gulp); this.project.name = this.project.address.split("/").pop(); this.global = process.cwd(); this.package = this.global + '/package.json'; }; public.prototype.readCommands = function(CONFIG) { }; public.prototype.loadPlugins = function(CONFIG) { try { var that = this; this.plugins = function() { return load({ pattern: '*', config: that.package, scope: that.mode.scope, replaceString: 'gulp-', camelize: true, lazy: true, rename: {} }); }(); } catch (err) { error.log("loadPlugins, load", err); } finally { success.log("loadPlugins Scope", JSON.stringify(this.mode.scope).replace(",", ", ")); } }; public.prototype.getTasksConfig = function(CONFIG) { try { this.config = require(this.plugins.path.join(this.project.address + ('/config' + this.mode.ext))); this.mode.config = this.project.name + "/config" + this.mode.ext; } catch (err) { try { warning.log("Config", err); notice.log("Config", "Trying to load global config" + this.mode.ext); var config = require('./config' + this.mode.ext); this.mode.config = 'global/config' + this.mode.ext; } catch (err2) { error.log("Config", err2); } } finally { this.gulp.config = this.config; success.log("Project", this.project.name); success.log("Config", this.mode.config); } }; public.prototype.loadTasks = function(CONFIG) { try { var async = require('async'); var tasks = []; tasks.push('./tasks/help.js'); for (var task in this.config) { tasks.push('./tasks/' + task + '.js'); } var that = this; async.map(tasks, function(file) { require(file)(that.gulp, that.plugins); }); } catch (err) { error.log("Tasks", err); } }; public.prototype.registerTasks = function(CONFIG) { this.gulp.task('default', ['help']); }; public.prototype.start = function(CONFIG) { };