Skip to content

Instantly share code, notes, and snippets.

@nottrobin
Created April 12, 2017 08:27
Show Gist options
  • Select an option

  • Save nottrobin/ef2cbcb3f00a9707b09fd703c25e9603 to your computer and use it in GitHub Desktop.

Select an option

Save nottrobin/ef2cbcb3f00a9707b09fd703c25e9603 to your computer and use it in GitHub Desktop.
A shell function to run a docker command to check if package.json contains a specific script name
package_has_script () {
script_name="${1}"
# Check if package.json contains a script of the given name
docker run \
--volume `pwd`:`pwd` --workdir `pwd` `# Use the current directory` \
--entrypoint node `# Run plain old node` \
canonicalwebteam/yarn:v0.2.0 `# Run a short inline node script to check the package.json` \
--eval "
process.exit(
! JSON.parse(
fs.readFileSync('package.json', 'utf8')
).scripts.hasOwnProperty('${script_name}')
)
"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment