cws-release 0.1.2 → 0.1.3

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/INSTALL.md CHANGED
@@ -1,39 +1,68 @@
1
1
  # Install
2
2
 
3
- Two ways, one trade-off:
3
+ Four options. Pick by **how many extensions you maintain**, not by taste:
4
4
 
5
- | | Way | What you run | When |
6
- | --- | --- | --- | --- |
7
- | **A** | **npx** — no install | `npx -y cws-release -- cws release` | Try it, or one-off releases from a terminal or CI |
8
- | **B** | **Install** — a permanent `cws` command | `npm i -g cws-release`, then `cws release` | You publish regularly; nothing to re-type |
5
+ | | Option | What you run | Version lives in | Best for |
6
+ | --- | --- | --- | --- | --- |
7
+ | A | npx, nothing saved | `npx cws-release release` | nowhere (latest each run) | Trying it out, a one-off hotfix |
8
+ | **B** | **dev dependency (recommended)** | `npm i -D cws-release`, then `npm run cws release` | `package.json` + lockfile, per repo | **Several extensions** |
9
+ | C | global | `npm i -g cws-release`, then `cws release` | your machine | One extension, or a throwaway VM |
10
+ | D | GitHub Action | `uses: XCreativeStudio/cws-release@v1` | the `@v1` tag | Release pipelines |
9
11
 
10
- Both handle the same repository config. If an agent maintains the release
11
- flow, **B** costs one more step and removes a long command from every run
12
- afterwards.
12
+ Every option reads the same `.cws.json` from the repository, so switching
13
+ between them later changes nothing else.
13
14
 
14
- ## A. npx — nothing to install
15
+ ## Option B in detail: a dev dependency, for several extensions
15
16
 
16
17
  ```sh
17
- npx -y cws-release -- cws init # once
18
- npx -y cws-release -- cws release # every release
18
+ npm i -D cws-release # in each extension repository
19
+ npm pkg set scripts.cws=cws
20
+ npm run cws init # once per repo
21
+ npm run cws release # every release
19
22
  ```
20
23
 
21
- Until `cws-release` is on npm, use
22
- `npx -y --package=github:XCreativeStudio/cws-release -- cws <command>`.
24
+ Why this scales to many repositories, while `-g` does not:
23
25
 
24
- The bare `npx -y <spec> <args>` form does **not** work here — npx passes `init`
25
- to `cws` as if it were a package name, and you get the `--help` text instead.
26
- Keep `--package=<spec> -- cws <command>`.
26
+ - **Each repo pins its own version.** Two extensions can sit on different
27
+ CLI versions at the same time; upgrading one is a one-line diff in *that*
28
+ repo, reviewable like any dependency bump.
29
+ - **CI and teammates get the same binary.** The lockfile travels with the
30
+ code, so `npm ci && npm run cws release` behaves identically everywhere.
31
+ A global install pins nothing: today's latest is tomorrow's surprise.
32
+ - **`npm run cws` always finds it**, and works from any subdirectory, because
33
+ npm puts `node_modules/.bin` on `PATH` for scripts.
34
+ - **`npx cws-release`** in a repo that has it installed uses the *local*
35
+ copy, so even ad-hoc commands respect the pin.
27
36
 
28
- `npx` caches the package in `~/.npm/_npx`; it writes nothing into the
29
- repository, so it adds no git churn and no lockfile entry. `npm run cws`
30
- still works if you prefer a script alias:
37
+ Cost: `node_modules` gains one package (it has no dependencies of its own).
31
38
 
32
- ```json
33
- { "scripts": { "cws": "npx -y cws-release -- cws" } }
39
+ Use `-g` only when the machine is not the project — a scratch VM, a shell
40
+ where you publish once. For a laptop that builds several extensions, `-g`
41
+ quietly couples every project to one version.
42
+
43
+ Keep it in `devDependencies`: this is a **publishing tool, not a runtime
44
+ dependency** of the extension. The CLI uploads a zip your build already
45
+ produced and never packages anything itself, so it has no effect on the
46
+ extension's contents.
47
+
48
+ ## Option A: npx — nothing saved
49
+
50
+ ```sh
51
+ npx cws-release init # once
52
+ npx cws-release release # every release
34
53
  ```
35
54
 
36
- ## B. Install — a `cws` command
55
+ The package name goes first, the command second — **no `--` separator**, which
56
+ would be forwarded to the CLI and rejected as an unknown option. Both `-y` and
57
+ `--no` are unnecessary here: since npm 7 `npx` installs a missing package
58
+ without asking. Add `--no` only when you want a missing install to fail fast
59
+ instead of fetching (`npx --no cws-release release`).
60
+
61
+ `npx` caches the package in `~/.npm/_npx`; it writes nothing into the
62
+ repository, so it adds no git churn and no lockfile entry. A repository that has
63
+ `cws-release` in `devDependencies` gets its **local** copy automatically.
64
+
65
+ ## Option C: install — a `cws` command
37
66
 
38
67
  Once per machine, for every extension repository:
39
68
 
@@ -54,7 +83,7 @@ npm install --no-save --no-audit --no-fund cws-release
54
83
  npm run cws release
55
84
  ```
