forked from mrsone40/storybook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-utils.ts
More file actions
58 lines (51 loc) · 1.33 KB
/
cli-utils.ts
File metadata and controls
58 lines (51 loc) · 1.33 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
import { spawn } from 'child_process';
import { join } from 'path';
import { existsSync } from 'fs';
const logger = console;
export const checkDependencies = async () => {
const scriptsPath = join(__dirname, '..');
const codePath = join(__dirname, '..', '..', 'code');
const tasks: Array<any> = [];
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<void>((res, rej) => {
t.on('exit', (code: number) => {
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);
});
}
};