1. #!/usr/bin/env node
    
  2. 
    
  3. 'use strict';
    
  4. 
    
  5. const {readFileSync, writeFileSync} = require('fs');
    
  6. const {readJson, writeJson} = require('fs-extra');
    
  7. const {join} = require('path');
    
  8. 
    
  9. const run = async ({cwd, packages, skipPackages, tags}) => {
    
  10.   if (!tags.includes('latest')) {
    
  11.     // Don't update version numbers for alphas.
    
  12.     return;
    
  13.   }
    
  14. 
    
  15.   const nodeModulesPath = join(cwd, 'build/node_modules');
    
  16.   const packagesPath = join(cwd, 'packages');
    
  17. 
    
  18.   // Update package versions and dependencies (in source) to mirror what was published to NPM.
    
  19.   for (let i = 0; i < packages.length; i++) {
    
  20.     const packageName = packages[i];
    
  21.     const publishedPackageJSON = await readJson(
    
  22.       join(nodeModulesPath, packageName, 'package.json')
    
  23.     );
    
  24.     const sourcePackageJSONPath = join(
    
  25.       packagesPath,
    
  26.       packageName,
    
  27.       'package.json'
    
  28.     );
    
  29.     const sourcePackageJSON = await readJson(sourcePackageJSONPath);
    
  30.     sourcePackageJSON.version = publishedPackageJSON.version;
    
  31.     sourcePackageJSON.dependencies = publishedPackageJSON.dependencies;
    
  32.     sourcePackageJSON.peerDependencies = publishedPackageJSON.peerDependencies;
    
  33. 
    
  34.     await writeJson(sourcePackageJSONPath, sourcePackageJSON, {spaces: 2});
    
  35.   }
    
  36. 
    
  37.   // Update the shared React version source file.
    
  38.   // (Unless this release does not include an update to React)
    
  39.   if (!skipPackages.includes('react')) {
    
  40.     const sourceReactVersionPath = join(cwd, 'packages/shared/ReactVersion.js');
    
  41.     const {version} = await readJson(
    
  42.       join(nodeModulesPath, 'react', 'package.json')
    
  43.     );
    
  44.     const sourceReactVersion = readFileSync(
    
  45.       sourceReactVersionPath,
    
  46.       'utf8'
    
  47.     ).replace(/export default '[^']+';/, `export default '${version}';`);
    
  48.     writeFileSync(sourceReactVersionPath, sourceReactVersion);
    
  49.   }
    
  50. };
    
  51. 
    
  52. module.exports = run;