-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostage
executable file
·73 lines (66 loc) · 1.73 KB
/
postage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /usr/bin/env node
const yargs = require("yargs");
const main = require("./main");
const args = yargs
.scriptName("postage")
.version()
.pkgConf("postage")
.option("no-overwrite", {
boolean: true,
describe: "Terminates process rather than overwriting old target path",
default: false
})
.option("use-file", {
describe: "Use provided file as `package.json`",
default: "package.json"
})
.option("omit", {
alias: "o",
array: true,
string: true,
describe: "Omit certain keys/sub-keys from the output package.json",
example: "--omit=scripts -o=contributors",
default: [""]
})
.option("include", {
alias: "i",
array: true,
string: true,
describe: "Include keys/sub-keys in the output package.json",
example: "--include=eslint -i=scripts.start,scripts.test",
default: [""]
})
.option("indent", {
string: true,
alias: "n",
default: "tab",
choices: ["2", "4", "tab"]
}).argv;
const indent = (function(arg) {
if (arg === "tab") return "\t";
if (arg === "4") return " ";
return " ";
})(args.indent);
const files = require("./files")(args._[0] || "dist");
async function execute() {
const package_json = await files.readPackage(args["use-file"]);
const publish_ready_package_json = main(package_json, {
indent,
include: args["include"].reduce(flattenKeySets, []),
omit: args["omit"].reduce(flattenKeySets, [])
});
await files.writePackage(publish_ready_package_json);
await files.copyFilesFrom(process.cwd());
}
/**
* @param {string[]} acc
* @param {string} csv
* @returns {string[]}
*/
function flattenKeySets(acc, csv) {
return acc.concat(csv.split(","));
}
execute().catch(err => {
console.error(err);
process.exit(1);
});