forked from midwayjs/midway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_status.js
35 lines (27 loc) · 965 Bytes
/
sync_status.js
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
const { execSync } = require('child_process');
const execa = require('execa');
const originData = execSync('npx lerna ls --json').toString();
const data = JSON.parse(originData);
const failed = [];
const finished = [];
async function checkSyncStatus(pkg) {
const npmVersion = await execa('npm', ['show', pkg, 'version']);
const tnpmVersion = await execa('tnpm', ['show', pkg, 'version']);
finished.push(pkg);
console.log(`[${finished.length}/${data.length}] ---->`, pkg);
if (npmVersion.stdout !== tnpmVersion.stdout) {
console.log(`===> npm: ${npmVersion.stdout}, tnpm: ${tnpmVersion.stdout}`);
failed.push(pkg);
}
}
async function start() {
const packages = data
.filter((item) => item.private === false)
.map((item) => item.name);
const task = packages.map((pkg) => checkSyncStatus(pkg));
await Promise.all(task);
if (failed.length) {
console.log(`output command => tnpm sync ${failed.join(' ')}`);
}
}
start();