random fixes + license

This commit is contained in:
Christopher Chedeau
2016-07-16 18:57:36 -07:00
parent 760d32e891
commit 614b2dbec4
8 changed files with 116 additions and 100 deletions

View File

@@ -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 <alternative create-react-app-scripts package> - 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 <alternative package>
* 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

View File

@@ -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;

View File

@@ -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!');

45
scripts/graduate.js Normal file
View File

@@ -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!');

View File

@@ -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));

View File

@@ -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');

View File

@@ -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');

View File

@@ -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');