-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Expand file tree
/
Copy pathcheck-dependencies.js
More file actions
71 lines (62 loc) · 1.7 KB
/
check-dependencies.js
File metadata and controls
71 lines (62 loc) · 1.7 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
/**
* This file needs to be run before any other script to ensure dependencies are installed Therefore,
* we cannot transform this file to Typescript, because it would require esbuild to be installed
*/
import { spawn } from 'child_process';
import { existsSync } from 'fs';
import { join } from 'path';
import * as url from 'url';
const logger = console;
const filename = url.fileURLToPath(import.meta.url);
const dirname = url.fileURLToPath(new URL('.', import.meta.url));
const checkDependencies = async () => {
const scriptsPath = join(dirname);
const codePath = join(dirname, '..', 'code');
const tasks = [];
if (!existsSync(join(scriptsPath, 'node_modules'))) {
tasks.push(
spawn('yarn', ['install'], {
cwd: scriptsPath,
shell: true,
stdio: ['inherit', 'inherit', 'inherit'],
})
);
}
if (!existsSync(join(codePath, 'node_modules'))) {
tasks.push(
spawn('yarn', ['install'], {
cwd: codePath,
shell: true,
stdio: ['inherit', 'inherit', 'inherit'],
})
);
}
if (tasks.length > 0) {
logger.log('installing dependencies');
await Promise.all(
tasks.map(
(t) =>
new Promise((res, rej) => {
t.on('exit', (code) => {
if (code !== 0) {
rej();
} else {
res();
}
});
})
)
).catch(() => {
tasks.forEach((t) => t.kill());
throw new Error('Failed to install dependencies');
});
// give the filesystem some time
await new Promise((res) => {
setTimeout(res, 1000);
});
}
};
checkDependencies().catch((e) => {
console.error(e);
process.exit(1);
});