-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate-taro
53 lines (48 loc) · 1.32 KB
/
update-taro
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
const { dependencies, devDependencies } = require('./package.json');
const { exec } = require('child_process');
const fetch = require('node-fetch');
const chalk = require('chalk');
const log = console.log;
const deps = [
'@tarojs/components',
'@tarojs/runtime',
'@tarojs/taro'
];
const devdeps = [
'@tarojs/cli',
'@tarojs/mini-runner',
'@tarojs/webpack-runner',
'babel-preset-taro',
'eslint-config-taro'
]
let version = ''
function fetchLatestVersion() {
return fetch('https://registry.npmjs.org/-/package/@tarojs/cli/dist-tags')
.then(res => res.json())
.then(res => {
version = res.latest
log(chalk.green('version: ') + version)
})
}
function createUpdateTaskChain(deps, dev) {
let p = Promise.resolve()
deps.forEach(dep => {
p = p.then(() => new Promise((resolve) => {
log(`start ${dep}`)
exec(`yarn add ${dep}@${version}${dev?' -D':''} -E`, (err, stdout, stderr) => {
if (err) {
log('err','\n',err)
log('stderr', '\n', stderr)
log(`deps: ${dep} update ` + chalk.red('failed'))
} else {
log(`deps: ${dep} update ` + chalk.green('success'))
}
resolve()
})
}))
});
return p
}
fetchLatestVersion()
.then(() => createUpdateTaskChain(deps, false))
.then(() => createUpdateTaskChain(devdeps, true))