-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
executable file
·88 lines (82 loc) · 2.45 KB
/
index.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env node
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { join } from "path";
import { readFileSync } from "fs";
import { fileURLToPath } from "url";
import { dirname } from "path";
import * as alias from "./commands/alias.js";
import * as init from "./commands/init.js";
import * as integrity from "./commands/integrity.js";
import * as login from "./commands/login.js";
import * as mapAlias from "./commands/map-alias.js";
import * as map from "./commands/map.js";
import * as meta from "./commands/meta.js";
import * as npmAlias from "./commands/npm-alias.js";
import * as packageAlias from "./commands/package-alias.js";
import * as ping from "./commands/ping.js";
import * as publish from "./commands/publish.js";
import * as version from "./commands/version.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const { version: cliVersion } = JSON.parse(
readFileSync(join(__dirname, "./package.json"), { encoding: "utf-8" }),
);
// Short circuit and provide a -v and --version flag.
// It's a known limitation in yargs that you can't have both a command
// and an option named version https://github.com/yargs/yargs/issues/2064
// We use the version name as a command in yargs, so handle the version
// option before using yargs.
if (
process.argv.includes("-v") ||
// last position only to avoid conflict with publish command
process.argv[process.argv.length - 1].includes("--version")
) {
console.log(cliVersion);
process.exit(0);
}
yargs(hideBin(process.argv))
.scriptName("eik")
// inspired by git
.usage(
`usage: $0 [-v | --version] [-h | --help] [-c <path> | --config <path>]
[--cwd <path>] [--debug] <command> [<args>]`,
)
.epilogue(
`Run $0 <command> --help to read more about a specific subcommand.
For a more detailed description of commands and options, see the reference documentation:
https://eik.dev/cli`,
)
.options({
config: {
alias: "c",
describe: "Path to Eik configuration file",
},
cwd: {
describe: "Path to a different working directory than the current",
},
debug: {
describe: "Show additional logs",
type: "boolean",
},
})
.command([
alias,
init,
integrity,
login,
map,
mapAlias,
meta,
npmAlias,
packageAlias,
ping,
publish,
version,
])
.demandCommand()
.wrap(null)
.version(false) // Turn off the built-in version option to not conflict with the version command
.help()
.alias("h", "help")
.parse();