-
Notifications
You must be signed in to change notification settings - Fork 5
/
npmUpdate.ts
67 lines (60 loc) · 1.89 KB
/
npmUpdate.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
import { isAtArtProjectRoot } from '../helpers/isAtArtProjectRoot';
import chalk from 'chalk';
import { FileNames } from '../constants/FileNames';
import { Stage } from '../enums/Stage';
import { join } from 'path';
import { existsSync } from 'fs';
import spawn from 'cross-spawn';
import preferredPm from 'preferred-pm';
export const npmUpdate = () => {
if (!isAtArtProjectRoot()) {
throw Error(chalk.red(`Cannot found "${FileNames.ARTCONFIGFILE}" file, please executing art cli command at art project root path`));
}
const notArtPkgGlob = '!art-*';
let bin;
if (process.env.STAGE === Stage.dev) {
bin = join(__dirname, '../../../../node_modules/.bin/npm-check');
} else {
const npmCheckPathOne = join(__dirname, '../../../npm-check-support-yarn/bin/cli.js');
const npmCheckPathTwo = join(__dirname, '../../node_modules/npm-check-support-yarn/bin/cli.js');
if (existsSync(npmCheckPathOne)) {
bin = npmCheckPathOne;
} else if (existsSync(npmCheckPathTwo)) {
bin = npmCheckPathTwo;
} else {
throw new Error('No npm-check package found globally');
}
}
preferredPm(process.cwd())
.then((pm) => {
const pmName = pm.name;
const env = Object.create( process.env );
env.UPDATE_INSTALLER = pmName;
const child = spawn(
bin,
[
'--update',
'--ignore', notArtPkgGlob,
'--skip-unused'
],
{
stdio: 'inherit',
env
}
);
child.on('close', (code) => {
if (code !== 0) {
console.log();
console.log(chalk.cyan('Art dependencies update') + ' exited with code ' + code + '.');
console.log();
return;
}
});
child.on('error', (err) => {
console.log(err);
});
})
.catch((err) => {
console.log(chalk.red('Package manage detection error: '), err);
});
};