Commit 2f62ff84 authored by Dan Abramov's avatar Dan Abramov
Browse files

Clarify some of the comments

parent 6c8713b7
No related merge requests found
Showing with 30 additions and 37 deletions
+30 -37
...@@ -5,14 +5,15 @@ ...@@ -5,14 +5,15 @@
# LICENSE file in the root directory of this source tree. An additional grant # LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory. # of patent rights can be found in the PATENTS file in the same directory.
# In success case, the only output to stdout is the packagename, # This script cleans up the code from blocks only used during local development.
# which might be used by the caller of `tasks/clean_pack.sh` # We call this as part of the `release.sh` script.
# On success, the only output to stdout is the package name.
# Start even if run from root directory # Start even if run from root directory
cd "$(dirname "$0")" cd "$(dirname "$0")"
# print error messages to stderr # Print error messages to stderr.
# the cleanup function is optionally defined in caller script # The calling script may then handle them.
function handle_error { function handle_error {
echo "$(basename $0): \033[31mERROR!\033[m An error was encountered executing \033[36mline $1\033[m." 1>&2; echo "$(basename $0): \033[31mERROR!\033[m An error was encountered executing \033[36mline $1\033[m." 1>&2;
cleanup cleanup
...@@ -28,8 +29,8 @@ function handle_exit { ...@@ -28,8 +29,8 @@ function handle_exit {
function cleanup { function cleanup {
cd $initial_path cd $initial_path
# remove Jest snap test file from local dev project if exists # Uncomment when snapshot testing is enabled by default:
rm ../template/src/__tests__/__snapshots__/App-test.js.snap # rm ../template/src/__snapshots__/App.test.js.snap
rm -rf ../$clean_path rm -rf ../$clean_path
} }
...@@ -39,29 +40,23 @@ trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR ...@@ -39,29 +40,23 @@ trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR
# Cleanup before exit on any termination signal # Cleanup before exit on any termination signal
trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP
# `tasks/clean_pack.sh` the two directories to make sure they are valid npm modules
initial_path=$PWD
# Go to root # Go to root
initial_path=$PWD
cd .. cd ..
# create a temporary clean folder that contains production only code
# do not overwrite any files in the current folder # Create a temporary clean folder that contains production-only code.
# Do not overwrite any files in the current folder.
clean_path=`mktemp -d clean_XXXX` clean_path=`mktemp -d clean_XXXX`
# copy files to folder .clean-pack # Copy some of the project files to the temporary folder.
# `npm publish` looks package.json, if it has a files field, only pack listed files # Exclude folders that definitely won’t be part of the package from processing.
# follwoing folders, although not listed in the files field, are not copied # We will strip the dev-only code there, and then copy files back.
# - .git : contains lot of small files
# - $clean_path : the destination folder
# - node_modules : contains lots of small files
# - build : .gitignored folder used in local development
rsync -av --exclude='.git' --exclude=$clean_path\ rsync -av --exclude='.git' --exclude=$clean_path\
--exclude='node_modules' --exclude='build'\ --exclude='node_modules' --exclude='build'\
'./' $clean_path >/dev/null './' $clean_path >/dev/null
# Now remove all the code relevant to development of Create React App.
cd $clean_path cd $clean_path
# remove dev-only code
files="$(find -L . -name "*.js" -type f)" files="$(find -L . -name "*.js" -type f)"
for file in $files; do for file in $files; do
sed -i.bak '/\/\/ @remove-on-publish-begin/,/\/\/ @remove-on-publish-end/d' $file sed -i.bak '/\/\/ @remove-on-publish-begin/,/\/\/ @remove-on-publish-end/d' $file
...@@ -71,8 +66,10 @@ done ...@@ -71,8 +66,10 @@ done
# Pack! # Pack!
packname=`npm pack` packname=`npm pack`
# copy package to current folder # Now we can copy the package back.
cd .. cd ..
cp -f $clean_path/$packname ./ cp -f $clean_path/$packname ./
cleanup cleanup
# Output the package name so `release.sh` can pick it up.
echo $packname echo $packname
...@@ -81,7 +81,8 @@ cd global-cli ...@@ -81,7 +81,8 @@ cd global-cli
npm install npm install
cli_path=$PWD/`npm pack` cli_path=$PWD/`npm pack`
# Install the cli in a temporary location ( http://unix.stackexchange.com/a/84980 ) # Install the CLI in a temporary location
# http://unix.stackexchange.com/a/84980
temp_cli_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_cli_path'` temp_cli_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_cli_path'`
cd $temp_cli_path cd $temp_cli_path
npm install $cli_path npm install $cli_path
......
...@@ -31,24 +31,19 @@ if [ -n "$(git status --porcelain)" ]; then ...@@ -31,24 +31,19 @@ if [ -n "$(git status --porcelain)" ]; then
exit 1; exit 1;
fi fi
# create a temporary clean folder that contains production only code # Create a temporary clean folder that contains production only code.
# do not overwrite any files in the current folder # Do not overwrite any files in the current folder.
clean_path=`mktemp -d clean_XXXX` clean_path=`mktemp -d clean_XXXX`
# copy files to folder .clean-pack # Copy some of the project files to the temporary folder.
# `npm publish` looks package.json, if it has a files field, only pack listed files # Exclude folders that definitely won’t be part of the package from processing.
# follwoing folders, although not listed in the files field, are not copied # We will strip the dev-only code there, and then copy files back.
# - .git : contains lot of small files
# - $clean_path : the destination folder
# - node_modules : contains lots of small files
# - build : .gitignored folder used in local development
rsync -av --exclude='.git' --exclude=$clean_path\ rsync -av --exclude='.git' --exclude=$clean_path\
--exclude='node_modules' --exclude='build'\ --exclude='node_modules' --exclude='build'\
'./' '$clean_path' >/dev/null './' '$clean_path' >/dev/null
# Now remove all the code relevant to development of Create React App.
cd $clean_path cd $clean_path
# remove dev-only code
files="$(find -L . -name "*.js" -type f)" files="$(find -L . -name "*.js" -type f)"
for file in $files; do for file in $files; do
sed -i.bak '/\/\/ @remove-on-publish-begin/,/\/\/ @remove-on-publish-end/d' $file sed -i.bak '/\/\/ @remove-on-publish-begin/,/\/\/ @remove-on-publish-end/d' $file
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment