opentmd

脚本参考

仓库内所有开发/运维脚本位于 scripts/,全部为 Bash,统一 source scripts/lib/common.sh (提供 step / ok / warn / note / die、错误栈、镜像源开关)。

git clone https://github.com/opentmd/opentmd-cli.git
cd opentmd-cli
./scripts/<name>.sh --help     # 所有脚本都支持 --help

一览

脚本 用途 面向用户
install.sh 从 GitHub Release 下载并安装(也可 --source 源码编译) ✅ 终端用户
uninstall.sh 分组卸载(二进制 / credentials / 状态) ✅ 终端用户
build.sh 构建、测试、vet、交叉编译发布包 开发者
check-test-layout.sh 强制测试实体仅在 tests/(包目录只允许符号链接) 开发者 / CI
check-version.sh 企业级版本门禁(VERSION ↔ CHANGELOG ↔ tag) 开发者 / CI
release.sh bump / tag / check 版本发布辅助 开发者
sync-to-tdc.sh 将本仓库(排除 .git)镜像同步到 ~/Desktop/TDC/opentmd 开发者
check-docs-links.sh 校验文档相对链接可达、且 docs/site/nav.json 覆盖全部用户/架构/开发文档 开发者 / CI
deploy-local.sh 构建并原子替换 PATH 中的 opentmd 开发者
run-local.sh 仓库内快捷启动(源码比产物新时自动重建) 开发者
setup-mirror.sh 持久化国内 Go/npm 镜像配置 开发者(国内网络)
mirror-env.sh 镜像环境变量库(被其它脚本 source,不单独执行) —
sysinfo.sh 收集本机环境信息(可选 JSON),用于报 issue ✅ 排障
lib/common.sh 公共函数库(被其它脚本 source) —

install.sh

# 一键安装(推荐)
curl -fsSL https://raw.githubusercontent.com/opentmd/opentmd-cli/master/scripts/install.sh | bash

# 仓库内安装(自动跳过下载失败,回退源码编译)
./scripts/install.sh
./scripts/install.sh --version v0.1.0 --dir ~/.local/bin
选项 说明
--version TAG 安装指定 release(v0.1.0 / 0.1.0 均可)
--dir DIR 安装目录(等价 OPENTMD_INSTALL_DIR)
--source 跳过 release,直接在当前源码目录编译
--skip-verify 不校验 sha256(不推荐)

行为要点:

环境变量见 安装指南 — 环境变量。

uninstall.sh

./scripts/uninstall.sh --dry-run      # 先看计划
./scripts/uninstall.sh                # 交互式(G1=yes / G2=no / G3=yes)
./scripts/uninstall.sh --purge --yes  # 全部清除,非交互
./scripts/uninstall.sh --keep-data --yes  # 只删二进制与 PATH

分组语义、备份策略与 shell rc 回滚细节见 卸载指南。

非交互环境(管道、CI)下若未给 --yes / --purge / --keep-data,脚本会以退出码 2 拒绝执行, 避免误删。退出码:0 成功、1 用户中止、2 参数或环境错误。

build.sh

./scripts/build.sh                    # → bin/opentmd(version=dev)
./scripts/build.sh --vet --test       # 先 vet + 测试
./scripts/build.sh --all              # vet + test + CLI + VS Code 扩展
VERSION=v0.1.0 ./scripts/build.sh --release   # 交叉编译 → dist/
./scripts/build.sh --clean            # 删除 bin/、dist/、扩展 out/

完整选项表、产物清单与 ldflags 说明见 构建指南。

deploy-local.sh

构建后把产物原子替换到 PATH 中已有 opentmd 所在目录;没有则依次尝试 /usr/local/bin、~/.local/bin。构建参数原样透传给 build.sh。

./scripts/deploy-local.sh
./scripts/deploy-local.sh --vet --test
OPENTMD_INSTALL_DIR=~/.local/bin ./scripts/deploy-local.sh
环境变量 说明
OPENTMD_INSTALL_DIR 目标目录(默认自动探测)
BUILD_OUTPUT 构建产物路径(默认 <repo>/bin/opentmd)
OPENTMD_NO_VERIFY 设为 1 跳过部署后的 --version 自检

run-local.sh

./opentmd 就是该脚本的入口(仓库根目录的软链/包装)。它会比较 cmd/、internal/、go.mod、go.sum 与产物的 mtime,源码更新后自动重建再 exec, 因此不需要每次手动 build 就能验证最新代码。

./opentmd --help
OPENTMD_NO_REBUILD=1 ./opentmd --version   # 强制使用现有产物
OUTPUT=bin/opentmd ./opentmd               # 自定义产物路径

setup-mirror.sh / mirror-env.sh

国内网络下 Go module 与 npm 下载常超时。build.sh / deploy-local.sh 默认在单次执行内 注入镜像环境变量(USE_CN_MIRROR=1),不落盘;需要持久生效时改用:

./scripts/setup-mirror.sh            # 写入持久配置
./scripts/setup-mirror.sh --show     # 查看当前镜像配置
./scripts/setup-mirror.sh --unset    # 还原
./scripts/setup-mirror.sh --dry-run  # 只打印将执行的命令

USE_CN_MIRROR=0 ./scripts/build.sh   # 单次关闭镜像
GOPROXY=https://proxy.example.com ./scripts/build.sh   # 自定义代理

sysinfo.sh

报 issue 时请附上该脚本输出,便于定位环境问题。

./scripts/sysinfo.sh                 # 人类可读
./scripts/sysinfo.sh --json          # JSON(字段结构稳定,适合上报)
./scripts/sysinfo.sh --verbose       # 附带 CPU 频率/缓存/内存插槽
./scripts/sysinfo.sh --no-color      # 关闭 ANSI 颜色(等价 NO_COLOR=1)

输出不包含 API Key;但会包含 OS、架构、Go/Node 版本、终端类型、opentmd --version 等基础信息,粘贴前请自行确认。

通用环境变量

变量 影响脚本 说明
OPENTMD_VERBOSE build / deploy / run-local 设为 1 回显实际执行的命令
USE_CN_MIRROR build / deploy 0 关闭国内镜像(默认 1)
VERSION build 注入 main.Version,默认 dev
OUTPUT build / run-local CLI 产物路径,默认 bin/opentmd
DIST build 发布产物目录,默认 dist
NO_STRIP build 1 保留符号表(--no-strip)
GOFLAGS build 透传给 go 的额外参数