-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.controller.js
179 lines (139 loc) · 5.39 KB
/
action.controller.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
var chalk = require ('chalk');
var constants = require ('./constants');
/**
* spawn is an EventEmitter object. Using spawn we can listen to
* stdout/stderr events and hence can display live.
*/
var spawn = require ('child_process').spawn;
//const exports = module.exports = {};
module.exports.execBasecampScript = function (next) {
var command = spawn ('git', ['clone', constants.es6BasecampRepo]);
command.stdout.on ('data', (data) => {
console.log (chalk.blue(data));
});
command.stderr.on ('data', (data) => {
console.error (chalk.green(data));
})
command.on ('exit', (code) => {
if (code == 128)
console.log (chalk.red('scaffolding already exists.. terminating'));
//console.log ('process executed with code '+ code);
next ();
})
}
/**
* for angularJS scaffolding URL
*/
module.exports.execBasecampAngularScript = function (next) {
var command = spawn ('git', ['clone', constants.es6BasecampAngularRepo]);
command.stdout.on ('data', (data) => {
console.log (chalk.green (data));
});
command.stdout.on ('data', (data) => {
console.error (chalk.red (data));
});
command.on ('exit', (code) => {
if (code == 128)
console.log (chalk.red('scaffolding already exists.. terminating'));
next();
});
}
/**
* the script to configure angular2 basecamp with Typescript and bootstrap
*/
module.exports.execBasecampAngular2Script = function (next) {
var command = spawn ('git', ['clone', constants.es6BasecampAngular2Repo]);
command.stdout.on ('data', (data) => console.log (chalk.green (data)));
command.stderr.on ('data', (data) => console.error (chalk.blue (data)));
command.on ('exit', (code) => {
if (code == 128)
console.log (chalk.red ('scaffolding already exists.. terminating'));
next();
});
}
module.exports.execBasecampReactScript = function (next) {
var command = spawn ('git', ['clone', constants.reactRepo]);
command.stdout.on ('data', data => console.log (chalk.green (data)));
command.stderr.on ('data', data => console.error (chalk.blue (data)));
command.on ('exit', code => {
if (code == 128)
console.log (chalk.red ('scaffolding already exists.terminating'))
next();
})
};
/**
* ES6, Node, Angular2, Passport scaffold
* https://github.com/sharma02gaurav/ENA2Pass-scaffold
*/
module.exports.execENA2PassScript = next => {
const command = spawn ('git', ['clone', constants.ENA2Pass]);
command.stdout.on ('data', data => console.log (chalk.green (data)));
command.stderr.on ('data', data => console.error (chalk.blue (data)));
command.on ('exit', code => {
if (code === 128) console.log (chalk.red ('Scaffold already exists. Terminating'))
next();
})
}
/**
* the common script to execute after cloning a repo
*/
module.exports.postCloningScript = function (directory) {
console.log (chalk.green('Done creating scaffold'));
console.log (chalk.green ('configuring your scaffold') );
var npmInstall = spawn ('npm', ['--prefix', directory ,'install', directory]);
npmInstall.stdout.on ('data', (data) => console.log (chalk.green (data)));
npmInstall.stderr.on ('data', (data) => console.log (chalk.blue (data)));
// npmInstall.stderr.pipe (process.stderr);
// npmInstall.stdout.pipe (process.stdout);
npmInstall.on ('exit', function (code) {
if (code == 0) {
console.log (chalk.green ('DONE!'))
/**
* after cloning.. remove the git support from the directory
*/
removeGitSupport (directory);
} else {
console.log (chalk.red ('Some error: '+ code));
}
});
}
/**
* script to remove the git repo support in the cloned repo. Run this after postCloningScript
* @param {string} directory
*/
function removeGitSupport (directory) {
console.log (chalk.green ('removing remote git'));
var script = spawn ('rm', ['-Rf', directory+'.git']);
script.stdout.on ('data', (data) => console.log (chalk.green (data)));
script.stderr.on ('data', (data) => console.log (chalk.red (data)));
script.on ('exit', (code) => {
if (code == 0)
console.log (chalk.green ('Configured'));
else
console.log (chalk.red ('error removing git from repo'));
});
}
/**
* script to update es6-scaffolder
*/
module.exports.updateScript = function (version) {
console.log (chalk.green ('Updating your es6-scaffold to '+ version));
var updateCommand = spawn ('npm', ['uninstall', '-g', 'es6-scaffolder']);
updateCommand.stderr.pipe (process.stderr);
updateCommand.stdout.pipe (process.stdout);
updateCommand.on ('exit', (code) => {
if (code == 0) {
updateCommand = spawn ('npm', ['install', '-g', 'es6-scaffolder']);
updateCommand.stderr.pipe (process.stderr);
updateCommand.stdout.pipe (process.stdout);
updateCommand.on ('exit', (code) => {
if (code == 0)
console.log (chalk.green ('scaffolder has been updated to '+ version));
else
console.log (chalk.red ('Error occured while updating to '+ version));
});
} else {
console.log (chalk.red ('Error occured while updationg to version '+ version));
}
});
}