-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
194 lines (166 loc) · 5.73 KB
/
install.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
const path = require('path');
const childProcess = require('child_process');
const root = process.cwd();
/**
* @param {string} package - The package to check via npm ls
* @param {boolean} global - Whether the package should be
* checked with the -g parameter
* @return {Promise<boolean>} - Whether the npm package is installed
*/
function npmCheckInstalled(package, global) {
return new Promise((resolve) => {
if (global) package = '-g ' + package;
let npm = childProcess.exec('npm ls ' + package, {
cwd: root,
env: process.env,
stdio: 'inherit',
});
npm.stdout.on('data', function(data) {
resolve(data.indexOf('-- (empty)') === -1);
});
});
}
/**
* Runs 'npm install' on the passed directory
* @param {string} path
* @return {Promise}
*/
function npmInstall(path) {
return new Promise((resolve) => {
let child = childProcess.exec('npm install', {
cwd: path,
env: process.env,
stdio: 'inherit',
});
child.on('exit', () => {
resolve();
});
child.on('error', (err) => {
console.log(err);
resolve();
});
});
}
/**
* @param {string} package - The package to be installed
* @param {boolean} global - Whether the package should be installed globally
* @return {Promise} - Resolves once the npm process exits
*/
function npmInstallPackage(package, global) {
return new Promise((resolve) => {
if (global) package = '-g ' + package;
let child = childProcess.exec('npm install ' + package, {
cwd: root,
env: process.env,
stdio: 'inherit',
});
child.on('exit', () => {
resolve();
});
child.on('error', (err) => {
console.log(err);
resolve();
});
});
}
let pendingInstalls = [];
// Runs npm install in the root folder
console.log('Installing core libraries...');
let coreInstallPromise =
npmInstall(root).then(() => {
console.log('Finished installing core libraries...');
});
pendingInstalls.push(coreInstallPromise);
// Runs npm install in the web-gen-core folder
console.log('Installing generator libraries...');
let webGenInstallPromise =
npmInstall(path.join(root, 'web-gen-core')).then(() => {
console.log('Finished installing generator libraries...');
});
pendingInstalls.push(webGenInstallPromise);
// Runs npm install in the web-gen-ui folder
console.log('Installing UI libraries...');
let uiInstallPromise =
npmInstall(path.join(root, 'web-gen-ui')).then(() => {
console.log('Finished installing UI libraries...');
});
pendingInstalls.push(uiInstallPromise);
// console.log('Checking for existing Angular CLI installation...');
// Installs Angular CLI globally if it isn't already installed
let angularCliCheckPromise =
npmCheckInstalled('@angular/cli', true)
.then((installed) => {
if (installed) {
console.log('Angular CLI already installed. ' +
'Skipping installation...');
} else {
console.log('No global Angular CLI installation found. ' +
'Installing now...');
return npmInstallPackage('@angular/cli', true).then(() => {
console.log('Angular CLI installation finished...');
});
}
});
pendingInstalls.push(angularCliCheckPromise);
// console.log('Checking for existing global TypeScript installation...');
// Installs TypeScript globally if it isn't already installed
// let typescriptCheckPromise =
// npmCheckInstalled('typescript', true)
// .then((installed) => {
// if (installed) {
// console.log('TypeScript already installed. ' +
// 'Skipping installation...');
// } else {
// console.log('No global TypeScript installation found. ' +
// 'Installing now...');
// return npmInstallPackage('typescript', true).then(() => {
// console.log('TypeScript installation finished...');
// });
// }
// });
// pendingInstalls.push(typescriptCheckPromise);
// Wait for libraries to finish installing
// then run ng build
Promise.all(pendingInstalls).then(() => {
console.log('All installations completed...');
console.log('Performing post-install tasks...');
let pendingPostInstalls = [];
// let compilePromise = new Promise((resolve) => {
// console.log('Compiling Settings Files...');
// let child =
// childProcess.exec('tsc generator.ts', {
// cwd: path.join(root),
// env: process.env,
// stdio: 'inherit',
// });
// child.on('exit', () => {
// resolve();
// });
// child.on('error', (err) => {
// console.log(err);
// resolve();
// });
// });
// pendingPostInstalls.push(compilePromise);
let buildPromise = new Promise((resolve) => {
console.log('Building UI...');
let child =
childProcess.exec('ng build --env=prod', {
cwd: path.join(root, 'web-gen-ui'),
env: process.env,
stdio: 'inherit',
});
child.on('exit', () => {
resolve();
});
child.on('error', (err) => {
console.log(err);
resolve();
});
});
pendingPostInstalls.push(buildPromise);
Promise.all(pendingPostInstalls).then(() => {
console.log('All post-install tasks completed...');
console.log('Run "node launch.js"');
});
});