UNPKG

transform-package-json

Version:

Utility script to transform package.json - Remove scripts, devDependencies and change properties.

62 lines (61 loc) 2.29 kB
#!/usr/bin/env node "use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path = __importStar(require("path")); const nopt_1 = __importDefault(require("nopt")); const lodash_omit_1 = __importDefault(require("lodash.omit")); const index_1 = require("../index"); const knownOpts = { "help": Boolean, "remove": Array, "replace": Boolean, "basePath": path, "name": String, "version": String, "description": String, "author": String, "license": String, "main": String, "private": Boolean }, shortHands = { "h": ["--help"], "r": ["--remove"], "i": ["--replace"], "b": ["--basePath"], "in-place": ["--replace"], "base-path": ["--basePath"] }; main(); function main() { const parsed = nopt_1.default(knownOpts, shortHands, process.argv, 2), [src, dest] = parsed.argv.remain; if (!src || parsed.help) { return help(); } index_1.transform(src, dest, lodash_omit_1.default(parsed, "argv")); console.log("> File " + src + " transformed !"); } function help() { console.log(""); console.log("$ package-transform [options] {input} [dest]"); console.log(""); console.log("Options:"); console.log(" --remove {field}, -r Removes specified properties from source package.json."); console.log(" --replace, -i Transform package.json in-place."); console.log(" --basePath {path}, -b Keep folder structre starting from `basePath`."); console.log(" Sets to `\"\"` to keep entire folder structure."); console.log(" --help, -h Print this message."); console.log(""); console.log("Tranforms:"); console.log(" --{key} {value} Set package.json `key` to `value`."); console.log(""); }