56
85
 
57
- ## CI / as a GitHub Action
86
+ ## Option D: a GitHub Action
58
87
 
59
88
  ```yaml
60
89
  - uses: XCreativeStudio/cws-release@v1
@@ -67,7 +96,7 @@ npm run cws release
67
96
  The action needs Node ≥ 22 on the runner (`actions/setup-node`), installs `cws`
68
97
  and returns the JSON envelope as `result` plus the failure `code`.
69
98
 
70
- ## C. For an agent
99
+ ## For an agent
71
100
 
72
101
  Some agents only read a skill directory; they cannot run a command first to
73
102
  discover one. Give them the skill and let the procedure carry the install
@@ -78,15 +107,14 @@ mkdir -p .agents/skills
78
107
  git clone --depth 1 https://github.com/XCreativeStudio/cws-release.git .agents/skills/chrome-web-store-publish
79
108
  ```
80
109
 
81
- The agent then reads `SKILL.md` and runs the npx or installed form from
82
- options A/B. A cloned skill directory is version-pinned and works offline,
83
- which is what an agent workspace wants. `cws init` also copies `SKILL.md`
84
- and this file into `.agents/skills/chrome-web-store-publish/`, so in a
85
- repository that has already done A or B the agent needs no extra step.
110
+ The agent then reads `SKILL.md` and runs the CLI from option A, B or C. A
111
+ cloned skill directory is version-pinned and works offline, which is what an
112
+ agent workspace wants. `cws init` also copies `SKILL.md` and this file into
113
+ `.agents/skills/chrome-web-store-publish/`, so a repository that already did B
114
+ or C needs no extra step.
86
115
 
87
116
  ## The package name is cws-release
88
117
 
89
118
  The npm name **`cws-publish` belongs to an unrelated project**, so never run
90
119
  `npx cws-publish` or `npm i -g cws-publish` — you would install someone else's
91
- code. This CLI is published as **`cws-release`**. If a release is not on npm yet,
92
- fall back to the `github:` specifier (`github:XCreativeStudio/cws-release`).
120
+ code. This CLI is published as **`cws-release`**.
package/README.md CHANGED
@@ -1,14 +1,33 @@
1
- # cws-publish
1
+ # cws-release
2
2
 
