# aaden-cli

Aaden系统的Cli应用.

usage:

```
$ >npm istall -g aaden-cli

$ >aaden-cli
                    _               _____ _      _____
     /\            | |             / ____| |    |_   _|
    /  \   __ _  __| | ___ _ __   | |    | |      | |
   / /\ \ / _` |/ _` |/ _ \ '_ \  | |    | |      | |
  / ____ \ (_| | (_| |  __/ | | | | |____| |____ _| |_
 /_/    \_\__,_|\__,_|\___|_| |_|  \_____|______|_____|


Aaden@InnerKen CLI Version:1.0.19


Usage: index [options] [command]

Options:
  -V, --version                           output the version number
  -d, --debug                             use Debug Out put
  -h, --help                              display help for command

Commands:
  update [channel]
  install [options] <deviceId> [channel]   装机（= AadenDeploy/aadensetup.sh）：撞号检查、装软件、部署后端、设备号、自检并上报
  set-device-id [deviceId]                 设定本机设备号：撞号检查、config.ini、主机名、ngrok、立即上报（镜像克隆的机器改号也用它）
  setup-wifi
  upgrade
  where
  help [command]                          display help for command

```

## 发布

1. 在 master 上运行 `npm run update`：release-it 把版本号升一个 patch，提交 `aaden-cli: release vX.Y.Z`，打 tag `X.Y.Z` 并推上去。本地不再发布 npm。
   要在普通 clone 里运行：release-it 13 认不出 `git worktree`，在 worktree 里只会改版本号，不会提交、打 tag。
2. tag 推上去后，GitHub Actions 的 `.github/workflows/publish.yml` 自动执行：
   - 校验 tag 和 `package.json` 的版本一致，并且 tag 指向的提交在 master 上；
   - 从这个 tag 对应的提交 `npm ci` 并用 ncc 打包，冒烟检查 `dist/index.js --version`；
   - 用 npm Trusted Publishing（OIDC）执行 `npm publish`，不需要 npm token 或 OTP；
   - 创建 GitHub Release。
3. 全网设备在第二天 04:55 自动 `npm install aaden-cli -g` 装上新版本。

⚠️ `latest` 一发布就是全网发布。要先在个别设备上试，用预发布通道：

- 在任意分支的提交上打 `x.y.z-后缀` 形式的 tag（如 `1.6.103-rc.0`）并推上去，CI 会把这个提交按 tag 的版本号发到 npm 的 `next`（不需要提交版本号）。
- 设备每天只装 `latest`，不会自动装 `next`。要试的设备上手动运行 `sudo npm i -g aaden-cli@next`；这台设备第二天 04:55 会自动回到 `latest`。

CI 发布失败时的手动兜底：在 tag 对应的提交上运行 `npx ncc build index.js -o dist -C && npm publish`（需要 npm 2FA）。

一次性配置：npmjs.com → aaden-cli → Settings → Trusted Publisher → GitHub Actions，填组织 `innerken-gmbh`、仓库 `aaden-cli`、workflow `publish.yml`；允许的操作要勾上 `npm publish`（2026-09-03 之后新建的配置默认只允许 `npm stage publish`，直接 publish 会报 403 "OIDC permission denied for this action"）。

## 私有分发（self-update，POS-46 第 2 期）

- `aaden-cli self-update`：从云端拿签名过的版本装到 `/opt/aaden-cli/<版本>/`，`/usr/local/bin/aaden-cli` 指向 `/opt/aaden-cli/current/package/dist/index.js`。第一次跑就把这台设备切到私有通道（root crontab 里的 npm 重装换成 self-update，标记 `/etc/aaden/config/cli-channel=private`）。实现见 `modules/self-update.js`。
- 设备命令白名单里只有 `SELF_UPDATE`（`aaden-cli self-update`）和 `CLI_BACK_TO_NPM`（`aaden-cli self-update --back-to-npm`），**没有带 `--force` 或 `--allow-downgrade` 的版本**：
  - 用 `--back-to-npm` 退回过 npm 的设备（标记是 `npm`），之后的 `self-update` 会拒绝，**只能有人登录上去手动跑 `aaden-cli self-update --force`** 才能切回 private；
  - 降级同理，只能登录上去手动 `aaden-cli self-update --allow-downgrade`。
- 私有通道的设备上**不要跑 `npm i -g aaden-cli`**：链接指向 `/opt` 时 npm 会报 EEXIST，还会把 `/usr/local/lib/node_modules/aaden-cli` 整个删掉。cron（`/usr/local/sbin/aaden-cli-install`，即 `AadenDeploy/Utils/cliInstall.sh`）和 `upgrade.sh` 都按链接实际指向自动选 self-update；`--back-to-npm` 发现 npm 那份不在会先挪开链接再重装。
