@@ -11,9 +11,9 @@ cd "$(dirname "$0")"
11
11
12
12
function cleanup {
13
13
echo ' Cleaning up.'
14
- cd $initial_path
14
+ cd $root_path
15
15
# Uncomment when snapshot testing is enabled by default:
16
- # rm .. /template/src/__snapshots__/App.test.js.snap
16
+ # rm ./template/src/__snapshots__/App.test.js.snap
17
17
rm -rf $temp_cli_path $temp_app_path
18
18
}
19
19
@@ -40,20 +40,36 @@ trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP
40
40
# Echo every command being executed
41
41
set -x
42
42
43
- # `tasks/clean_pack.sh` the two directories to make sure they are valid npm modules
44
- initial_path=$PWD
45
-
43
+ # Go to root
46
44
cd ..
45
+ root_path=$PWD
46
+
47
+ # Create a temporary clean folder that contains production only code.
48
+ # Do not overwrite any files in the current folder.
49
+ clean_path=` mktemp -d 2> /dev/null || mktemp -d -t ' clean_path' `
50
+
51
+ # Copy some of the project files to the temporary folder.
52
+ # Exclude folders that definitely won’t be part of the package from processing.
53
+ # We will strip the dev-only code there, `npm pack`, and copy the package back.
54
+ rsync -av --exclude=' .git' --exclude=$clean_path \
55
+ --exclude=' node_modules' --exclude=' build' \
56
+ ' ./' $clean_path > /dev/null
57
+ cd $clean_path
58
+
59
+ # Now remove all the code relevant to development of Create React App.
60
+ files=" $( find -L . -name " *.js" -type f) "
61
+ for file in $files ; do
62
+ sed -i.bak ' /\/\/ @remove-on-publish-begin/,/\/\/ @remove-on-publish-end/d' $file
63
+ rm $file .bak
64
+ done
47
65
48
66
# A hacky way to avoid bundling dependencies.
49
67
# Packing with them enabled takes too much memory, and Travis crashes.
50
- # End to end script is meant to run on Travis so it's not a big deal.
51
- # If you run it locally, you'll need to `git checkout -- package.json`.
52
68
perl -i -p0e ' s/bundledDependencies.*?]/bundledDependencies": []/s' package.json
53
69
54
70
# Pack react-scripts
55
71
npm install
56
- scripts_path=$PWD / ` tasks/clean_pack.sh `
72
+ scripts_path=$clean_path / ` npm pack `
57
73
58
74
# Lint
59
75
./node_modules/.bin/eslint --ignore-path .gitignore ./
0 commit comments