forked from noodlapp/noodl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.ts
88 lines (76 loc) · 2.29 KB
/
start.ts
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
import { exec } from 'child_process';
import fs from 'fs';
import path from 'path';
import { ConsoleColor, attachStdio } from './utils/process';
const CWD = path.join(__dirname, '..');
const LOCAL_GIT_DIRECTORY = path.join(__dirname, '..', 'node_modules', 'dugite', 'git');
const LOCAL_GIT_TRAMPOLINE_DIRECTORY = path.join(
__dirname,
'..',
'node_modules',
'desktop-trampoline/build/Release/desktop-trampoline'
);
// Print variables for easy debugging
console.log('---');
console.log(`> CWD: `, CWD);
console.log(`> LOCAL_GIT_DIRECTORY: `, LOCAL_GIT_DIRECTORY);
console.log(`> LOCAL_GIT_TRAMPOLINE_DIRECTORY: `, LOCAL_GIT_TRAMPOLINE_DIRECTORY);
console.log('---');
// Verify git path
switch (process.platform) {
case 'win32': {
const gitExist = fs.existsSync(path.join(LOCAL_GIT_DIRECTORY, 'mingw64/bin', 'git.exe'));
if (gitExist) {
console.log('> Found git.exe');
} else {
throw new Error("'git.exe' is missing, this can be caused by node_modules issues.");
}
break;
}
case 'darwin': {
const gitExist = fs.existsSync(path.join(LOCAL_GIT_DIRECTORY, 'bin', 'git'));
if (gitExist) {
console.log('> Found git executable');
} else {
throw new Error("'git' is missing, this can be caused by node_modules issues.");
}
break;
}
}
console.log('---');
// Start processes
const processOptions = {
cwd: CWD,
env: {
...process.env,
LOCAL_GIT_DIRECTORY,
LOCAL_GIT_TRAMPOLINE_DIRECTORY
}
};
const argBuildViewers = process.argv.includes('--build-viewer');
const viewerScript = argBuildViewers ? 'build' : 'start';
const viewerProcess = attachStdio(
exec(`npx lerna exec --scope @noodl/noodl-viewer-react -- npm run ${viewerScript}`, processOptions),
{
prefix: 'Viewer',
color: ConsoleColor.FgMagenta
}
);
const cloudRuntimeProcess = attachStdio(
exec(`npx lerna exec --scope @noodl/cloud-runtime -- npm run ${viewerScript}`, processOptions),
{
prefix: 'Cloud',
color: ConsoleColor.FgMagenta
}
);
const editorProcess = attachStdio(exec('npx lerna exec --scope noodl-editor -- npm run start', processOptions), {
prefix: 'Editor',
color: ConsoleColor.FgCyan
});
editorProcess.on('exit', (code) => {
if (typeof code === 'number') {
viewerProcess.kill(0);
cloudRuntimeProcess.kill(0);
process.exit(0);
}
});