@pmate/cli 0.20.2 → 0.20.4

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/dist/index.d.ts CHANGED
@@ -168,6 +168,14 @@ type QuizCommandArgs = {
168
168
  apiBaseUrl?: string;
169
169
  linkBaseUrl?: string;
170
170
  activate: boolean;
171
+ } | {
172
+ type: Command.Quiz;
173
+ action: "update-step";
174
+ paperId: string;
175
+ stepId: string;
176
+ filePath: string;
177
+ apiBaseUrl?: string;
178
+ linkBaseUrl?: string;
171
179
  };
172
180
  type LinearPrCommandArgs = {
173
181
  type: Command.Linear;
package/dist/index.js CHANGED
@@ -18047,7 +18047,7 @@ init_sessionStore();
18047
18047
 
18048
18048
  // src/services/QuizService.ts
18049
18049
  var INTRO_STEP_COUNT = 2;
18050
- var QUIZ_APP_ID = "quiz";
18050
+ var QUIZ_APP_ID = "pmate:quiz";
18051
18051
  var DEFAULT_MIN_LENGTHS = Object.freeze({
18052
18052
  teachingArticle: 36,
18053
18053
  explanation: 60
@@ -18370,6 +18370,38 @@ async function appendQuizPaperStep({
18370
18370
  data
18371
18371
  };
18372
18372
  }
18373
+ async function updateQuizPaperStep({
18374
+ fetchImpl = fetch,
18375
+ apiBaseUrl,
18376
+ linkBaseUrl,
18377
+ paperId,
18378
+ stepId,
18379
+ step,
18380
+ token
18381
+ }) {
18382
+ const trimmedApiBaseUrl = apiBaseUrl.replace(/\/+$/, "");
18383
+ const trimmedLinkBaseUrl = linkBaseUrl.replace(/\/+$/, "");
18384
+ const previewLink = `${trimmedLinkBaseUrl}/?paper=${encodeURIComponent(paperId)}`;
18385
+ const data = await requestJson(
18386
+ fetchImpl,
18387
+ `${trimmedApiBaseUrl}/api/quiz/papers/${encodeURIComponent(paperId)}/steps/${encodeURIComponent(stepId)}`,
18388
+ {
18389
+ method: "PATCH",
18390
+ headers: {
18391
+ Authorization: `Bearer ${token}`,
18392
+ "Content-Type": "application/json"
18393
+ },
18394
+ body: JSON.stringify(step)
18395
+ },
18396
+ `\u66F4\u65B0\u9898\u76EE\uFF08${stepId}\uFF09`
18397
+ );
18398
+ return {
18399
+ apiBaseUrl: trimmedApiBaseUrl,
18400
+ paperId,
18401
+ previewLink,
18402
+ data
18403
+ };
18404
+ }
18373
18405
  async function reorderQuizPaperSteps({
18374
18406
  fetchImpl = fetch,
18375
18407
  apiBaseUrl,
@@ -18512,6 +18544,22 @@ var QuizCommandHandler = class {
18512
18544
  ui.info("stepId", String(step.stepId));
18513
18545
  return;
18514
18546
  }
18547
+ if (args.action === "update-step") {
18548
+ const resolvedFilePath = import_node_path14.default.resolve(process.cwd(), args.filePath);
18549
+ const step = JSON.parse((0, import_node_fs9.readFileSync)(resolvedFilePath, "utf8"));
18550
+ step.stepId = args.stepId;
18551
+ const result = await updateQuizPaperStep({
18552
+ apiBaseUrl,
18553
+ linkBaseUrl,
18554
+ paperId: args.paperId,
18555
+ stepId: args.stepId,
18556
+ step,
18557
+ token: session.token
18558
+ });
18559
+ ui.success("Quiz \u9898\u76EE\u5DF2\u66F4\u65B0", result.previewLink);
18560
+ ui.info("stepId", args.stepId);
18561
+ return;
18562
+ }
18515
18563
  if (args.action === "reorder") {
18516
18564
  const result = await reorderQuizPaperSteps({
18517
18565
  apiBaseUrl,
@@ -22236,6 +22284,7 @@ var HELP_TEXT = [
22236
22284
  ` ${import_chalk3.default.gray(" create-draft --paper-id <id>")}`,
22237
22285
  ` ${import_chalk3.default.gray(" update-meta --paper-id <id> --file <metadata.json>")}`,
22238
22286
  ` ${import_chalk3.default.gray(" append-step --paper-id <id> --file <step.json>")}`,
22287
+ ` ${import_chalk3.default.gray(" update-step --paper-id <id> --step-id <step-id> --file <step.json>")}`,
22239
22288
  ` ${import_chalk3.default.gray(" reorder --paper-id <id> --step-ids <id1,id2,...>")}`,
22240
22289
  ` ${import_chalk3.default.gray(" activate --paper-id <id>")}`,
22241
22290
  ` ${import_chalk3.default.gray(" view --paper-id <id>")}`,
@@ -22836,7 +22885,7 @@ function parseQuizArgs(tokens) {
22836
22885
  const rest = [...tokens];
22837
22886
  const action = rest.shift();
22838
22887
  if (!action) {
22839
- throw new Error("Missing quiz action. Usage: quiz create-draft|update-meta|append-step|reorder|activate|view|edit-step");
22888
+ throw new Error("Missing quiz action. Usage: quiz create-draft|update-meta|append-step|update-step|reorder|activate|view|edit-step");
22840
22889
  }
22841
22890
  if (action === "create-draft") {
22842
22891
  let paperId;
@@ -22947,6 +22996,53 @@ function parseQuizArgs(tokens) {
22947
22996
  linkBaseUrl
22948
22997
  };
22949
22998
  }
22999
+ if (action === "update-step") {
23000
+ let paperId;
23001
+ let stepId;
23002
+ let filePath;
23003
+ let apiBaseUrl;
23004
+ let linkBaseUrl;
23005
+ while (rest.length > 0) {
23006
+ const token = rest.shift();
23007
+ switch (token) {
23008
+ case "--paper-id":
23009
+ paperId = requireValue8(rest, token);
23010
+ break;
23011
+ case "--step-id":
23012
+ stepId = requireValue8(rest, token);
23013
+ break;
23014
+ case "--file":
23015
+ filePath = requireValue8(rest, token);
23016
+ break;
23017
+ case "--base-url":
23018
+ apiBaseUrl = requireValue8(rest, token);
23019
+ break;
23020
+ case "--link-base":
23021
+ linkBaseUrl = requireValue8(rest, token);
23022
+ break;
23023
+ default:
23024
+ throw new Error(`Unknown quiz update-step option: ${token}`);
23025
+ }
23026
+ }
23027
+ if (!paperId) {
23028
+ throw new Error("Missing --paper-id. Usage: quiz update-step --paper-id <id> --step-id <id> --file <step.json>.");
23029
+ }
23030
+ if (!stepId) {
23031
+ throw new Error("Missing --step-id. Usage: quiz update-step --paper-id <id> --step-id <id> --file <step.json>.");
23032
+ }
23033
+ if (!filePath) {
23034
+ throw new Error("Missing --file. Usage: quiz update-step --paper-id <id> --step-id <id> --file <step.json>.");
23035
+ }
23036
+ return {
23037
+ type: "quiz" /* Quiz */,
23038
+ action: "update-step",
23039
+ paperId,
23040
+ stepId,
23041
+ filePath,
23042
+ apiBaseUrl,
23043
+ linkBaseUrl
23044
+ };
23045
+ }
22950
23046
  if (action === "reorder") {
22951
23047
  let paperId;
22952
23048
  let stepIdsRaw;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/cli",
3
- "version": "0.20.2",
3
+ "version": "0.20.4",
4
4
  "description": "CLI utilities for the pMate project",
5
5
  "license": "MIT",
6
6
  "bin": {