@qcplay/cli 1.0.0 → 1.0.1

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/bin/qcplay.js CHANGED
@@ -8,6 +8,18 @@ import { fileURLToPath } from "url";
8
8
 
9
9
  const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = path.dirname(__filename);
11
+ const PACKAGE_JSON = path.resolve(__dirname, "../package.json");
12
+
13
+ function readPackageVersion() {
14
+ try {
15
+ const packageJson = JSON.parse(fs.readFileSync(PACKAGE_JSON, "utf8"));
16
+ return packageJson.version || "0.0.0";
17
+ } catch {
18
+ return "0.0.0";
19
+ }
20
+ }
21
+
22
+ const PACKAGE_VERSION = readPackageVersion();
11
23
 
12
24
  const QCPLAY_DIR = path.join(os.homedir(), ".qcplay");
13
25
  const AUTH_FILE = path.join(QCPLAY_DIR, "auth.json");
@@ -38,6 +50,7 @@ function printRootHelp() {
38
50
  Usage:
39
51
  qcplay-cli install
40
52
  qcplay-cli auth [login|status|logout]
53
+ qcplay-cli auth permissions [--key <key>] [--json]
41
54
  qcplay-cli article
42
55
  qcplay-cli article init [file]
43
56
  qcplay-cli article publish <file> [--env <env>] [--url <url>] [--dry-run]
@@ -56,6 +69,7 @@ function printAuthHelp() {
56
69
  console.log(" qcplay-cli auth");
57
70
  console.log(" qcplay-cli auth status");
58
71
  console.log(" qcplay-cli auth logout");
72
+ console.log(" qcplay-cli auth permissions [--key <key>] [--json]");
59
73
  }
60
74
 
61
75
  function printArticleHelp() {
@@ -114,6 +128,20 @@ function runNative(name, args = []) {
114
128
  });
115
129
  }
116
130
 
131
+ async function runAuthLogin() {
132
+ try {
133
+ await runNative("qcplay-auth", []);
134
+ } catch (err) {
135
+ const message = String(err?.message || err);
136
+
137
+ if (!message.includes("退出码")) {
138
+ throw err;
139
+ }
140
+
141
+ await runNative("qcplay-auth", ["login"]);
142
+ }
143
+ }
144
+
117
145
  async function pathExists(targetPath) {
118
146
  try {
119
147
  await fs.promises.access(targetPath);
@@ -176,7 +204,7 @@ async function installSkills() {
176
204
  async function saveConfig() {
177
205
  await writeJson(CONFIG_FILE, {
178
206
  cli: "qcplay-cli",
179
- version: "1.0.0",
207
+ version: PACKAGE_VERSION,
180
208
  auth_file: AUTH_FILE,
181
209
  skills_dir: SKILLS_DIR,
182
210
  configured_at: Date.now()
@@ -252,6 +280,11 @@ function printFeatures() {
252
280
  console.log(" qcplay-cli auth");
253
281
  console.log("");
254
282
 
283
+ console.log(chalk.cyan("2. 查看权限"));
284
+ console.log(" qcplay-cli auth permissions");
285
+ console.log(" qcplay-cli auth permissions --key www-article-list.store");
286
+ console.log("");
287
+
255
288
  console.log(chalk.cyan("4. 发布官网文章"));
256
289
  console.log(" qcplay-cli www-article-list.store article.md");
257
290
  console.log(chalk.gray(" 文章标题、分类、缩略图、标签等信息写在 article.md 顶部 Front Matter 中。"));
@@ -266,6 +299,37 @@ function printWhere() {
266
299
  console.log(QCPLAY_DIR);
267
300
  }
268
301
 
302
+ function parsePermissionsOptions(args) {
303
+ const options = {
304
+ key: undefined,
305
+ json: false
306
+ };
307
+
308
+ for (let index = 0; index < args.length; index += 1) {
309
+ const current = args[index];
310
+
311
+ if (current === "--json") {
312
+ options.json = true;
313
+ continue;
314
+ }
315
+
316
+ if (current === "--key") {
317
+ const next = args[index + 1];
318
+ if (!next || next.startsWith("--")) {
319
+ throw new Error("--key 缺少参数值");
320
+ }
321
+
322
+ options.key = next;
323
+ index += 1;
324
+ continue;
325
+ }
326
+
327
+ throw new Error(`未知参数: ${current}`);
328
+ }
329
+
330
+ return options;
331
+ }
332
+
269
333
  async function installCommand() {
270
334
  console.log("");
271
335
  console.log(chalk.cyan("正在安装 QCPlay CLI..."));
@@ -289,7 +353,7 @@ async function installCommand() {
289
353
  console.log(chalk.gray("请在浏览器中完成账号密码登录。"));
290
354
  console.log("");
291
355
 
292
- await runNative("qcplay-auth", ["login"]);
356
+ await runAuthLogin();
293
357
 
294
358
  const loginStatus = await getLoginStatus();
295
359
  if (!loginStatus.ok) {
@@ -306,13 +370,13 @@ async function installCommand() {
306
370
  printFeatures();
307
371
  }
308
372
 
309
- async function authCommand(action) {
373
+ async function authCommand(action, args = []) {
310
374
  if (!action || action === "login") {
311
375
  console.log("");
312
376
  console.log(chalk.cyan("正在打开 QCPlay 登录窗口..."));
313
377
  console.log("");
314
378
 
315
- await runNative("qcplay-auth", ["login"]);
379
+ await runAuthLogin();
316
380
 
317
381
  const loginStatus = await getLoginStatus();
318
382
  if (!loginStatus.ok) {
@@ -348,6 +412,28 @@ async function authCommand(action) {
348
412
  return;
349
413
  }
350
414
 
415
+ if (action === "permissions") {
416
+ const loginStatus = await getLoginStatus();
417
+
418
+ if (!loginStatus.ok) {
419
+ throw new Error(`未检测到有效登录状态。\n原因: ${loginStatus.reason}\n请先执行:qcplay-cli auth`);
420
+ }
421
+
422
+ const options = parsePermissionsOptions(args);
423
+ const nativeArgs = ["permissions"];
424
+
425
+ if (options.key) {
426
+ nativeArgs.push("--key", options.key);
427
+ }
428
+
429
+ if (options.json) {
430
+ nativeArgs.push("--json");
431
+ }
432
+
433
+ await runNative("qcplay-auth", nativeArgs);
434
+ return;
435
+ }
436
+
351
437
  printAuthHelp();
352
438
  }
353
439
 
@@ -584,7 +670,7 @@ async function main() {
584
670
  }
585
671
 
586
672
  if (command === "-V" || command === "--version") {
587
- console.log("1.0.0");
673
+ console.log(PACKAGE_VERSION);
588
674
  return;
589
675
  }
590
676
 
@@ -599,7 +685,7 @@ async function main() {
599
685
  return;
600
686
  }
601
687
 
602
- await runWithErrorBanner("认证失败", () => authCommand(subcommand));
688
+ await runWithErrorBanner("认证失败", () => authCommand(subcommand, rest));
603
689
  return;
604
690
  }
605
691
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qcplay/cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "QCPlay CLI",
5
5
  "type": "module",
6
6
  "bin": {
Binary file