Skip to content

Commit 3d0cb3a

Browse files
djgrantSpaceK33z
authored andcommitted
Modularise scripts (facebook#1433)
* Refactor start script into modules * Move dev server config into config file * Replace eject file whitelist with a "remove-file-on-eject" flag * Move utils into scripts folder (for inclusion in ejection) * Add missed changes * Pass showInstructions as an argument * Fix eject bug * Don't eject babelTransform # Conflicts: # packages/react-cy-scripts/scripts/eject.js # packages/react-cy-scripts/scripts/start.js # packages/react-cy-scripts/utils/createJestConfig.js # packages/react-scripts/scripts/utils/createJestConfig.js # packages/react-scripts/utils/createJestConfig.js
1 parent 151f08f commit 3d0cb3a

File tree

9 files changed

+353
-273
lines changed

9 files changed

+353
-273
lines changed

packages/react-cy-scripts/config/jest/babelTransform.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-file-on-eject
12
/**
23
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
34
*

packages/react-cy-scripts/scripts/eject.js

+30-24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-file-on-eject
12
/**
23
* Copyright (c) 2015-present, Facebook, Inc.
34
* All rights reserved.
@@ -7,13 +8,14 @@
78
* of patent rights can be found in the PATENTS file in the same directory.
89
*/
910

10-
var createJestConfig = require('../utils/createJestConfig');
1111
var fs = require('fs-extra');
1212
var path = require('path');
13-
var paths = require('../config/paths');
14-
var prompt = require('react-cy-dev-utils/prompt');
1513
var spawnSync = require('cross-spawn').sync;
1614
var chalk = require('chalk');
15+
var prompt = require('react-dev-utils/prompt');
16+
var paths = require('../config/paths');
17+
var createJestConfig = require('./utils/createJestConfig');
18+
1719
var green = chalk.green;
1820
var cyan = chalk.cyan;
1921

@@ -45,44 +47,48 @@ prompt(
4547

4648
var folders = [
4749
'config',
48-
path.join('config', 'jest'),
49-
'scripts'
50+
'config/jest',
51+
'scripts',
52+
'scripts/utils',
5053
];
5154

52-
var files = [
53-
path.join('config', 'env.js'),
54-
path.join('config', 'paths.js'),
55-
path.join('config', 'polyfills.js'),
56-
path.join('config', 'webpack.config.dev.js'),
57-
path.join('config', 'webpack.config.prod.js'),
58-
path.join('config', 'jest', 'cssTransform.js'),
59-
path.join('config', 'jest', 'fileTransform.js'),
60-
path.join('scripts', 'build.js'),
61-
path.join('scripts', 'start.js'),
62-
path.join('scripts', 'test.js')
63-
];
55+
// Make shallow array of files paths
56+
var files = folders.reduce(function (files, folder) {
57+
return files.concat(
58+
fs.readdirSync(path.join(ownPath, folder))
59+
// set full path
60+
.map(file => path.join(ownPath, folder, file))
61+
// omit dirs from file list
62+
.filter(file => fs.lstatSync(file).isFile())
63+
);
64+
}, []);
6465

6566
// Ensure that the app folder is clean and we won't override any files
6667
folders.forEach(verifyAbsent);
6768
files.forEach(verifyAbsent);
6869

69-
// Copy the files over
70+
console.log();
71+
console.log(cyan('Copying files into ' + appPath));
72+
7073
folders.forEach(function(folder) {
7174
fs.mkdirSync(path.join(appPath, folder))
7275
});
7376

74-
console.log();
75-
console.log(cyan('Copying files into ' + appPath));
7677
files.forEach(function(file) {
77-
console.log(' Adding ' + cyan(file) + ' to the project');
78-
var content = fs
79-
.readFileSync(path.join(ownPath, file), 'utf8')
78+
var content = fs.readFileSync(file, 'utf8');
79+
80+
// Skip flagged files
81+
if (content.match(/\/\/ @remove-file-on-eject/)) {
82+
return;
83+
}
84+
content = content
8085
// Remove dead code from .js files on eject
8186
.replace(/\/\/ @remove-on-eject-begin([\s\S]*?)\/\/ @remove-on-eject-end/mg, '')
8287
// Remove dead code from .applescript files on eject
8388
.replace(/-- @remove-on-eject-begin([\s\S]*?)-- @remove-on-eject-end/mg, '')
8489
.trim() + '\n';
85-
fs.writeFileSync(path.join(appPath, file), content);
90+
console.log(' Adding ' + cyan(file.replace(ownPath, '')) + ' to the project');
91+
fs.writeFileSync(file.replace(ownPath, appPath), content);
8692
});
8793
console.log();
8894

packages/react-cy-scripts/scripts/init.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-file-on-eject
12
/**
23
* Copyright (c) 2015-present, Facebook, Inc.
34
* All rights reserved.

0 commit comments

Comments
 (0)