pkg.macro
v1.0.1
Published
Fetch properties of your project's `package.json` at compile time.
Readme
pkg.macro ·

Fetch properties of your project's
package.jsonat compile time.
pkg.macro allows you to turn pkg(["name", "version"]) into
{ name: "your-package", version: "1.0.0" } as a build time constant.
installation
yarn add --dev pkg.macroMake sure you also have [Babel][babel] and [babel-plugin-macros][babel-plugin-macros] installed:
yarn add --dev @babel/cli @babel/core babel-plugin-macros... and configured with Babel:
module.exports = {
presets: [],
plugins: ["babel-plugin-macros"]
}usage
import pkg from "pkg.macro"
const props = pkg([
"name",
"version",
"scripts.test",
["dependencies", "some-package"]
])The above is transformed to:
const props = {
name: "your-package",
version: "1.0.0",
scripts: {
test: "test-script"
},
dependencies: {
"some-package": "1.0.0"
}
}see also
- param.macro – macro for partial application, inspired by Scala's
_& Kotlin'sit
development
- Clone the repo:
git clone https://github.com/citycide/pkg.macro.git - Move into the new directory:
cd pkg.macro - Install dependencies:
yarnornpm install - Build the source:
yarn buildornpm run build - Run tests:
yarn testornpm test
contributing
Pull requests and any issues found are always welcome.
- Fork the project, and preferably create a branch named something like
feat-make-better - Follow the build steps above but using your forked repo
- Modify the source files in the
srcdirectory as needed - Make sure all tests continue to pass, and it never hurts to have more tests
- Push & pull request! :tada:
license
MIT © Bo Lingen / citycide
