forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-scripts-worker-client.ts
More file actions
124 lines (103 loc) · 3.55 KB
/
app-scripts-worker-client.ts
File metadata and controls
124 lines (103 loc) · 3.55 KB
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
import { fork, ChildProcess } from 'child_process';
import { dirname, join } from 'path';
import { MessageToWorker, WorkerProcess } from './interfaces';
export function runWorker(pathToAppScripts: string, debug: boolean, appEntryPoint: string, appNgModulePath: string, srcDir: string, distDir: string, tsConfig: string, ionicAngularDir: string, sassConfigPath: string, copyConfigPath: string, isDev: boolean, minifyCss: boolean, minifyJs: boolean, optimizeJs: boolean) {
return new Promise((resolve, reject) => {
const msgToWorker: MessageToWorker = {
pathToAppScripts: pathToAppScripts,
appEntryPoint: appEntryPoint,
appNgModulePath: appNgModulePath,
debug: debug,
srcDir: srcDir,
distDir: distDir,
tsConfig: tsConfig,
ionicAngularDir: ionicAngularDir,
sassConfigPath: sassConfigPath,
copyConfigPath: copyConfigPath,
isDev: isDev,
minifyCss: minifyCss,
minifyJs: minifyJs,
optimizeJs: optimizeJs
};
const worker = <ChildProcess>createWorker(msgToWorker);
console.log(`Starting to do a ${isDev ? 'dev' : 'prod'} build test ${appEntryPoint}`);
worker.on('error', (err: any) => {
console.error(`worker error, entrypoint: ${appEntryPoint}, pid: ${worker.pid}, error: ${err}`);
reject(err);
});
worker.on('exit', (code: number) => {
console.log(`Finished building test ${appEntryPoint}`);
if (code === 0) {
resolve(code);
} else {
reject(new Error(`${appEntryPoint} exited with non-zero status code`));
}
});
});
}
export function createWorker(msg: MessageToWorker): any {
for (var i = workers.length - 1; i >= 0; i--) {
if (workers[i].appEntryPoint === msg.appEntryPoint) {
try {
workers[i].worker.kill('SIGKILL');
} catch (e) {
console.log(`createWorker, kill('SIGKILL'): ${e}`);
} finally {
delete workers[i].worker;
workers.splice(i, 1);
}
}
}
// default it to use the test/basic, or test/xyz directory
const deepLinksDir = dirname(dirname(msg.appNgModulePath));
try {
let scriptArgs = [
'build',
'--appEntryPoint', msg.appEntryPoint,
'--appNgModulePath', msg.appNgModulePath,
'--deepLinksDir', deepLinksDir,
'--srcDir', msg.srcDir,
'--wwwDir', msg.distDir,
'--tsconfig', msg.tsConfig,
'--readConfigJson', 'false',
'--experimentalManualTreeshaking', 'false',
'--experimentalPurgeDecorators', 'false',
'--ionicAngularDir', msg.ionicAngularDir,
'--sass', msg.sassConfigPath,
'--copy', msg.copyConfigPath,
'--enableLint', 'false',
'--skipIonicAngularVersion', 'true'
];
// TODO, use prod once we're a little more settled
if (!msg.isDev) {
scriptArgs.push('--aot');
}
if (msg.debug) {
scriptArgs.push('--debug');
}
if (msg.minifyJs) {
scriptArgs.push('--minifyJs');
}
if (msg.minifyCss) {
scriptArgs.push('--minifyCss');
}
if (msg.optimizeJs) {
scriptArgs.push('--optimizeJs');
}
const workerModule = join(process.cwd(), 'node_modules', '@ionic', 'app-scripts', 'bin', 'ionic-app-scripts.js');
const worker = fork(workerModule, scriptArgs, {
env: {
FORCE_COLOR: true,
npm_config_argv: process.env.npm_config_argv
}
});
workers.push({
appEntryPoint: msg.appEntryPoint,
worker: worker
});
return worker;
} catch (e) {
throw new Error(`unable to create worker-process: ${e.msg}`);
}
}
export const workers: WorkerProcess[] = [];