UNPKG

3.18 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.10.0
2(function() {
3 var changecase, colors, cson, fs, mkdirp, mustache, pluralize, spawn;
4
5 changecase = require('change-case');
6
7 colors = require('colors');
8
9 cson = require('season');
10
11 fs = require('fs');
12
13 mkdirp = require('mkdirp');
14
15 mustache = require('mustache');
16
17 pluralize = require('pluralize');
18
19 spawn = require('cross-spawn');
20
21 exports.generate = require('./generate');
22
23 module.exports = function(opts) {
24 var buildCmd, i, scripts;
25 opts = opts || {};
26 this.path = (function() {
27 switch (true) {
28 case opts._ && opts._[1]:
29 return opts._[1];
30 case typeof opts.path === 'string':
31 return opts.path;
32 case this.path !== void 0:
33 return this.path;
34 default:
35 return process.cwd();
36 }
37 }).call(this);
38 if (!fs.existsSync(this.path)) {
39 mkdirp.sync(this.path);
40 }
41 process.chdir(this.path);
42 if (!this.config && (this.config = this.load()) === false) {
43 throw new Error('Unable to load configuration.');
44 }
45 if (this.config.name) {
46 console.log(("\n" + this.config.name).bold);
47 }
48 if (this.config.description) {
49 console.log("" + this.config.description);
50 }
51 if (this.config.author) {
52 console.log("by " + this.config.author.name + " <" + this.config.author.email + "> (" + this.config.author.url + ")");
53 }
54 console.log("at " + this.path + "\n");
55 if (opts.skipGeneration !== true) {
56 if (this.generate(opts) === false) {
57 throw new Error('Unable to generate code.');
58 }
59 }
60 if ((opts._ && (opts._[0] === 'publish' || opts._[0] === 'run')) || !this.config.scripts || !this.config.scripts.build || opts.skipScripts) {
61 console.log("\n" + ' DONE! '.bgGreen.white);
62 if (opts && opts.complete) {
63 opts.complete();
64 }
65 return;
66 }
67 console.log("\nBUILD:".bold);
68 scripts = this.config.scripts;
69 i = 0;
70 buildCmd = function() {
71 var arg, build, cmd, command, description, proc;
72 if (!scripts.build[i]) {
73 console.log("\n" + ' DONE! '.bgGreen.white);
74 if (opts && opts.complete) {
75 opts.complete();
76 }
77 return;
78 }
79 description = scripts.build[i].description || scripts.build[i];
80 command = scripts.build[i].command || scripts.build[i];
81 console.log(' BUILD SCRIPT '.bgGreen.white + (' ' + description + ' ').bgWhite + " \n" + command.gray);
82 build = command;
83 build = [build.substr(0, build.indexOf(' ')), build.substr(build.indexOf(' ') + 1)];
84 cmd = build[0];
85 arg = build[1].split(' ');
86 proc = spawn(cmd, arg);
87 proc.stdout.on('data', function(data) {
88 return console.log(data.toString());
89 });
90 proc.on('exit', function(err) {
91 return buildCmd();
92 });
93 proc.on('error', function(err) {
94 console.log("\n" + ' ERROR '.bgRed.white + (' ' + err.message + ' ').bgWhite);
95 return console.log(JSON.stringify(err, null, ' ').red);
96 });
97 return i++;
98 };
99 if (opts && opts.skipScripts === true) {
100 return;
101 }
102 return buildCmd();
103 };
104
105}).call(this);