@pmate/cli 0.18.0 → 0.19.0

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
@@ -139,6 +139,16 @@ type QuizCommandArgs = {
139
139
  paperId: string;
140
140
  apiBaseUrl?: string;
141
141
  linkBaseUrl?: string;
142
+ } | {
143
+ type: Command.Quiz;
144
+ action: "edit-step";
145
+ paperId: string;
146
+ stepId: string;
147
+ filePath: string;
148
+ newPaperId?: string;
149
+ apiBaseUrl?: string;
150
+ linkBaseUrl?: string;
151
+ activate: boolean;
142
152
  };
143
153
  type LinearPrCommandArgs = {
144
154
  type: Command.Linear;
package/dist/index.js CHANGED
@@ -18097,6 +18097,26 @@ async function viewQuizPaper({
18097
18097
  data
18098
18098
  };
18099
18099
  }
18100
+ async function getQuizPaper({
18101
+ fetchImpl = fetch,
18102
+ apiBaseUrl,
18103
+ linkBaseUrl,
18104
+ paperId,
18105
+ token
18106
+ }) {
18107
+ const viewed = await viewQuizPaper({
18108
+ fetchImpl,
18109
+ apiBaseUrl,
18110
+ linkBaseUrl,
18111
+ paperId,
18112
+ token
18113
+ });
18114
+ const paper = viewed.data;
18115
+ if (!paper || !Array.isArray(paper.steps)) {
18116
+ throw new Error("\u67E5\u770B\u8BD5\u5377\u5931\u8D25\uFF1A\u8FD4\u56DE\u6570\u636E\u4E0D\u5305\u542B\u6709\u6548 steps\u3002");
18117
+ }
18118
+ return paper;
18119
+ }
18100
18120
 
18101
18121
  // src/commands/QuizCommandHandler.ts
18102
18122
  var QuizCommandHandler = class {
@@ -18128,6 +18148,51 @@ var QuizCommandHandler = class {
18128
18148
  }
18129
18149
  return;
18130
18150
  }
18151
+ if (args.action === "edit-step") {
18152
+ const basePaper = await getQuizPaper({
18153
+ apiBaseUrl,
18154
+ linkBaseUrl,
18155
+ paperId: args.paperId,
18156
+ token: session.token
18157
+ });
18158
+ const targetIndex = basePaper.steps.findIndex((item) => item.stepId === args.stepId);
18159
+ if (targetIndex < 0) {
18160
+ throw new Error(`\u672A\u627E\u5230 stepId=${args.stepId}\uFF0C\u65E0\u6CD5\u66F4\u65B0\u8BE5\u9898\u76EE\u3002`);
18161
+ }
18162
+ const resolvedFilePath2 = import_node_path14.default.resolve(process.cwd(), args.filePath);
18163
+ const nextStep = JSON.parse((0, import_node_fs9.readFileSync)(resolvedFilePath2, "utf8"));
18164
+ nextStep.stepId = args.stepId;
18165
+ const nextSteps = [...basePaper.steps];
18166
+ nextSteps[targetIndex] = nextStep;
18167
+ const nextPaperId = args.newPaperId || `${args.paperId}-rev-${this.timestampTag()}`;
18168
+ const result2 = await publishQuizPaper({
18169
+ apiBaseUrl,
18170
+ linkBaseUrl,
18171
+ paperId: nextPaperId,
18172
+ payload: {
18173
+ eyebrow: basePaper.eyebrow ?? "",
18174
+ completionTitle: basePaper.completionTitle ?? "",
18175
+ completionSummaryPerfect: basePaper.completionSummaryPerfect ?? "",
18176
+ completionSummaryReview: basePaper.completionSummaryReview ?? "",
18177
+ steps: nextSteps
18178
+ },
18179
+ token: session.token,
18180
+ activate: args.activate
18181
+ });
18182
+ if (result2.status === "draft") {
18183
+ ui.success("Quiz \u5355\u9898\u4FEE\u8BA2\u7A3F\u5DF2\u521B\u5EFA", result2.previewLink);
18184
+ ui.info("\u6765\u6E90\u8BD5\u5377", args.paperId);
18185
+ ui.info("\u4FEE\u8BA2\u9898\u76EE", args.stepId);
18186
+ ui.info("\u65B0\u8BD5\u5377", nextPaperId);
18187
+ ui.info("\u4E0B\u4E00\u6B65", `pmate quiz activate --paper-id ${nextPaperId}`);
18188
+ return;
18189
+ }
18190
+ ui.success("Quiz \u5355\u9898\u4FEE\u8BA2\u7A3F\u5DF2\u53D1\u5E03", result2.link);
18191
+ ui.info("\u6765\u6E90\u8BD5\u5377", args.paperId);
18192
+ ui.info("\u4FEE\u8BA2\u9898\u76EE", args.stepId);
18193
+ ui.info("\u65B0\u8BD5\u5377", nextPaperId);
18194
+ return;
18195
+ }
18131
18196
  const resolvedFilePath = import_node_path14.default.resolve(process.cwd(), args.filePath);
18132
18197
  const payload = JSON.parse((0, import_node_fs9.readFileSync)(resolvedFilePath, "utf8"));
18133
18198
  const result = await publishQuizPaper({
@@ -18146,6 +18211,19 @@ var QuizCommandHandler = class {
18146
18211
  }
18147
18212
  ui.success("Quiz \u5DF2\u53D1\u5E03", result.link);
18148
18213
  }
18214
+ timestampTag() {
18215
+ const now = /* @__PURE__ */ new Date();
18216
+ const pad = (value) => String(value).padStart(2, "0");
18217
+ return [
18218
+ now.getFullYear(),
18219
+ pad(now.getMonth() + 1),
18220
+ pad(now.getDate()),
18221
+ "-",
18222
+ pad(now.getHours()),
18223
+ pad(now.getMinutes()),
18224
+ pad(now.getSeconds())
18225
+ ].join("");
18226
+ }
18149
18227
  };
18150
18228
 
18151
18229
  // src/commands/CollectCommandHandler.ts
@@ -21826,6 +21904,7 @@ var HELP_TEXT = [
21826
21904
  ` ${import_chalk3.default.gray(" publish --file <json> --paper-id <id> [--activate]")}`,
21827
21905
  ` ${import_chalk3.default.gray(" activate --paper-id <id>")}`,
21828
21906
  ` ${import_chalk3.default.gray(" view --paper-id <id>")}`,
21907
+ ` ${import_chalk3.default.gray(" edit-step --paper-id <id> --step-id <step-id> --file <step.json> [--new-paper-id <id>] [--activate]")}`,
21829
21908
  ` ${import_chalk3.default.cyan("linear")} Create Linear issues`,
21830
21909
  ` ${import_chalk3.default.gray(" (default) create via REPL")}`,
21831
21910
  ` ${import_chalk3.default.gray(" create --repl [--cwd <dir>]")}`,
@@ -22530,6 +22609,63 @@ function parseQuizArgs(tokens) {
22530
22609
  linkBaseUrl
22531
22610
  };
22532
22611
  }
22612
+ if (action === "edit-step") {
22613
+ let paperId;
22614
+ let stepId;
22615
+ let filePath;
22616
+ let newPaperId;
22617
+ let apiBaseUrl;
22618
+ let linkBaseUrl;
22619
+ let activate = false;
22620
+ while (rest.length > 0) {
22621
+ const token = rest.shift();
22622
+ switch (token) {
22623
+ case "--paper-id":
22624
+ paperId = requireValue8(rest, token);
22625
+ break;
22626
+ case "--step-id":
22627
+ stepId = requireValue8(rest, token);
22628
+ break;
22629
+ case "--file":
22630
+ filePath = requireValue8(rest, token);
22631
+ break;
22632
+ case "--new-paper-id":
22633
+ newPaperId = requireValue8(rest, token);
22634
+ break;
22635
+ case "--base-url":
22636
+ apiBaseUrl = requireValue8(rest, token);
22637
+ break;
22638
+ case "--link-base":
22639
+ linkBaseUrl = requireValue8(rest, token);
22640
+ break;
22641
+ case "--activate":
22642
+ activate = true;
22643
+ break;
22644
+ default:
22645
+ throw new Error(`Unknown quiz edit-step option: ${token}`);
22646
+ }
22647
+ }
22648
+ if (!paperId) {
22649
+ throw new Error("Missing --paper-id. Usage: quiz edit-step --paper-id <id> --step-id <id> --file <step.json>.");
22650
+ }
22651
+ if (!stepId) {
22652
+ throw new Error("Missing --step-id. Usage: quiz edit-step --paper-id <id> --step-id <id> --file <step.json>.");
22653
+ }
22654
+ if (!filePath) {
22655
+ throw new Error("Missing --file. Usage: quiz edit-step --paper-id <id> --step-id <id> --file <step.json>.");
22656
+ }
22657
+ return {
22658
+ type: "quiz" /* Quiz */,
22659
+ action: "edit-step",
22660
+ paperId,
22661
+ stepId,
22662
+ filePath,
22663
+ newPaperId,
22664
+ apiBaseUrl,
22665
+ linkBaseUrl,
22666
+ activate
22667
+ };
22668
+ }
22533
22669
  throw new Error(`Unknown quiz action: ${action}`);
22534
22670
  }
22535
22671
  function parseLinearArgs(tokens) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/cli",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "CLI utilities for the pMate project",
5
5
  "license": "MIT",
6
6
  "bin": {