mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-01-12 22:46:30 +08:00
Get graduate working
This commit is contained in:
committed by
Christopher Chedeau
parent
4b4a8a155d
commit
2987cc69b9
@@ -2,8 +2,8 @@
|
||||
"name": "create-react-app-scripts",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"start": "node scripts/start.js local",
|
||||
"build": "node scripts/build.js local",
|
||||
"start": "node scripts/start.js",
|
||||
"build": "node scripts/build.js",
|
||||
"create-react-app": "node global-cli/index.js --scripts-version \"$PWD/`npm pack`\""
|
||||
},
|
||||
"bin": {
|
||||
|
||||
@@ -9,11 +9,14 @@
|
||||
|
||||
process.env.NODE_ENV = 'production';
|
||||
|
||||
var path = require('path');
|
||||
var spawnSync = require('child_process').spawnSync;
|
||||
var webpack = require('webpack');
|
||||
var config = require('../webpack.config.prod');
|
||||
|
||||
var relative = process.argv[2] === 'local' ? '.' : '../..';
|
||||
var isInNodeModules = 'node_modules' ===
|
||||
path.basename(path.resolve(path.join(__dirname, '..', '..')));
|
||||
var relative = isInNodeModules ? '../..' : '.';
|
||||
spawnSync('rm', ['-rf', relative + '/build']);
|
||||
|
||||
webpack(config).run(function(err, stats) {
|
||||
|
||||
@@ -8,26 +8,28 @@
|
||||
*/
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
console.log('Extracting scripts...');
|
||||
console.log();
|
||||
|
||||
var hostPath = __dirname;
|
||||
var selfPath = hostPath + '/node_modules/create-react-app-scripts';
|
||||
var selfPath = path.join(__dirname, '..');
|
||||
var hostPath = path.join(selfPath, '..', '..');
|
||||
|
||||
var files = [
|
||||
'scripts',
|
||||
'.webpack.config.dev.js',
|
||||
'.webpack.config.prod.js',
|
||||
'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)) {
|
||||
if (fs.existsSync(path.join(hostPath, file))) {
|
||||
console.error(
|
||||
'`' + file + '` already exists on your app folder, we cannot ' +
|
||||
'continue as you would lose all the changes in that file.',
|
||||
'`' + file + '` already exists in your app folder. We cannot ' +
|
||||
'continue as you would lose all the changes in that file or directory. ' +
|
||||
'Please delete it (maybe make a copy for backup) and run this ' +
|
||||
'command again.'
|
||||
);
|
||||
@@ -37,9 +39,38 @@ files.forEach(function(file) {
|
||||
|
||||
// Move the files over
|
||||
files.forEach(function(file) {
|
||||
fs.renameSync(selfPath + '/' + file, hostPath + '/' + file);
|
||||
console.log('Moving ' + file + ' to ' + hostPath);
|
||||
fs.renameSync(path.join(selfPath, file), path.join(hostPath, file));
|
||||
});
|
||||
|
||||
var hostPackage = require(hostPath + '/package.json');
|
||||
// These are unnecessary after graduation
|
||||
fs.unlinkSync(path.join(hostPath, 'scripts', 'init.js'));
|
||||
fs.unlinkSync(path.join(hostPath, 'scripts', 'graduate.js'));
|
||||
|
||||
console.log();
|
||||
|
||||
var selfPackage = require(path.join(selfPath, 'package.json'));
|
||||
var hostPackage = require(path.join(hostPath, 'package.json'));
|
||||
|
||||
console.log('Removing dependency: create-react-app-scripts');
|
||||
delete hostPackage.devDependencies['create-react-app-scripts'];
|
||||
|
||||
Object.keys(selfPackage.dependencies).forEach(function (key) {
|
||||
console.log('Adding dependency: ' + key);
|
||||
hostPackage.devDependencies[key] = selfPackage.dependencies[key];
|
||||
});
|
||||
|
||||
console.log('Updating scripts');
|
||||
Object.keys(hostPackage.scripts).forEach(function (key) {
|
||||
hostPackage.scripts[key] = 'node ./scripts/' + key + '.js'
|
||||
});
|
||||
delete hostPackage.scripts['graduate'];
|
||||
|
||||
console.log('Writing package.json...');
|
||||
fs.writeFileSync(
|
||||
path.join(hostPath, 'package.json'),
|
||||
JSON.stringify(hostPackage, null, 2)
|
||||
);
|
||||
|
||||
console.log();
|
||||
console.log('Done!');
|
||||
|
||||
@@ -8,12 +8,13 @@
|
||||
*/
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
module.exports = function(hostPath, appName) {
|
||||
var selfPath = hostPath + '/node_modules/create-react-app-scripts';
|
||||
var selfPath = path.join(hostPath, 'node_modules', 'create-react-app-scripts');
|
||||
|
||||
var hostPackage = require(hostPath + '/package.json');
|
||||
var selfPackage = require(selfPath + '/package.json');
|
||||
var hostPackage = require(path.join(hostPath, 'package.json'));
|
||||
var selfPackage = require(path.join(selfPath, 'package.json'));
|
||||
|
||||
// Copy over devDependencies
|
||||
hostPackage.dependencies = hostPackage.dependencies || {};
|
||||
@@ -28,12 +29,15 @@ module.exports = function(hostPath, appName) {
|
||||
command + '-react-app';
|
||||
});
|
||||
|
||||
fs.writeFileSync(hostPath + '/package.json', JSON.stringify(hostPackage, null, 2));
|
||||
fs.writeFileSync(
|
||||
path.join(hostPath, 'package.json'),
|
||||
JSON.stringify(hostPackage, null, 2)
|
||||
);
|
||||
|
||||
// TODO: run npm install in hostPath, (not needed for npm 3 if we accept some hackery)
|
||||
|
||||
// Move the src folder
|
||||
fs.renameSync(selfPath + '/src', hostPath + '/src');
|
||||
fs.renameSync(path.join(selfPath, 'src'), path.join(hostPath, 'src'));
|
||||
|
||||
console.log('Success! Created ' + appName + ' at ' + hostPath + '.');
|
||||
console.log();
|
||||
|
||||
@@ -12,7 +12,9 @@ var autoprefixer = require('autoprefixer');
|
||||
var webpack = require('webpack');
|
||||
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
|
||||
var relative = process.argv[2] === 'local' ? '.' : '../..';
|
||||
var isInNodeModules = 'node_modules' ===
|
||||
path.basename(path.resolve(path.join(__dirname, '..')));
|
||||
var relative = isInNodeModules ? '../..' : '.';
|
||||
|
||||
module.exports = {
|
||||
devtool: 'eval',
|
||||
|
||||
@@ -12,7 +12,9 @@ var autoprefixer = require('autoprefixer');
|
||||
var webpack = require('webpack');
|
||||
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
|
||||
var relative = process.argv[2] === 'local' ? '.' : '../..';
|
||||
var isInNodeModules = 'node_modules' ===
|
||||
path.basename(path.resolve(path.join(__dirname, '..')));
|
||||
var relative = isInNodeModules ? '../..' : '.';
|
||||
|
||||
module.exports = {
|
||||
devtool: 'source-map',
|
||||
|
||||
Reference in New Issue
Block a user