1 | import spawn from 'cross-spawn';
|
2 |
|
3 | export function getRegistryUrl(packageManager: string) {
|
4 | return new Promise<any>((resolve, reject) => {
|
5 | const command = packageManager;
|
6 | const args = ['config', 'get', 'registry'];
|
7 |
|
8 | const child = spawn(command, args, { windowsHide: true });
|
9 |
|
10 | let output = '';
|
11 |
|
12 | child.stdout!.on('data', (data) => {
|
13 | output += data;
|
14 | });
|
15 |
|
16 | child.on('close', (code) => {
|
17 | if (code !== 0) {
|
18 | reject({
|
19 | command: `${command} ${args.join(' ')}`
|
20 | });
|
21 | return;
|
22 | }
|
23 | output = output.replace(/\n/, '').replace(/\/$/, '');
|
24 | resolve(output);
|
25 | });
|
26 | });
|
27 | }
|
28 |
|
29 | export function install(
|
30 | packageManager: string,
|
31 | root: any,
|
32 | cmd: any,
|
33 | dependencies: any,
|
34 | verbose: boolean,
|
35 | isOnline: boolean
|
36 | ) {
|
37 | return new Promise((resolve, reject) => {
|
38 | const command = packageManager;
|
39 | const args = [cmd, '--save', '--save-exact', '--loglevel', 'error'].concat(
|
40 | dependencies
|
41 | );
|
42 |
|
43 | if (verbose) {
|
44 | args.push('--verbose');
|
45 | }
|
46 |
|
47 | const child = spawn(command, args, { stdio: 'inherit', cwd: root, windowsHide: true });
|
48 | child.on('close', (code) => {
|
49 | if (code !== 0) {
|
50 | reject({
|
51 | command: `${command} ${args.join(' ')}`
|
52 | });
|
53 | return;
|
54 | }
|
55 | resolve();
|
56 | });
|
57 | });
|
58 | }
|
59 |
|
\ | No newline at end of file |