@learnosity/lib-qti-converter 0.12.1 → 0.12.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.
- package/README.md +9 -3
- package/docs/GETTING_STARTED.md +10 -4
- package/docs/TAGS_TO_QTI_METADATA.md +291 -0
- package/docs/_sidebar.md +10 -9
- package/package.json +9 -9
- package/packages/cli/dist/batchProcessors-BfmvnTQ5.js +215 -0
- package/packages/cli/dist/batchProcessors-BfmvnTQ5.js.map +1 -0
- package/packages/cli/dist/batchWorker.js +1 -1
- package/packages/cli/dist/configOutput-FwkFyQmk.js +399 -0
- package/packages/cli/dist/configOutput-FwkFyQmk.js.map +1 -0
- package/packages/cli/dist/create-prompt-DU9wLVhI.js +1392 -0
- package/packages/cli/dist/create-prompt-DU9wLVhI.js.map +1 -0
- package/packages/cli/dist/dist-DjpU2mIj.js +278 -0
- package/packages/cli/dist/dist-DjpU2mIj.js.map +1 -0
- package/packages/cli/dist/learnosityToQti-B0PoimXr.js +102 -0
- package/packages/cli/dist/learnosityToQti-B0PoimXr.js.map +1 -0
- package/packages/cli/dist/learnosityToQtiPackage-RyClxvZj.js +632 -0
- package/packages/cli/dist/learnosityToQtiPackage-RyClxvZj.js.map +1 -0
- package/packages/cli/dist/main.js +32 -37131
- package/packages/cli/dist/main.js.map +1 -1
- package/packages/cli/dist/pathUtils-CwZnJ55s.js +2386 -0
- package/packages/cli/dist/pathUtils-CwZnJ55s.js.map +1 -0
- package/packages/cli/dist/qtiPackageToLearnosity-0rkZKKOK.js +354 -0
- package/packages/cli/dist/qtiPackageToLearnosity-0rkZKKOK.js.map +1 -0
- package/packages/cli/dist/qtiToLearnosity-jiFTBiQU.js +97 -0
- package/packages/cli/dist/qtiToLearnosity-jiFTBiQU.js.map +1 -0
- package/packages/cli/dist/resolveOptions-gH_YAxxc.js +31578 -0
- package/packages/cli/dist/resolveOptions-gH_YAxxc.js.map +1 -0
- package/packages/cli/dist/rolldown-runtime-B4iAMlE-.js +35 -0
- package/packages/cli/dist/{batchProcessors-B8EQvMbH.js → table-DYcNeyJ_.js} +906 -1150
- package/packages/cli/dist/table-DYcNeyJ_.js.map +1 -0
- package/packages/core/dist/index.js +162 -144
- package/packages/core/dist/node.js +162 -144
- package/packages/cli/dist/batchProcessors-B8EQvMbH.js.map +0 -1
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
import { _ as isEnterKey, c as usePrefix, f as useState, g as isDownKey, l as makeTheme, m as ValidationError, n as cursorHide, o as useKeypress, t as createPrompt, u as figures, v as isNumberKey, x as isUpKey, y as isSpaceKey } from "./create-prompt-DU9wLVhI.js";
|
|
2
|
+
import { i as useMemo, n as Separator, r as usePagination, t as dist_default$1 } from "./dist-DjpU2mIj.js";
|
|
3
|
+
import { l as dist_default$2, n as loadConfig, r as showBanner, t as expandTilde } from "./pathUtils-CwZnJ55s.js";
|
|
4
|
+
import { n as formatDiagnosticsSummaryTable, r as formatDiagnosticsTable, s as writeDiagnostics } from "./table-DYcNeyJ_.js";
|
|
5
|
+
import { t as processLearnosityToQtiPackage } from "./batchProcessors-BfmvnTQ5.js";
|
|
6
|
+
import { i as processBatchParallel, n as displayConfiguration, r as processBatch, t as configField } from "./configOutput-FwkFyQmk.js";
|
|
7
|
+
import { styleText } from "node:util";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "fs";
|
|
10
|
+
import { buildPackageFromActivity, convertActivity, ensureUniqueFolderName, loadLearnosityBundle, mergeActivityPackage, sanitizeFolderName, saveQtiContentPackage } from "@learnosity/converter-core/node";
|
|
11
|
+
//#region ../../node_modules/.pnpm/@inquirer+checkbox@5.2.2_@types+node@26.3.0/node_modules/@inquirer/checkbox/dist/index.js
|
|
12
|
+
const checkboxTheme = {
|
|
13
|
+
icon: {
|
|
14
|
+
checked: styleText("green", figures.circleFilled),
|
|
15
|
+
unchecked: figures.circle,
|
|
16
|
+
cursor: figures.pointer,
|
|
17
|
+
disabledChecked: styleText("green", figures.circleDouble),
|
|
18
|
+
disabledUnchecked: "-"
|
|
19
|
+
},
|
|
20
|
+
style: {
|
|
21
|
+
disabled: (text) => styleText("dim", text),
|
|
22
|
+
renderSelectedChoices: (selectedChoices) => selectedChoices.map((choice) => choice.short).join(", "),
|
|
23
|
+
description: (text) => styleText("cyan", text),
|
|
24
|
+
keysHelpTip: (keys) => keys.map(([key, action]) => `${styleText("bold", key)} ${styleText("dim", action)}`).join(styleText("dim", " • "))
|
|
25
|
+
},
|
|
26
|
+
i18n: { disabledError: "This option is disabled and cannot be toggled." }
|
|
27
|
+
};
|
|
28
|
+
function isSelectable(item) {
|
|
29
|
+
return !Separator.isSeparator(item) && !item.disabled;
|
|
30
|
+
}
|
|
31
|
+
function isNavigable(item) {
|
|
32
|
+
return !Separator.isSeparator(item);
|
|
33
|
+
}
|
|
34
|
+
function isChecked(item) {
|
|
35
|
+
return !Separator.isSeparator(item) && item.checked;
|
|
36
|
+
}
|
|
37
|
+
function toggle(item) {
|
|
38
|
+
return isSelectable(item) ? {
|
|
39
|
+
...item,
|
|
40
|
+
checked: !item.checked
|
|
41
|
+
} : item;
|
|
42
|
+
}
|
|
43
|
+
function check(checked) {
|
|
44
|
+
return function(item) {
|
|
45
|
+
return isSelectable(item) ? {
|
|
46
|
+
...item,
|
|
47
|
+
checked
|
|
48
|
+
} : item;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function normalizeChoices(choices) {
|
|
52
|
+
return choices.map((choice) => {
|
|
53
|
+
if (Separator.isSeparator(choice)) return choice;
|
|
54
|
+
if (typeof choice !== "object" || choice === null || !("value" in choice)) {
|
|
55
|
+
const name = String(choice);
|
|
56
|
+
return {
|
|
57
|
+
value: choice,
|
|
58
|
+
name,
|
|
59
|
+
short: name,
|
|
60
|
+
checkedName: name,
|
|
61
|
+
disabled: false,
|
|
62
|
+
checked: false
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const name = choice.name ?? String(choice.value);
|
|
66
|
+
const normalizedChoice = {
|
|
67
|
+
value: choice.value,
|
|
68
|
+
name,
|
|
69
|
+
short: choice.short ?? name,
|
|
70
|
+
checkedName: choice.checkedName ?? name,
|
|
71
|
+
disabled: choice.disabled ?? false,
|
|
72
|
+
checked: choice.checked ?? false
|
|
73
|
+
};
|
|
74
|
+
if (choice.description) normalizedChoice.description = choice.description;
|
|
75
|
+
return normalizedChoice;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
var dist_default = createPrompt((config, done) => {
|
|
79
|
+
const { pageSize = 7, loop = true, required, validate = () => true } = config;
|
|
80
|
+
const shortcuts = {
|
|
81
|
+
all: "a",
|
|
82
|
+
invert: "i",
|
|
83
|
+
...config.shortcuts
|
|
84
|
+
};
|
|
85
|
+
const theme = makeTheme(checkboxTheme, config.theme);
|
|
86
|
+
const { keybindings } = theme;
|
|
87
|
+
const [status, setStatus] = useState("idle");
|
|
88
|
+
const prefix = usePrefix({
|
|
89
|
+
status,
|
|
90
|
+
theme
|
|
91
|
+
});
|
|
92
|
+
const [items, setItems] = useState(normalizeChoices(config.choices));
|
|
93
|
+
const bounds = useMemo(() => {
|
|
94
|
+
const first = items.findIndex(isNavigable);
|
|
95
|
+
const last = items.findLastIndex(isNavigable);
|
|
96
|
+
if (first === -1) throw new ValidationError("[checkbox prompt] No selectable choices. All choices are disabled.");
|
|
97
|
+
return {
|
|
98
|
+
first,
|
|
99
|
+
last
|
|
100
|
+
};
|
|
101
|
+
}, [items]);
|
|
102
|
+
const [active, setActive] = useState(bounds.first);
|
|
103
|
+
const [errorMsg, setError] = useState();
|
|
104
|
+
useKeypress(async (key) => {
|
|
105
|
+
if (isEnterKey(key)) {
|
|
106
|
+
const selection = items.filter(isChecked);
|
|
107
|
+
const isValid = await validate([...selection]);
|
|
108
|
+
if (required && !selection.length) setError("At least one choice must be selected");
|
|
109
|
+
else if (isValid === true) {
|
|
110
|
+
setStatus("done");
|
|
111
|
+
done(selection.map((choice) => choice.value));
|
|
112
|
+
} else setError(isValid || "You must select a valid value");
|
|
113
|
+
} else if (isUpKey(key, keybindings) || isDownKey(key, keybindings)) {
|
|
114
|
+
if (errorMsg) setError(void 0);
|
|
115
|
+
if (loop || isUpKey(key, keybindings) && active !== bounds.first || isDownKey(key, keybindings) && active !== bounds.last) {
|
|
116
|
+
const offset = isUpKey(key, keybindings) ? -1 : 1;
|
|
117
|
+
let next = active;
|
|
118
|
+
do
|
|
119
|
+
next = (next + offset + items.length) % items.length;
|
|
120
|
+
while (!isNavigable(items[next]));
|
|
121
|
+
setActive(next);
|
|
122
|
+
}
|
|
123
|
+
} else if (isSpaceKey(key)) {
|
|
124
|
+
const activeItem = items[active];
|
|
125
|
+
if (activeItem && !Separator.isSeparator(activeItem)) {
|
|
126
|
+
if (activeItem.disabled) setError(theme.i18n.disabledError);
|
|
127
|
+
else {
|
|
128
|
+
setError(void 0);
|
|
129
|
+
setItems(items.map((choice, i) => i === active ? toggle(choice) : choice));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} else if (key.name === shortcuts.all) {
|
|
133
|
+
const selectAll = items.some((choice) => isSelectable(choice) && !choice.checked);
|
|
134
|
+
setItems(items.map(check(selectAll)));
|
|
135
|
+
} else if (key.name === shortcuts.invert) setItems(items.map(toggle));
|
|
136
|
+
else if (isNumberKey(key)) {
|
|
137
|
+
const selectedIndex = Number(key.name) - 1;
|
|
138
|
+
let selectableIndex = -1;
|
|
139
|
+
const position = items.findIndex((item) => {
|
|
140
|
+
if (Separator.isSeparator(item)) return false;
|
|
141
|
+
selectableIndex++;
|
|
142
|
+
return selectableIndex === selectedIndex;
|
|
143
|
+
});
|
|
144
|
+
const selectedItem = items[position];
|
|
145
|
+
if (selectedItem && isSelectable(selectedItem)) {
|
|
146
|
+
setActive(position);
|
|
147
|
+
setItems(items.map((choice, i) => i === position ? toggle(choice) : choice));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
const message = theme.style.message(config.message, status);
|
|
152
|
+
let description;
|
|
153
|
+
const page = usePagination({
|
|
154
|
+
items,
|
|
155
|
+
active,
|
|
156
|
+
renderItem({ item, isActive }) {
|
|
157
|
+
if (Separator.isSeparator(item)) return ` ${item.separator}`;
|
|
158
|
+
const cursor = isActive ? theme.icon.cursor : " ";
|
|
159
|
+
if (item.disabled) {
|
|
160
|
+
const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
|
|
161
|
+
const checkbox = item.checked ? theme.icon.disabledChecked : theme.icon.disabledUnchecked;
|
|
162
|
+
return theme.style.disabled(`${cursor}${checkbox} ${item.name} ${disabledLabel}`);
|
|
163
|
+
}
|
|
164
|
+
if (isActive) description = item.description;
|
|
165
|
+
const checkbox = item.checked ? theme.icon.checked : theme.icon.unchecked;
|
|
166
|
+
const name = item.checked ? item.checkedName : item.name;
|
|
167
|
+
return (isActive ? theme.style.highlight : (x) => x)(`${cursor}${checkbox} ${name}`);
|
|
168
|
+
},
|
|
169
|
+
pageSize,
|
|
170
|
+
loop
|
|
171
|
+
});
|
|
172
|
+
if (status === "done") {
|
|
173
|
+
const selection = items.filter(isChecked);
|
|
174
|
+
return [
|
|
175
|
+
prefix,
|
|
176
|
+
message,
|
|
177
|
+
theme.style.answer(theme.style.renderSelectedChoices(selection, items))
|
|
178
|
+
].filter(Boolean).join(" ");
|
|
179
|
+
}
|
|
180
|
+
const keys = [["↑↓", "navigate"], ["space", "select"]];
|
|
181
|
+
if (shortcuts.all) keys.push([shortcuts.all, "all"]);
|
|
182
|
+
if (shortcuts.invert) keys.push([shortcuts.invert, "invert"]);
|
|
183
|
+
keys.push(["⏎", "submit"]);
|
|
184
|
+
const helpLine = theme.style.keysHelpTip(keys);
|
|
185
|
+
return `${[
|
|
186
|
+
[prefix, message].filter(Boolean).join(" "),
|
|
187
|
+
page,
|
|
188
|
+
" ",
|
|
189
|
+
description ? theme.style.description(description) : "",
|
|
190
|
+
errorMsg ? theme.style.error(errorMsg) : "",
|
|
191
|
+
helpLine
|
|
192
|
+
].filter(Boolean).join("\n").trimEnd()}${cursorHide}`;
|
|
193
|
+
});
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/commands/learnosityToQtiPackage.ts
|
|
196
|
+
/**
|
|
197
|
+
* Register learnosity-to-qti-package command
|
|
198
|
+
*/
|
|
199
|
+
function registerLearnosityToQtiPackageCommand(program, version) {
|
|
200
|
+
program.command("learnosity-to-qti-package").description("Convert a Learnosity bundle to a QTI Content Package").option("--in <path>", "Input bundle directory path").option("--activity <id...>", "Activity reference(s) to convert (space-separated). Omit to convert all activities.").option("--out <path>", "Output package path (.zip or directory)").option("--format <type>", "Output format: zip or dir (default: auto-detect from --out path)").option("--qti-version <version>", "QTI version: 2.1 or 2.2 (default: 2.2)").option("--recursive", "Process all subdirectories in the input path (default: false)").option("--concurrency <number>", "Worker threads for --recursive batch conversion (default: 1 = serial)", parseInt).option("--diagnostics <mode>", "Diagnostics output (stderr|file|both|none, default: file)").option("--fail-on-warn", "Exit with error code 1 if warnings exist (default: false)").option("--config <path>", "Path to config file").option("--no-config", "Disable config file loading").option("-i, --interactive", "Enable interactive prompts (default: false)").option("--pretty", "Pretty-print XML output (default: false)").option("-q, --quiet", "Suppress non-essential output (default: false)").option("-v, --verbose", "Show INFO level diagnostics (default: false)").option("--include-learnosity-source", "Copy input bundle to source/ folder in output package (default: false)").action(async (opts) => {
|
|
201
|
+
await executeLearnosityToQtiPackage(opts, version);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
function parseDiagnosticsMode(cliValue) {
|
|
205
|
+
if (cliValue === "stderr" || cliValue === "file" || cliValue === "both" || cliValue === "none") return { mode: cliValue };
|
|
206
|
+
if (cliValue) return {
|
|
207
|
+
mode: "file",
|
|
208
|
+
customPath: cliValue
|
|
209
|
+
};
|
|
210
|
+
return { mode: "file" };
|
|
211
|
+
}
|
|
212
|
+
async function resolveInputPath(cliIn, interactive) {
|
|
213
|
+
let bundleDir = cliIn;
|
|
214
|
+
if (!bundleDir && interactive) bundleDir = await dist_default$2({ message: "Input bundle directory path:" });
|
|
215
|
+
if (!bundleDir) {
|
|
216
|
+
console.error("Error: --in is required. Use --in <path> or -i/--interactive.");
|
|
217
|
+
process.exit(1);
|
|
218
|
+
}
|
|
219
|
+
return expandTilde(bundleDir);
|
|
220
|
+
}
|
|
221
|
+
async function resolveOutputPath(cliOut, interactive) {
|
|
222
|
+
let outputPath = cliOut;
|
|
223
|
+
if (!outputPath && interactive) outputPath = await dist_default$2({ message: "Output package path (.zip or directory):" });
|
|
224
|
+
if (!outputPath) {
|
|
225
|
+
console.error("Error: --out is required. Use --out <path> or -i/--interactive.");
|
|
226
|
+
process.exit(1);
|
|
227
|
+
}
|
|
228
|
+
return expandTilde(outputPath);
|
|
229
|
+
}
|
|
230
|
+
async function resolveQtiVersion(cliVersion, interactive, configVersion) {
|
|
231
|
+
let qtiVersion = cliVersion || configVersion || "2.2";
|
|
232
|
+
if (interactive && !cliVersion && !configVersion) qtiVersion = await dist_default$1({
|
|
233
|
+
message: "QTI version:",
|
|
234
|
+
choices: [{
|
|
235
|
+
value: "2.2",
|
|
236
|
+
name: "2.2 (default)"
|
|
237
|
+
}, {
|
|
238
|
+
value: "2.1",
|
|
239
|
+
name: "2.1"
|
|
240
|
+
}],
|
|
241
|
+
default: "2.2"
|
|
242
|
+
});
|
|
243
|
+
return qtiVersion;
|
|
244
|
+
}
|
|
245
|
+
async function resolveActivityRefs(cliActivity, interactive, bundle) {
|
|
246
|
+
if (cliActivity) {
|
|
247
|
+
const activityRefs = Array.isArray(cliActivity) ? cliActivity : [cliActivity];
|
|
248
|
+
for (const activityRef of activityRefs) if (!bundle.activityRefs.includes(activityRef)) {
|
|
249
|
+
console.error(`\nError: Activity '${activityRef}' not found in bundle. Available activities:\n ${bundle.activityRefs.join("\n ")}`);
|
|
250
|
+
process.exit(1);
|
|
251
|
+
}
|
|
252
|
+
return activityRefs;
|
|
253
|
+
}
|
|
254
|
+
if (interactive && bundle.activityRefs.length > 1) {
|
|
255
|
+
const selectedActivities = await dist_default({
|
|
256
|
+
message: "Select activities to convert (space to select, enter to confirm):",
|
|
257
|
+
choices: bundle.activityRefs.map((ref) => ({
|
|
258
|
+
value: ref,
|
|
259
|
+
name: ref,
|
|
260
|
+
checked: true
|
|
261
|
+
}))
|
|
262
|
+
});
|
|
263
|
+
if (selectedActivities.length === 0) {
|
|
264
|
+
console.error("\nError: No activities selected");
|
|
265
|
+
process.exit(1);
|
|
266
|
+
}
|
|
267
|
+
return selectedActivities;
|
|
268
|
+
}
|
|
269
|
+
if (bundle.activityRefs.length === 0) {
|
|
270
|
+
console.error("\nError: No activities found in bundle");
|
|
271
|
+
process.exit(1);
|
|
272
|
+
}
|
|
273
|
+
return bundle.activityRefs;
|
|
274
|
+
}
|
|
275
|
+
function convertActivities(activityRefs, bundle, options, diagnostics) {
|
|
276
|
+
const usedFolderNames = /* @__PURE__ */ new Set();
|
|
277
|
+
const convertedActivities = [];
|
|
278
|
+
let totalItemsConverted = 0;
|
|
279
|
+
let totalItemsFailed = 0;
|
|
280
|
+
for (const activityRef of activityRefs) {
|
|
281
|
+
const itemRefs = bundle.activityItemRefs.get(activityRef);
|
|
282
|
+
if (!itemRefs || itemRefs.length === 0) {
|
|
283
|
+
console.error(`\nWarning: Activity '${activityRef}' has no items, skipping...`);
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
const totalItems = itemRefs.length;
|
|
287
|
+
if (activityRefs.length > 1) process.stderr.write(`\nConverting activity: ${activityRef} (${totalItems} items)...\n`);
|
|
288
|
+
else process.stderr.write(`Converting activity (${totalItems} items)...\n`);
|
|
289
|
+
const convertResult = convertActivity(bundle, activityRef, options);
|
|
290
|
+
diagnostics.push(...convertResult.diagnostics);
|
|
291
|
+
const successfulItems = new Set(convertResult.items.map((item) => item.reference));
|
|
292
|
+
itemRefs.forEach((itemRef, index) => {
|
|
293
|
+
const status = successfulItems.has(itemRef) ? "\x1B[32m✓\x1B[0m" : "\x1B[31m✗\x1B[0m";
|
|
294
|
+
process.stderr.write(` [${index + 1}/${totalItems}] ${itemRef} ${status}\n`);
|
|
295
|
+
});
|
|
296
|
+
totalItemsConverted += successfulItems.size;
|
|
297
|
+
totalItemsFailed += totalItems - successfulItems.size;
|
|
298
|
+
if (!convertResult.testXml || convertResult.items.length === 0) {
|
|
299
|
+
process.stderr.write(` Activity '${activityRef}' conversion FAILED\n`);
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
const sanitizedName = sanitizeFolderName(activityRef, `activity_${convertedActivities.length + 1}`);
|
|
303
|
+
const folderName = ensureUniqueFolderName(sanitizedName, usedFolderNames);
|
|
304
|
+
convertedActivities.push({
|
|
305
|
+
activityRef,
|
|
306
|
+
folderName,
|
|
307
|
+
conversion: convertResult
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
convertedActivities,
|
|
312
|
+
totalItemsConverted,
|
|
313
|
+
totalItemsFailed
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Execute learnosity-to-qti-package conversion
|
|
318
|
+
*/
|
|
319
|
+
async function executeLearnosityToQtiPackage(cliOpts, version) {
|
|
320
|
+
const allDiagnostics = [];
|
|
321
|
+
const startTime = Date.now();
|
|
322
|
+
const interactive = cliOpts.interactive ?? false;
|
|
323
|
+
const quiet = cliOpts.quiet ?? false;
|
|
324
|
+
let verbose = cliOpts.verbose ?? false;
|
|
325
|
+
let { mode: diagnosticsMode, customPath: customDiagnosticsPath } = parseDiagnosticsMode(cliOpts.diagnostics);
|
|
326
|
+
try {
|
|
327
|
+
showBanner("learnosity-to-qti-package", version, quiet);
|
|
328
|
+
const { config, diagnostics: configDiagnostics } = await loadConfig(cliOpts.config, cliOpts.noConfig);
|
|
329
|
+
allDiagnostics.push(...configDiagnostics);
|
|
330
|
+
if (configDiagnostics.some((d) => d.level === "error")) {
|
|
331
|
+
console.error("\n" + formatDiagnosticsTable(allDiagnostics, verbose));
|
|
332
|
+
process.exit(1);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
verbose = cliOpts.verbose ?? config?.verbose ?? false;
|
|
336
|
+
if (!cliOpts.diagnostics && config?.diagnostics) {
|
|
337
|
+
const reparsed = parseDiagnosticsMode(config.diagnostics);
|
|
338
|
+
diagnosticsMode = reparsed.mode;
|
|
339
|
+
customDiagnosticsPath = reparsed.customPath;
|
|
340
|
+
}
|
|
341
|
+
const bundleDir = await resolveInputPath(cliOpts.in, interactive);
|
|
342
|
+
const outputPath = await resolveOutputPath(cliOpts.out, interactive);
|
|
343
|
+
const qtiVersion = await resolveQtiVersion(cliOpts.qtiVersion, interactive, config?.qtiVersion);
|
|
344
|
+
const pretty = cliOpts.pretty ?? config?.pretty ?? false;
|
|
345
|
+
const failOnWarn = cliOpts.failOnWarn ?? false;
|
|
346
|
+
const includeLearnositySource = cliOpts.includeLearnositySource ?? false;
|
|
347
|
+
if (qtiVersion !== "2.1" && qtiVersion !== "2.2") {
|
|
348
|
+
console.error(`Error: --qti-version must be 2.1 or 2.2 (got: ${qtiVersion})`);
|
|
349
|
+
process.exit(1);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (!existsSync(bundleDir) || !statSync(bundleDir).isDirectory()) {
|
|
353
|
+
console.error(`Error: Bundle directory not found: ${bundleDir}`);
|
|
354
|
+
process.exit(1);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (cliOpts.recursive ?? false) {
|
|
358
|
+
await executeBatchLearnosityToQtiPackage({
|
|
359
|
+
inputPath: bundleDir,
|
|
360
|
+
outputPath,
|
|
361
|
+
qtiVersion,
|
|
362
|
+
pretty,
|
|
363
|
+
failOnWarn,
|
|
364
|
+
includeLearnositySource,
|
|
365
|
+
diagnosticsMode,
|
|
366
|
+
verbose,
|
|
367
|
+
quiet,
|
|
368
|
+
version,
|
|
369
|
+
concurrency: cliOpts.concurrency ?? 1
|
|
370
|
+
});
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
let isZipOutput;
|
|
374
|
+
const formatOption = cliOpts.format?.toLowerCase();
|
|
375
|
+
if (formatOption) {
|
|
376
|
+
if (formatOption !== "zip" && formatOption !== "dir") {
|
|
377
|
+
console.error("Error: --format must be \"zip\" or \"dir\"");
|
|
378
|
+
process.exit(1);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
isZipOutput = formatOption === "zip";
|
|
382
|
+
} else isZipOutput = outputPath.toLowerCase().endsWith(".zip");
|
|
383
|
+
const loadResult = loadLearnosityBundle(bundleDir);
|
|
384
|
+
allDiagnostics.push(...loadResult.diagnostics);
|
|
385
|
+
if (!loadResult.bundle) {
|
|
386
|
+
console.error("\nError: Failed to load bundle\n");
|
|
387
|
+
console.error(formatDiagnosticsTable(allDiagnostics, verbose));
|
|
388
|
+
if (diagnosticsMode === "file" || diagnosticsMode === "both") {
|
|
389
|
+
const diagnosticsPath = customDiagnosticsPath ?? (isZipOutput ? outputPath.replace(/\.zip$/i, "-diagnostics.json") : `${outputPath}/diagnostics.json`);
|
|
390
|
+
try {
|
|
391
|
+
await writeDiagnostics(allDiagnostics, "file", diagnosticsPath, outputPath, false, {
|
|
392
|
+
inputPath: bundleDir,
|
|
393
|
+
outputPath,
|
|
394
|
+
totalItemsFound: 0,
|
|
395
|
+
convertedFiles: [],
|
|
396
|
+
failedFiles: []
|
|
397
|
+
});
|
|
398
|
+
console.error(`Diagnostics written to ${diagnosticsPath}`);
|
|
399
|
+
} catch (error) {
|
|
400
|
+
console.error(`Warning: Failed to write diagnostics: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
process.exit(1);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const bundle = loadResult.bundle ?? (() => {
|
|
407
|
+
throw new Error("Bundle is unexpectedly null after load check");
|
|
408
|
+
})();
|
|
409
|
+
const activityRefs = await resolveActivityRefs(cliOpts.activity, interactive, bundle);
|
|
410
|
+
if (!quiet) {
|
|
411
|
+
console.log(`
|
|
412
|
+
Configuration:`);
|
|
413
|
+
console.log(` Input: ${bundleDir}`);
|
|
414
|
+
console.log(` Output: ${outputPath}`);
|
|
415
|
+
console.log(` QTI: ${qtiVersion}`);
|
|
416
|
+
console.log(` Format: ${isZipOutput ? "ZIP" : "directory"}`);
|
|
417
|
+
console.log(` Diagnostics: ${diagnosticsMode}`);
|
|
418
|
+
console.log(` Activities: ${activityRefs.length === 1 ? activityRefs[0] : `${activityRefs.length} activities`}${cliOpts.activity ? "" : " (all)"}`);
|
|
419
|
+
if (activityRefs.length > 1) activityRefs.forEach((ref) => {
|
|
420
|
+
console.log(` - ${ref}`);
|
|
421
|
+
});
|
|
422
|
+
console.log(` Pretty: ${pretty}`);
|
|
423
|
+
console.log(` Verbose: ${verbose}`);
|
|
424
|
+
console.log(` Fail on warn: ${failOnWarn}`);
|
|
425
|
+
console.log(` Include src: ${includeLearnositySource}`);
|
|
426
|
+
console.log("");
|
|
427
|
+
}
|
|
428
|
+
process.stderr.write("Loading complete ✓\n");
|
|
429
|
+
const { convertedActivities: allConvertedActivities, totalItemsConverted, totalItemsFailed } = convertActivities(activityRefs, bundle, {
|
|
430
|
+
pretty,
|
|
431
|
+
version: qtiVersion
|
|
432
|
+
}, allDiagnostics);
|
|
433
|
+
if (allConvertedActivities.length === 0) {
|
|
434
|
+
process.stderr.write("\nConversion FAILED - no activities could be converted\n\n");
|
|
435
|
+
console.error(formatDiagnosticsTable(allDiagnostics, verbose));
|
|
436
|
+
process.exit(1);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
const hasErrors = allDiagnostics.filter((d) => d.level === "error").length > 0;
|
|
440
|
+
if (hasErrors && totalItemsConverted === 0) {
|
|
441
|
+
process.stderr.write(`\nConversion FAILED - no items could be converted\n\n`);
|
|
442
|
+
console.error(formatDiagnosticsTable(allDiagnostics, verbose));
|
|
443
|
+
process.exit(1);
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
if (hasErrors) {
|
|
447
|
+
process.stderr.write(`\nConversion completed with ERRORS (${totalItemsConverted} succeeded, ${totalItemsFailed} failed)\n`);
|
|
448
|
+
process.stderr.write(`Proceeding with ${totalItemsConverted} successfully converted items...\n\n`);
|
|
449
|
+
} else process.stderr.write(`\nConverted ${allConvertedActivities.length} ${allConvertedActivities.length === 1 ? "activity" : "activities"}, ${totalItemsConverted} items ✓\n`);
|
|
450
|
+
process.stderr.write("Building package... ");
|
|
451
|
+
const pkg = {
|
|
452
|
+
zipPath: "",
|
|
453
|
+
resources: [],
|
|
454
|
+
entries: /* @__PURE__ */ new Map(),
|
|
455
|
+
items: [],
|
|
456
|
+
assets: []
|
|
457
|
+
};
|
|
458
|
+
const allConvertedItemRefs = [];
|
|
459
|
+
const allFailedItemRefs = [];
|
|
460
|
+
const addedResourceIds = /* @__PURE__ */ new Set();
|
|
461
|
+
for (const { activityRef, folderName, conversion } of allConvertedActivities) {
|
|
462
|
+
const packageResult = buildPackageFromActivity(conversion, {
|
|
463
|
+
bundleDir,
|
|
464
|
+
activityRef,
|
|
465
|
+
version: qtiVersion
|
|
466
|
+
});
|
|
467
|
+
allDiagnostics.push(...packageResult.diagnostics);
|
|
468
|
+
if (!packageResult.package) {
|
|
469
|
+
process.stderr.write(`FAILED (activity: ${activityRef})\n\n`);
|
|
470
|
+
console.error(formatDiagnosticsTable(allDiagnostics, verbose));
|
|
471
|
+
process.exit(1);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
mergeActivityPackage(pkg, folderName, packageResult, addedResourceIds);
|
|
475
|
+
const itemRefs = bundle.activityItemRefs.get(activityRef) || [];
|
|
476
|
+
const successfulItems = new Set(conversion.items.map((item) => item.reference));
|
|
477
|
+
allConvertedItemRefs.push(...itemRefs.filter((ref) => successfulItems.has(ref)));
|
|
478
|
+
allFailedItemRefs.push(...itemRefs.filter((ref) => !successfulItems.has(ref)));
|
|
479
|
+
}
|
|
480
|
+
process.stderr.write("✓\n");
|
|
481
|
+
if (includeLearnositySource) {
|
|
482
|
+
process.stderr.write("Copying source files... ");
|
|
483
|
+
const sourceEntries = readDirectoryAsEntries(bundleDir, "source/");
|
|
484
|
+
for (const [entryPath, entry] of sourceEntries) pkg.entries.set(entryPath, entry);
|
|
485
|
+
const activitiesDirEntry = "source/activities/";
|
|
486
|
+
if (!pkg.entries.has(activitiesDirEntry) && !Array.from(pkg.entries.keys()).some((k) => k.startsWith(activitiesDirEntry))) pkg.entries.set(activitiesDirEntry, {
|
|
487
|
+
file: activitiesDirEntry,
|
|
488
|
+
size: 0,
|
|
489
|
+
data: Buffer.alloc(0)
|
|
490
|
+
});
|
|
491
|
+
process.stderr.write(`✓ (${sourceEntries.size} files)\n`);
|
|
492
|
+
}
|
|
493
|
+
process.stderr.write(`Writing ${isZipOutput ? "ZIP" : "directory"} package... `);
|
|
494
|
+
const saveResult = saveQtiContentPackage(pkg, outputPath);
|
|
495
|
+
allDiagnostics.push(...saveResult.diagnostics);
|
|
496
|
+
if (saveResult.diagnostics.some((d) => d.level === "error")) {
|
|
497
|
+
process.stderr.write("FAILED\n\n");
|
|
498
|
+
console.error(formatDiagnosticsTable(allDiagnostics, verbose));
|
|
499
|
+
process.exit(1);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
process.stderr.write("✓\n");
|
|
503
|
+
if (diagnosticsMode === "file" || diagnosticsMode === "both") {
|
|
504
|
+
const diagnosticsPath = customDiagnosticsPath || (isZipOutput ? outputPath.replace(/\.zip$/i, "-diagnostics.json") : `${outputPath.replace(/\/$/, "")}/diagnostics.json`);
|
|
505
|
+
const convertedFiles = [];
|
|
506
|
+
const failedFiles = [];
|
|
507
|
+
for (const itemRef of allConvertedItemRefs) {
|
|
508
|
+
const filename = bundle.itemRefToFilename.get(itemRef);
|
|
509
|
+
if (filename) convertedFiles.push(filename);
|
|
510
|
+
}
|
|
511
|
+
for (const itemRef of allFailedItemRefs) {
|
|
512
|
+
const filename = bundle.itemRefToFilename.get(itemRef);
|
|
513
|
+
if (filename) failedFiles.push(filename);
|
|
514
|
+
}
|
|
515
|
+
const convertedActivityRefs = allConvertedActivities.map((a) => `activities/${a.activityRef}.json`);
|
|
516
|
+
const failedActivityRefs = activityRefs.filter((ref) => !allConvertedActivities.some((a) => a.activityRef === ref)).map((ref) => `activities/${ref}.json`);
|
|
517
|
+
process.stderr.write(`Writing diagnostics to ${diagnosticsPath}... `);
|
|
518
|
+
await writeDiagnostics(allDiagnostics, "file", diagnosticsPath, outputPath, false, {
|
|
519
|
+
inputPath: bundleDir,
|
|
520
|
+
outputPath,
|
|
521
|
+
totalItemsFound: totalItemsConverted + totalItemsFailed,
|
|
522
|
+
totalActivitiesFound: activityRefs.length,
|
|
523
|
+
convertedFiles,
|
|
524
|
+
failedFiles,
|
|
525
|
+
convertedActivities: convertedActivityRefs,
|
|
526
|
+
failedActivities: failedActivityRefs
|
|
527
|
+
});
|
|
528
|
+
process.stderr.write("✓\n");
|
|
529
|
+
}
|
|
530
|
+
const elapsed = ((Date.now() - startTime) / 1e3).toFixed(1);
|
|
531
|
+
process.stderr.write(`\nCompleted in ${elapsed}s\n`);
|
|
532
|
+
if (!quiet) {
|
|
533
|
+
const summaryTable = formatDiagnosticsSummaryTable(allDiagnostics);
|
|
534
|
+
if (summaryTable) {
|
|
535
|
+
console.log("\nDiagnostics Summary:");
|
|
536
|
+
console.log(summaryTable);
|
|
537
|
+
console.log("");
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (diagnosticsMode === "stderr" || diagnosticsMode === "both") console.error(formatDiagnosticsTable(allDiagnostics, verbose));
|
|
541
|
+
const warnings = allDiagnostics.filter((d) => d.level === "warning");
|
|
542
|
+
if (failOnWarn && warnings.length > 0) {
|
|
543
|
+
process.stderr.write(`\n${warnings.length} warning(s) found - exiting with error (--fail-on-warn)\n`);
|
|
544
|
+
process.exit(1);
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
if (hasErrors) process.stderr.write(`\nPackage written with ${totalItemsFailed} item(s) skipped due to errors\n`);
|
|
548
|
+
process.exit(0);
|
|
549
|
+
} catch (error) {
|
|
550
|
+
if (error instanceof Error && error.name === "ExitPromptError") process.exit(130);
|
|
551
|
+
process.stderr.write("\n\nERROR: ");
|
|
552
|
+
console.error(error instanceof Error ? error.message : "Unknown error");
|
|
553
|
+
if (allDiagnostics.length > 0 && (diagnosticsMode === "stderr" || diagnosticsMode === "both")) console.error("\n" + formatDiagnosticsTable(allDiagnostics, verbose));
|
|
554
|
+
process.exit(1);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Recursively reads all files from a directory and returns them as package entries
|
|
559
|
+
* with paths prefixed by the given prefix (e.g., 'source/')
|
|
560
|
+
*/
|
|
561
|
+
function readDirectoryAsEntries(dirPath, prefix) {
|
|
562
|
+
const entries = /* @__PURE__ */ new Map();
|
|
563
|
+
function readRecursive(currentPath, relativePath) {
|
|
564
|
+
const items = readdirSync(currentPath, { withFileTypes: true });
|
|
565
|
+
for (const item of items) {
|
|
566
|
+
const itemPath = join(currentPath, item.name);
|
|
567
|
+
const itemRelativePath = relativePath ? `${relativePath}/${item.name}` : item.name;
|
|
568
|
+
if (item.isDirectory()) readRecursive(itemPath, itemRelativePath);
|
|
569
|
+
else if (item.isFile()) {
|
|
570
|
+
const data = readFileSync(itemPath);
|
|
571
|
+
const entryPath = `${prefix}${itemRelativePath}`;
|
|
572
|
+
entries.set(entryPath, {
|
|
573
|
+
file: entryPath,
|
|
574
|
+
size: data.length,
|
|
575
|
+
data
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
readRecursive(dirPath, "");
|
|
581
|
+
return entries;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Execute batch Learnosity to QTI package conversion for multiple subdirectories
|
|
585
|
+
*/
|
|
586
|
+
async function executeBatchLearnosityToQtiPackage(opts) {
|
|
587
|
+
if (opts.concurrency > 1) {
|
|
588
|
+
await processBatchParallel({
|
|
589
|
+
inputPath: opts.inputPath,
|
|
590
|
+
outputPath: opts.outputPath,
|
|
591
|
+
packageType: "learnosity",
|
|
592
|
+
direction: "learnosity-to-qti",
|
|
593
|
+
options: {
|
|
594
|
+
qtiVersion: opts.qtiVersion,
|
|
595
|
+
pretty: opts.pretty
|
|
596
|
+
},
|
|
597
|
+
concurrency: opts.concurrency,
|
|
598
|
+
quiet: opts.quiet
|
|
599
|
+
});
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
const { inputPath, outputPath, qtiVersion, pretty, failOnWarn, includeLearnositySource, diagnosticsMode, verbose, quiet } = opts;
|
|
603
|
+
displayConfiguration([
|
|
604
|
+
configField("Input:", inputPath),
|
|
605
|
+
configField("Output:", outputPath),
|
|
606
|
+
configField("QTI:", qtiVersion),
|
|
607
|
+
configField("Format:", "directory"),
|
|
608
|
+
configField("Diagnostics:", diagnosticsMode),
|
|
609
|
+
configField("Activities:", "all (batch mode)"),
|
|
610
|
+
configField("Recursive:", true),
|
|
611
|
+
configField("Pretty:", pretty),
|
|
612
|
+
configField("Verbose:", verbose),
|
|
613
|
+
configField("Fail on warn:", failOnWarn),
|
|
614
|
+
configField("Include src:", includeLearnositySource)
|
|
615
|
+
], { quiet });
|
|
616
|
+
if (!quiet) {
|
|
617
|
+
console.log("🔄 Batch Processing Mode");
|
|
618
|
+
console.log(`Scanning: ${inputPath}\n`);
|
|
619
|
+
}
|
|
620
|
+
await processBatch({
|
|
621
|
+
inputPath,
|
|
622
|
+
outputPath,
|
|
623
|
+
packageType: "learnosity",
|
|
624
|
+
options: opts,
|
|
625
|
+
quiet,
|
|
626
|
+
processPackage: (pkg, packageOutputPath, options) => processLearnosityToQtiPackage(pkg, packageOutputPath, options, quiet)
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
//#endregion
|
|
630
|
+
export { registerLearnosityToQtiPackageCommand };
|
|
631
|
+
|
|
632
|
+
//# sourceMappingURL=learnosityToQtiPackage-RyClxvZj.js.map
|