-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { execSync } = require('child_process'); | ||
const execa = require('execa'); | ||
const { resolve } = require('path'); | ||
|
||
const originData = execSync('npx lerna ls --json').toString(); | ||
const data = JSON.parse(originData); | ||
const finished = []; | ||
|
||
async function syncPackage(pkg) { | ||
await execa('tnpm', ['sync', pkg]); | ||
finished.push(pkg); | ||
console.log(`[${finished.length}/${data.length}] ${pkg} sync finished`); | ||
} | ||
|
||
async function sync() { | ||
console.log('\n=== start sync ===\n'); | ||
const packages = data.map((item) => item.name); | ||
|
||
console.log(`sync ${packages.length} packages:\n${packages.join('\n')}\n`); | ||
const task = packages.map((pkg) => syncPackage(pkg)); | ||
await Promise.all(task); | ||
|
||
console.log('\n=== check sync status ===\n'); | ||
await execa('node', [resolve(__dirname, 'sync_status.js')], { | ||
stdio: 'inherit', | ||
}); | ||
|
||
console.log('\n=== sync finished ==='); | ||
process.exit(1); | ||
} | ||
|
||
sync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
const { execSync } = require('child_process'); | ||
const execa = require('execa'); | ||
|
||
const originData = execSync('npx lerna ls --json').toString(); | ||
const data = JSON.parse(originData); | ||
|
||
const arr = []; | ||
|
||
for (const item of data) { | ||
console.log('---->', item.name); | ||
if (item.private === false) { | ||
const npmVersion = execSync(`npm show ${item.name} version`) | ||
.toString() | ||
.replace('\n', ''); | ||
const tnpmVersion = execSync(`tnpm show ${item.name} version`) | ||
.toString() | ||
.replace('\n', ''); | ||
if (npmVersion !== tnpmVersion) { | ||
console.log(`===> npm: ${npmVersion}, tnpm: ${tnpmVersion}`); | ||
arr.push(item.name); | ||
} | ||
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(item.name); | ||
} | ||
} | ||
|
||
if (arr.length) { | ||
console.log(`output command => tnpm sync ${arr.join(' ')}`); | ||
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(); |