1.0.0 • Published 9 years ago
derive-pkg-cli v1.0.0
derive-pkg
A helper utility for publishing transpiled code to npm
Turn require('your-module/lib/submodule') into require('your-module/submodule')
What is this for?
The standard convention when publishing code transpiled with Babel is to place source code into src/ and transpiled code into lib/. Unfortunately, this makes consuming individual submodules inconvenient because they don't exist at the root of the package, e.g. one must require('the-module/lib/some-submodule.js').
This utility derives npm package metadata from your root directory and copies it to your build directory so you can publish it instead. Now lib/ is the root of your package!
derive-pkg does the following:
- Copies
package.jsonfrom root with the changes below- Rebase
main,bin, andbrowserfield entry paths fromlib/to/ - Omit
devDependencies
- Rebase
- Copies files from root that npm will never ignore and should be included when publishing (e.g. readme, license, and changelog)
- Copies
.gitignore/.npmignorefrom root as.npmignore
Install
npm install derive-pkg-cli --save-devQuick Example
babel-cli src -d lib
derive-pkg -d lib
npm publish libUsage
Usage: derive-pkg [directory] [options]
Options:
directory The base directory containing the package.json (default: ".")
--out-dir, -d The output directory for the derived package.json
--name, -n Override the name field of the derived package.json
--version, -v Override the version field of the derived package.jsonFAQ
Couldn't this just be a shell script?
Yep, but derive-pkg is cross-platform and has unit tests.