cws-release 0.1.4 → 0.1.5

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,6 +1,8 @@
1
1
  # Install
2
2
 
3
- Four options. Pick by **how many extensions you maintain**, not by taste:
3
+ Requires **Node.js 22 or later**. Installing the CLI is only one part of first-time setup: the extension item must already exist, and you must enable the Chrome Web Store API, authorize a service account, and fill in `.cws.json`. Follow the [one-time setup in the README](README.md#one-time-setup) before the first release.
4
+
5
+ For a quick trial or one-off release, use `npx`. For a project you maintain, use a dev dependency. The four options:
4
6
 
5
7
  | | Option | What you run | Version lives in | Best for |
6
8
  | --- | --- | --- | --- | --- |
package/README.md CHANGED
@@ -11,22 +11,20 @@ exact reason it refused.
11
11
 
12
12
  ## Quick start
13
13
 
14
+ Requires **Node.js 22 or later** and an extension item that already exists in the Chrome Web Store. Creating the item and completing its listing and privacy details still require the Developer Dashboard.
15
+
14
16
  ```sh
15
17
  npm i -D cws-release # in your extension repository
16
18
  npx cws-release init # once: writes .cws.json + the agent skill
17
-
19
+ # Complete the one-time Google setup below; fill in .cws.json and the key path
18
20
  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
21
+ npx cws-release check # also checks store access when both IDs are set
22
+ npx cws-release release --staged # submit for review; deploy manually after approval
21
23
  ```
22
24
 
23
- Nothing above works until the [one-time setup](#one-time-setup) is done: the API
24
- enabled, a service-account key, that account added to the publisher, and two
25
- identifiers in `.cws.json`. `check` names whichever piece is missing. Budget
26
- about ten minutes for it; you will not repeat it per release.
25
+ First-time path: **confirm the item exists → enable the API and authorize a service account → fill in `publisherId`, `itemId` and the zip path → set the key → run `check` → publish**. See [one-time setup](#one-time-setup); it is done once per publisher account.
27
26
 
28
- The API cannot create a new item — the first upload and the listing, privacy and
29
- visibility tabs are manual.
27
+ With only the key configured, `check` verifies authentication. It checks store access only when both `publisherId` and `itemId` are set. Plain `release` uses `DEFAULT_PUBLISH` and goes live automatically after review; use `--staged` for a first release or whenever you want to deploy manually.
30
28
 
31
29
  ## One-time setup
32
30
 
@@ -114,8 +112,7 @@ secret:
114
112
  export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
115
113
  ```
116
114
 
117
- Then `npx cws-release check`. It exchanges the token and calls `fetchStatus`, so
118
- a `PUBLISHER_FORBIDDEN` at this point means step 4 or 5 — not the key.
115
+ With both identifiers filled in `.cws.json`, run `npx cws-release check`. It exchanges the token and calls `fetchStatus`, so a `PUBLISHER_FORBIDDEN` at this point means step 4 or 5 — not the key. Without the IDs, `check` verifies authentication only.
119
116
 
120
117
  `CWS_ACCESS_TOKEN` skips the key entirely for a one-off run
121
118
  (`gcloud auth print-access-token --scopes=https://www.googleapis.com/auth/chromewebstore`);
@@ -159,7 +156,7 @@ publisher. Treat it as one secret, not as config:
159
156
  | You have… | Use | Pin |
160
157
  | --- | --- | --- |
161
158
  | **Several extensions** | `npm i -D cws-release`, then `npx cws-release <cmd>` | `package.json` + lockfile, per repo |
162
- | One extension, or trying it | `npm i -g cws-release` | your machine |
159
+ | Trying it or a one-off release | `npx cws-release <cmd>` | not pinned; latest each run |
163
160
  | A release pipeline | `uses: XCreativeStudio/cws-release@v1` | the tag |
164
161
 
165
162
  With a dev dependency each repository pins its own version, so upgrading one
@@ -183,8 +180,9 @@ Commit identifiers, never secrets, in `.cws.json` (`init` writes the template):
183
180
  ```
184
181
 
185
182
  `publisherId` and `itemId` come from the dashboard's **Settings** page
186
- ([step 5](#one-time-setup)); `itemId` is the 32-character extension id. `zip`
187
- may be a single `*`/`?` glob, because build output usually carries the version.
183
+ ([step 5](#one-time-setup)); `itemId` is the 32-character extension id. `init`
184
+ defaults `zip` to `.output/*-chrome.zip`; change it to your build output path if
185
+ needed. A `*`/`?` glob is supported when it matches exactly one file.
188
186
 
189
187
  The key is pointed at separately, by environment variable:
190
188
 
@@ -204,16 +202,17 @@ override the matching keys.
204
202
  | Command | What it does |
205
203
  | --- | --- |
206
204
  | `cws init` | Write a `.cws.json` template plus the agent skill into this repository; leaves existing files alone without `--force` |
207
- | `cws check` | Exchange the token and call `fetchStatus`; separates "the secret is set" from "the secret works" |
205
+ | `cws check` | Verify credentials; checks store access when both IDs are configured |
208
206
  | `cws upload [zip]` | Upload the package, then wait for asynchronous processing |
209
207
  | `cws publish` | Submit the uploaded package for review |
210
208
  | `cws release [zip]` | upload → publish → status, in one step |
211
209
  | `cws status` | Published and submitted revision state |
212
210
  | `cws cancel` | Cancel a submission that is under review |
213
211
 
214
- Flags: `--staged` (`STAGED_PUBLISH`), `--live` (`DEFAULT_PUBLISH`),
215
- `--block-on-warnings`, `--json`, `--timeout <ms>`, `--config <path>`,
216
- `--api <url>`, `--force` (with `init`).
212
+ Flags: `--staged` (manual deploy after approval), `--live` (automatic deploy after approval),
213
+ `--block-on-warnings`, `--json`, `--timeout <ms>` (upload polling for `upload`/`release`),
214
+ `--config <path>`, `--api <url>`, `--force` (only with `init`). Extra positional arguments
215
+ and flags that do not apply to the selected command are rejected.
217
216
 
218
217
  `status` is the honest answer to "is it live yet?": `PUBLISHED` in
219
218
  `publishedItemRevisionStatus` means live, anything else is still in review.
@@ -290,7 +289,7 @@ npx cws-release init # writes .cws.json + the skill
290
289
  # paste publisherId and itemId from the dashboard Settings page
291
290
  export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
292
291
 
293
- npx cws-release check # credentials + store access, ~3 s
292
+ npx cws-release check # credentials + store access
294
293
  npx cws-release upload # glob picks the only zip; waits for processing
295
294
  npx cws-release publish --staged # submit for review, deploy manually later
296
295
  npx cws-release status # current live version and the one in review
package/README.zh-CN.md CHANGED
@@ -10,20 +10,20 @@
10
10
 
11
11
  ## 快速开始
12
12
 
13
- ```sh
14
- npm i -D cws-release # 在你的扩展仓库里
15
- npx cws-release init # 一次性:生成 .cws.json + agent skill
13
+ 需要 **Node.js 22 或更新版本**,并且扩展条目已在 Chrome Web Store 创建。首次创建条目、填写商店信息和隐私问卷仍需在开发者后台手动完成。
16
14
 
15
+ ```sh
16
+ npm i -D cws-release # 在扩展仓库中安装
17
+ npx cws-release init # 生成 .cws.json 和 agent skill
18
+ # 先完成下方的一次性 Google 授权,并填写 .cws.json 与密钥路径
17
19
  export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
18
- npx cws-release check # 三秒内验证凭据可用
19
- npx cws-release release # 上传 → 提交审核 → 打印状态
20
+ npx cws-release check # 有两个 ID 时也会验证商店访问权限
21
+ npx cws-release release --staged # 上传并提交审核;审核通过后再手动上线
20
22
  ```
21
23
 
22
- 上面的命令都要先完成[一次性配置](#一次性配置)才能用:启用 API、拿到服务账号密钥、
23
- 把该账号加入发布者、并在 `.cws.json` 里填好两个标识符。缺哪一块 `check` 就报哪一块。
24
- 这件事大约十分钟,不必每次发版重复。
24
+ 初次配置按这个顺序走:**确认条目已创建 → 启用 API 并授权服务账号 → 填写 `publisherId`、`itemId` 和 zip 路径 → 设置密钥 → 运行 `check` → 发布**。完整步骤见[一次性配置](#一次性配置),通常只需为每个发布者账号做一次。
25
25
 
26
- API 无法创建新条目——首次上传和商店信息、隐私、可见性页都需手动完成。
26
+ `check` 只设置密钥时会验证认证;补齐 `publisherId` 和 `itemId` 后才会验证商店访问。默认 `release` 使用 `DEFAULT_PUBLISH`,审核通过后会自动上线;首次发布建议显式使用 `--staged`。
27
27
 
28
28
  ## 一次性配置
29
29
 
@@ -99,8 +99,7 @@ chmod 600 ~/.config/cws/service-account.json
99
99
  export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
100
100
  ```
101
101
 
102
- 然后 `npx cws-release check`。它会换取令牌并调用 `fetchStatus`,所以此时若仍返回
103
- `PUBLISHER_FORBIDDEN`,问题在第 4 步或第 5 步,不在密钥。
102
+ 确保 `.cws.json` 已填写两个标识符后运行 `npx cws-release check`。此时它会换取令牌并调用 `fetchStatus`;若仍返回 `PUBLISHER_FORBIDDEN`,问题在第 4 步或第 5 步,不在密钥。若 ID 尚未填写,`check` 只验证认证,不验证商店访问。
104
103
 
105
104
  一次性运行也可以完全不用密钥,改用 `CWS_ACCESS_TOKEN`
106
105
  (`gcloud auth print-access-token --scopes=https://www.googleapis.com/auth/chromewebstore`),
@@ -139,7 +138,7 @@ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
139
138
  | 你的情况 | 用 | 版本固定在哪 |
140
139
  | --- | --- | --- |
141
140
  | **维护多个扩展** | `npm i -D cws-release`,然后 `npx cws-release <命令>` | 每个仓库的 `package.json` + lockfile |
142
- | 只有一个扩展,或试用 | `npm i -g cws-release` | 你的机器 |
141
+ | 试用或临时发布 | `npx cws-release <命令>` | 不固定;使用最新版本 |
143
142
  | 发布流水线 | `uses: XCreativeStudio/cws-release@v1` | 标签 |
144
143
 
145
144
  用 dev dependency 时,每个仓库固定自己的版本,升级一个扩展不会影响另一个,CI 装的
@@ -161,7 +160,7 @@ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
161
160
  ```
162
161
 
163
162
  `publisherId` 和 `itemId` 来自后台的 **Settings** 页([第 5 步](#一次性配置));
164
- `itemId` 是 32 位扩展 ID。`zip` 可以是单个 `*`/`?` 通配符,因为构建产物通常带版本号。
163
+ `itemId` 是 32 位扩展 ID。`init` 默认写入 `.output/*-chrome.zip`;如果构建产物路径或名称不同,请改成你的 zip 路径。也可使用只匹配一个文件的 `*`/`?` 通配符。
165
164
 
166
165
  密钥单独通过环境变量指向:
167
166
 
@@ -180,16 +179,16 @@ export CWS_ACCESS_TOKEN="$(gcloud auth print-access-token \
180
179
  | 命令 | 作用 |
181
180
  | --- | --- |
182
181
  | `cws init` | 在当前仓库写入 `.cws.json` 模板和 agent skill;不加 `--force` 时不动已存在的文件 |
183
- | `cws check` | 换取令牌并调用 `fetchStatus`;区分"密钥已配置"和"密钥可用" |
182
+ | `cws check` | 验证密钥;配置两个 ID 后再验证商店访问 |
184
183
  | `cws upload [zip]` | 上传包,然后等待异步处理完成 |
185
184
  | `cws publish` | 把已上传的包提交审核 |
186
185
  | `cws release [zip]` | 一步完成 上传 → 提交审核 → 状态 |
187
186
  | `cws status` | 已发布和已提交的版本状态 |
188
187
  | `cws cancel` | 取消正在审核中的提交 |
189
188
 
190
- 参数:`--staged`(`STAGED_PUBLISH`)、`--live`(`DEFAULT_PUBLISH`)、
191
- `--block-on-warnings`、`--json`、`--timeout <ms>`、`--config <path>`、
192
- `--api <url>`、`--force`(配合 `init`)。
189
+ 参数:`--staged`(审核通过后手动上线)、`--live`(审核通过后自动上线)、
190
+ `--block-on-warnings`、`--json`、`--timeout <ms>`(仅用于 `upload`/`release` 的上传等待)、
191
+ `--config <path>`、`--api <url>`、`--force`(仅用于 `init`)。多余的位置参数和不适用于当前命令的选项会报用法错误。
193
192
 
194
193
  "到底上线了吗"——用 `status` 回答:`publishedItemRevisionStatus` 里的
195
194
  `PUBLISHED` 才算已上线,其余都还在审核中。
@@ -232,7 +231,7 @@ cws:json {"ok":false,"error":{"code":"PUBLISHER_FORBIDDEN","status":403,
232
231
  | `PUBLISHER_FORBIDDEN` | 账号没在后台 **Settings** 页加入,或 `publisherId` 不对。这个 403 也会掩盖"API 未启用",所以按[第 1–5 步](#一次性配置)顺序排查 |
233
232
  | `UPLOAD_REJECTED` | 把 manifest 版本号提高到已发布版本之上 |
234
233
 
235
- 全部 14 个错误码的完整含义与修复方式见 [docs/errors.md](docs/errors.md)。退出码对
234
+ 全部 14 个错误码的完整含义与修复方式见[中文错误码说明](docs/zh-CN/errors.md)。退出码对
236
235
  shell 保持粗粒度——`0` 成功、`1` 失败、`2` 用法错误——`data` 里的字段是未经改动的
237
236
  原始 API 响应。
238
237
 
@@ -261,9 +260,9 @@ npx cws-release init # 生成 .cws.json 和 skill
261
260
  # 从后台 Settings 页填入 publisherId 和 itemId
262
261
  export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
263
262
 
264
- npx cws-release check # 凭据与商店权限,约 3 秒
265
- npx cws-release upload # 通配符匹配唯一的 zip,并等待处理完成
266
- npx cws-release publish --staged # 提交审核,通过后再手动上线
263
+ npx cws-release check # 验证凭据和商店访问
264
+ npx cws-release upload # 通配符匹配唯一 zip,并等待处理完成
265
+ npx cws-release publish --staged # 提交审核,通过后再手动上线
267
266
  npx cws-release status # 当前线上版本与审核中的版本
268
267
  ```
269
268
 
package/SKILL.md CHANGED
@@ -105,7 +105,7 @@ Run from the repository root. `node <skill-dir>/cws.mjs …` and
105
105
 
106
106
  ```sh
107
107
  cws init # write .cws.json + this skill into the current repository
108
- cws check # prove the credentials work, then print the item status
108
+ cws check # verify credentials; checks item status when both IDs are set
109
109
  cws upload # upload .cws.json's zip (or: cws upload path/to.zip)
110
110
  cws publish # submit the uploaded package for review
111
111
  cws release # upload + publish + print the resulting status
@@ -113,8 +113,7 @@ cws status # published / submitted revision state
113
113
  cws cancel # cancel a submission that is under review
114
114
  ```
115
115
 
116
- `cws check` first, every time: it separates "the secret is set" from "the
117
- secret works" in three seconds.
116
+ Run `cws check` before publishing. With only credentials configured it verifies authentication; when both IDs are set it also checks store access and prints the item status.
118
117
 
119
118
  Options: `--staged` (STAGED_PUBLISH: approved but not deployed), `--live`
120
119
  (DEFAULT_PUBLISH), `--block-on-warnings`, `--json`, `--timeout <ms>`,
@@ -160,9 +159,9 @@ JSON; everything else on stderr is progress text.
160
159
  again.
161
160
  - Never commit, echo, or log the service-account key. Do not put it in
162
161
  `.cws.json`, and do not include tokens in error output.
163
- - `STAGED_PUBLISH` is the right default when a human should decide when to
164
- deploy; `DEFAULT_PUBLISH` is right for tag-driven releases that are already
165
- reviewed.
162
+ - Use `--staged` for a first release or whenever a human should decide when to
163
+ deploy. Plain `release` defaults to `DEFAULT_PUBLISH`, which goes live after
164
+ approval; use it only when that automatic deployment is intended.
166
165
 
167
166
  ## CI (GitHub Actions)
168
167
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cws-release",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
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/cli.mjs CHANGED
@@ -11,10 +11,10 @@ const USAGE = `cws — Chrome Web Store API v2 CLI
11
11
 
12
12
  Usage
13
13
  cws init write .cws.json and the skill into the current repository
14
- cws check prove the credentials work, and read the item status
14
+ cws check verify credentials; also checks store access when both IDs are set
15
15
  cws upload [zip] upload a package to an existing item
16
16
  cws publish submit the uploaded package for review
17
- cws release [zip] upload, then publish, then print the status
17
+ cws release [zip] upload, publish (auto-live after approval by default), then print status
18
18
  cws status print the published and submitted revision state
19
19
  cws cancel cancel a submission that is under review
20
20
 
@@ -22,11 +22,11 @@ Options
22
22
  --config <path> .cws.json to use (default: ./.cws.json)
23
23
  --zip <path> package path or a single * / ? glob
24
24
  --staged publish with STAGED_PUBLISH (approve now, deploy later)
25
- --live publish with DEFAULT_PUBLISH (overrides .cws.json)
25
+ --live publish with DEFAULT_PUBLISH (automatic after approval)
26
26
  --block-on-warnings make the publish request fail when validation warns
27
27
  --api <url> override the API base URL (tests, mock store)
28
28
  --json print { ok, command, data } on stdout; progress goes to stderr
29
- --timeout <ms> upload polling timeout (default: 180000)
29
+ --timeout <ms> upload polling timeout for upload/release (default: 180000)
30
30
  --force with init: overwrite existing files
31
31
  -h, --help
32
32
  -v, --version
@@ -152,6 +152,24 @@ export async function runCli({
152
152
  if (!['init', 'check', 'upload', 'publish', 'release', 'status', 'cancel'].includes(command)) {
153
153
  throw new UsageError(`unknown command: ${command}`);
154
154
  }
155
+ const allowedOptions = {
156
+ init: ['json', 'force'],
157
+ check: ['json', 'config', 'api'],
158
+ upload: ['json', 'config', 'zip', 'api', 'timeout'],
159
+ publish: ['json', 'config', 'api', 'staged', 'live', 'blockOnWarnings'],
160
+ release: ['json', 'config', 'zip', 'api', 'timeout', 'staged', 'live', 'blockOnWarnings'],
161
+ status: ['json', 'config', 'api'],
162
+ cancel: ['json', 'config', 'api'],
163
+ }[command];
164
+ const unsupported = Object.keys(options).filter((option) => !['help', 'version'].includes(option) && !allowedOptions.includes(option));
165
+ if (unsupported.length > 0) {
166
+ throw new UsageError(`${unsupported.map((option) => `--${option}`).join(', ')} cannot be used with ${command}`);
167
+ }
168
+ const maxArgs = ['upload', 'release'].includes(command) ? 1 : 0;
169
+ if (args.length > maxArgs) {
170
+ throw new UsageError(`${command} accepts at most ${maxArgs} positional ${maxArgs === 1 ? 'argument' : 'arguments'}`);
171
+ }
172
+ const emit = (data) => stdout.write(`${JSON.stringify(envelope(command, data), null, 2)}\n`);
155
173
  if (command === 'init') {
156
174
  const lines = [];
157
175
  const result = init({ cwd, force: options.force === true, log: (line) => lines.push(line) });
@@ -163,9 +181,10 @@ export async function runCli({
163
181
  const log = options.json
164
182
  ? (line) => stderr.write(`${line}\n`)
165
183
  : (line) => stdout.write(`${line}\n`);
166
- const emit = (data) => stdout.write(`${JSON.stringify(envelope(command, data), null, 2)}\n`);
167
184
 
168
185
  const config = loadConfig({ cwd, configPath: options.config, env });
186
+ if (command !== 'check') requireFields(config, ['publisherId', 'itemId']);
187
+
169
188
  const access = await getAccessToken({ env, fetchImpl });
170
189
  log(`ok authenticated (${access.source})`);
171
190
  const client = createStoreClient({
@@ -182,14 +201,12 @@ export async function runCli({
182
201
  printStatus(log, status, config.itemId);
183
202
  if (options.json) emit(status);
184
203
  } else {
185
- log('hint set publisherId and itemId in .cws.json to verify store access too');
186
- if (options.json) emit({ authenticated: true, source: access.source });
204
+ log('ok authenticated; store access not checked (set publisherId and itemId in .cws.json)');
205
+ if (options.json) emit({ authenticated: true, storeAccessChecked: false, source: access.source });
187
206
  }
188
207
  return 0;
189
208
  }
190
209
 
191
- requireFields(config, ['publisherId', 'itemId']);
192
-
193
210
  if (command === 'status') {
194
211
  const status = await client.fetchStatus(config);
195
212
  printStatus(log, status, config.itemId);
@@ -220,7 +237,7 @@ export async function runCli({
220
237
  const zipPath = resolveZipPath(args[0] ?? options.zip ?? config.zip, cwd);
221
238
  const bytes = readFileSync(zipPath);
222
239
  if (bytes.length < 4 || bytes[0] !== 0x50 || bytes[1] !== 0x4b) {
223
- throw new UsageError(`${zipPath} is not a zip file`);
240
+ throw new ConfigError(`${zipPath} is not a zip file`, { code: 'INVALID_PACKAGE' });
224
241
  }
225
242
  log(`... uploading ${basename(zipPath)} (${bytes.length.toLocaleString('en-US')} bytes)`);
226
243