|
| 1 | +// @remove-file-on-eject |
1 | 2 | /**
|
2 | 3 | * Copyright (c) 2015-present, Facebook, Inc.
|
3 | 4 | * All rights reserved.
|
|
7 | 8 | * of patent rights can be found in the PATENTS file in the same directory.
|
8 | 9 | */
|
9 | 10 |
|
10 |
| -var createJestConfig = require('../utils/createJestConfig'); |
11 | 11 | var fs = require('fs-extra');
|
12 | 12 | var path = require('path');
|
13 |
| -var paths = require('../config/paths'); |
14 |
| -var prompt = require('react-dev-utils/prompt'); |
15 | 13 | var spawnSync = require('cross-spawn').sync;
|
16 | 14 | 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 | + |
17 | 19 | var green = chalk.green;
|
18 | 20 | var cyan = chalk.cyan;
|
19 | 21 |
|
@@ -45,44 +47,48 @@ prompt(
|
45 | 47 |
|
46 | 48 | var folders = [
|
47 | 49 | 'config',
|
48 |
| - path.join('config', 'jest'), |
49 |
| - 'scripts' |
| 50 | + 'config/jest', |
| 51 | + 'scripts', |
| 52 | + 'scripts/utils', |
50 | 53 | ];
|
51 | 54 |
|
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 | + }, []); |
64 | 65 |
|
65 | 66 | // Ensure that the app folder is clean and we won't override any files
|
66 | 67 | folders.forEach(verifyAbsent);
|
67 | 68 | files.forEach(verifyAbsent);
|
68 | 69 |
|
69 |
| - // Copy the files over |
| 70 | + console.log(); |
| 71 | + console.log(cyan('Copying files into ' + appPath)); |
| 72 | + |
70 | 73 | folders.forEach(function(folder) {
|
71 | 74 | fs.mkdirSync(path.join(appPath, folder))
|
72 | 75 | });
|
73 | 76 |
|
74 |
| - console.log(); |
75 |
| - console.log(cyan('Copying files into ' + appPath)); |
76 | 77 | 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 |
80 | 85 | // Remove dead code from .js files on eject
|
81 | 86 | .replace(/\/\/ @remove-on-eject-begin([\s\S]*?)\/\/ @remove-on-eject-end/mg, '')
|
82 | 87 | // Remove dead code from .applescript files on eject
|
83 | 88 | .replace(/-- @remove-on-eject-begin([\s\S]*?)-- @remove-on-eject-end/mg, '')
|
84 | 89 | .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); |
86 | 92 | });
|
87 | 93 | console.log();
|
88 | 94 |
|
|
0 commit comments