3
- Upload and publish Chrome extensions with the **Chrome Web Store API v2**, from
4
- one zero-dependency Node CLI.
3
+ Publish Chrome extensions from the terminal, your CI, or an AI agent — with the
4
+ **Chrome Web Store API v2**, from one zero-dependency Node CLI.
5
+
6
+ **English** · [简体中文](README.zh-CN.md) · [Project site](https://xcreativestudio.github.io/cws-release/)
7
+
8
+ Stop clicking through the developer dashboard for every release. `cws` uploads
9
+ your zip, submits it for review, and tells you the store's real state — or the
10
+ exact reason it refused.
11
+
12
+ ## Quick start
5
13
 
6
14
  ```sh
7
- cws check # prove the credentials work, then print the item status
8
- cws release # upload the zip, submit for review, print the result
9
- cws status # published / submitted revision state
15
+ npm i -D cws-release # in your extension repository
16
+ npx cws-release init # once: writes .cws.json + the agent skill
17
+
18
+ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
19
+ npx cws-release check # proves the credentials work, in three seconds
20
+ npx cws-release release # upload -> submit for review -> print the state
10
21
  ```
11
22
 
23
+ Prerequisites (`check` will tell you what is missing): the item already exists
24
+ in the store, the publisher has 2FA on, and the service account is added under
25
+ **Account** in the [Developer Dashboard](https://chrome.google.com/webstore/devconsole).
26
+ The API cannot create a new item — the first upload and the listing tabs are
27
+ manual.
28
+
29
+ ## Why this one
30
+
12
31
  - **No dependencies.** Node ≥ 22 signs the service-account JWT with `node:crypto`
13
32
  and uses the built-in `fetch`; there is nothing to install or audit.
14
33
  - **Service account, not a refresh token.** One key, added once in the Web Store
@@ -17,54 +36,29 @@ cws status # published / submitted revision state
17
36
  the store's state instead of inventing one.
18
37
  - **Built for agents.** Every command accepts `--json` and returns
19
38
  `{ ok, command, data }`; a failure returns a stable `error.code` and a hint on
20
- what to fix. No log scraping.
21
-
22
- It also ships as a [skill](SKILL.md) for coding agents: the skill directory
23
- holds the procedure, the guardrails and the CLI together.
39
+ what to fix. No log scraping — see [For agents and scripts](#for-agents-and-scripts).
40
+ - **Ships as a [skill](SKILL.md)** for coding agents: the procedure, the
41
+ guardrails and the CLI live together.
24
42
 
25
43
  ## Install
26
44
 
27
- Two ways, same CLI. **npx** — nothing to install:
28
-
29
- ```sh
30
- npx -y cws-release -- cws init # once; on npm
31
- npx -y cws-release -- cws release # every release; on npm
32
- ```
33
-
34
- **Install** — a permanent `cws` command, for regular publishers and CI:
35
-
36
- ```sh
37
- npm i -g cws-release
38
- cws release
39
- ```
40
-
41
- Until `cws-release` is on npm, use the GitHub specifier instead:
42
- `npx -y --package=github:XCreativeStudio/cws-release -- cws release` /
43
- `npm i -g github:XCreativeStudio/cws-release`.
44
-
45
- Run `init` once in each extension repository: it writes a `.cws.json` template
46
- and copies the agent skill into `.agents/skills/chrome-web-store-publish/`.
47
- Installing into an agent instead? Clone the repo into that skill directory and
48
- the agent follows [SKILL.md](SKILL.md) — that is option C in
49
- [INSTALL.md](INSTALL.md).
50
-
51
- The npm package is **`cws-release`** (not `cws-publish` — that name belongs to an
52
- unrelated project). No build step, no `npm install` inside this repository.
53
-
54
- ## One-time setup
45
+ | You have… | Use | Pin |
46
+ | --- | --- | --- |
47
+ | **Several extensions** | `npm i -D cws-release`, then `npx cws-release <cmd>` | `package.json` + lockfile, per repo |
48
+ | One extension, or trying it | `npm i -g cws-release` | your machine |
49
+ | A release pipeline | `uses: XCreativeStudio/cws-release@v1` | the tag |
55
50
 
56
- 1. Google Cloud Console: enable **Chrome Web Store API**, create a service
57
- account, download a JSON key.
58
- 2. [Developer Dashboard](https://chrome.google.com/webstore/devconsole) →
59
- **Account** → add the service-account email (one per publisher).
60
- 3. Note the **Publisher ID** and the **item ID** (the extension ID).
51
+ With a dev dependency each repository pins its own version, so upgrading one
52
+ extension never changes another and CI installs exactly what you tested. A
53
+ global install pins nothing — every project on that machine shares one version.
54
+ [INSTALL.md](INSTALL.md) compares all four options, including running `cws` from
55
+ an agent skill directory.
61
56
 
62
- The API cannot create items: the first upload and the listing/privacy tabs are
63
- manual. After that, everything below is scriptable.
57
+ No build step, and no `npm install` inside this repository.
64
58
 
65
59
  ## Configure
66
60
 
67
- Commit identifiers in `.cws.json`:
61
+ Commit identifiers, never secrets, in `.cws.json` (`init` writes the template):
68
62
 
69
63
  ```json
70
64
  {
@@ -74,82 +68,81 @@ Commit identifiers in `.cws.json`:
74
68
  }
75
69
  ```
76
70
 
77
- Keep the key out of the repository:
71
+ `itemId` is the 32-character extension id; `zip` may be a single `*`/`?` glob
72
+ because build output usually carries the version. Point the CLI at the key:
78
73
 
79
74
  ```sh
80
- export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
81
- # or, in CI:
82
- export CWS_SERVICE_ACCOUNT="$(cat key.json)"
83
- # or reuse a token from gcloud / the OAuth playground:
84
- export CWS_ACCESS_TOKEN="$(gcloud auth print-access-token --scopes=https://www.googleapis.com/auth/chromewebstore)"
75
+ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json" # local
76
+ export CWS_SERVICE_ACCOUNT="$(cat key.json)" # CI secret
77
+ export CWS_ACCESS_TOKEN="$(gcloud auth print-access-token \
78
+ --scopes=https://www.googleapis.com/auth/chromewebstore)" # short-lived
85
79
  ```
86
80
 
87
- Environment overrides the file; `--zip` overrides both.
81
+ Environment overrides the file; `--zip` overrides both. `CWS_PUBLISHER_ID`,
82
+ `CWS_ITEM_ID` (`CWS_EXTENSION_ID` also works), `CWS_ZIP` and `CWS_PUBLISH_TYPE`
83
+ override the matching keys.
88
84
 
89
85
  ## Commands
90
86
 
91
87
  | Command | What it does |
92
88
  | --- | --- |
93
- | `cws init` | Write a `.cws.json` template and the skill into the current repository |
94
- | `cws check` | Token exchange + `fetchStatus`; separates "the secret is set" from "the secret works" |
95
- | `cws upload [zip]` | `upload` the package and wait for asynchronous processing |
96
- | `cws publish` | `publish` the uploaded package for review |
97
- | `cws release [zip]` | upload + publish + status |
98
- | `cws status` | published and submitted revision state |
99
- | `cws cancel` | cancel a submission under review |
89
+ | `cws init` | Write a `.cws.json` template and the agent skill into this repository |
90
+ | `cws check` | Exchange the token and call `fetchStatus`; separates "the secret is set" from "the secret works" |
91
+ | `cws upload [zip]` | Upload the package, then wait for asynchronous processing |
92
+ | `cws publish` | Submit the uploaded package for review |
93
+ | `cws release [zip]` | upload → publish → status, in one step |
94
+ | `cws status` | Published and submitted revision state |
95
+ | `cws cancel` | Cancel a submission that is under review |
100
96
 
101
97
  Flags: `--staged` (`STAGED_PUBLISH`), `--live` (`DEFAULT_PUBLISH`),
102
98
  `--block-on-warnings`, `--json`, `--timeout <ms>`, `--config <path>`,
103
- `--api <url>`.
99
+ `--api <url>`, `--force` (with `init`).
100
+
101
+ `status` is the honest answer to "is it live yet?": `PUBLISHED` in
102
+ `publishedItemRevisionStatus` means live, anything else is still in review.
104
103
 
105
104
  ## For agents and scripts
106
105
 
107
- `--json` turns the CLI into an interface an agent can trust, instead of a log to
108
- scrape. Success goes to stdout, progress lines go to stderr.
106
+ `--json` turns the CLI into an interface instead of a log to scrape. Success
107
+ goes to stdout; progress lines go to stderr.
109
108
 
110
109
  ```jsonc
111
- // cws release --json (success, stdout)
112
- { "ok": true, "command": "release", "data": { "upload": {...}, "publish": {...}, "status": {...} } }
110
+ // cws release --json (stdout)
111
+ { "ok": true, "command": "release", "data": { "upload": {…}, "publish": {…}, "status": {…} } }
113
112
  ```
114
113
 
115
- Failure writes exactly one structured line to stderr, prefixed so it can be
114
+ A failure writes exactly one structured line to stderr, prefixed so it can be
116
115
  found among the progress lines:
117
116
 
118
117
  ```sh
119
- cws:json {"ok":false,"error":{"code":"PUBLISHER_FORBIDDEN","status":403,"reason":"PERMISSION_DENIED","message":"HTTP 403: PERMISSION_DENIED: ...","hint":"Add the service-account email under Account in the Developer Dashboard, and check publisherId in .cws.json."}}
118
+ cws:json {"ok":false,"error":{"code":"PUBLISHER_FORBIDDEN","status":403,
119
+ "reason":"PERMISSION_DENIED","message":"HTTP 403: PERMISSION_DENIED: …",
120
+ "hint":"Add the service-account email under Account in the Developer Dashboard, and check publisherId in .cws.json."}}
120
121
  ```
121
122
 
122
- `error.code` is stable and safe to branch on:
123
+ Extract it with `sed -n 's/^cws:json //p'` and branch on `error.code`, which
124
+ never changes meaning. The most common ones:
123
125
 
124
- | `code` | Meaning | Usual fix |
125
- | --- | --- | --- |
126
- | `NO_CREDENTIALS` | No key or token configured | Set `CWS_SERVICE_ACCOUNT_FILE` / `CWS_ACCESS_TOKEN` |
127
- | `CREDENTIALS_UNREADABLE` | Key file missing or malformed | Paste the whole JSON key, newlines included |
128
- | `AUTH_FAILED` | Google rejected the token | Token expired (≈1 h) or key is wrong |
129
- | `PUBLISHER_FORBIDDEN` | Account not authorized for the item | Add the service account in the dashboard |
130
- | `ITEM_NOT_FOUND` | Wrong `itemId`/`publisherId` | Fix `.cws.json` |
131
- | `ITEM_STATE_CONFLICT` | State blocks the request | Run `cws status`, act on the state |
132
- | `RATE_LIMITED` | Store throttled the call | Back off and retry |
133
- | `UPLOAD_REJECTED` | Store rejected the package | Raise the manifest version; check the manifest |
134
- | `UPLOAD_TIMEOUT` | Async upload did not settle | `--timeout`, or check the dashboard |
135
- | `MISCONFIGURED` | `.cws.json` is invalid | Fill the identifiers |
136
- | `INVALID_PACKAGE` | Zip missing, ambiguous or not a zip | Build the package, or pass an exact path |
137
- | `USAGE` | Command line could not be parsed | Fix arguments (exit code 2) |
138
- | `API_ERROR` | Unclassified store error | Read `status`/`reason` |
139
-
140
- Exit codes stay coarse for shells: `0` success, `1` failure, `2` usage. The
141
- `--json` shape for success is `{ ok, command, data }`; the keys of `data` are the
142
- raw API responses, unchanged.
126
+ | `code` | Usual fix |
127
+ | --- | --- |
128
+ | `NO_CREDENTIALS` | Set `CWS_SERVICE_ACCOUNT_FILE` or `CWS_ACCESS_TOKEN` |
129
+ | `PUBLISHER_FORBIDDEN` | Add the service account in the dashboard; check `publisherId` |
130
+ | `UPLOAD_REJECTED` | Raise the manifest version above the published one |
131
+
132
+ All 14 codes, with meanings and fixes: [docs/errors.md](docs/errors.md). Exit
133
+ codes stay coarse for shells — `0` success, `1` failure, `2` usage — and the
134
+ keys of `data` are the raw API responses, unchanged.
143
135
 
144
136
  ## CI
145
137
 
146
- As a GitHub Action (no install step, `result` and `code` as outputs):
138
+ As a GitHub Action — it installs the CLI, checks the Node version, and exposes
139
+ the JSON envelope as `result` and the failure code as `code`:
147
140
 
148
141
  ```yaml
149
142
  - uses: actions/checkout@v4
150
143
  - uses: actions/setup-node@v4
151
144
  with:
152
- node-version: 22 # the CLI needs Node ≥ 22; the action checks this
145
+ node-version: 22
153
146
  - uses: XCreativeStudio/cws-release@v1
154
147
  with:
155
148
  command: release
@@ -158,41 +151,24 @@ As a GitHub Action (no install step, `result` and `code` as outputs):
158
151
  CWS_SERVICE_ACCOUNT: ${{ secrets.CWS_SERVICE_ACCOUNT }}
159
152
  ```
160
153
 
161
- Inputs: `command` (`release`, `upload`, `publish`, `status`, `check`, `cancel`),
162
- `zip`, `staged`, `block_on_warnings`, `timeout`, `json`, `cli_version`.
163
- Credentials are **not** inputs — put them in the step `env`, so they never show
164
- up in the action's resolved inputs.
154
+ Inputs: `command`, `zip`, `staged`, `block_on_warnings`, `timeout`, `json`,
155
+ `cli_version`. Credentials are **not** inputs — keep them in the step `env` so
156
+ they never appear in the action's resolved inputs.
165
157
 
166
- As a plain command, on any CI:
158
+ Other CI systems: [docs/ci.md](docs/ci.md).
167
159
 
168
- ```yaml
169
- - run: npx -y cws-release -- cws release
170
- env:
171
- CWS_SERVICE_ACCOUNT: ${{ secrets.CWS_SERVICE_ACCOUNT }}
172
- ```
173
-
174
- Or, as a script that fails with the API's own reason and hint:
175
-
176
- ```sh
177
- out=$(npx -y cws-release -- cws release --json 2>err.log) || {
178
- sed -n 's/^cws:json //p' err.log | jq -r '.error | "\(.code): \(.message) — \(.hint // "")"'
179
- exit 1
180
- }
181
- echo "$out" | jq -r '.data.status.publishedItemRevisionStatus.state'
182
- ```
160
+ ## What this CLI does and does not do
183
161
 
184
- ## What the API can and cannot do
162
+ Implemented: `upload`, `publish` (DEFAULT and STAGED), `fetchStatus`,
163
+ `cancelSubmission`.
185
164
 
186
- | Can | Cannot |
187
- | --- | --- |
188
- | `upload` a package | create a new item |
189
- | `publish` (DEFAULT or STAGED) | edit the listing, screenshots or privacy answers |
190
- | `fetchStatus`, `fetchReviews`, `queryMetrics` | change visibility |
191
- | `cancelSubmission`, `rollback`, `setPublishedDeployPercentage` | — |
165
+ Not implemented: `fetchReviews`, `getRatingSummary`, `queryMetrics`, `rollback`,
166
+ `setPublishedDeployPercentage`. The v2 API offers them; this CLI does not call
167
+ them — see the roadmap on the [project site](https://xcreativestudio.github.io/cws-release/).
192
168
 
193
- Details: [Using the API](https://developer.chrome.com/docs/webstore/using-api),
194
- [service accounts](https://developer.chrome.com/docs/webstore/service-accounts),
195
- [REST v2](https://developer.chrome.com/docs/webstore/api/reference/rest).
169
+ Outside the API's reach, so do these by hand in the dashboard: creating a new
170
+ item, editing the listing, screenshots, privacy answers, visibility and
171
+ pricing.
196
172
 
197
173
  ## Development
198
174
 
@@ -201,8 +177,8 @@ node --test
201
177
  ```
202
178
 
203
179
  The suite covers JWT signing, config precedence, upload/publish request shapes,
204
- asynchronous polling, error mapping, and one real HTTP round trip against a
205
- local server. No credentials needed.
180
+ asynchronous polling, error mapping, the JSON error contract, and real HTTP
181
+ round trips against a local server. No credentials needed.
206
182
 
207
183
  ## License
208
184
 
@@ -0,0 +1,172 @@
1
+ # cws-release
2
+
3
+ 从终端、CI,或让 AI 助手,用 **Chrome Web Store API v2** 发布 Chrome 扩展——
4
+ 一个零依赖的 Node CLI。
5
+
6
+ [English](README.md) · **简体中文** · [项目主页](https://xcreativestudio.github.io/cws-release/)
7
+
8
+ 每次发版不用再在开发者后台里点来点去。`cws` 上传你的 zip、提交审核,并告诉你
9
+ 商店的真实状态——或者它拒绝的准确原因。
10
+
11
+ ## 快速开始
12
+
13
+ ```sh
14
+ npm i -D cws-release # 在你的扩展仓库里
15
+ npx cws-release init # 一次性:生成 .cws.json + agent skill
16
+
17
+ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
18
+ npx cws-release check # 三秒内验证凭据可用
19
+ npx cws-release release # 上传 → 提交审核 → 打印状态
20
+ ```
21
+
22
+ 前置条件(`check` 会告诉你还差什么):条目已在商店中存在、发布者已开启两步验证、
23
+ 服务账号已加入[开发者后台](https://chrome.google.com/webstore/devconsole)的
24
+ **Account** 页。API 无法创建新条目——首次上传和商店信息页需手动完成。
25
+
26
+ ## 为什么用它
27
+
28
+ - **零依赖。** Node ≥ 22 用 `node:crypto` 自签服务账号 JWT,用内置 `fetch` 发请求;
29
+ 没有东西需要安装或审计。
30
+ - **服务账号,不是 refresh token。** 一把密钥在后台加一次,该发布者下所有条目通用,
31
+ 且不会过期。
32
+ - **诚实的输出。** `publish` 返回的是审核状态而不是"已上线";CLI 打印商店的真实状态,
33
+ 不编造。
34
+ - **为 AI 设计。** 所有命令都支持 `--json`,返回 `{ ok, command, data }`;失败返回
35
+ 稳定的 `error.code` 和修复提示,不需要爬日志——见[给 AI 和脚本使用](#给-ai-和脚本使用)。
36
+ - **附带 [skill](SKILL.md)** 给编码助手:操作流程、护栏和 CLI 放在一起。
37
+
38
+ ## 安装
39
+
40
+ | 你的情况 | 用 | 版本固定在哪 |
41
+ | --- | --- | --- |
42
+ | **维护多个扩展** | `npm i -D cws-release`,然后 `npx cws-release <命令>` | 每个仓库的 `package.json` + lockfile |
43
+ | 只有一个扩展,或试用 | `npm i -g cws-release` | 你的机器 |
44
+ | 发布流水线 | `uses: XCreativeStudio/cws-release@v1` | 标签 |
45
+
46
+ 用 dev dependency 时,每个仓库固定自己的版本,升级一个扩展不会影响另一个,CI 装的
47
+ 正是你测过的那个。全局安装不固定任何版本——那台机器上所有项目共用一个版本。
48
+ [INSTALL.md](INSTALL.md) 对比了全部四种方式,包括从 agent skill 目录运行。
49
+
50
+ 没有构建步骤,本仓库内部也不需要 `npm install`。
51
+
52
+ ## 配置
53
+
54
+ 把标识符(不是密钥)提交进 `.cws.json`(`init` 会生成模板):
55
+
56
+ ```json
57
+ {
58
+ "publisherId": "…",
59
+ "itemId": "…",
60
+ "zip": ".output/*-chrome.zip"
61
+ }
62
+ ```
63
+
64
+ `itemId` 是 32 位的扩展 ID;`zip` 可以是单个 `*`/`?` 通配符,因为构建产物通常带版本号。
65
+ 让 CLI 找到密钥:
66
+
67
+ ```sh
68
+ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json" # 本地
69
+ export CWS_SERVICE_ACCOUNT="$(cat key.json)" # CI 密钥
70
+ export CWS_ACCESS_TOKEN="$(gcloud auth print-access-token \
71
+ --scopes=https://www.googleapis.com/auth/chromewebstore)" # 短期令牌
72
+ ```
73
+
74
+ 环境变量覆盖配置文件;`--zip` 覆盖两者。`CWS_PUBLISHER_ID`、`CWS_ITEM_ID`
75
+ (`CWS_EXTENSION_ID` 也可)、`CWS_ZIP`、`CWS_PUBLISH_TYPE` 覆盖对应字段。
76
+
77
+ ## 命令
78
+
79
+ | 命令 | 作用 |
80
+ | --- | --- |
81
+ | `cws init` | 在当前仓库写入 `.cws.json` 模板和 agent skill |
82
+ | `cws check` | 换取令牌并调用 `fetchStatus`;区分"密钥已配置"和"密钥可用" |
83
+ | `cws upload [zip]` | 上传包,然后等待异步处理完成 |
84
+ | `cws publish` | 把已上传的包提交审核 |
85
+ | `cws release [zip]` | 一步完成 上传 → 提交审核 → 状态 |
86
+ | `cws status` | 已发布和已提交的版本状态 |
87
+ | `cws cancel` | 取消正在审核中的提交 |
88
+
89
+ 参数:`--staged`(`STAGED_PUBLISH`)、`--live`(`DEFAULT_PUBLISH`)、
90
+ `--block-on-warnings`、`--json`、`--timeout <ms>`、`--config <path>`、
91
+ `--api <url>`、`--force`(配合 `init`)。
92
+
93
+ "到底上线了吗"——用 `status` 回答:`publishedItemRevisionStatus` 里的
94
+ `PUBLISHED` 才算已上线,其余都还在审核中。
95
+
96
+ ## 给 AI 和脚本使用
97
+
98
+ `--json` 把 CLI 变成可解析的接口,而不是需要爬取的日志。成功写 stdout;进度行写 stderr。
99
+
100
+ ```jsonc
101
+ // cws release --json (stdout)
102
+ { "ok": true, "command": "release", "data": { "upload": {…}, "publish": {…}, "status": {…} } }
103
+ ```
104
+
105
+ 失败时 stderr 恰好写一行结构化数据,带前缀,便于在进度行中定位:
106
+
107
+ ```sh
108
+ cws:json {"ok":false,"error":{"code":"PUBLISHER_FORBIDDEN","status":403,
109
+ "reason":"PERMISSION_DENIED","message":"HTTP 403: PERMISSION_DENIED: …",
110
+ "hint":"Add the service-account email under Account in the Developer Dashboard, and check publisherId in .cws.json."}}
111
+ ```
112
+
113
+ 用 `sed -n 's/^cws:json //p'` 提取,然后对 `error.code` 分支——它的含义永不改变。
114
+ 最常见的几个:
115
+
116
+ | `code` | 通常的修复方式 |
117
+ | --- | --- |
118
+ | `NO_CREDENTIALS` | 设置 `CWS_SERVICE_ACCOUNT_FILE` 或 `CWS_ACCESS_TOKEN` |
119
+ | `PUBLISHER_FORBIDDEN` | 在后台加入服务账号;检查 `publisherId` |
120
+ | `UPLOAD_REJECTED` | 把 manifest 版本号提高到已发布版本之上 |
121
+
122
+ 全部 14 个错误码的完整含义与修复方式见 [docs/errors.md](docs/errors.md)。退出码对
123
+ shell 保持粗粒度——`0` 成功、`1` 失败、`2` 用法错误——`data` 里的字段是未经改动的
124
+ 原始 API 响应。
125
+
126
+ ## CI
127
+
128
+ 作为 GitHub Action——它会安装 CLI、检查 Node 版本,并把 JSON 信封暴露为 `result`、
129
+ 把失败码暴露为 `code`:
130
+
131
+ ```yaml
132
+ - uses: actions/checkout@v4
133
+ - uses: actions/setup-node@v4
134
+ with:
135
+ node-version: 22
136
+ - uses: XCreativeStudio/cws-release@v1
137
+ with:
138
+ command: release
139
+ zip: .output/*-chrome.zip
140
+ env:
141
+ CWS_SERVICE_ACCOUNT: ${{ secrets.CWS_SERVICE_ACCOUNT }}
142
+ ```
143
+
144
+ 输入:`command`、`zip`、`staged`、`block_on_warnings`、`timeout`、`json`、
145
+ `cli_version`。凭据**不是**输入项——放进步骤的 `env`,这样它们不会出现在 action
146
+ 的已解析输入日志里。
147
+
148
+ 其他 CI 系统见 [docs/ci.md](docs/ci.md)。
149
+
150
+ ## 本 CLI 能做与不能做
151
+
152
+ 已实现:`upload`、`publish`(DEFAULT 与 STAGED)、`fetchStatus`、`cancelSubmission`。
153
+
154
+ 未实现:`fetchReviews`、`getRatingSummary`、`queryMetrics`、`rollback`、
155
+ `setPublishedDeployPercentage`。v2 API 提供了它们,但本 CLI 不调用——路线图见
156
+ [项目主页](https://xcreativestudio.github.io/cws-release/)。
157
+
158
+ API 边界之外、需要在后台手动完成的:创建新条目、编辑商店信息、截图、隐私问卷、
159
+ 可见性和定价。
160
+
161
+ ## 开发
162
+
163
+ ```sh
164
+ node --test
165
+ ```
166
+
167
+ 测试覆盖 JWT 签名、配置优先级、上传/发布请求结构、异步轮询、错误映射、JSON 错误契约,
168
+ 以及针对本地服务器的真实 HTTP 往返。无需任何凭据。
169
+
170
+ ## 许可证
171
+
172
+ MIT
package/SKILL.md CHANGED
@@ -15,17 +15,17 @@ Nothing is installed next to this file: GitHub is the source. Use whichever
15
15
  form is already available, from the repository root:
16
16
 
17
17
  ```sh
18
- npx -y cws-release -- cws <command> # nothing installed
19
- npm run cws <command> # "scripts": { "cws": "cws" }
20
- node <skill-dir>/cws.mjs <command> # this clone, no network
18
+ npx cws-release <command> # installed as a dev dependency, or fetched
19
+ npm run cws <command> # if package.json has "scripts": { "cws": "cws" }
20
+ node <skill-dir>/cws.mjs <command> # this clone, no network
21
21
  ```
22
22
 
23
- Both npm forms run with the repository root as cwd, so `.cws.json` resolves
24
- correctly. Run `cws init` once per repository: it writes the `.cws.json`
25
- template and copies this skill into `.agents/skills/` when missing. Do not
26
- retry with a bare `npx cws-publish` — that name on npm is another project. The
27
- package is `cws-release`; if a release is not on npm yet, use
28
- `--package=github:XCreativeStudio/cws-release --`.
23
+ The package name comes first and the command second — **no `--` separator**,
24
+ which the CLI would reject as an unknown option. Both npm forms run with the
25
+ repository root as cwd, so `.cws.json` resolves correctly. Run `cws init` once
26
+ per repository: it writes the `.cws.json` template and copies this skill into
27
+ `.agents/skills/` when missing. Never run `npx cws-publish` — that npm name is
28
+ an unrelated project.
29
29
 
30
30
  A clone whose `cws.mjs --help` shows no `init` line predates `init`; run it with
31
31
  the npx form above.
@@ -160,8 +160,8 @@ Or inline, with no extra action:
160
160
  ```
161
161
 
162
162
  The CLI has no dependencies, so the install step only clones and caches it; no
163
- `pnpm install` is needed. `npx -y cws-release -- cws release`
164
- also works as a single step — the cache warm-up is the only cost from then on.
163
+ `pnpm install` is needed. `npx cws-release release` also works as a single
164
+ step — the cache warm-up is the only cost from then on.
165
165
 
166
166
  ## Troubleshooting
167
167
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cws-release",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Zero-dependency CLI for the Chrome Web Store API v2: upload, publish and check extension status with a service account.",
5
5
  "type": "module",
6
6
  "bin": { "cws": "./cws.mjs" },
package/src/init.mjs CHANGED
@@ -42,7 +42,7 @@ export function init({ cwd = process.cwd(), force = false, log = (line) => proce
42
42
  if (!existsSync(configPath) || defaultsOnly(configPath)) {
43
43
  log(`\nnext fill publisherId and itemId in ${CONFIG_FILE} (never the key)`);
44
44
  }
45
- log(' check npx -y --package=github:XCreativeStudio/cws-release -- cws check');
45
+ log(' check npx cws-release check');
46
46
  return 0;
47
47
  }
48
48