-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.js
97 lines (77 loc) · 2.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var Peak = require('../')
, pkg = require('../../package.json')
, colors = require('colors')
, path = require('path');
var Commands = function (process, args) {
var root_path = args.path;
if (process) root_path = path.resolve(process.cwd(), root_path || '');
delete args.path;
this.action = args.action;
delete args.action;
this.mute = args.mute;
delete args.mute;
this.peak = new Peak(root_path, args);
this.emitter = this.peak.emitter;
this.process = process;
}
Commands.prototype = {
init: function () {
var promise;
if (!this.mute) {
this.intro();
this.bind();
}
return this.exec()
.catch(this.error.bind(this));
},
exec: function () {
switch (this.action) {
case 'deploy':
return this.peak.deploy();
case 'new':
return this.peak.generate();
default:
return this.peak.watch();
}
},
exit: function () {
if (this.process) this.process.exit();
this.emitter.emit('exit');
},
error: function (error) {
this.write('\nERROR: '.bold.red + error.message.red + '\n');
},
intro: function () {
console.log((" " + pkg.name + " ").inverse.bold);
console.log(('version ' + pkg.version).grey);
console.log();
},
bind: function () {
this.emitter
.on('init', this.initEvent.bind(this))
.on('done', this.doneEvent.bind(this))
.on('start', this.startEvent.bind(this))
.on('finish', this.finishEvent.bind(this))
.on('sync', this.syncEvent.bind(this))
if (this.process) this.process.on('SIGINT', this.exit.bind(this));
},
write: function (str) {
if (this.process) this.process.stdout.write(str);
},
initEvent: function (action) {
this.write((String(action) + '... ').grey);
},
doneEvent: function () {
this.write('done!'.green + '\n');
},
startEvent: function (action) {
this.write(('started ' + String(action) + '!').green + '\n');
},
finishEvent: function (action) {
this.write(('finished '.bold + String(action) + '!').green + '\n');
},
syncEvent: function (action) {
this.write((String(action) + '!').green.bold + '\n');
}
}
module.exports = Commands;