-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·67 lines (57 loc) · 1.65 KB
/
cli.js
File metadata and controls
executable file
·67 lines (57 loc) · 1.65 KB
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
#!/usr/bin/env node
const { existsSync, readFileSync } = require("fs");
const { resolve } = require("path");
const { convertPack } = require(".");
const args = require("minimist")(process.argv.slice(2), {
alias: {
"input-version": ["iv"],
"output-version": ["ov"],
"input-edition": ["ie"],
"output-edition": ["oe"],
verbose: ["v"],
help: ["h"],
},
boolean: ["verbose", "help"],
});
if (args.help) {
const manPage = readFileSync(resolve(__dirname, "./convert-pack.1"), { encoding: "utf8" });
// very quick solution to support man pages and a help menu with the same file
const helpPage = manPage.replace(/\n\.br\n/g, "\n");
console.log(helpPage);
process.exit();
}
if (!Object.groupBy || typeof Object.groupBy !== "function") {
console.error(`You need a newer version of Node.js to run this program! (>=21.0)`);
process.exit(1);
}
const options = {
inputDir: args._?.[0],
outputDir: args._?.[1],
inputEdition: args.ie,
outputEdition: args.oe,
inputVersion: args.iv,
outputVersion: args.ov,
verbose: args.verbose,
};
// validation stuff
if (!args._?.[0] || !existsSync(args._?.[0])) {
console.error(`Input folder doesn't exist! (received "${args._?.[0]}")`);
process.exit(1);
}
if (!args._?.[1]) {
console.error("No output directory specified!");
process.exit(1);
}
if (!options.inputEdition && !options.inputVersion) {
console.error(
"Not enough input information provided! (edition or version required at minimum)",
);
process.exit(1);
}
if (!options.outputEdition && !options.outputVersion) {
console.error(
"Not enough output information provided! (edition or version required at minimum)",
);
process.exit(1);
}
convertPack(options);