Created
April 12, 2017 08:27
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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