Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏗 Add a way to run NPM scripts that live outside package.json (via nps) #32481

Merged
merged 1 commit into from
Feb 8, 2021
Merged

🏗 Add a way to run NPM scripts that live outside package.json (via nps) #32481

merged 1 commit into from
Feb 8, 2021

Conversation

rsimha
Copy link
Contributor

@rsimha rsimha commented Feb 6, 2021

This PR introduces a way to run npm scripts without adding them to package.json. Scripts are defined in package-scripts.js and run using nps (short for npm-package-scripts).

This will prevent us from going back to a situation like this:

amphtml/package.json

Lines 17 to 26 in ee2dea7

"scripts": {
"test": "gulp test && ava",
"ava": "ava",
"lint": "gulp lint",
"build": "gulp build",
"dist": "gulp dist",
"heroku-postbuild": "npm run test-env-var && gulp clean && gulp build --fortesting && gulp dist --fortesting && npm run prepend-amp && npm run prepend-v0",
"test-env-var": "if [ -z \"${AMP_TESTING_HOST}\" ]; then echo \"ERROR: Please set the 'AMP_TESTING_HOST' environment variable. If you are in heroku this can be set by executing 'heroku config:set AMP_TESTING_HOST=my-heroku-subdomain.herokuapp.com' on the command line.\"; exit 1; fi",
"prepend-amp": "gulp prepend-global --prod node_modules/AMP_CONFIG.json --local --target dist/amp.js && gulp prepend-global --prod node_modules/AMP_CONFIG.json --local --target dist.3p/current/integration.js",
"prepend-v0": "gulp prepend-global --prod node_modules/AMP_CONFIG.json --local --target dist/v0.js && gulp prepend-global --prod node_modules/AMP_CONFIG.json --local --target dist.3p/current-min/f.js"

Usage:

# One-time install of package script runner
npm i -g nps

# Invoke any script
nps filesize

Example:

image

Addresses #32476 (comment)

Copy link
Contributor

@kristoferbaxter kristoferbaxter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good change, and a way for us to move off gulp in smaller... bites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants