api2cli-publish-to-github

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Publish to GitHub

发布到GitHub

Push an api2cli-generated CLI (from
~/.cli/<app>-cli/
) to a new GitHub repository.
将api2cli生成的CLI(来自
~/.cli/<app>-cli/
)推送到新的GitHub仓库。

Phase 1: Pre-flight

阶段1:前置检查

Auth

鉴权

Run
gh auth status
. If not logged in, tell the user to run
gh auth login
first. Stop and wait.
Note the GitHub username from the output (e.g.
Logged in to github.com account <username>
).
运行
gh auth status
。如果未登录,告知用户需要先运行
gh auth login
停止操作并等待用户完成。
从输出结果中记录GitHub用户名(例如
Logged in to github.com account <username>
)。

Resolve the CLI

确定CLI对象

If the user didn't specify which CLI, check
~/.cli/
and ask which one. Read
package.json
to get the package name.
如果用户没有指定要处理的CLI,检查
~/.cli/
目录并询问用户选择目标CLI。读取
package.json
文件获取包名。

Phase 2: Prepare the repo

阶段2:准备仓库

From the CLI directory (
~/.cli/<app>-cli/
):
  1. Ensure
    .gitignore
    exists
    with at least:
    node_modules/
    dist/
  2. Init or check git:
    • If no
      .git/
      : run
      git init && git add -A && git commit -m "Initial commit: <app>-cli"
    • If already a git repo: stage and commit any uncommitted changes.
  3. Never commit
    node_modules/
    or
    dist/
    .
    If already tracked,
    git rm -r --cached
    them and rewrite history so secrets in dependencies don't trigger GitHub push protection.
在CLI目录(
~/.cli/<app>-cli/
)下执行以下操作:
  1. 确保
    .gitignore
    文件存在
    ,至少包含以下内容:
    node_modules/
    dist/
  2. 初始化或检查git状态:
    • 如果不存在
      .git/
      目录:运行
      git init && git add -A && git commit -m "Initial commit: <app>-cli"
    • 如果已经是git仓库:暂存并提交所有未提交的变更。
  3. 绝对不要提交
    node_modules/
    dist/
    目录。
    如果它们已经被跟踪,执行
    git rm -r --cached
    命令移除它们并重写提交历史,避免依赖中的敏感信息触发GitHub推送保护。

Phase 3: Create the repo and push

阶段3:创建仓库并推送

bash
gh repo create <app>-cli --public --source=. --push --description "<description from package.json>"
  • If
    gh repo create
    succeeds but push fails (e.g. push protection), fix the issue per Phase 2 and run
    git push -u origin <branch> --force
    .
  • If
    gh repo create
    says "unable to add remote" (remote already exists), just push:
    git push -u origin <branch>
    .
  • If the repo name is taken, ask the user for an alternative name.
bash
gh repo create <app>-cli --public --source=. --push --description "<description from package.json>"
  • 如果
    gh repo create
    执行成功但推送失败(例如触发推送保护),按照阶段2的要求修复问题后运行
    git push -u origin <branch> --force
  • 如果
    gh repo create
    提示“无法添加远程仓库”(远程仓库已存在),直接执行推送命令即可:
    git push -u origin <branch>
  • 如果仓库名已被占用,询问用户提供备选名称。

Phase 3.5: Update README

阶段3.5:更新README

After pushing, check if the README contains
<user>/
in the install commands. If so, replace
<user>
with the actual GitHub username and commit + push the fix.
推送完成后,检查README中的安装命令是否包含
<user>/
占位符。如果存在,将
<user>
替换为实际的GitHub用户名,提交并推送该修改。

Phase 4: Done

阶段4:完成

Report:
  • Repo URL:
    https://github.com/<username>/<app>-cli
  • What was pushed (file count, branch name)
向用户反馈以下信息:
  • 仓库地址:
    https://github.com/<username>/<app>-cli
  • 推送内容说明:文件数量、分支名称

Do NOT

禁止操作

  • Do not commit
    node_modules/
    ,
    dist/
    ,
    .env
    , or token files.
  • Do not force-push to an existing repo with other contributors without asking.
  • Do not change the git user config.
  • 不要提交
    node_modules/
    dist/
    .env
    或令牌文件。
  • 不要在未征得用户同意的情况下,强制推送到有其他贡献者的已有仓库。
  • 不要修改git用户配置。