I have an npm package that manages my github repository and has scripts that build my publishable npm package. Due to the nature of the package, the published npm package (the distribution) cannot match my repository's package (the source). I am moving closer to test-driven development and continuous integration, but am learning it step-by-step. Here is the current flow and it works flawlessly, so far:
From the command line:
> npm run patch
- runs
npm version patch
- This invokes source's
preversion
,- cleans the distro:
npm run clean
- runs the tests:
npm test
- This invokes
pretest
,npm run build
- Runs distro's tests
- Failure: Errors and process ends
- Success: Branch complete,
- This invokes
- cleans the distro:
- invokes the source's
postversion
:git push
all commits and tags
- This invokes source's
- runs distro's
npm version patch
- invokes distro's
postversion
npm publish
- invokes distro's
(Source) package.json
{
...,
"scripts": {
"patch": "npm version patch && cd dist && npm version patch",
"minor": "npm version minor && cd dist && npm version minor",
"major": "npm version major && cd dist && npm version major",
"preversion": "npm run clean && npm test",
"clean": /* clean commands */,
"pretest": "npm run build",
"test": "cd dist && npm test",
"postversion": "git push origin --all && git push origin --tags"
},
...
}
(Distro) package.json
{
...,
"scripts": {
"test": /* test commands */,
"postversion": "npm publish"
},
...
}
I would like to have a simpler interface. As you can see, I have to npm run <major|minor|patch>
. I would instead like to npm run dist
with a commandline arg passed to both npm versions.
Example:
> npm run dist patch
--------------------
<<< npm version patch
<<< cd dist && npm version patch
> npm run dist major
--------------------
<<< npm version major
<<< cd dist && npm version major
Is it possible to pass commandline args down the tree? Or, better yet, can I distribute a commandline arg across commands in a single scripts entry? I can easily add an entry to scripts
that accepts a commandline argument, but cannot seem to figure out how to share that argument more than once with writing a separate .js
script.