@laomojituan/cli 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/README.md +92 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # @laomojituan/cli
2
+
3
+ 一个最小可运行的 Node CLI 骨架,演示如何让工具支持 `npx` 免安装直接运行,并实现自己的 `install` 子命令。
4
+
5
+ - 零安装体验:`npx -y @laomojituan/cli@latest <command>`
6
+ - 基于 [commander](https://www.npmjs.com/package/commander) 解析子命令
7
+ - 配置写入用户目录 `~/.darkdemo/`,全局/ npx 场景下均可正常工作
8
+ - 要求 Node.js >= 18
9
+
10
+ ## 快速开始
11
+
12
+ 无需安装,直接用 npx 运行:
13
+
14
+ ```bash
15
+ npx -y @laomojituan/cli@latest hello 世界
16
+ npx -y @laomojituan/cli@latest doctor
17
+ ```
18
+
19
+ 想全局安装后使用短命令:
20
+
21
+ ```bash
22
+ npm install -g @laomojituan/cli
23
+ darkdemo --version
24
+ ```
25
+
26
+ 或者在 `~/.zshrc` / `~/.bashrc` 中加一个别名:
27
+
28
+ ```bash
29
+ alias darkdemo="npx @laomojituan/cli@latest"
30
+ ```
31
+
32
+ ## 命令
33
+
34
+ | 命令 | 说明 |
35
+ | --- | --- |
36
+ | `darkdemo install` | 初始化工具:预检 Node 版本、写入配置文件 `~/.darkdemo/config.json`、输出别名提示 |
37
+ | `darkdemo hello [name]` | 演示命令,打个招呼;`-y, --yell` 大写输出 |
38
+ | `darkdemo doctor` | 检查运行环境与安装状态,未安装时给出提示,失败时退出码为 1 |
39
+ | `darkdemo --version` | 输出版本号 |
40
+ | `darkdemo --help` | 查看帮助 |
41
+
42
+ ### install
43
+
44
+ ```bash
45
+ npx -y @laomojituan/cli@latest install
46
+ ```
47
+
48
+ 常用选项:
49
+
50
+ - `-f, --force`:已安装时覆盖配置、重新安装
51
+
52
+ 安装成功后生成的配置文件示例:
53
+
54
+ ```json
55
+ {
56
+ "version": "1.0.0",
57
+ "installedAt": "2026-09-05T04:01:34.542Z",
58
+ "node": "26.5.0",
59
+ "platform": "darwin/arm64"
60
+ }
61
+ ```
62
+
63
+ ## 本地开发
64
+
65
+ ```bash
66
+ git clone <repo> && cd darkdemocli
67
+ npm install
68
+ node cli.js --help # 直接运行
69
+ npm link # 全局软链,之后可直接用 darkdemo 命令
70
+ darkdemo hello dev
71
+ npm rm -g @laomojituan/cli # 解除软链
72
+ ```
73
+
74
+ 入口 [cli.js](cli.js) 首行的 shebang(`#!/usr/bin/env node`)和 `package.json` 中的 `bin` 字段是 CLI 能被 npx/npm 识别的关键。新增子命令时,在 `cli.js` 中注册 `program.command(...)`,并在 `src/` 下新增对应模块即可。
75
+
76
+ ## 发布
77
+
78
+ ```bash
79
+ npm version patch # 修订号 +1(minor=新功能,major=破坏性变更)
80
+ npm publish --access public # scoped 包必须带 --access public
81
+ ```
82
+
83
+ 发布说明:
84
+
85
+ - 每次发布必须递增版本号,npm 不允许覆盖已发布版本
86
+ - 账号开启 2FA 时需追加 `--otp=<验证码>`;CI 场景建议使用勾选了 Bypass 2FA 的 Granular Access Token
87
+ - 发布测试版可用 `npm publish --tag beta`,用户通过 `@beta` 安装,不影响 `latest`
88
+ - 发布后 registry 副本同步可能有 1~2 分钟延迟,期间 `npm view` 短暂 404 属正常现象
89
+
90
+ ## License
91
+
92
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laomojituan/cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Demo: a minimal npx-runnable Node CLI with an install subcommand",
5
5
  "bin": {
6
6
  "darkdemo": "cli.js"