55# LICENSE file in the root directory of this source tree. An additional grant
66# of patent rights can be found in the PATENTS file in the same directory.
77
8- # In success case, the only output to stdout is the packagename,
9- # which might be used by the caller of `tasks/clean_pack.sh`
8+ # This script cleans up the code from blocks only used during local development.
9+ # We call this as part of the `release.sh` script.
10+ # On success, the only output to stdout is the package name.
1011
1112# Start even if run from root directory
1213cd " $( dirname " $0 " ) "
1314
14- # print error messages to stderr
15- # the cleanup function is optionally defined in caller script
15+ # Print error messages to stderr.
16+ # The calling script may then handle them.
1617function handle_error {
1718 echo " $( basename $0 ) : \033[31mERROR!\033[m An error was encountered executing \033[36mline $1 \033[m." 1>&2 ;
1819 cleanup
@@ -28,8 +29,8 @@ function handle_exit {
2829
2930function cleanup {
3031 cd $initial_path
31- # remove Jest snap test file from local dev project if exists
32- rm ../template/src/__tests__/ __snapshots__/App- test.js.snap
32+ # Uncomment when snapshot testing is enabled by default:
33+ # rm ../template/src/__snapshots__/App. test.js.snap
3334 rm -rf ../$clean_path
3435}
3536
@@ -39,29 +40,23 @@ trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR
3940# Cleanup before exit on any termination signal
4041trap ' set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP
4142
42- # `tasks/clean_pack.sh` the two directories to make sure they are valid npm modules
43- initial_path=$PWD
44-
4543# Go to root
44+ initial_path=$PWD
4645cd ..
47- # create a temporary clean folder that contains production only code
48- # do not overwrite any files in the current folder
46+
47+ # Create a temporary clean folder that contains production-only code.
48+ # Do not overwrite any files in the current folder.
4949clean_path=` mktemp -d clean_XXXX`
5050
51- # copy files to folder .clean-pack
52- # `npm publish` looks package.json, if it has a files field, only pack listed files
53- # follwoing folders, although not listed in the files field, are not copied
54- # - .git : contains lot of small files
55- # - $clean_path : the destination folder
56- # - node_modules : contains lots of small files
57- # - build : .gitignored folder used in local development
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, and then copy files back.
5854rsync -av --exclude=' .git' --exclude=$clean_path \
59- --exclude=' node_modules' --exclude=' build' \
60- ' ./' $clean_path > /dev/null
55+ --exclude=' node_modules' --exclude=' build' \
56+ ' ./' $clean_path > /dev/null
6157
58+ # Now remove all the code relevant to development of Create React App.
6259cd $clean_path
63-
64- # remove dev-only code
6560files=" $( find -L . -name " *.js" -type f) "
6661for file in $files ; do
6762 sed -i.bak ' /\/\/ @remove-on-publish-begin/,/\/\/ @remove-on-publish-end/d' $file
7166# Pack!
7267packname=` npm pack`
7368
74- # copy package to current folder
69+ # Now we can copy the package back.
7570cd ..
7671cp -f $clean_path /$packname ./
7772cleanup
73+
74+ # Output the package name so `release.sh` can pick it up.
7875echo $packname
0 commit comments