5
5
# LICENSE file in the root directory of this source tree. An additional grant
6
6
# of patent rights can be found in the PATENTS file in the same directory.
7
7
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.
10
11
11
12
# Start even if run from root directory
12
13
cd " $( dirname " $0 " ) "
13
14
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.
16
17
function handle_error {
17
18
echo " $( basename $0 ) : \033[31mERROR!\033[m An error was encountered executing \033[36mline $1 \033[m." 1>&2 ;
18
19
cleanup
@@ -28,8 +29,8 @@ function handle_exit {
28
29
29
30
function cleanup {
30
31
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
33
34
rm -rf ../$clean_path
34
35
}
35
36
@@ -39,29 +40,23 @@ trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR
39
40
# Cleanup before exit on any termination signal
40
41
trap ' set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP
41
42
42
- # `tasks/clean_pack.sh` the two directories to make sure they are valid npm modules
43
- initial_path=$PWD
44
-
45
43
# Go to root
44
+ initial_path=$PWD
46
45
cd ..
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.
49
49
clean_path=` mktemp -d clean_XXXX`
50
50
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.
58
54
rsync -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
61
57
58
+ # Now remove all the code relevant to development of Create React App.
62
59
cd $clean_path
63
-
64
- # remove dev-only code
65
60
files=" $( find -L . -name " *.js" -type f) "
66
61
for file in $files ; do
67
62
sed -i.bak ' /\/\/ @remove-on-publish-begin/,/\/\/ @remove-on-publish-end/d' $file
71
66
# Pack!
72
67
packname=` npm pack`
73
68
74
- # copy package to current folder
69
+ # Now we can copy the package back.
75
70
cd ..
76
71
cp -f $clean_path /$packname ./
77
72
cleanup
73
+
74
+ # Output the package name so `release.sh` can pick it up.
78
75
echo $packname
0 commit comments