forked from fedify-dev/fedify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.ts
More file actions
149 lines (140 loc) · 4.16 KB
/
Copy pathcommand.ts
File metadata and controls
149 lines (140 loc) · 4.16 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import {
argument,
choice,
command,
constant,
type InferValue,
merge,
message,
multiple,
object,
option,
optional,
optionNames,
or,
} from "@optique/core";
import { path } from "@optique/run";
import {
KV_STORE,
MESSAGE_QUEUE,
PACKAGE_MANAGER,
WEB_FRAMEWORK,
} from "./const.ts";
const webFramework = optional(option(
"-w",
"--web-framework",
choice(WEB_FRAMEWORK, { metavar: "WEB_FRAMEWORK" }),
{
description: message`The web framework to integrate Fedify with.`,
},
));
const packageManager = optional(option(
"-p",
"--package-manager",
choice(PACKAGE_MANAGER, { metavar: "PACKAGE_MANAGER" }),
{
description:
message`The package manager to use for installing dependencies.`,
},
));
const kvStore = optional(option(
"-k",
"--kv-store",
choice(KV_STORE, { metavar: "KV_STORE" }),
{
description:
message`The key-value store to use for caching and some other features.`,
},
));
const messageQueue = optional(option(
"-m",
"--message-queue",
choice(MESSAGE_QUEUE, { metavar: "MESSAGE_QUEUE" }),
{
description: message`The message queue to use for background tasks.`,
},
));
/**
* The `@optique/core` option schema for the `fedify init` command.
* Defines `dir`, `webFramework`, `packageManager`, `kvStore`, `messageQueue`,
* `dryRun`, and `allowNonEmpty` options that the CLI parser will accept.
*/
export const initOptions = object("Initialization options", {
dir: optional(argument(path({ metavar: "DIR" }), {
description:
message`The project directory to initialize. If a specified directory does not exist, it will be created.`,
})),
webFramework,
packageManager,
kvStore,
messageQueue,
dryRun: option("--dry-run", {
description: message`Perform a trial run with no changes made.`,
}),
allowNonEmpty: option("--allow-non-empty", {
description:
message`Allow initializing in a non-empty directory when the selected framework scaffolder supports it, failing if any generated file already exists.`,
}),
skipInstall: option("--skip-install", {
description:
message`Skip installing dependencies after scaffolding the project.`,
}),
});
/**
* The `fedify init` CLI command parser.
*/
export const initCommand = command(
"init",
merge(
initOptions,
object({ command: constant("init") }),
),
{
brief: message`Initialize a new Fedify project directory.`,
description: message`Initialize a new Fedify project directory.
By default, it initializes the current directory. You can specify a different directory as an argument.
Unless you specify all options (${optionNames(["-w", "--web-framework"])}, ${
optionNames(["-p", "--package-manager"])
}, ${optionNames(["-k", "--kv-store"])}, and ${
optionNames(["-m", "--message-queue"])
}), it will prompt you to select the options interactively.`,
},
);
/** The inferred value type produced by parsing the `fedify init` command. */
export type InitCommand = InferValue<typeof initCommand>;
const noHydRun = object({
noHydRun: option("--no-hyd-run", {
description: message`Log outputs without creating files.`,
}),
});
const noDryRun = object({
noDryRun: option("--no-dry-run", {
description: message`Test with files creations and installations.`,
}),
});
/**
* The `test-init` CLI command parser.
*/
export const testInitCommand = command(
"test-init",
merge(
object("Initialization options", {
webFramework: multiple(webFramework),
packageManager: multiple(packageManager),
kvStore: multiple(kvStore),
messageQueue: multiple(messageQueue),
}),
optional(or(noHydRun, noDryRun)),
),
{
brief: message`Test an initializing command.`,
description: message`Test an initializing command on temporary directories.
Unless you specify all options (${optionNames(["-w", "--web-framework"])}, ${
optionNames(["-p", "--package-manager"])
}, ${optionNames(["-k", "--kv-store"])}, and ${
optionNames(["-m", "--message-queue"])
}), it will test all combinations of the options.`,
},
);
/** The inferred value type produced by parsing the `test-init` command. */
export type TestInitCommand = InferValue<typeof testInitCommand>;