-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update package JSONs automatically after stable release is publish
- Loading branch information
Brian Vaughn
committed
Nov 20, 2018
1 parent
3585929
commit 03182f4
Showing
3 changed files
with
77 additions
and
25 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
50 changes: 50 additions & 0 deletions
50
scripts/release/publish-commands/update-stable-version-numbers.js
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,50 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const {readFileSync, writeFileSync} = require('fs'); | ||
const {readJson, writeJson} = require('fs-extra'); | ||
const {join} = require('path'); | ||
|
||
const run = async ({cwd, packages, tags}) => { | ||
if (!tags.includes('latest')) { | ||
// Don't update version numbers for alphas. | ||
return; | ||
} | ||
|
||
const nodeModulesPath = join(cwd, 'build/node_modules'); | ||
const packagesPath = join(cwd, 'packages'); | ||
|
||
// Update package versions and dependencies (in source) to mirror what was published to NPM. | ||
for (let i = 0; i < packages.length; i++) { | ||
const packageName = packages[i]; | ||
const publishedPackageJSON = await readJson( | ||
join(nodeModulesPath, packageName, 'package.json') | ||
); | ||
const sourcePackageJSONPath = join( | ||
packagesPath, | ||
packageName, | ||
'package.json' | ||
); | ||
const sourcePackageJSON = await readJson(sourcePackageJSONPath); | ||
sourcePackageJSON.version = publishedPackageJSON.version; | ||
sourcePackageJSON.dependencies = publishedPackageJSON.dependencies; | ||
sourcePackageJSON.peerDependencies = publishedPackageJSON.peerDependencies; | ||
|
||
await writeJson(sourcePackageJSONPath, sourcePackageJSON, {spaces: 2}); | ||
} | ||
|
||
// Update the shared React version source file. | ||
const sourceReactVersionPath = join(cwd, 'packages/shared/ReactVersion.js'); | ||
const {version} = await readJson( | ||
join(nodeModulesPath, 'react', 'package.json') | ||
); | ||
const sourceReactVersion = readFileSync( | ||
sourceReactVersionPath, | ||
'utf8' | ||
).replace(/module\.exports = '[^']+';/, `module.exports = '${version}';`); | ||
writeFileSync(sourceReactVersionPath, sourceReactVersion); | ||
}; | ||
|
||
// Run this directly because logPromise would interfere with printing package dependencies. | ||
module.exports = run; |
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