Skip to content

Commit 688e8b2

Browse files
committed
update:check version
1 parent 02e52f5 commit 688e8b2

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

utils/index.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
const path = require('path')
2-
const childProcess = require('child_process')
3-
const { execSync } = childProcess
4-
2+
const http = require('http');
53
// upgrade logger
64
function upgradeLogger () {
75
const currPkg = require('../package.json')
86
const cwd = path.resolve(__dirname, '../')
97
const pkgName = currPkg.name || 'mpvue-simple'
10-
const pkg = JSON.parse(execSync(`curl \`npm config get registry\`${pkgName} -s`, { cwd }))
11-
const latestVesion = pkg['dist-tags'].latest
128

13-
if (latestVesion !== currPkg.version) {
14-
console.log(`${pkgName} 有新版本 ${latestVesion} 啦,请注意升级。\n例如: npm install ${pkgName} -g\n`)
15-
}
9+
http.get('http://registry.npmjs.org/' + currPkg.name, (res) => {
10+
let rawData = '';
11+
res.on('data', (chunk) => rawData += chunk);
12+
res.on('end', () => {
13+
try {
14+
const parsedData = JSON.parse(rawData);
15+
let latestVesion = parsedData['dist-tags'].latest;
16+
if (latestVesion !== currPkg.version) {
17+
console.log(`${pkgName} 有新版本 ${latestVesion} 啦,请注意升级。\n例如: npm install ${pkgName} -g\n`)
18+
}
19+
} catch (e) {
20+
console.log(e.message);
21+
}
22+
});
23+
})
1624
}
1725

1826
exports.upgradeLogger = upgradeLogger

0 commit comments

Comments
 (0)