diff --git a/global-cli/index.js b/global-cli/index.js index 2c91e75b..e1900817 100644 --- a/global-cli/index.js +++ b/global-cli/index.js @@ -9,9 +9,9 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// /!\ DO NOT MODIFY THIS FILE /!\ -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// /!\ DO NOT MODIFY THIS FILE /!\ +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // create-react-app is installed globally on people's computers. This means // that it is extremely difficult to have them upgrade the version and @@ -21,17 +21,17 @@ // The only job of create-react-app is to init the repository and then // forward all the commands to the local version of create-react-app. // -// If you need to add a new command, please add it to local-cli/. +// If you need to add a new command, please add it to the scripts/ folder. // // The only reason to modify this file is to add more warnings and -// troubleshooting information for the `react init` command. +// troubleshooting information for the `create-react-app` command. // // Do not make breaking changes! We absolutely don't want to have to // tell people to update their global version of create-react-app. // -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// /!\ DO NOT MODIFY THIS FILE /!\ -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// /!\ DO NOT MODIFY THIS FILE /!\ +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'use strict'; @@ -40,18 +40,18 @@ var path = require('path'); var spawn = require('child_process').spawn; var chalk = require('chalk'); var semver = require('semver'); -/** - * Used arguments: - * -v --version - to print current version of create-react-app and create-react-app-scripts dependency - * --verbose - to print logs while init - * --scripts-version - override default (https://registry.npmjs.org/create-react-app-scripts@latest), - * package to install, examples: - * - "0.22.0-rc1" - A new app will be created using a specific version of React CLI from npm repo - * - "https://registry.npmjs.org/create-react-app-scripts/-/create-react-app-scripts-0.20.0.tgz" - a .tgz archive from any npm repo - * - "/Users/home/create-react-app/create-react-app-scripts-0.22.0.tgz" - for package prepared with `npm pack`, useful for e2e tests - */ var argv = require('minimist')(process.argv.slice(2)); +/** + * Arguments: + * --version - to print current version + * --verbose - to print logs while init + * --scripts-version + * Example of valid values: + * - a specific npm version: "0.22.0-rc1" + * - a .tgz archive from any npm repo: "https://registry.npmjs.org/create-react-app-scripts/-/create-react-app-scripts-0.20.0.tgz" + * - a package prepared with `npm pack`: "/Users/home/vjeux/create-react-app/create-react-app-scripts-0.22.0.tgz" + */ var commands = argv._; if (commands.length === 0) { console.error( @@ -60,8 +60,8 @@ if (commands.length === 0) { process.exit(1); } -if (argv.v || argv.version) { - console.log('create-react-app: ' + require('./package.json').version); +if (argv.version) { + console.log('create-react-app version: ' + require('./package.json').version); process.exit(); } @@ -70,7 +70,7 @@ createApp(commands[0], argv.verbose, argv['scripts-version']); function createApp(name, verbose, version) { if (fs.existsSync(name)) { console.log('Directory `' + name + '` already exists. Aborting.'); - process.exit(); + process.exit(1); } var root = path.resolve(name); @@ -146,11 +146,12 @@ function checkNodeVersion() { if (!packageJson.engines || !packageJson.engines.node) { return; } + if (!semver.satisfies(process.version, packageJson.engines.node)) { console.error( chalk.red( - 'You are currently running Node %s but React CLI requires %s. ' + - 'Please use a supported version of Node.\n' + 'You are currently running Node %s but create-react-app requires %s.' + + ' Please use a supported version of Node.\n' ), process.version, packageJson.engines.node diff --git a/scripts/build.js b/scripts/build.js index 0799a6b9..93b08992 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -1,3 +1,12 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + process.env.NODE_ENV = 'production'; var spawnSync = require('child_process').spawnSync; diff --git a/scripts/export-scripts.js b/scripts/export-scripts.js deleted file mode 100644 index 02f26471..00000000 --- a/scripts/export-scripts.js +++ /dev/null @@ -1,76 +0,0 @@ -var fs = require('fs'); - -if (!( - process.argv[2] === '--i-know-what-im-doing' && - process.argv[3] === '--there-is-no-going-back' -)) { - console.log( - 'This command will copy all the scripts and configurations', - 'from the create-react-app command to your directory.', - 'You will be able to tweak and extend them but be aware that', - 'this is a one way operation, there is no going back' - ); - console.log( - 'If you want to run this, please type the following command' - ); - console.log( - ' npm run export-scripts --i-know-what-im-doing --there-is-no-going-back' - ); - process.exit(1); -} - -console.log('Extracting scripts...'); - -var hostPath = __dirname; -var selfPath = hostPath + '/node_modules/create-react-app-scripts'; - -var files = [ - 'scripts', - '.webpack.config.dev.js', - '.webpack.config.prod.js', - '.babelrc', - '.eslintrc', -]; - -// Ensure that the host folder is clean and we won't override any files -files.forEach(function(file) { - if (fs.existsSync(hostPath + '/' + file)) { - console.error( - '`' + file + '` already exists on your app folder, we cannot ' + - 'continue as you would lose all the changes.', - 'Please delete it (maybe make a copy for backup) and run this ' + - 'command again.' - ); - process.exit(1); - } -}); - -// Move the files over -files.forEach(function(file) { - fs.renameSync(selfPath + '/' + file, hostPath + '/' + file); -}); - -var hostPackage = require(hostPath + '/package.json'); -var selfPackage = require(selfPath + '/package.json'); - -// Copy over dependencies -hostPackage.dependencies = hostPackage.dependencies || {}; -for (var key in selfPackage.dependencies) { - hostPackage.devDependencies[key] = selfPackage.dependencies[key]; -} - -delete hostPackage.dependencies['create-react-app-scripts']; - -// Update the script rules -['start', 'build'].forEach(function(command) { - hostPackage.scripts[command] = 'node scripts/' + command + '.js local'; -}); -delete hostPackage['export-scripts']; - -fs.writeFileSync(hostPath + '/package.json', JSON.stringify(hostPackage, null, 2)); - -// TODO: run npm install in hostPath - -// Move the src folder - -console.log('Done!'); diff --git a/scripts/graduate.js b/scripts/graduate.js new file mode 100644 index 00000000..5d646a24 --- /dev/null +++ b/scripts/graduate.js @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +var fs = require('fs'); + +console.log('Extracting scripts...'); + +var hostPath = __dirname; +var selfPath = hostPath + '/node_modules/create-react-app-scripts'; + +var files = [ + 'scripts', + '.webpack.config.dev.js', + '.webpack.config.prod.js', + '.babelrc', + '.eslintrc', +]; + +// Ensure that the host folder is clean and we won't override any files +files.forEach(function(file) { + if (fs.existsSync(hostPath + '/' + file)) { + console.error( + '`' + file + '` already exists on your app folder, we cannot ' + + 'continue as you would lose all the changes in that file.', + 'Please delete it (maybe make a copy for backup) and run this ' + + 'command again.' + ); + process.exit(1); + } +}); + +// Move the files over +files.forEach(function(file) { + fs.renameSync(selfPath + '/' + file, hostPath + '/' + file); +}); + +var hostPackage = require(hostPath + '/package.json'); + +console.log('Done!'); diff --git a/scripts/init.js b/scripts/init.js index c022af68..70e50a89 100644 --- a/scripts/init.js +++ b/scripts/init.js @@ -1,3 +1,12 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + var fs = require('fs'); module.exports = function(hostPath, appName) { @@ -15,7 +24,8 @@ module.exports = function(hostPath, appName) { // Setup the script rules hostPackage.scripts = {}; ['start', 'build'].forEach(function(command) { - hostPackage.scripts[command] = 'node node_modules/create-react-app-scripts/scripts/' + command + '.js'; + hostPackage.scripts[command] = + 'node node_modules/create-react-app-scripts/scripts/' + command + '.js'; }); fs.writeFileSync(hostPath + '/package.json', JSON.stringify(hostPackage, null, 2)); diff --git a/scripts/start.js b/scripts/start.js index 55ac226a..55a4f854 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -1,3 +1,12 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + process.env.NODE_ENV = 'development'; var webpack = require('webpack'); diff --git a/webpack.config.dev.js b/webpack.config.dev.js index 9dd26773..e9b8a7f5 100644 --- a/webpack.config.dev.js +++ b/webpack.config.dev.js @@ -1,3 +1,12 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + var path = require('path'); var autoprefixer = require('autoprefixer'); var webpack = require('webpack'); diff --git a/webpack.config.prod.js b/webpack.config.prod.js index 67fff0cf..20b5d7a2 100644 --- a/webpack.config.prod.js +++ b/webpack.config.prod.js @@ -1,3 +1,12 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + var path = require('path'); var autoprefixer = require('autoprefixer'); var webpack = require('webpack');