-
Notifications
You must be signed in to change notification settings - Fork 34
/
install.ts
75 lines (67 loc) · 2.08 KB
/
install.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
import ora from 'ora';
import {execa} from 'execa';
import padStream from 'pad-stream';
import {isInDebugMode, compact} from '@reskript/core';
import {UserOptions} from '../interface.js';
const PACKAGE_MANAGER_INSTALL_COMMAND: Record<string, [string, string]> = {
npm: ['npm', 'install'],
yarn: ['yarn', 'add'],
pnpm: ['pnpm', 'add'],
};
const installWith = (cwd: string, packageManager: string) => {
const [command, route] = PACKAGE_MANAGER_INSTALL_COMMAND[packageManager];
return async (description: string, flags: string[], dependencies: Array<string | false>) => {
const spinner = ora(description);
const cmd = execa(command, [route, ...flags, ...compact(dependencies)], {cwd});
if (isInDebugMode()) {
spinner.stopAndPersist();
cmd.stdout?.pipe(padStream(2, ' ')).pipe(process.stdout);
cmd.stderr?.pipe(padStream(2, ' ')).pipe(process.stderr);
}
else {
spinner.start();
}
await cmd;
if (!isInDebugMode()) {
spinner.succeed();
}
};
};
export default async (cwd: string, options: UserOptions) => {
const install = installWith(cwd, options.packageManager);
await install(
'Installing runtime dependencies',
[],
[
'core-js',
'react',
'react-dom',
]
);
await install(
'Installing development dependencies',
['-D'],
[
'eslint',
'stylelint',
'typescript',
'webpack',
options.gerrit ? 'husky@4.x' : 'husky',
'@types/react',
'@types/react-dom',
]
);
await install(
'Installing reSKRipt packages',
['-D', '-E'],
[
'@reskript/cli',
'@reskript/cli-dev',
'@reskript/cli-build',
'@reskript/cli-lint',
'@reskript/config-lint',
options.tasks.includes('test') && '@reskript/cli-test',
options.tasks.includes('play') && '@reskript/cli-play',
]
);
};