Skip to content

Instantly share code, notes, and snippets.

@thomd
Created January 9, 2018 21:18
Show Gist options
  • Select an option

  • Save thomd/031d94c2cabc479507a8d07dafe79d46 to your computer and use it in GitHub Desktop.

Select an option

Save thomd/031d94c2cabc479507a8d07dafe79d46 to your computer and use it in GitHub Desktop.
Test lifecycle of npm scripts
#!/usr/bin/env bash
# npm help 7 npm-scripts
scripts=(prepublish prepare prepublishOnly prepack postpack publish postpublish preinstall install postinstall
preuninstall uninstall postuninstall preversion version postversion pretest test posttest prestop stop
poststop prestart start poststart prerestart restart postrestart preshrinkwrap shrinkwrap postshrinkwrap)
n=${#scripts[@]}
cat <<EOF > package.json
{
"name": "npm-scripts-lifetime",
"version": "1.0.0",
"description": "Check which system npm scripts are running",
"scripts": {
EOF
for script in ${scripts[@]:0:$[$n-1]}
do
echo " \"$script\": \"echo $script\"," >> package.json
done
last=${scripts[$[$n-1]]}
echo " \"$last\": \"echo $last\"" >> package.json
cat <<EOF >> package.json
}
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment