@@ -6,6 +6,7 @@ const {exec} = require('child-process-promise');
66const chalk = require ( 'chalk' ) ;
77const { join} = require ( 'path' ) ;
88const semver = require ( 'semver' ) ;
9+ const yargs = require ( 'yargs' ) ;
910const fs = require ( 'fs' ) ;
1011
1112const INSTALL_PACKAGES = [ 'react-dom' , 'react' , 'react-test-renderer' ] ;
@@ -16,7 +17,10 @@ const ROOT_PATH = join(__dirname, '..', '..');
1617const buildPath = join ( ROOT_PATH , `build` , 'oss-experimental' ) ;
1718const regressionBuildPath = join ( ROOT_PATH , REGRESSION_FOLDER ) ;
1819
20+ const argv = yargs ( process . argv . slice ( 2 ) ) . argv ;
21+
1922const version = process . argv [ 2 ] ;
23+ const shouldReplaceBuild = ! ! argv . replaceBuild ;
2024
2125async function downloadRegressionBuild ( ) {
2226 console . log ( chalk . bold . white ( `Downloading React v${ version } \n` ) ) ;
@@ -39,6 +43,12 @@ async function downloadRegressionBuild() {
3943 `npm install --prefix ${ REGRESSION_FOLDER } ${ downloadPackagesStr } `
4044 ) ;
4145
46+ // If we shouldn't replace the build folder, we can stop here now
47+ // before we modify anything
48+ if ( ! shouldReplaceBuild ) {
49+ return ;
50+ }
51+
4252 // Remove all the packages that we downloaded in the original build folder
4353 // so we can move the modules from the regression build over
4454 const removePackagesStr = INSTALL_PACKAGES . reduce (
@@ -102,12 +112,20 @@ async function downloadRegressionBuild() {
102112
103113async function main ( ) {
104114 try {
115+ if ( ! version ) {
116+ console . log ( chalk . red ( 'Must specify React version to download' ) ) ;
117+ return ;
118+ }
105119 await downloadRegressionBuild ( ) ;
106120 } catch ( e ) {
107121 console . log ( chalk . red ( e ) ) ;
108122 } finally {
109- console . log ( chalk . bold . white ( `Removing regression build` ) ) ;
110- await exec ( `rm -r ${ regressionBuildPath } ` ) ;
123+ // We shouldn't remove the regression-build folder unless we're using
124+ // it to replace the build folder
125+ if ( shouldReplaceBuild ) {
126+ console . log ( chalk . bold . white ( `Removing regression build` ) ) ;
127+ await exec ( `rm -r ${ regressionBuildPath } ` ) ;
128+ }
111129 }
112130}
113131
0 commit comments