mioku 0.9.2 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,17 @@
1
1
  #!/usr/bin/env node
2
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const require_chunk = require('../chunk-CUT6urMc.cjs');
3
+ const mri = require_chunk.__toESM(require("mri"));
3
4
  const node_fs = require_chunk.__toESM(require("node:fs"));
4
5
  const node_child_process = require_chunk.__toESM(require("node:child_process"));
5
- const mri = require_chunk.__toESM(require("mri"));
6
6
  const node_path = require_chunk.__toESM(require("node:path"));
7
- const dedent = require_chunk.__toESM(require("dedent"));
8
7
  const consola = require_chunk.__toESM(require("consola"));
8
+ const dedent = require_chunk.__toESM(require("dedent"));
9
9
 
10
10
  //#region package.json
11
- var version = "0.9.2";
11
+ var version = "0.9.4";
12
12
 
13
13
  //#endregion
14
- //#region src/cli.ts
14
+ //#region src/cli/shared.ts
15
15
  const DEFAULT_PACKAGES = [
16
16
  "mioku",
17
17
  "mioku-plugin-boot",
@@ -24,9 +24,8 @@ const DEFAULT_PACKAGES = [
24
24
  ];
25
25
  const PLUGIN_PREFIX = "mioku-plugin-";
26
26
  const SERVICE_PREFIX = "mioku-service-";
27
- const args = process.argv.slice(2);
28
27
  function run(cmd, args$1 = [], options = {}) {
29
- return (0, node_child_process.execFileSync)(cmd, args$1, {
28
+ (0, node_child_process.execFileSync)(cmd, args$1, {
30
29
  stdio: "inherit",
31
30
  shell: process.platform === "win32",
32
31
  ...options
@@ -79,8 +78,7 @@ function findNpmPath() {
79
78
  shell: true
80
79
  });
81
80
  const lines = result.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
82
- const cmdPath = lines.find((line) => line.endsWith(".cmd"));
83
- return cmdPath || lines[0] || null;
81
+ return lines.find((l) => l.endsWith(".cmd")) || lines[0] || null;
84
82
  } catch {
85
83
  return null;
86
84
  }
@@ -102,42 +100,11 @@ function ensurePackageManager() {
102
100
  function getAddCommand(packages) {
103
101
  return ["bun", ["add", ...packages]];
104
102
  }
105
- function normalizePackageName(input$1) {
106
- if (input$1.startsWith(PLUGIN_PREFIX) || input$1.startsWith(SERVICE_PREFIX)) return input$1;
107
- if (input$1.startsWith("mioku-")) return input$1;
108
- return `${PLUGIN_PREFIX}${input$1}`;
109
- }
110
- function detectType(name) {
111
- if (name.startsWith(PLUGIN_PREFIX)) return "plugin";
112
- if (name.startsWith(SERVICE_PREFIX)) return "service";
113
- return "unknown";
114
- }
115
103
  function execAdd(packages, cwd) {
116
104
  const [cmd, args$1] = getAddCommand(packages);
117
105
  console.log(`执行: ${cmd} ${args$1.join(" ")}`);
118
106
  run(cmd, args$1, { cwd });
119
107
  }
120
- async function installPackage(name, cwd) {
121
- const normalized = normalizePackageName(name);
122
- const type = detectType(normalized);
123
- if (type === "unknown") {
124
- consola.default.error(`无法识别的包类型: ${name}`);
125
- return false;
126
- }
127
- try {
128
- execAdd([normalized], cwd);
129
- consola.default.success(`已安装 ${normalized}`);
130
- if (type === "plugin" && cwd) {
131
- const enabled = appendToMiokiPlugins(cwd, normalized);
132
- if (enabled) consola.default.success(`已在 mioki.plugins 中启用 ${normalized.slice(PLUGIN_PREFIX.length)}`);
133
- else consola.default.info(`${normalized.slice(PLUGIN_PREFIX.length)} 已在 mioki.plugins 中,跳过`);
134
- }
135
- return true;
136
- } catch {
137
- consola.default.error(`安装失败: ${normalized}`);
138
- return false;
139
- }
140
- }
141
108
  function appendToMiokiPlugins(cwd, pkgName) {
142
109
  if (!pkgName.startsWith(PLUGIN_PREFIX)) return false;
143
110
  const shortName = pkgName.slice(PLUGIN_PREFIX.length);
@@ -157,9 +124,7 @@ function appendToMiokiPlugins(cwd, pkgName) {
157
124
  }
158
125
  async function getInstalledPackages(cwd) {
159
126
  try {
160
- const pkgPath = node_path.default.join(cwd, "package.json");
161
- const content = (0, node_fs.readFileSync)(pkgPath, "utf-8");
162
- const pkg = JSON.parse(content);
127
+ const pkg = JSON.parse((0, node_fs.readFileSync)(node_path.default.join(cwd, "package.json"), "utf-8"));
163
128
  const deps = {
164
129
  ...pkg.dependencies,
165
130
  ...pkg.devDependencies
@@ -169,13 +134,45 @@ async function getInstalledPackages(cwd) {
169
134
  return [];
170
135
  }
171
136
  }
172
- (async () => {
173
- const cli = (0, mri.default)(args, { alias: {
174
- v: "version",
175
- h: "help"
176
- } });
177
- const helpInfo = (0, dedent.default)(`
178
- mioku 命令行工具 v${version}
137
+ function withRoot(p) {
138
+ return node_path.default.resolve(process.cwd(), p);
139
+ }
140
+ const NPM_REGISTRY = "https://registry.npmjs.org";
141
+ async function fetchNpmKeywords(packageName) {
142
+ try {
143
+ const res = await fetch(`${NPM_REGISTRY}/${encodeURIComponent(packageName)}`, { headers: {
144
+ Accept: "application/json",
145
+ "User-Agent": "mioku-cli"
146
+ } });
147
+ if (!res.ok) return null;
148
+ const data = await res.json();
149
+ const latestVersion = String(data?.["dist-tags"]?.latest || "").trim();
150
+ const keywords = latestVersion ? data?.versions?.[latestVersion]?.keywords : data?.keywords;
151
+ return Array.isArray(keywords) ? keywords.map(String) : [];
152
+ } catch {
153
+ return null;
154
+ }
155
+ }
156
+ function gracefullyExit() {
157
+ console.log("Bye!");
158
+ process.exit(0);
159
+ }
160
+ function makeFileTree(fileTree, base) {
161
+ for (const [name, content] of Object.entries(fileTree)) if (typeof content === "object" && content !== null) {
162
+ const subPath = `${base}/${name}`;
163
+ if (!node_fs.default.existsSync(subPath)) node_fs.default.mkdirSync(subPath, { recursive: true });
164
+ for (const [subName, subContent] of Object.entries(content)) if (typeof subContent === "object") makeFileTree(subContent, node_path.default.join(subPath, subName));
165
+ else node_fs.default.writeFileSync(`${subPath}/${subName}`, subContent);
166
+ } else {
167
+ const filePath = `${base}/${name}`;
168
+ const dirname = node_path.default.dirname(filePath);
169
+ if (!node_fs.default.existsSync(dirname)) node_fs.default.mkdirSync(dirname, { recursive: true });
170
+ node_fs.default.writeFileSync(filePath, content);
171
+ }
172
+ }
173
+ function buildHelpInfo(version$1) {
174
+ return (0, dedent.default)(`
175
+ mioku 命令行工具 v${version$1}
179
176
 
180
177
  用法: mioku <命令> [选项]
181
178
 
@@ -201,214 +198,145 @@ async function getInstalledPackages(cwd) {
201
198
  --admins <admins> 指定管理员 QQ,英文逗号分隔,可空
202
199
  --use-npm-mirror 使用 npm 镜像源加速依赖安装,默认否
203
200
  `);
204
- const [cmd, ...cmdArgs] = args;
205
- switch (cmd) {
206
- case "install": {
207
- ensurePackageManager();
208
- const cwd = process.cwd();
209
- const type = cmdArgs[0];
210
- const name = cmdArgs[1];
211
- if (!type || !name) {
212
- consola.default.error("请指定类型和名称: mioku install plugin <名称> 或 mioku install service <名称>");
213
- console.log(helpInfo);
214
- process.exitCode = 1;
215
- return;
216
- }
217
- if (type !== "plugin" && type !== "service") {
218
- consola.default.error(`无效的类型 "${type}",请使用 plugin 或 service`);
219
- console.log(helpInfo);
220
- process.exitCode = 1;
221
- return;
222
- }
223
- const prefix = type === "plugin" ? PLUGIN_PREFIX : SERVICE_PREFIX;
224
- const normalized = `${prefix}${name}`;
225
- const success = await installPackage(normalized, cwd);
226
- process.exitCode = success ? 0 : 1;
227
- return;
201
+ }
202
+ async function confirm(message, options) {
203
+ return consola.default.prompt(message, {
204
+ type: "confirm",
205
+ cancel: "reject",
206
+ ...options
207
+ });
208
+ }
209
+ async function input(message, options) {
210
+ const result = await consola.default.prompt(message, {
211
+ type: "text",
212
+ cancel: "reject",
213
+ ...options
214
+ });
215
+ if (options?.required && !result) return input(message, options);
216
+ return result;
217
+ }
218
+
219
+ //#endregion
220
+ //#region src/cli/install.ts
221
+ async function installCommand(cmdArgs, helpInfo) {
222
+ ensurePackageManager();
223
+ const cwd = process.cwd();
224
+ const [type, name] = cmdArgs;
225
+ if (!type || !name) {
226
+ consola.default.error("请指定类型和名称: mioku install plugin <名称> 或 mioku install service <名称>");
227
+ console.log(helpInfo);
228
+ return 1;
229
+ }
230
+ if (type !== "plugin" && type !== "service") {
231
+ consola.default.error(`无效的类型 "${type}",请使用 plugin 或 service`);
232
+ console.log(helpInfo);
233
+ return 1;
234
+ }
235
+ const prefix = type === "plugin" ? PLUGIN_PREFIX : SERVICE_PREFIX;
236
+ const normalized = `${prefix}${name}`;
237
+ if (type === "plugin") {
238
+ const proceed = await warnIfPrivatePlugin(normalized);
239
+ if (!proceed) {
240
+ consola.default.info("已取消安装");
241
+ return 1;
228
242
  }
229
- case "update": {
230
- ensurePackageManager();
231
- const cwd = process.cwd();
232
- const target = cmdArgs[0];
233
- if (!target || target === "check") {
234
- run("bun", ["update", "-i"], { cwd });
235
- process.exitCode = 0;
236
- return;
237
- }
238
- if (target === "all") {
239
- const packages = await getInstalledPackages(cwd);
240
- const filtered = packages.filter((p) => p.startsWith("mioku-"));
241
- if (filtered.length === 0) {
242
- consola.default.info("未找到 mioku- 相关依赖");
243
- process.exitCode = 0;
244
- return;
245
- }
246
- console.log(`执行: bun update ${filtered.join(" ")} --latest`);
247
- run("bun", [
248
- "update",
249
- ...filtered,
250
- "--latest"
251
- ], { cwd });
252
- process.exitCode = 0;
253
- return;
254
- }
255
- if (target === "self") {
256
- console.log("执行: bun update mioku --latest");
257
- run("bun", [
258
- "update",
259
- "mioku",
260
- "--latest"
261
- ], { cwd });
262
- process.exitCode = 0;
263
- return;
264
- }
265
- if (target === "plugin" || target === "service") {
266
- const name = cmdArgs[1];
267
- if (!name) {
268
- const packages = await getInstalledPackages(cwd);
269
- const prefix = target === "plugin" ? PLUGIN_PREFIX : SERVICE_PREFIX;
270
- const filtered = packages.filter((p) => p.startsWith(prefix));
271
- if (filtered.length === 0) {
272
- consola.default.info(`未找到 ${prefix}* 相关依赖`);
273
- process.exitCode = 0;
274
- return;
275
- }
276
- console.log(`执行: bun update ${filtered.join(" ")} --latest`);
277
- run("bun", [
278
- "update",
279
- ...filtered,
280
- "--latest"
281
- ], { cwd });
282
- } else {
283
- const prefix = target === "plugin" ? PLUGIN_PREFIX : SERVICE_PREFIX;
284
- const normalized = name.startsWith(prefix) ? name : `${prefix}${name}`;
285
- console.log(`执行: bun update ${normalized} --latest`);
286
- run("bun", [
287
- "update",
288
- normalized,
289
- "--latest"
290
- ], { cwd });
291
- }
292
- process.exitCode = 0;
293
- return;
294
- }
295
- console.log(`执行: bun update ${target} --latest`);
296
- run("bun", [
297
- "update",
298
- target,
299
- "--latest"
300
- ], { cwd });
301
- process.exitCode = 0;
302
- return;
243
+ }
244
+ try {
245
+ execAdd([normalized], cwd);
246
+ consola.default.success(`已安装 ${normalized}`);
247
+ if (type === "plugin") {
248
+ const shortName = normalized.slice(PLUGIN_PREFIX.length);
249
+ if (appendToMiokiPlugins(cwd, normalized)) consola.default.success(`已在 mioki.plugins 中启用 ${shortName}`);
250
+ else consola.default.info(`${shortName} 已在 mioki.plugins 中,跳过`);
303
251
  }
304
- default: {
305
- const cli$1 = (0, mri.default)(args, { alias: {
306
- v: "version",
307
- h: "help"
308
- } });
309
- switch (true) {
310
- case cli$1.version:
311
- console.log(`v${version}`);
312
- process.exitCode = 0;
313
- return;
314
- case cli$1.help:
315
- console.log(helpInfo);
316
- process.exitCode = 0;
317
- return;
318
- default: break;
319
- }
320
- const name = await input("请输入项目名称", {
321
- default: "mioku-bot",
322
- placeholder: "mioku-bot",
323
- required: true
324
- });
325
- const owners = await input("请输入主人 QQ (最高权限,英文逗号分隔,必填)", {
326
- placeholder: "请输入",
327
- default: "",
328
- required: true
329
- });
330
- const host = await input("请输入 NapCat WS 主机", {
331
- default: "localhost",
332
- placeholder: "localhost",
333
- required: true
334
- });
335
- const port = parseInt(await input("请输入 NapCat WS 端口", {
336
- default: "3001",
337
- placeholder: "3001",
338
- required: true
339
- }));
340
- const token = await input("请输入 NapCat WS Token(如无则留空)", { placeholder: "请输入" });
341
- ensurePackageManager();
342
- const pkgJson = (0, dedent.default)(`
343
- {
344
- "name": "${name}",
345
- "private": true,
346
- "type": "module",
347
- "dependencies": {},
348
- "mioki": {
349
- "prefix": "#",
350
- "owners": [${String(owners).split(",").map((o) => o.trim()).join(", ")}],
351
- "admins": [],
352
- "plugins": ["boot", "help", "chat", "demo"],
353
- "log_level": "info",
354
- "online_push": false,
355
- "error_push": false,
356
- "napcat": [
357
- {
358
- "protocol": "ws",
359
- "port": ${port},
360
- "host": "${host}",
361
- "token": "${token}"
362
- }
363
- ]
364
- },
365
- "scripts": {
366
- "start": "bun run app.ts",
367
- "dev": "bun run --watch app.ts"
368
- }
369
- }
370
- `);
371
- const pluginCode = (0, dedent.default)(`
372
- import { definePlugin } from 'mioku'
373
-
374
- export default definePlugin({
375
- name: 'demo',
376
- version: '${version}',
377
- async setup(ctx) {
378
- ctx.logger.info('Demo 插件已加载')
379
-
380
- ctx.handle('message', async (e) => {
381
- if (e.raw_message === 'hello') {
382
- e.reply('world', true)
383
- }
384
- })
252
+ return 0;
253
+ } catch {
254
+ consola.default.error(`安装失败: ${normalized}`);
255
+ return 1;
256
+ }
257
+ }
258
+ async function warnIfPrivatePlugin(pkgName) {
259
+ const keywords = await fetchNpmKeywords(pkgName);
260
+ if (keywords === null) return true;
261
+ if (keywords.includes("mioku")) return true;
262
+ consola.default.warn(`${pkgName} 看起来是私有插件"`);
263
+ consola.default.warn("该插件未上架插件市场,可能存在风险");
264
+ return confirm("仍要继续安装吗?", { initial: false });
265
+ }
385
266
 
386
- return () => {
387
- ctx.logger.info('Demo 插件已卸载')
388
- }
389
- },
390
- })
391
- `);
392
- const fileTree = {
393
- "app.ts": "import { start } from 'mioku'\n\nstart({ cwd: import.meta.dirname }).then()\n",
394
- "package.json": pkgJson,
395
- plugins: { demo: { "index.ts": pluginCode } },
396
- config: {},
397
- data: {}
398
- };
399
- const installWebui = await confirm("是否安装 WebUI 管理面板?(建议安装)", { initial: true });
400
- await createNewProject(name, fileTree, installWebui);
401
- console.log("\n若需启动机器人,请运行:");
402
- console.log(" cd", name);
403
- console.log(" bun run start");
404
- }
267
+ //#endregion
268
+ //#region src/cli/update.ts
269
+ async function updatePackages(packages, cwd) {
270
+ if (packages.length === 0) {
271
+ consola.default.info("未找到 mioku- 相关依赖");
272
+ return;
405
273
  }
406
- })();
274
+ console.log(`执行: bun update ${packages.join(" ")} --latest`);
275
+ run("bun", [
276
+ "update",
277
+ ...packages,
278
+ "--latest"
279
+ ], { cwd });
280
+ }
281
+ async function updateByPrefix(prefix, cwd, name) {
282
+ if (name) {
283
+ const normalized = name.startsWith(prefix) ? name : `${prefix}${name}`;
284
+ console.log(`执行: bun update ${normalized} --latest`);
285
+ run("bun", [
286
+ "update",
287
+ normalized,
288
+ "--latest"
289
+ ], { cwd });
290
+ return;
291
+ }
292
+ const packages = (await getInstalledPackages(cwd)).filter((p) => p.startsWith(prefix));
293
+ if (packages.length === 0) {
294
+ consola.default.info(`未找到 ${prefix}* 相关依赖`);
295
+ return;
296
+ }
297
+ await updatePackages(packages, cwd);
298
+ }
299
+ async function updateCommand(cmdArgs) {
300
+ ensurePackageManager();
301
+ const cwd = process.cwd();
302
+ const [target, name] = cmdArgs;
303
+ if (!target || target === "check") {
304
+ run("bun", ["update", "-i"], { cwd });
305
+ return 0;
306
+ }
307
+ if (target === "all") {
308
+ await updatePackages(await getInstalledPackages(cwd), cwd);
309
+ return 0;
310
+ }
311
+ if (target === "self") {
312
+ console.log("执行: bun update mioku --latest");
313
+ run("bun", [
314
+ "update",
315
+ "mioku",
316
+ "--latest"
317
+ ], { cwd });
318
+ return 0;
319
+ }
320
+ if (target === "plugin" || target === "service") {
321
+ const prefix = target === "plugin" ? PLUGIN_PREFIX : SERVICE_PREFIX;
322
+ await updateByPrefix(prefix, cwd, name);
323
+ return 0;
324
+ }
325
+ console.log(`执行: bun update ${target} --latest`);
326
+ run("bun", [
327
+ "update",
328
+ target,
329
+ "--latest"
330
+ ], { cwd });
331
+ return 0;
332
+ }
333
+
334
+ //#endregion
335
+ //#region src/cli/scaffold.ts
407
336
  async function createNewProject(name, fileTree, installWebui = false) {
408
- const projectName = name;
409
- const projectPath = withRoot(`./${projectName}`);
337
+ const projectPath = withRoot(`./${name}`);
410
338
  if (node_fs.default.existsSync(projectPath)) {
411
- const overwrite = await confirm(`项目 ${projectName} 已存在,是否覆盖?`);
339
+ const overwrite = await confirm(`项目 ${name} 已存在,是否覆盖?`);
412
340
  if (!overwrite) gracefullyExit();
413
341
  if (projectPath === process.cwd()) {
414
342
  if (node_fs.default.readdirSync(projectPath).length !== 0) {
@@ -420,48 +348,131 @@ async function createNewProject(name, fileTree, installWebui = false) {
420
348
  }
421
349
  node_fs.default.mkdirSync(projectPath, { recursive: true });
422
350
  makeFileTree(fileTree, projectPath);
423
- console.log(`项目 ${projectName} 创建成功!`);
351
+ console.log(`项目 ${name} 创建成功!`);
424
352
  const packages = installWebui ? [...DEFAULT_PACKAGES, "mioku-service-webui"] : DEFAULT_PACKAGES;
425
353
  const [cmd, args$1] = getAddCommand(packages);
426
354
  console.log(`正在安装 Mioku 依赖: ${cmd} ${args$1.join(" ")}`);
427
355
  run(cmd, args$1, { cwd: projectPath });
428
356
  }
429
- function gracefullyExit() {
430
- console.log("Bye!");
431
- process.exit(0);
432
- }
433
- function withRoot(_path) {
434
- return node_path.default.resolve(process.cwd(), _path);
435
- }
436
- async function confirm(message, options) {
437
- return consola.default.prompt(message, {
438
- type: "confirm",
439
- cancel: "reject",
440
- ...options
357
+ async function scaffoldCommand(version$1) {
358
+ const name = await input("请输入项目名称", {
359
+ default: "mioku-bot",
360
+ placeholder: "mioku-bot",
361
+ required: true
441
362
  });
442
- }
443
- async function input(message, options) {
444
- const result = await consola.default.prompt(message, {
445
- type: "text",
446
- cancel: "reject",
447
- ...options
363
+ const owners = await input("请输入主人 QQ (最高权限,英文逗号分隔,必填)", {
364
+ placeholder: "请输入",
365
+ default: "",
366
+ required: true
448
367
  });
449
- if (options?.required && !result) return input(message, options);
450
- return result;
368
+ const host = await input("请输入 NapCat WS 主机", {
369
+ default: "localhost",
370
+ placeholder: "localhost",
371
+ required: true
372
+ });
373
+ const port = parseInt(await input("请输入 NapCat WS 端口", {
374
+ default: "3001",
375
+ placeholder: "3001",
376
+ required: true
377
+ }), 10);
378
+ const token = await input("请输入 NapCat WS Token(如无则留空)", { placeholder: "请输入" });
379
+ ensurePackageManager();
380
+ const ownersList = String(owners).split(",").map((o) => o.trim()).join(", ");
381
+ const pkgJson = (0, dedent.default)(`
382
+ {
383
+ "name": "${name}",
384
+ "private": true,
385
+ "type": "module",
386
+ "dependencies": {},
387
+ "mioki": {
388
+ "prefix": "#",
389
+ "owners": [${ownersList}],
390
+ "admins": [],
391
+ "plugins": ["boot", "help", "chat", "demo"],
392
+ "log_level": "info",
393
+ "online_push": false,
394
+ "error_push": false,
395
+ "napcat": [
396
+ {
397
+ "protocol": "ws",
398
+ "port": ${port},
399
+ "host": "${host}",
400
+ "token": "${token}"
401
+ }
402
+ ]
403
+ },
404
+ "scripts": {
405
+ "start": "bun run app.ts",
406
+ "dev": "bun run --watch app.ts"
407
+ }
408
+ }
409
+ `);
410
+ const pluginCode = (0, dedent.default)(`
411
+ import { definePlugin } from 'mioku'
412
+
413
+ export default definePlugin({
414
+ name: 'demo',
415
+ version: '${version$1}',
416
+ async setup(ctx) {
417
+ ctx.logger.info('Demo 插件已加载')
418
+
419
+ ctx.handle('message', async (e) => {
420
+ if (e.raw_message === 'hello') {
421
+ e.reply('world', true)
422
+ }
423
+ })
424
+
425
+ return () => {
426
+ ctx.logger.info('Demo 插件已卸载')
427
+ }
428
+ },
429
+ })
430
+ `);
431
+ const fileTree = {
432
+ "app.ts": "import { start } from 'mioku'\n\nstart({ cwd: import.meta.dirname }).then()\n",
433
+ "package.json": pkgJson,
434
+ plugins: { demo: { "index.ts": pluginCode } },
435
+ config: {},
436
+ data: {}
437
+ };
438
+ const installWebui = await confirm("是否安装 WebUI 管理面板?(建议安装)", { initial: true });
439
+ await createNewProject(name, fileTree, installWebui);
440
+ console.log("\n若需启动机器人,请运行:");
441
+ console.log(" cd", name);
442
+ console.log(" bun run start");
443
+ return 0;
451
444
  }
452
- function makeFileTree(fileTree, base) {
453
- for (const [name, content] of Object.entries(fileTree)) if (typeof content === "object" && content !== null) {
454
- const subPath = `${base}/${name}`;
455
- if (!node_fs.default.existsSync(subPath)) node_fs.default.mkdirSync(subPath, { recursive: true });
456
- for (const [subName, subContent] of Object.entries(content)) if (typeof subContent === "object") makeFileTree(subContent, node_path.default.join(subPath, subName));
457
- else node_fs.default.writeFileSync(`${subPath}/${subName}`, subContent);
458
- } else {
459
- const filePath = `${base}/${name}`;
460
- const dirname = node_path.default.dirname(filePath);
461
- if (!node_fs.default.existsSync(dirname)) node_fs.default.mkdirSync(dirname, { recursive: true });
462
- node_fs.default.writeFileSync(filePath, content);
445
+
446
+ //#endregion
447
+ //#region src/cli/index.ts
448
+ const args = process.argv.slice(2);
449
+ (async () => {
450
+ const cli = (0, mri.default)(args, { alias: {
451
+ v: "version",
452
+ h: "help"
453
+ } });
454
+ const helpInfo = buildHelpInfo(version);
455
+ const [cmd, ...cmdArgs] = args;
456
+ switch (cmd) {
457
+ case "install":
458
+ process.exitCode = await installCommand(cmdArgs, helpInfo);
459
+ return;
460
+ case "update":
461
+ process.exitCode = await updateCommand(cmdArgs);
462
+ return;
463
+ default:
464
+ if (cli.version) {
465
+ console.log(`v${version}`);
466
+ return;
467
+ }
468
+ if (cli.help) {
469
+ console.log(helpInfo);
470
+ return;
471
+ }
472
+ process.exitCode = await scaffoldCommand(version);
473
+ return;
463
474
  }
464
- }
475
+ })();
465
476
 
466
477
  //#endregion
467
- //# sourceMappingURL=cli.cjs.map
478
+ //# sourceMappingURL=index.cjs.map