@mo7yw4ng/openape 1.0.6 → 2.0.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.
Files changed (152) hide show
  1. package/bin/openape +29 -0
  2. package/bin/openape.js +29 -0
  3. package/package.json +22 -28
  4. package/LICENSE +0 -21
  5. package/README.md +0 -138
  6. package/esm/_dnt.polyfills.d.ts +0 -101
  7. package/esm/_dnt.polyfills.d.ts.map +0 -1
  8. package/esm/_dnt.polyfills.js +0 -127
  9. package/esm/_dnt.shims.d.ts +0 -6
  10. package/esm/_dnt.shims.d.ts.map +0 -1
  11. package/esm/_dnt.shims.js +0 -61
  12. package/esm/deno.d.ts +0 -25
  13. package/esm/deno.d.ts.map +0 -1
  14. package/esm/deno.js +0 -23
  15. package/esm/package.json +0 -3
  16. package/esm/src/commands/announcements.d.ts +0 -3
  17. package/esm/src/commands/announcements.d.ts.map +0 -1
  18. package/esm/src/commands/announcements.js +0 -71
  19. package/esm/src/commands/assignments.d.ts +0 -3
  20. package/esm/src/commands/assignments.d.ts.map +0 -1
  21. package/esm/src/commands/assignments.js +0 -229
  22. package/esm/src/commands/auth.d.ts +0 -3
  23. package/esm/src/commands/auth.d.ts.map +0 -1
  24. package/esm/src/commands/auth.js +0 -290
  25. package/esm/src/commands/calendar.d.ts +0 -3
  26. package/esm/src/commands/calendar.d.ts.map +0 -1
  27. package/esm/src/commands/calendar.js +0 -127
  28. package/esm/src/commands/courses.d.ts +0 -3
  29. package/esm/src/commands/courses.d.ts.map +0 -1
  30. package/esm/src/commands/courses.js +0 -312
  31. package/esm/src/commands/forums.d.ts +0 -3
  32. package/esm/src/commands/forums.d.ts.map +0 -1
  33. package/esm/src/commands/forums.js +0 -190
  34. package/esm/src/commands/grades.d.ts +0 -3
  35. package/esm/src/commands/grades.d.ts.map +0 -1
  36. package/esm/src/commands/grades.js +0 -84
  37. package/esm/src/commands/materials.d.ts +0 -3
  38. package/esm/src/commands/materials.d.ts.map +0 -1
  39. package/esm/src/commands/materials.js +0 -402
  40. package/esm/src/commands/quizzes.d.ts +0 -3
  41. package/esm/src/commands/quizzes.d.ts.map +0 -1
  42. package/esm/src/commands/quizzes.js +0 -236
  43. package/esm/src/commands/skills.d.ts +0 -3
  44. package/esm/src/commands/skills.d.ts.map +0 -1
  45. package/esm/src/commands/skills.js +0 -106
  46. package/esm/src/commands/upload.d.ts +0 -3
  47. package/esm/src/commands/upload.d.ts.map +0 -1
  48. package/esm/src/commands/upload.js +0 -55
  49. package/esm/src/commands/videos.d.ts +0 -3
  50. package/esm/src/commands/videos.d.ts.map +0 -1
  51. package/esm/src/commands/videos.js +0 -266
  52. package/esm/src/index.d.ts +0 -28
  53. package/esm/src/index.d.ts.map +0 -1
  54. package/esm/src/index.js +0 -164
  55. package/esm/src/lib/auth.d.ts +0 -66
  56. package/esm/src/lib/auth.d.ts.map +0 -1
  57. package/esm/src/lib/auth.js +0 -286
  58. package/esm/src/lib/config.d.ts +0 -6
  59. package/esm/src/lib/config.d.ts.map +0 -1
  60. package/esm/src/lib/config.js +0 -36
  61. package/esm/src/lib/logger.d.ts +0 -3
  62. package/esm/src/lib/logger.d.ts.map +0 -1
  63. package/esm/src/lib/logger.js +0 -26
  64. package/esm/src/lib/moodle.d.ts +0 -447
  65. package/esm/src/lib/moodle.d.ts.map +0 -1
  66. package/esm/src/lib/moodle.js +0 -1353
  67. package/esm/src/lib/session.d.ts +0 -8
  68. package/esm/src/lib/session.d.ts.map +0 -1
  69. package/esm/src/lib/session.js +0 -42
  70. package/esm/src/lib/token.d.ts +0 -38
  71. package/esm/src/lib/token.d.ts.map +0 -1
  72. package/esm/src/lib/token.js +0 -178
  73. package/esm/src/lib/types.d.ts +0 -189
  74. package/esm/src/lib/types.d.ts.map +0 -1
  75. package/esm/src/lib/types.js +0 -2
  76. package/esm/src/lib/utils.d.ts +0 -52
  77. package/esm/src/lib/utils.d.ts.map +0 -1
  78. package/esm/src/lib/utils.js +0 -122
  79. package/script/_dnt.polyfills.d.ts +0 -101
  80. package/script/_dnt.polyfills.d.ts.map +0 -1
  81. package/script/_dnt.polyfills.js +0 -130
  82. package/script/_dnt.shims.d.ts +0 -6
  83. package/script/_dnt.shims.d.ts.map +0 -1
  84. package/script/_dnt.shims.js +0 -65
  85. package/script/deno.d.ts +0 -25
  86. package/script/deno.d.ts.map +0 -1
  87. package/script/deno.js +0 -25
  88. package/script/package.json +0 -3
  89. package/script/src/commands/announcements.d.ts +0 -3
  90. package/script/src/commands/announcements.d.ts.map +0 -1
  91. package/script/src/commands/announcements.js +0 -74
  92. package/script/src/commands/assignments.d.ts +0 -3
  93. package/script/src/commands/assignments.d.ts.map +0 -1
  94. package/script/src/commands/assignments.js +0 -268
  95. package/script/src/commands/auth.d.ts +0 -3
  96. package/script/src/commands/auth.d.ts.map +0 -1
  97. package/script/src/commands/auth.js +0 -296
  98. package/script/src/commands/calendar.d.ts +0 -3
  99. package/script/src/commands/calendar.d.ts.map +0 -1
  100. package/script/src/commands/calendar.js +0 -133
  101. package/script/src/commands/courses.d.ts +0 -3
  102. package/script/src/commands/courses.d.ts.map +0 -1
  103. package/script/src/commands/courses.js +0 -315
  104. package/script/src/commands/forums.d.ts +0 -3
  105. package/script/src/commands/forums.d.ts.map +0 -1
  106. package/script/src/commands/forums.js +0 -193
  107. package/script/src/commands/grades.d.ts +0 -3
  108. package/script/src/commands/grades.d.ts.map +0 -1
  109. package/script/src/commands/grades.js +0 -87
  110. package/script/src/commands/materials.d.ts +0 -3
  111. package/script/src/commands/materials.d.ts.map +0 -1
  112. package/script/src/commands/materials.js +0 -408
  113. package/script/src/commands/quizzes.d.ts +0 -3
  114. package/script/src/commands/quizzes.d.ts.map +0 -1
  115. package/script/src/commands/quizzes.js +0 -239
  116. package/script/src/commands/skills.d.ts +0 -3
  117. package/script/src/commands/skills.d.ts.map +0 -1
  118. package/script/src/commands/skills.js +0 -112
  119. package/script/src/commands/upload.d.ts +0 -3
  120. package/script/src/commands/upload.d.ts.map +0 -1
  121. package/script/src/commands/upload.js +0 -61
  122. package/script/src/commands/videos.d.ts +0 -3
  123. package/script/src/commands/videos.d.ts.map +0 -1
  124. package/script/src/commands/videos.js +0 -272
  125. package/script/src/index.d.ts +0 -28
  126. package/script/src/index.d.ts.map +0 -1
  127. package/script/src/index.js +0 -171
  128. package/script/src/lib/auth.d.ts +0 -66
  129. package/script/src/lib/auth.d.ts.map +0 -1
  130. package/script/src/lib/auth.js +0 -296
  131. package/script/src/lib/config.d.ts +0 -6
  132. package/script/src/lib/config.d.ts.map +0 -1
  133. package/script/src/lib/config.js +0 -42
  134. package/script/src/lib/logger.d.ts +0 -3
  135. package/script/src/lib/logger.d.ts.map +0 -1
  136. package/script/src/lib/logger.js +0 -29
  137. package/script/src/lib/moodle.d.ts +0 -447
  138. package/script/src/lib/moodle.d.ts.map +0 -1
  139. package/script/src/lib/moodle.js +0 -1425
  140. package/script/src/lib/session.d.ts +0 -8
  141. package/script/src/lib/session.d.ts.map +0 -1
  142. package/script/src/lib/session.js +0 -45
  143. package/script/src/lib/token.d.ts +0 -38
  144. package/script/src/lib/token.d.ts.map +0 -1
  145. package/script/src/lib/token.js +0 -189
  146. package/script/src/lib/types.d.ts +0 -189
  147. package/script/src/lib/types.d.ts.map +0 -1
  148. package/script/src/lib/types.js +0 -3
  149. package/script/src/lib/utils.d.ts +0 -52
  150. package/script/src/lib/utils.d.ts.map +0 -1
  151. package/script/src/lib/utils.js +0 -167
  152. package/skills/openape/SKILL.md +0 -115
