Extract package.json properties.
npm install @yandeu/extract
"name": "awesomepackage",
"version": "1.2.0",
"keywords": [
"awesome",
"fast"
],
"scripts": {
"extract-version": "extract version VERSION.js",
"test": "jest --coverage"
},
npm run extract-version
will generate:
// VERSION.js
exports.VERSION = "1.2.0";
Format file after extraction
"scripts": {
"version": "extract version src/version.ts && prettier --write src/version.ts",
},
npm run version
will extract the version and format it with prettier.
"scripts": {
"extract": "extract name keywords scripts.test src/const.ts",
},
npm run extract
will generate:
// src/const.ts
export const NAME = "awesomepackage";
export const KEYWORDS = ["awesome", "fast"];
export const TEST = "jest --coverage";
// index.cjs
const { extract } = require('extract')
extract(['name', 'version'], 'properties.js', false)
// index.mjs
import { extract } from 'extract/lib/extract.js'
extract(['name', 'version'], 'properties.js', false)
// index.ts
import { extract } from 'extract'
extract(['name', 'version'], 'properties.js', false)