Repository navigation
Expand file tree
/
Copy pathbootstrap-cli.mjs
More file actions
340 lines (333 loc) · 10.6 KB
/
Copy pathbootstrap-cli.mjs
File metadata and controls
340 lines (333 loc) · 10.6 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/usr/bin/env -S node --no-deprecation
const [major] = process.versions.node.split(".").map(Number)
if (major < 22) {
console.error(
`\nQuartz requires Node.js >= 22, but you are running Node.js ${process.version}.\n` +
`Please upgrade: https://nodejs.org/\n`,
)
process.exit(1)
}
import yargs from "yargs"
import { hideBin } from "yargs/helpers"
import {
handleBuild,
handleCreate,
handleUpgrade,
handleRestore,
handleSync,
} from "./cli/handlers.js"
import {
handlePluginInstallUnified,
handlePluginAdd,
handlePluginRemove,
handlePluginList,
handlePluginStatus,
handlePluginEnable,
handlePluginDisable,
handlePluginConfig,
handlePluginPrune,
handlePluginDoctor,
} from "./cli/plugin-git-handlers.js"
import { CommonArgv, BuildArgv, CreateArgv, SyncArgv } from "./cli/args.js"
import { version } from "./cli/constants.js"
async function launchTui() {
const { join } = await import("path")
const { existsSync } = await import("fs")
const { spawn } = await import("child_process")
const tuiPath = join(process.cwd(), ".quartz", "plugins", "tui", "dist", "App.mjs")
if (!existsSync(tuiPath)) {
console.error(
// installed from GitHub into .quartz/plugins (it is not published to npm)
"TUI plugin not installed. Install with:\n" +
" npx quartz plugin add github:quartz-community/tui\n",
)
process.exit(1)
}
// OpenTUI requires Bun runtime (uses bun:ffi for Zig renderer)
return new Promise((resolve, reject) => {
const child = spawn("bun", ["run", tuiPath], {
stdio: "inherit",
cwd: process.cwd(),
})
child.on("error", (err) => {
if (err.code === "ENOENT") {
console.error(
"Error: Bun runtime not found. The TUI requires Bun to run.\n" +
"Install Bun: https://bun.sh/docs/installation",
)
}
reject(err)
})
child.on("close", (code) => {
if (code === 0) {
resolve()
} else {
reject(new Error(`TUI exited with code ${code}`))
}
})
})
}
yargs(hideBin(process.argv))
.scriptName("quartz")
.version(version)
.usage("$0 <cmd> [args]")
.command("create", "Initialize Quartz", CreateArgv, async (argv) => {
await handleCreate(argv)
})
.command(
["upgrade", "update"],
"Upgrade Quartz to the latest version",
CommonArgv,
async (argv) => {
await handleUpgrade(argv)
},
)
.command(
"restore",
"Try to restore your content folder from the cache",
CommonArgv,
async (argv) => {
await handleRestore(argv)
},
)
.command("sync", "Sync your Quartz to and from GitHub.", SyncArgv, async (argv) => {
await handleSync(argv)
})
.command("build", "Build Quartz into a bundle of static HTML files", BuildArgv, async (argv) => {
await handleBuild(argv)
})
.command(
"info",
"Print Quartz version, environment and plugins (paste it into bug reports)",
{ json: { boolean: true, default: false, describe: "Print JSON instead of Markdown" } },
async (argv) => {
const { handleInfo } = await import("./cli/info.js")
await handleInfo({ json: argv.json })
},
)
.command("tui", "Launch interactive plugin manager", CommonArgv, async () => {
await launchTui()
})
.command(
"plugin [subcommand]",
"Manage Quartz plugins",
(yargs) => {
return (
yargs
.command(
"install [names..]",
"Install plugins from lockfile or config",
{
...CommonArgv,
"from-config": {
boolean: true,
default: false,
describe: "install plugins referenced in quartz.config.yaml instead of lockfile",
},
latest: {
boolean: true,
default: false,
describe: "fetch latest version from remote instead of pinned lockfile commit",
},
clean: {
boolean: true,
default: false,
describe: "skip plugins whose directory already exists",
},
"dry-run": {
boolean: true,
default: false,
describe: "show what would happen without making changes",
},
},
async (argv) => {
await handlePluginInstallUnified({
names: argv.names?.length ? argv.names : undefined,
fromConfig: argv.fromConfig,
latest: argv.latest,
clean: argv.clean,
dryRun: argv.dryRun,
concurrency: argv.concurrency,
})
},
)
.command(
"add <repos..>",
"Add plugins from Git repositories",
{
...CommonArgv,
name: {
string: true,
alias: ["as"],
describe: "Override the plugin name (for resolving conflicts with duplicate names)",
},
subdir: {
string: true,
describe: "Subdirectory within the repository containing the plugin",
},
},
async (argv) => {
await handlePluginAdd(argv.repos, {
name: argv.name,
subdir: argv.subdir,
concurrency: argv.concurrency,
})
},
)
.command("remove <names..>", "Remove installed plugins", CommonArgv, async (argv) => {
await handlePluginRemove(argv.names)
})
.command("list", "List all installed plugins", CommonArgv, async () => {
await handlePluginList()
})
.command(
"enable <names..>",
"Enable plugins in quartz.config.yaml",
CommonArgv,
async (argv) => {
await handlePluginEnable(argv.names)
},
)
.command(
"disable <names..>",
"Disable plugins in quartz.config.yaml",
CommonArgv,
async (argv) => {
await handlePluginDisable(argv.names)
},
)
.command(
"config <name>",
"View or set plugin options",
{
...CommonArgv,
set: {
string: true,
array: true,
describe:
"Set an option (key=value; value is parsed as JSON when possible; nested keys with a.b=value). Repeatable",
},
unset: {
string: true,
array: true,
describe: "Remove an option so the plugin default applies. Repeatable",
},
},
async (argv) => {
await handlePluginConfig(argv.name, { set: argv.set, unset: argv.unset })
},
)
.command(
"doctor",
"Check plugin config, lockfile and installs for problems",
{
...CommonArgv,
fix: {
boolean: true,
default: false,
describe:
"Rewrite quartz.config.yaml for plugins that are now built into Quartz (keeps comments)",
},
},
async (argv) => {
await handlePluginDoctor({ verbose: argv.verbose, fix: argv.fix })
},
)
.command(
"prune",
"Remove installed plugins no longer referenced in config",
{
...CommonArgv,
"dry-run": {
boolean: true,
default: false,
describe: "show what would be pruned without making changes",
},
},
async (argv) => {
await handlePluginPrune({ dryRun: argv.dryRun })
},
)
// Hidden deprecated aliases
.command("restore", false, CommonArgv, async (argv) => {
console.log(
"\x1b[33m⚠ 'plugin restore' is deprecated. Use 'plugin install --clean' instead.\x1b[0m",
)
await handlePluginInstallUnified({ clean: true, concurrency: argv.concurrency })
})
.command("update [names..]", false, CommonArgv, async (argv) => {
console.log(
"\x1b[33m⚠ 'plugin update' is deprecated. Use 'plugin install --latest' instead.\x1b[0m",
)
await handlePluginInstallUnified({
names: argv.names?.length ? argv.names : undefined,
latest: true,
concurrency: argv.concurrency,
})
})
.command("check", false, CommonArgv, async (argv) => {
console.log(
"\x1b[33m⚠ 'plugin check' is deprecated. Use 'plugin install --latest --dry-run' instead.\x1b[0m",
)
await handlePluginInstallUnified({
latest: true,
dryRun: true,
concurrency: argv.concurrency,
})
})
.command(
"resolve",
false,
{
...CommonArgv,
"dry-run": {
boolean: true,
default: false,
describe: "show what would be resolved without making changes",
},
},
async (argv) => {
console.log(
"\x1b[33m⚠ 'plugin resolve' is deprecated. Use 'plugin install --from-config' instead.\x1b[0m",
)
await handlePluginInstallUnified({
fromConfig: true,
dryRun: argv.dryRun,
concurrency: argv.concurrency,
})
},
)
.demandCommand(0, "")
)
},
async (argv) => {
if (argv.subcommand !== undefined) {
const known = [
"install",
"add",
"remove",
"list",
"enable",
"disable",
"config",
"prune",
"doctor",
]
const { suggestClosest } = await import("./cli/plugin-validation.js")
const suggestion = suggestClosest(String(argv.subcommand), known)
console.error(
`Unknown plugin command "${argv.subcommand}".` +
(suggestion ? ` Did you mean "quartz plugin ${suggestion}"?` : "") +
`\nRun 'npx quartz plugin --help' to see all commands.`,
)
process.exitCode = 1
return
}
if (!argv._.includes("plugin") || argv._.length > 1) return
await handlePluginStatus()
},
)
.showHelpOnFail(true)
.help()
.strict()
.demandCommand().argv