Unroll indirection in paths (#191)

This commit is contained in:
Dan Abramov
2016-07-25 22:45:27 +01:00
committed by GitHub
parent d69ee278f7
commit dfecfea6ba
7 changed files with 134 additions and 102 deletions

View File

@@ -11,40 +11,40 @@ var fs = require('fs-extra');
var path = require('path');
var spawn = require('cross-spawn');
module.exports = function(hostPath, appName, verbose, originalDirectory) {
var selfPath = path.join(hostPath, 'node_modules', 'react-scripts');
module.exports = function(appPath, appName, verbose, originalDirectory) {
var ownPath = path.join(appPath, 'node_modules', 'react-scripts');
var hostPackage = require(path.join(hostPath, 'package.json'));
var selfPackage = require(path.join(selfPath, 'package.json'));
var appPackage = require(path.join(appPath, 'package.json'));
var ownPackage = require(path.join(ownPath, 'package.json'));
// Copy over some of the devDependencies
hostPackage.dependencies = hostPackage.dependencies || {};
appPackage.dependencies = appPackage.dependencies || {};
['react', 'react-dom'].forEach(function (key) {
hostPackage.dependencies[key] = selfPackage.devDependencies[key];
appPackage.dependencies[key] = ownPackage.devDependencies[key];
});
// Setup the script rules
hostPackage.scripts = {};
appPackage.scripts = {};
['start', 'build', 'eject'].forEach(function(command) {
hostPackage.scripts[command] = 'react-scripts ' + command;
appPackage.scripts[command] = 'react-scripts ' + command;
});
// explicitly specify ESLint config path for editor plugins
hostPackage.eslintConfig = {
appPackage.eslintConfig = {
extends: './node_modules/react-scripts/config/eslint.js',
};
fs.writeFileSync(
path.join(hostPath, 'package.json'),
JSON.stringify(hostPackage, null, 2)
path.join(appPath, 'package.json'),
JSON.stringify(appPackage, null, 2)
);
// Copy the files for the user
fs.copySync(path.join(selfPath, 'template'), hostPath);
fs.copySync(path.join(ownPath, 'template'), appPath);
// Rename gitignore after the fact to prevent npm from renaming it to .npmignore
// See: https://github.com/npm/npm/issues/1862
fs.move(path.join(hostPath, 'gitignore'), path.join(hostPath, '.gitignore'), []);
fs.move(path.join(appPath, 'gitignore'), path.join(appPath, '.gitignore'), []);
// Run another npm install for react and react-dom
console.log('Installing react and react-dom from npm...');
@@ -65,13 +65,13 @@ module.exports = function(hostPath, appName, verbose, originalDirectory) {
// backward compatibility with old global-cli's.
var cdpath;
if (originalDirectory &&
path.join(originalDirectory, appName) === hostPath) {
path.join(originalDirectory, appName) === appPath) {
cdpath = appName;
} else {
cdpath = hostPath;
cdpath = appPath;
}
console.log('Success! Created ' + appName + ' at ' + hostPath + '.');
console.log('Success! Created ' + appName + ' at ' + appPath + '.');
console.log('Inside that directory, you can run several commands:');
console.log();
console.log(' * npm start: Starts the development server.');