forked from react-native-community/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update metro to 0.64 (react-native-community#1316)
- Loading branch information
1 parent
668485b
commit 5c563f7
Showing
4 changed files
with
206 additions
and
187 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
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,66 @@ | ||
#!/usr/bin/env nodes | ||
|
||
/** | ||
* Script to update metro monorepo to current latest version on npm | ||
* This script wiil update all package.json | ||
*/ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const cp = require('child_process'); | ||
const glob = require('glob').sync; | ||
const chalk = require('chalk'); | ||
|
||
/** | ||
* Fetches the current latest version of specific package | ||
*/ | ||
const getLatestVersion = (pkgName) => { | ||
const latestVersion = cp.execSync(`npm show ${pkgName} version`, { | ||
encoding: 'utf8', | ||
}); | ||
return `^${latestVersion.trim()}`; | ||
}; | ||
|
||
/** | ||
* Updates metro version in specific object (dependencies) | ||
*/ | ||
const updateDependencies = (depsObject) => { | ||
const updatedJson = Object.keys(depsObject).reduce((result, packageName) => { | ||
if (!packageName.includes('metro')) { | ||
return depsObject; | ||
} | ||
const prevVersion = depsObject[packageName]; | ||
const latestVersion = getLatestVersion(packageName); | ||
if (latestVersion !== prevVersion) { | ||
console.log( | ||
`Updated ${packageName} ${prevVersion} -> ${chalk.cyan(latestVersion)}`, | ||
); | ||
} | ||
return Object.assign(depsObject, {[packageName]: latestVersion}); | ||
}, depsObject); | ||
|
||
return updatedJson; | ||
}; | ||
|
||
const start = new Date().getTime(); | ||
['./package.json', ...glob('./packages/*/package.json')].forEach((pkgPath) => { | ||
const pkg = require(path.join(process.cwd(), pkgPath)); | ||
|
||
const updatedDependency = pkg.dependencies | ||
? Object.assign(pkg, { | ||
dependencies: updateDependencies(pkg.dependencies), | ||
}) | ||
: pkg; | ||
const updatedDevDependency = pkg.devDependencies | ||
? Object.assign(updatedDependency, { | ||
devDependencies: updateDependencies(pkg.devDependencies), | ||
}) | ||
: updatedDependency; | ||
|
||
fs.writeFileSync( | ||
pkgPath, | ||
`${JSON.stringify(updatedDevDependency, null, 2)}\n`, | ||
); | ||
}); | ||
const end = new Date().getTime(); | ||
const ellapsedTime = (end - start) / 1000; | ||
console.log(`✨ Done in ${ellapsedTime}s.`); |
Oops, something went wrong.