Skip to content

Instantly share code, notes, and snippets.

@adriangalilea
Last active May 3, 2024 07:03
Show Gist options
  • Save adriangalilea/7f5f4602b80099b86b0d9b06a9dd3373 to your computer and use it in GitHub Desktop.
Save adriangalilea/7f5f4602b80099b86b0d9b06a9dd3373 to your computer and use it in GitHub Desktop.
useful package.json scripts and bash function to use it from cli
function npm-scripts() {
# Define the Gist URL directly within the function
local gist_url="https://gist.githubusercontent.com/adriangalilea/7f5f4602b80099b86b0d9b06a9dd3373/raw/808d9b8e81b6216f7eab85fe13e33edce0a286d5/scripts.json"
# Check if package.json exists in the current directory
if [ -f "package.json" ]; then
# Fetch JSON from Gist and update package.json
curl -s "$gist_url" | jq --slurpfile newScripts /dev/stdin '.scripts |= . + $newScripts[0]' package.json > package.json.tmp && mv package.json.tmp package.json
echo "Scripts updated in package.json"
else
echo "No package.json found in the current directory."
fi
}
{
"format": "prettier --write .",
"validate": "npm run lint && npm run lint:js && npm run format",
"purge": "rm -rf node_modules package-lock.json && npm cache clean --force",
"purge:all": "npm run purge && rm -rf .next build",
"reinstall": "npm run purge && npm install",
"reinstall:all": "npm run purge:all && npm install"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment