@atomservice/cli 0.1.3 → 0.1.5

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.
package/bin/atom.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  import { UserError } from "@atomservice/core"
3
3
  import { type ArgsDef, type CommandDef, defineCommand, renderUsage, runCommand, runMain } from "citty"
4
4
  import pc from "picocolors"
5
+ import pkg from "../package.json" with { type: "json" }
5
6
  import { addCmd } from "../src/add/add.cmd.ts"
6
7
  import { initCmd } from "../src/init/init.cmd.ts"
7
8
  import { runCmd } from "../src/run/index.ts"
@@ -19,7 +20,7 @@ async function showUsage<T extends ArgsDef>(cmd: CommandDef<T>, parent?: Command
19
20
  }
20
21
 
21
22
  const main = defineCommand({
22
- meta: { name: "atom", version: "0.0.1", description: "原子化自托管服务编排工具" },
23
+ meta: { name: "atom", version: pkg.version, description: "原子化自托管服务编排工具" },
23
24
  subCommands: async () => ({
24
25
  init: initCmd,
25
26
  add: addCmd,
@@ -37,9 +38,15 @@ const wantsHelpOrVersion =
37
38
  argv.includes("--help") || argv.includes("-h") || (argv.length === 1 && argv[0] === "--version")
38
39
 
39
40
  if (wantsHelpOrVersion) {
40
- // help / version 由 citty 自带逻辑处理
41
41
  await runMain(main, { showUsage })
42
42
  } else {
43
+ const subCommands = await (main.subCommands as () => Promise<Record<string, unknown>>)()
44
+ const requested = argv.find((a) => !a.startsWith("-"))
45
+ if (requested && !(requested in subCommands)) {
46
+ console.error(`\n${pc.red("✗")} ${pc.yellow(requested)} 不是有效的命令\n`)
47
+ await showUsage(main)
48
+ process.exit(1)
49
+ }
43
50
  try {
44
51
  await runCommand(main, { rawArgs: argv })
45
52
  } catch (err) {
@@ -48,7 +55,7 @@ if (wantsHelpOrVersion) {
48
55
  if (err.hint) console.error(pc.dim(` ${err.hint}`))
49
56
  } else {
50
57
  console.error(`\n${pc.red("✗")} ${err instanceof Error ? err.message : String(err)}`)
51
- console.error(pc.dim(" 如果这看起来是个 bug,可加 --verbose 查看详细堆栈"))
58
+ console.error(pc.dim(" 遇到意外错误,使用 --verbose 查看错误详情"))
52
59
  if (process.env.ATOMSERVICE_VERBOSE && err instanceof Error && err.stack) {
53
60
  console.error(pc.dim(err.stack))
54
61
  }
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@atomservice/cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "atomservice 命令行工具(atom):init / run / add / service",
5
5
  "type": "module",
6
6
  "author": "openorson",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/openorson/atomservice.git",
10
- "directory": "packages/cli"
10
+ "directory": "framework/cli"
11
11
  },
12
12
  "bugs": "https://github.com/openorson/atomservice/issues",
13
- "homepage": "https://github.com/openorson/atomservice/tree/main/packages/cli#readme",
13
+ "homepage": "https://github.com/openorson/atomservice/tree/main/framework/cli#readme",
14
14
  "keywords": [
15
15
  "atomservice",
16
16
  "cli",
@@ -19,7 +19,7 @@
19
19
  "bun"
20
20
  ],
21
21
  "engines": {
22
- "bun": ">=1.0.0"
22
+ "bun": ">=1.3.14"
23
23
  },
24
24
  "files": [
25
25
  "src",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@clack/prompts": "1.5.0",
33
- "@atomservice/core": "0.1.3",
33
+ "@atomservice/core": "0.1.5",
34
34
  "citty": "0.2.2",
35
35
  "cli-table3": "0.6.5",
36
36
  "log-update": "8.0.0",
package/src/cli.consts.ts CHANGED
@@ -4,11 +4,11 @@ import { ATOMSERVICE_DIR } from "@atomservice/core"
4
4
  export const CONFIG_PATH = path.join(ATOMSERVICE_DIR, "atom.config.ts")
5
5
 
6
6
  export const OFFICIAL_SERVICES: Array<{ value: string; label: string; hint: string }> = [
7
- { value: "service-redis", label: "service-redis", hint: "Redis 缓存" },
8
- { value: "service-postgres", label: "service-postgres", hint: "PostgreSQL 数据库" },
9
- { value: "service-gateway", label: "service-gateway", hint: "反向代理 + HTTPS" },
10
- { value: "service-gitea", label: "service-gitea", hint: "Gitea Git 服务" },
11
- { value: "service-config", label: "service-config", hint: "通用配置中心" },
12
- { value: "service-app", label: "service-app", hint: "容器化后端应用部署" },
13
- { value: "service-site", label: "service-site", hint: "静态网站部署" },
7
+ { value: "redis", label: "redis", hint: "Redis 缓存" },
8
+ { value: "postgres", label: "postgres", hint: "PostgreSQL 数据库" },
9
+ { value: "gateway", label: "gateway", hint: "反向代理 + HTTPS" },
10
+ { value: "gitea", label: "gitea", hint: "Gitea Git 服务" },
11
+ { value: "config", label: "config", hint: "通用配置中心" },
12
+ { value: "app", label: "app", hint: "容器化后端应用部署" },
13
+ { value: "site", label: "site", hint: "静态网站部署" },
14
14
  ]
@@ -12,10 +12,7 @@ async function ensureDir() {
12
12
 
13
13
  const pkgPath = path.join(ATOMSERVICE_DIR, "package.json")
14
14
  if (!fs.existsSync(pkgPath)) {
15
- await Bun.write(
16
- pkgPath,
17
- `${JSON.stringify({ name: "atomservice-config", private: true, type: "module" }, null, 2)}\n`,
18
- )
15
+ await Bun.write(pkgPath, `${JSON.stringify({ name: "atomconfig", private: true, type: "module" }, null, 2)}\n`)
19
16
  }
20
17
  }
21
18