@@ -1,236 +0,0 @@
1
- import { formatTimestamp, getOutputFormat } from "../lib/utils.js";
2
- import { getEnrolledCoursesApi, getQuizzesByCoursesApi, startQuizAttemptApi, getQuizAttemptDataApi, getAllQuizAttemptDataApi, processQuizAttemptApi } from "../lib/moodle.js";
3
- import { createApiContext } from "../lib/auth.js";
4
- import { formatAndOutput } from "../index.js";
5
- function stripHtmlKeepLines(html) {
6
- return html
7
- .replace(/<br\s*\/?>/gi, "\n")
8
- .replace(/<\/p>/gi, "\n")
9
- .replace(/<[^>]+>/g, "")
10
- .replace(/&nbsp;/g, " ")
11
- .replace(/&amp;/g, "&")
12
- .replace(/&lt;/g, "<")
13
- .replace(/&gt;/g, ">")
14
- .replace(/\n{3,}/g, "\n\n")
15
- .trim();
16
- }
17
- function parseQuestionHtml(html) {
18
- const qtextMatch = html.match(/<div class="qtext">([\s\S]*?)<\/div>\s*<\/div>/);
19
- const text = stripHtmlKeepLines(qtextMatch?.[1] ?? "");
20
- const options = [];
21
- const optionRegex = /data-region="answer-label">([\s\S]*?)<\/div>\s*<\/div>/g;
22
- let match;
23
- while ((match = optionRegex.exec(html)) !== null) {
24
- options.push(stripHtmlKeepLines(match[1]));
25
- }
26
- return { text, options };
27
- }
28
- function parseSavedAnswer(html) {
29
- const radioChecked = html.match(/<input type="radio"[^>]*value="(\d+)"[^>]*checked="checked"/);
30
- if (radioChecked && radioChecked[1] !== "-1")
31
- return radioChecked[1];
32
- const checkboxChecked = [...html.matchAll(/<input type="checkbox"[^>]*name="[^"]*choice(\d+)"[^>]*checked="checked"/g)];
33
- if (checkboxChecked.length > 0)
34
- return checkboxChecked.map(m => m[1]);
35
- // Match <input> with both name="*_answer" and type="text" in any attribute order
36
- const textMatch = html.match(/<input[^>]*(?:name="[^"]*:_answer"|type="text")[^>]*(?:name="[^"]*:_answer"|type="text")[^>]*value="([^"]*)"/);
37
- if (textMatch && textMatch[1] !== "")
38
- return textMatch[1];
39
- return null;
40
- }
41
- function parseQuizQuestions(questions) {
42
- return Object.values(questions).map((q) => {
43
- const parsed = parseQuestionHtml(q.html ?? "");
44
- const savedAnswer = parseSavedAnswer(q.html ?? "");
45
- return {
46
- slot: q.slot,
47
- type: q.type,
48
- status: q.status,
49
- stateclass: q.stateclass,
50
- savedAnswer,
51
- question: parsed.text,
52
- options: parsed.options,
53
- };
54
- });
55
- }
56
- export function registerQuizzesCommand(program) {
57
- const quizzesCmd = program.command("quizzes");
58
- quizzesCmd.description("Quiz operations");
59
- quizzesCmd
60
- .command("list")
61
- .description("List incomplete quizzes in a course")
62
- .argument("<course-id>", "Course ID")
63
- .option("--all", "Include completed quizzes")
64
- .option("--output <format>", "Output format: json|csv|table|silent")
65
- .action(async (courseId, options, command) => {
66
- const output = getOutputFormat(command);
67
- const apiContext = await createApiContext(options, command);
68
- if (!apiContext) {
69
- process.exitCode = 1;
70
- return;
71
- }
72
- const quizzes = await getQuizzesByCoursesApi(apiContext.session, [parseInt(courseId, 10)]);
73
- // Default: only show incomplete quizzes
74
- const filtered = options.all ? quizzes : quizzes.filter(q => !q.isComplete);
75
- const formattedQuizzes = filtered.map(({ courseId, ...q }) => ({
76
- ...q,
77
- timeClose: q.timeClose ? formatTimestamp(q.timeClose) : null,
78
- }));
79
- formatAndOutput(formattedQuizzes, output, apiContext.log);
80
- });
81
- quizzesCmd
82
- .command("list-all")
83
- .description("List all incomplete quizzes across all courses")
84
- .option("--level <type>", "Course level: in_progress (default) | all", "in_progress")
85
- .option("--all", "Include completed quizzes")
86
- .option("--output <format>", "Output format: json|csv|table|silent")
87
- .action(async (options, command) => {
88
- const output = getOutputFormat(command);
89
- const apiContext = await createApiContext(options, command);
90
- if (!apiContext) {
91
- process.exitCode = 1;
92
- return;
93
- }
94
- const classification = options.level === "all" ? undefined : "inprogress";
95
- const courses = await getEnrolledCoursesApi(apiContext.session, {
96
- classification,
97
- });
98
- // Get quizzes via WS API (no browser needed!)
99
- const courseIds = courses.map(c => c.id);
100
- const apiQuizzes = await getQuizzesByCoursesApi(apiContext.session, courseIds);
101
- // Build a map of courseId -> course for quick lookup
102
- const courseMap = new Map(courses.map(c => [c.id, c]));
103
- const allQuizzes = [];
104
- for (const q of apiQuizzes) {
105
- const course = courseMap.get(q.courseId);
106
- if (course && (options.all || !q.isComplete)) {
107
- allQuizzes.push({
108
- courseName: course.fullname,
109
- courseId: q.courseId,
110
- name: q.name,
111
- url: q.url,
112
- quizid: q.quizid,
113
- isComplete: q.isComplete,
114
- attemptsUsed: q.attemptsUsed,
115
- maxAttempts: q.maxAttempts,
116
- timeClose: q.timeClose ? formatTimestamp(q.timeClose) : null,
117
- });
118
- }
119
- }
120
- apiContext.log.info(`\n總計發現 ${allQuizzes.length} 個測驗。`);
121
- formatAndOutput(allQuizzes, output, apiContext.log);
122
- });
123
- quizzesCmd
124
- .command("start")
125
- .description("Start a new quiz attempt")
126
- .argument("<quiz-id>", "Quiz ID")
127
- .option("--output <format>", "Output format: json|csv|table|silent")
128
- .action(async (quizCmid, options, command) => {
129
- const output = getOutputFormat(command);
130
- const apiContext = await createApiContext(options, command);
131
- if (!apiContext) {
132
- process.exitCode = 1;
133
- return;
134
- }
135
- try {
136
- const result = await startQuizAttemptApi(apiContext.session, quizCmid);
137
- apiContext.log.success(`Quiz attempt ${result.attempt.attemptid} started.`);
138
- const attemptId = result.attempt.attemptid;
139
- const data = await getAllQuizAttemptDataApi(apiContext.session, attemptId);
140
- const questions = parseQuizQuestions(data.questions);
141
- const outputData = [{
142
- attemptId,
143
- quizId: result.attempt.quizid,
144
- state: result.attempt.state,
145
- timeStart: formatTimestamp(result.attempt.timestart),
146
- timeFinish: result.attempt.timefinish
147
- ? formatTimestamp(result.attempt.timefinish)
148
- : null,
149
- isPreview: result.attempt.preview,
150
- totalQuestions: questions.length,
151
- questions,
152
- }];
153
- formatAndOutput(outputData, output, apiContext.log);
154
- }
155
- catch (error) {
156
- apiContext.log.error(`Failed to start quiz attempt: ${error instanceof Error ? error.message : String(error)}`);
157
- process.exitCode = 1;
158
- }
159
- });
160
- quizzesCmd
161
- .command("info")
162
- .description("Get quiz attempt data and questions")
163
- .argument("<attempt-id>", "Quiz attempt ID")
164
- .option("--page <number>", "Page number (-1 for all pages)", "-1")
165
- .option("--output <format>", "Output format: json|csv|table|silent")
166
- .action(async (attemptId, options, command) => {
167
- const output = getOutputFormat(command);
168
- const apiContext = await createApiContext(options, command);
169
- if (!apiContext) {
170
- process.exitCode = 1;
171
- return;
172
- }
173
- try {
174
- const pageNumber = parseInt(options.page);
175
- const data = pageNumber === -1
176
- ? await getAllQuizAttemptDataApi(apiContext.session, parseInt(attemptId))
177
- : await getQuizAttemptDataApi(apiContext.session, parseInt(attemptId), pageNumber);
178
- const questions = parseQuizQuestions(data.questions);
179
- const outputData = [{
180
- attemptId: data.attempt.attemptid,
181
- quizId: data.attempt.quizid,
182
- state: data.attempt.state,
183
- totalQuestions: questions.length,
184
- questions,
185
- }];
186
- apiContext.log.success(`Retrieved attempt ${data.attempt.attemptid}`);
187
- formatAndOutput(outputData, output, apiContext.log);
188
- }
189
- catch (error) {
190
- apiContext.log.error(`Failed to get attempt data: ${error instanceof Error ? error.message : String(error)}`);
191
- process.exitCode = 1;
192
- }
193
- });
194
- quizzesCmd
195
- .command("save")
196
- .description("Save answers for a quiz attempt")
197
- .argument("<attempt-id>", "Quiz attempt ID")
198
- .argument("<answers>", "Answers JSON: [{slot:1,answer:\"0\"}] multichoice=number, multichoices=\"0,2\", shortanswer=\"text\"")
199
- .option("--submit", "Submit the attempt after saving")
200
- .option("--output <format>", "Output format: json|csv|table|silent")
201
- .action(async (attemptId, answersJson, options, command) => {
202
- const output = getOutputFormat(command);
203
- const apiContext = await createApiContext(options, command);
204
- if (!apiContext) {
205
- process.exitCode = 1;
206
- return;
207
- }
208
- let answers;
209
- try {
210
- answers = JSON.parse(answersJson);
211
- }
212
- catch {
213
- apiContext.log.error("Invalid answers JSON. Expected format: [{\"slot\":1,\"answer\":\"0\"},...]");
214
- process.exitCode = 1;
215
- return;
216
- }
217
- try {
218
- // Get attempt data to find uniqueid and sequencecheck values
219
- const attemptData = await getAllQuizAttemptDataApi(apiContext.session, parseInt(attemptId));
220
- const uniqueId = attemptData.attempt.uniqueid ?? attemptData.attempt.attemptid;
221
- const sequenceChecks = new Map();
222
- for (const q of Object.values(attemptData.questions)) {
223
- if (q.sequencecheck !== undefined) {
224
- sequenceChecks.set(q.slot, q.sequencecheck);
225
- }
226
- }
227
- const result = await processQuizAttemptApi(apiContext.session, parseInt(attemptId), uniqueId, answers, sequenceChecks, !!options.submit);
228
- apiContext.log.success(`Attempt ${attemptId} state: ${result.state}`);
229
- formatAndOutput([result], output, apiContext.log);
230
- }
231
- catch (error) {
232
- apiContext.log.error(`Failed to submit attempt: ${error instanceof Error ? error.message : String(error)}`);
233
- process.exitCode = 1;
234
- }
235
- });
236
- }
@@ -1,3 +0,0 @@
1
- import { Command } from "commander";
2
- export declare function registerSkillsCommand(program: Command): void;
3
- //# sourceMappingURL=skills.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../../../src/src/commands/skills.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA2CpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAuE5D"}
@@ -1,106 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import os from "node:os";
4
- import { fileURLToPath } from "node:url";
5
- const SKILL_NAME = "openape";
6
- const GITHUB_RAW_URL = `https://raw.githubusercontent.com/mo7yw4ng/openape/refs/heads/main/skills/${SKILL_NAME}/SKILL.md`;
7
- /**
8
- * Known agent platforms and their skills directories
9
- */
10
- const PLATFORMS = {
11
- claude: { name: "Claude Code", path: path.join(os.homedir(), ".claude", "skills") },
12
- codex: { name: "Codex CLI", path: path.join(os.homedir(), ".codex", "skills") },
13
- opencode: { name: "OpenCode", path: path.join(os.homedir(), ".opencode", "skills") },
14
- };
15
- /**
16
- * Try to read SKILL.md from local project first (dev mode / bundled build),
17
- * fallback to fetching from GitHub (when installed globally via npm).
18
- */
19
- async function readSkillContent() {
20
- // Try local path first (relative to this file's location)
21
- try {
22
- const base = path.dirname(fileURLToPath(globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url));
23
- // When running from source: src/commands/ → ../../skills/openape/SKILL.md
24
- // When bundled by dnt into build/: esm/commands/ or script/ → ../../skills/openape/SKILL.md
25
- const localPath = path.resolve(base, "..", "..", "skills", SKILL_NAME, "SKILL.md");
26
- return await fs.promises.readFile(localPath, "utf-8");
27
- }
28
- catch {
29
- // import.meta.url may be unavailable in some environments, or file doesn't exist
30
- }
31
- // Fallback: fetch from GitHub
32
- const res = await fetch(GITHUB_RAW_URL, { headers: { "User-Agent": "openape-cli" } });
33
- if (!res.ok) {
34
- throw new Error(`Failed to fetch skill from GitHub: ${res.status} ${res.statusText}`);
35
- }
36
- return res.text();
37
- }
38
- export function registerSkillsCommand(program) {
39
- const skills = program
40
- .command("skills")
41
- .description("Manage OpenApe skills for AI agents");
42
- skills
43
- .command("install [platform]")
44
- .description("Install the OpenApe skill to an agent platform (claude, codex, opencode)")
45
- .option("--all", "Detect installed agents and install to all")
46
- .action(async (platform, opts) => {
47
- try {
48
- let targets = [];
49
- if (opts?.all) {
50
- for (const [key, info] of Object.entries(PLATFORMS)) {
51
- const parentDir = path.dirname(info.path);
52
- if (fs.existsSync(parentDir)) {
53
- targets.push({ key, ...info });
54
- }
55
- }
56
- if (targets.length === 0) {
57
- console.log("No supported agents detected. Supported platforms: " + Object.keys(PLATFORMS).join(", "));
58
- return;
59
- }
60
- }
61
- else if (platform) {
62
- const info = PLATFORMS[platform.toLowerCase()];
63
- if (!info) {
64
- console.error(`Unknown platform: ${platform}`);
65
- console.error(`Supported platforms: ${Object.keys(PLATFORMS).join(", ")}`);
66
- process.exitCode = 1;
67
- return;
68
- }
69
- targets = [{ key: platform.toLowerCase(), ...info }];
70
- }
71
- else {
72
- console.error("Specify a platform or use --all.");
73
- console.error(`Example: openape skills install claude`);
74
- process.exitCode = 1;
75
- return;
76
- }
77
- console.log(`Fetching ${SKILL_NAME} skill...`);
78
- const content = await readSkillContent();
79
- for (const target of targets) {
80
- console.log(`Installing to ${target.name} (${target.path})...`);
81
- const destDir = path.join(target.path, SKILL_NAME);
82
- await fs.promises.mkdir(destDir, { recursive: true });
83
- await fs.promises.writeFile(path.join(destDir, "SKILL.md"), content, "utf-8");
84
- console.log(` \x1b[32m✔\x1b[0m ${SKILL_NAME} installed!`);
85
- }
86
- console.log("\nDone!");
87
- }
88
- catch (err) {
89
- console.error(`\x1b[31mFailed to install skill: ${err.message}\x1b[0m`);
90
- process.exitCode = 1;
91
- }
92
- });
93
- skills
94
- .command("show")
95
- .description("Print the raw SKILL.md content")
96
- .action(async () => {
97
- try {
98
- const content = await readSkillContent();
99
- process.stdout.write(content);
100
- }
101
- catch (err) {
102
- console.error(`\x1b[31mFailed: ${err.message}\x1b[0m`);
103
- process.exitCode = 1;
104
- }
105
- });
106
- }
@@ -1,3 +0,0 @@
1
- import { Command } from "commander";
2
- export declare function registerUploadCommand(program: Command): void;
3
- //# sourceMappingURL=upload.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/src/commands/upload.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAwD5D"}
@@ -1,55 +0,0 @@
1
- import { getOutputFormat, formatFileSize } from "../lib/utils.js";
2
- import { uploadFileApi } from "../lib/moodle.js";
3
- import { createApiContext } from "../lib/auth.js";
4
- import { formatAndOutput } from "../index.js";
5
- import path from "node:path";
6
- import fs from "node:fs/promises";
7
- export function registerUploadCommand(program) {
8
- const uploadCmd = program.command("upload");
9
- uploadCmd.description("Upload files to Moodle draft area");
10
- uploadCmd
11
- .command("file")
12
- .description("Upload a file to Moodle draft area")
13
- .argument("<file-path>", "Path to the file to upload")
14
- .option("--filename <name>", "Custom filename (default: original filename)")
15
- .option("--output <format>", "Output format: json|csv|table|silent")
16
- .action(async (filePath, options, command) => {
17
- const output = getOutputFormat(command);
18
- const apiContext = await createApiContext(options, command);
19
- if (!apiContext) {
20
- process.exitCode = 1;
21
- return;
22
- }
23
- const resolvedPath = path.resolve(filePath);
24
- let stats;
25
- try {
26
- stats = await fs.stat(resolvedPath);
27
- }
28
- catch {
29
- apiContext.log.error(`檔案不存在: ${filePath}`);
30
- process.exitCode = 1;
31
- return;
32
- }
33
- const fileSizeKB = formatFileSize(stats.size);
34
- apiContext.log.info(`上傳檔案: ${path.basename(resolvedPath)} (${fileSizeKB} KB)`);
35
- // Upload file
36
- const result = await uploadFileApi(apiContext.session, resolvedPath, {
37
- filename: options.filename,
38
- });
39
- if (!result.success) {
40
- apiContext.log.error(`上傳失敗: ${result.error}`);
41
- process.exitCode = 1;
42
- return;
43
- }
44
- apiContext.log.info(`✓ 上傳成功!Draft ID: ${result.draftId}`);
45
- const uploadResult = {
46
- success: true,
47
- draft_id: result.draftId,
48
- filename: path.basename(resolvedPath),
49
- filesize: stats.size,
50
- filesize_kb: formatFileSize(stats.size),
51
- message: "Use this draft ID for assignment submission or forum posts",
52
- };
53
- formatAndOutput(uploadResult, output, apiContext.log);
54
- });
55
- }
@@ -1,3 +0,0 @@
1
- import { Command } from "commander";
2
- export declare function registerVideosCommand(program: Command): void;
3
- //# sourceMappingURL=videos.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"videos.d.ts","sourceRoot":"","sources":["../../../src/src/commands/videos.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAgT5D"}