UNPKG

autocode-cli

Version:

code automation for every language, framework and platform

107 lines (95 loc) 3.21 kB
// Generated by CoffeeScript 1.10.0 (function() { var changecase, colors, cson, fs, mkdirp, mustache, pluralize, spawn; changecase = require('change-case'); colors = require('colors'); cson = require('season'); fs = require('fs'); mkdirp = require('mkdirp'); mustache = require('mustache'); pluralize = require('pluralize'); spawn = require('cross-spawn'); exports.generate = require('./generate'); module.exports = function(opts) { var buildCmd, i, scripts; opts = opts || {}; this.path = (function() { switch (true) { case opts._ && opts._[1]: return opts._[1]; case typeof opts.path === 'string': return opts.path; case this.path !== void 0: return this.path; default: return process.cwd(); } }).call(this); if (!fs.existsSync(this.path)) { mkdirp.sync(this.path); } process.chdir(this.path); if (!this.config && (this.config = this.load()) === false) { throw new Error('Unable to load configuration.'); } if (this.config.name) { console.log(("\n" + this.config.name).bold); } if (this.config.description) { console.log("" + this.config.description); } if (this.config.author) { console.log("by " + this.config.author.name + " <" + this.config.author.email + "> (" + this.config.author.url + ")"); } console.log("at " + this.path + "\n"); if (opts.skipGeneration !== true) { if (this.generate(opts) === false) { throw new Error('Unable to generate code.'); } } if ((opts._ && (opts._[0] === 'publish' || opts._[0] === 'run')) || !this.config.scripts || !this.config.scripts.build || opts.skipScripts) { console.log("\n" + ' DONE! '.bgGreen.white); if (opts && opts.complete) { opts.complete(); } return; } console.log("\nBUILD:".bold); opts = this.opts; scripts = this.config.scripts; i = 0; buildCmd = function() { var arg, build, cmd, command, description, proc; if (!scripts.build[i]) { console.log("\n" + ' DONE! '.bgGreen.white); if (opts && opts.complete) { opts.complete(); } return; } description = scripts.build[i].description || scripts.build[i]; command = scripts.build[i].command || scripts.build[i]; console.log(' BUILD SCRIPT '.bgGreen.white + (' ' + description + ' ').bgWhite + " \n" + command.gray); build = command; build = [build.substr(0, build.indexOf(' ')), build.substr(build.indexOf(' ') + 1)]; cmd = build[0]; arg = build[1].split(' '); proc = spawn(cmd, arg); proc.stdout.on('data', function(data) { return console.log(data.toString()); }); proc.on('exit', function(err) { return buildCmd(); }); proc.on('error', function(err) { console.log("\n" + ' ERROR '.bgRed.white + (' ' + err.message + ' ').bgWhite); return console.log(JSON.stringify(err, null, ' ').red); }); return i++; }; if (opts && (opts.skipScripts = true)) { return; } return buildCmd(); }; }).call(this);