-
-
Save oirodolfo/cec1d4ecfb729ad95c788d53df8dd7f1 to your computer and use it in GitHub Desktop.
Add script to package.json via command line
This file contains 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
# Reusable bash function you can add to your ~/.zshrc or ~/.bashrc file | |
# | |
# Usage: pkg-script start "node index.js" | |
# | |
function pkg-script () { | |
echo $(jq --arg key "${1}" --arg val "${2}" '.scripts[$key]=$val' package.json) | jq . | > package.json | |
} |
This file contains 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
# Add "test": "jest" to scripts object of node package | |
echo $(jq '.scripts.test="jest"' package.json) | jq . | > package.json | |
# Update package name | |
echo $(jq '.name="new-name"' package.json) | jq . | > package.json | |
# NOTE | |
# If you get this error: "pkg-script:1: file exists: package.json" | |
# run the following: | |
# | |
setopt clobber |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment