Skip to content

Commit

Permalink
Update package JSONs automatically after stable release is publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Nov 20, 2018
1 parent 3585929 commit 03182f4
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 25 deletions.
50 changes: 25 additions & 25 deletions scripts/release/publish-commands/print-follow-up-instructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,39 @@ const run = async ({cwd, packages, tags}) => {
);

if (tags.includes('latest')) {
console.log();
console.log(
theme.header`\nLocal versions may require updating after a stable release. Please verify the following files:`
theme.header`Please review and commit all local, staged changes.`
);

console.log();
console.log('Version numbers have been updated in the following files:');
for (let i = 0; i < packages.length; i++) {
const packageName = packages[i];
console.log(theme.path`• packages/%s/package.json`, packageName);
}
console.log(theme.path`• packages/shared/ReactVersion.js`);

console.log();
if (environment === 'ci') {
console.log('Auto-generated error codes have been updated as well:');
console.log(theme.path`• scripts/error-codes/codes.json`);
} else {
console.log(
theme`{caution The release that was just published was created locally.} ` +
theme`Because of this, you will need to update the generated ` +
theme`{path scripts/error-codes/codes.json} file manually:`
);
console.log(theme` {command git checkout} {version ${commit}}`);
console.log(theme` {command yarn build -- --extract-errors}`);
}
}

console.log();
console.log(
theme`{header Don't forget to update and commit the }{path CHANGELOG}`
);

// Prompt the release engineer to tag the commit and update the CHANGELOG.
// (The script could automatically do this, but this seems safer.)
console.log();
Expand All @@ -49,31 +72,8 @@ const run = async ({cwd, packages, tags}) => {
);
console.log(theme.command` git push origin --tags`);

if (tags.includes('latest')) {
console.log();
console.log(
theme`{header Don't forget to commit the generated }{path scripts/error-codes/codes.json}`
);
if (environment === 'ci') {
console.log(
`This file has been updated locally. Please review it before committing.`
);
} else {
console.log(
`The release that was just published was created locally. ` +
`Because of this, you will need to update error codes manually with the following commands:`
);
console.log(theme` {command git checkout} {version ${commit}}`);
console.log(theme` {command yarn build -- --extract-errors}`);
}
}

console.log();
console.log(
theme`{header Don't forget to update and commit the }{path CHANGELOG}`
);
console.log();
console.log(theme.header`Then fill in the release on GitHub:`);
console.log(theme.header`Lastly, please fill in the release on GitHub:`);
console.log(
theme.link`https://github.com/facebook/react/releases/tag/v%s`,
version
Expand Down
50 changes: 50 additions & 0 deletions scripts/release/publish-commands/update-stable-version-numbers.js
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;
2 changes: 2 additions & 0 deletions scripts/release/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const parseParams = require('./publish-commands/parse-params');
const printFollowUpInstructions = require('./publish-commands/print-follow-up-instructions');
const promptForOTP = require('./publish-commands/prompt-for-otp');
const publishToNPM = require('./publish-commands/publish-to-npm');
const updateStableVersionNumbers = require('./publish-commands/update-stable-version-numbers');
const validateTags = require('./publish-commands/validate-tags');

const run = async () => {
Expand All @@ -26,6 +27,7 @@ const run = async () => {
const otp = await promptForOTP(params);
await publishToNPM(params, otp);
await downloadErrorCodesFromCI(params);
await updateStableVersionNumbers(params);
await printFollowUpInstructions(params);
} catch (error) {
handleError(error);
Expand Down

0 comments on commit 03182f4

Please sign in to comment.