@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,354 @@
|
|
|
1
|
+
import { l as dist_default, n as loadConfig, r as showBanner, t as expandTilde } from "./pathUtils-CwZnJ55s.js";
|
|
2
|
+
import { r as formatDiagnosticsTable, s as writeDiagnostics } from "./table-DYcNeyJ_.js";
|
|
3
|
+
import { n as processQtiPackageToLearnosity } from "./batchProcessors-BfmvnTQ5.js";
|
|
4
|
+
import { i as processBatchParallel, n as displayConfiguration, r as processBatch, t as configField } from "./configOutput-FwkFyQmk.js";
|
|
5
|
+
import { existsSync, readFileSync, statSync } from "fs";
|
|
6
|
+
import { convertQtiPackageToLearnosityBundle, loadPackageDirectory, nodeFileAccess, writeLearnosityBundle } from "@learnosity/converter-core/node";
|
|
7
|
+
//#region src/commands/qtiPackageToLearnosity.ts
|
|
8
|
+
/**
|
|
9
|
+
* Register qti-package-to-learnosity command
|
|
10
|
+
*/
|
|
11
|
+
function registerQtiPackageToLearnosityCommand(program, version) {
|
|
12
|
+
program.command("qti-package-to-learnosity").alias("convert qti-package").description("Convert a QTI Content Package to a Learnosity bundle").option("--in <path>", "Input package path (.zip or directory)").option("--out <path>", "Output bundle path (.zip or directory)").option("--format <type>", "Output format: zip or dir (default: auto-detect from --out path)").option("--organisation_id <number>", "Organisation ID for Learnosity CDN asset URLs", parseInt).option("--org_id <number>", "Alias for --organisation_id", parseInt).option("--mediavault", "Use media-vault subdomain instead of assets (default: false)").option("--custom-asset-url <url>", "Custom asset URL prefix to override default Learnosity CDN").option("--item-reference-source <source>", "How to generate item references: sourceFilename (default), qti (identifier), or uuid").option("--item-filename-source <source>", "How to name output JSON files: sourceFilename or qti (default: same as --item-reference-source)").option("--truncate-tags", "Truncate tag types and names to 255 characters instead of failing (default: false)").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("--verbose", "Show INFO level diagnostics in table (default: false)").option("-q, --quiet", "Suppress non-essential output (default: false)").action(async (opts) => {
|
|
13
|
+
await executeQtiPackageToLearnosity(opts, version);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Write diagnostics to file and/or stderr depending on mode
|
|
18
|
+
*/
|
|
19
|
+
async function outputDiagnostics(allDiagnostics, diagnosticsMode, verbose, diagnosticsPath, outputPath, metadata) {
|
|
20
|
+
if (diagnosticsMode === "file" || diagnosticsMode === "both") await writeDiagnostics(allDiagnostics, "file", diagnosticsPath, outputPath, false, metadata);
|
|
21
|
+
if (diagnosticsMode === "stderr" || diagnosticsMode === "both") {
|
|
22
|
+
const table = formatDiagnosticsTable(allDiagnostics, verbose);
|
|
23
|
+
if (table) console.error(table);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolve an interactive or CLI-provided path option
|
|
28
|
+
* Returns the expanded path or exits with an error.
|
|
29
|
+
*/
|
|
30
|
+
async function resolvePathOption(value, interactive, promptMessage, errorMessage) {
|
|
31
|
+
let resolved = value;
|
|
32
|
+
if (!resolved && interactive) resolved = await dist_default({ message: promptMessage });
|
|
33
|
+
if (!resolved) {
|
|
34
|
+
console.error(errorMessage);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
return expandTilde(resolved);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Parse the --diagnostics CLI option into mode and optional custom path
|
|
41
|
+
*/
|
|
42
|
+
function resolveDiagnosticsConfig(diagnosticsOpt) {
|
|
43
|
+
if (!diagnosticsOpt || [
|
|
44
|
+
"stderr",
|
|
45
|
+
"file",
|
|
46
|
+
"both",
|
|
47
|
+
"none"
|
|
48
|
+
].includes(diagnosticsOpt)) return { mode: diagnosticsOpt ?? "file" };
|
|
49
|
+
return {
|
|
50
|
+
mode: "file",
|
|
51
|
+
customPath: diagnosticsOpt
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Resolve organisation ID from CLI options with optional interactive prompt
|
|
56
|
+
*/
|
|
57
|
+
async function resolveOrganisationId(cliOpts, interactive, configOrgId) {
|
|
58
|
+
let organisationId = cliOpts.organisation_id ?? cliOpts.org_id ?? configOrgId;
|
|
59
|
+
if (organisationId === void 0 && interactive) {
|
|
60
|
+
const orgIdInput = await dist_default({ message: "Organisation ID for Learnosity CDN asset URLs:" });
|
|
61
|
+
organisationId = orgIdInput ? parseInt(orgIdInput, 10) : void 0;
|
|
62
|
+
}
|
|
63
|
+
if (organisationId === void 0 || organisationId === null) {
|
|
64
|
+
console.error("Error: --organisation_id is required. Use -i or --interactive for prompts or specify --organisation_id <number>");
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
return organisationId;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Validate input path exists and determine its type
|
|
71
|
+
*/
|
|
72
|
+
function validateInputPath(inputPath) {
|
|
73
|
+
if (!existsSync(inputPath)) {
|
|
74
|
+
console.error(`Error: Input not found: ${inputPath}`);
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
const isZipInput = inputPath.toLowerCase().endsWith(".zip");
|
|
78
|
+
if (!isZipInput && !statSync(inputPath).isDirectory()) {
|
|
79
|
+
console.error(`Error: Input must be a directory or .zip file: ${inputPath}`);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
return { isZipInput };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Resolve output format (zip or directory) from path and explicit format option
|
|
86
|
+
*/
|
|
87
|
+
function resolveOutputFormat(outputPath, formatOption) {
|
|
88
|
+
if (formatOption) {
|
|
89
|
+
const fmt = formatOption.toLowerCase();
|
|
90
|
+
if (fmt !== "zip" && fmt !== "dir") {
|
|
91
|
+
console.error("Error: --format must be \"zip\" or \"dir\"");
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
const isZipOutput = fmt === "zip";
|
|
95
|
+
return {
|
|
96
|
+
isZipOutput,
|
|
97
|
+
finalOutputPath: isZipOutput && !outputPath.toLowerCase().endsWith(".zip") ? `${outputPath}.zip` : outputPath
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
isZipOutput: outputPath.toLowerCase().endsWith(".zip"),
|
|
102
|
+
finalOutputPath: outputPath
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Display conversion progress for activities and items
|
|
107
|
+
*/
|
|
108
|
+
function displayConversionProgress(convertResult) {
|
|
109
|
+
const convertedActivityFiles = convertResult.convertedActivityFiles || [];
|
|
110
|
+
if (convertedActivityFiles.length > 0) {
|
|
111
|
+
process.stderr.write(" Assessment tests:\n");
|
|
112
|
+
convertedActivityFiles.forEach((sourceFile, index) => {
|
|
113
|
+
process.stderr.write(` [${index + 1}/${convertedActivityFiles.length}] ${sourceFile} \x1b[32m✓\x1b[0m\n`);
|
|
114
|
+
});
|
|
115
|
+
process.stderr.write("\n");
|
|
116
|
+
}
|
|
117
|
+
const convertedFiles = convertResult.convertedSourceFiles || [];
|
|
118
|
+
const failedFiles = convertResult.failedSourceFiles || [];
|
|
119
|
+
const totalFiles = convertedFiles.length + failedFiles.length;
|
|
120
|
+
if (totalFiles > 0) {
|
|
121
|
+
process.stderr.write(" Assessment items:\n");
|
|
122
|
+
const successSet = new Set(convertedFiles);
|
|
123
|
+
[...convertedFiles, ...failedFiles].sort().forEach((sourceFile, index) => {
|
|
124
|
+
const status = successSet.has(sourceFile) ? "\x1B[32m✓\x1B[0m" : "\x1B[31m✗\x1B[0m";
|
|
125
|
+
process.stderr.write(` [${index + 1}/${totalFiles}] ${sourceFile} ${status}\n`);
|
|
126
|
+
});
|
|
127
|
+
if (failedFiles.length > 0) {
|
|
128
|
+
process.stderr.write(`\nConversion completed with ERRORS (${convertedFiles.length} succeeded, ${failedFiles.length} failed)\n`);
|
|
129
|
+
process.stderr.write(`Proceeding with ${convertedFiles.length} successfully converted items...\n\n`);
|
|
130
|
+
} else process.stderr.write(`\nConverted ${convertedFiles.length} items ✓\n\n`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Build metadata object for diagnostics output
|
|
135
|
+
*/
|
|
136
|
+
function buildDiagnosticsMetadata(inputPath, outputPath, convertResult, failed) {
|
|
137
|
+
const convertedFiles = convertResult.convertedSourceFiles || [];
|
|
138
|
+
const failedFiles = convertResult.failedSourceFiles || [];
|
|
139
|
+
const convertedActivityFiles = convertResult.convertedActivityFiles || [];
|
|
140
|
+
const itemRefs = convertResult.bundle ? Array.from(convertResult.bundle.items.keys()) : [];
|
|
141
|
+
return {
|
|
142
|
+
inputPath,
|
|
143
|
+
outputPath,
|
|
144
|
+
totalItemsFound: failed ? itemRefs.length : convertedFiles.length + failedFiles.length,
|
|
145
|
+
totalActivitiesFound: convertedActivityFiles.length,
|
|
146
|
+
convertedFiles: failed ? [] : convertedFiles,
|
|
147
|
+
failedFiles: failed ? itemRefs.map((ref) => `items/${ref}.xml`) : failedFiles,
|
|
148
|
+
convertedActivities: convertedActivityFiles
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Execute qti-package-to-learnosity conversion
|
|
153
|
+
*/
|
|
154
|
+
async function executeQtiPackageToLearnosity(cliOpts, version) {
|
|
155
|
+
const allDiagnostics = [];
|
|
156
|
+
const startTime = Date.now();
|
|
157
|
+
const quiet = cliOpts.quiet ?? false;
|
|
158
|
+
try {
|
|
159
|
+
showBanner("qti-package-to-learnosity", version, quiet);
|
|
160
|
+
const interactive = cliOpts.interactive ?? false;
|
|
161
|
+
const { config, diagnostics: configDiagnostics } = await loadConfig(cliOpts.config, cliOpts.noConfig);
|
|
162
|
+
allDiagnostics.push(...configDiagnostics);
|
|
163
|
+
if (configDiagnostics.some((d) => d.level === "error")) {
|
|
164
|
+
console.log("\n" + formatDiagnosticsTable(configDiagnostics));
|
|
165
|
+
process.exit(1);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const inputPath = await resolvePathOption(cliOpts.in, interactive, "Input QTI package path (.zip or directory):", "Error: --in is required. Use -i or --interactive for prompts or specify --in <path>");
|
|
169
|
+
const outputPath = await resolvePathOption(cliOpts.out, interactive, "Output bundle path (.zip or directory):", "Error: --out is required. Use -i or --interactive for prompts or specify --out <path>");
|
|
170
|
+
const failOnWarn = cliOpts.failOnWarn ?? false;
|
|
171
|
+
const verbose = cliOpts.verbose ?? config?.verbose ?? false;
|
|
172
|
+
const { mode: diagnosticsMode, customPath: customDiagnosticsPath } = resolveDiagnosticsConfig(cliOpts.diagnostics ?? config?.diagnostics);
|
|
173
|
+
const organisationId = await resolveOrganisationId(cliOpts, interactive, config?.organisationId);
|
|
174
|
+
const mediaVault = cliOpts.mediavault ?? config?.mediaVault ?? false;
|
|
175
|
+
const customAssetUrl = cliOpts.customAssetUrl ?? config?.customAssetUrl;
|
|
176
|
+
const itemReferenceSource = cliOpts.itemReferenceSource ?? config?.itemReferenceSource;
|
|
177
|
+
const itemFilenameSource = cliOpts.itemFilenameSource ?? config?.itemFilenameSource;
|
|
178
|
+
const truncateTags = cliOpts.truncateTags ?? config?.truncateTags ?? false;
|
|
179
|
+
const { isZipInput } = validateInputPath(inputPath);
|
|
180
|
+
if (cliOpts.recursive) {
|
|
181
|
+
if (isZipInput) {
|
|
182
|
+
console.error("Error: --recursive flag cannot be used with ZIP input. Please provide a directory containing subdirectories.");
|
|
183
|
+
process.exit(1);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
await executeBatchQtiPackageToLearnosity({
|
|
187
|
+
inputPath,
|
|
188
|
+
outputPath,
|
|
189
|
+
organisationId,
|
|
190
|
+
mediaVault,
|
|
191
|
+
customAssetUrl,
|
|
192
|
+
itemReferenceSource,
|
|
193
|
+
itemFilenameSource,
|
|
194
|
+
truncateTags,
|
|
195
|
+
diagnosticsMode,
|
|
196
|
+
failOnWarn,
|
|
197
|
+
verbose,
|
|
198
|
+
quiet,
|
|
199
|
+
version,
|
|
200
|
+
concurrency: cliOpts.concurrency ?? 1
|
|
201
|
+
});
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const { isZipOutput, finalOutputPath } = resolveOutputFormat(outputPath, cliOpts.format);
|
|
205
|
+
if (!quiet) displayConfiguration([
|
|
206
|
+
configField("Input:", inputPath),
|
|
207
|
+
configField("Output:", finalOutputPath),
|
|
208
|
+
configField("Format:", isZipOutput ? "ZIP" : "directory"),
|
|
209
|
+
configField("Diagnostics:", diagnosticsMode),
|
|
210
|
+
configField("Org ID:", organisationId),
|
|
211
|
+
configField("Media vault:", mediaVault),
|
|
212
|
+
configField("Item ref src:", itemReferenceSource ?? "sourceFilename (default)"),
|
|
213
|
+
configField("Item filename:", itemFilenameSource ?? "same as item ref src"),
|
|
214
|
+
configField("Verbose:", verbose),
|
|
215
|
+
configField("Fail on warn:", failOnWarn)
|
|
216
|
+
], { quiet });
|
|
217
|
+
process.stderr.write("Converting QTI package...\n");
|
|
218
|
+
const convertOpts = {
|
|
219
|
+
organisationId,
|
|
220
|
+
mediaVault,
|
|
221
|
+
customAssetUrl,
|
|
222
|
+
itemReferenceSource,
|
|
223
|
+
itemFilenameSource,
|
|
224
|
+
truncateTags,
|
|
225
|
+
packageVersion: version
|
|
226
|
+
};
|
|
227
|
+
let convertResult;
|
|
228
|
+
if (isZipInput) convertResult = convertQtiPackageToLearnosityBundle({ zipBytes: new Uint8Array(readFileSync(inputPath)) }, convertOpts);
|
|
229
|
+
else {
|
|
230
|
+
const loaded = loadPackageDirectory(inputPath);
|
|
231
|
+
convertResult = loaded.entries ? convertQtiPackageToLearnosityBundle({ entries: loaded.entries }, {
|
|
232
|
+
...convertOpts,
|
|
233
|
+
sourceDir: inputPath,
|
|
234
|
+
fileAccess: nodeFileAccess
|
|
235
|
+
}) : { diagnostics: loaded.diagnostics };
|
|
236
|
+
}
|
|
237
|
+
allDiagnostics.push(...convertResult.diagnostics);
|
|
238
|
+
displayConversionProgress(convertResult);
|
|
239
|
+
const getDiagPath = () => customDiagnosticsPath || (isZipOutput ? finalOutputPath.replace(/\.zip$/i, "-diagnostics.json") : `${finalOutputPath.replace(/\/$/, "")}/diagnostics.json`);
|
|
240
|
+
const errors = allDiagnostics.filter((d) => d.level === "error");
|
|
241
|
+
const warnings = allDiagnostics.filter((d) => d.level === "warning");
|
|
242
|
+
const hasValidBundle = convertResult.bundle && convertResult.bundle.items.size > 0;
|
|
243
|
+
if (errors.length > 0 && !hasValidBundle) {
|
|
244
|
+
process.stderr.write("\nConversion FAILED with errors\n\n");
|
|
245
|
+
await outputDiagnostics(allDiagnostics, diagnosticsMode, verbose, getDiagPath(), finalOutputPath, buildDiagnosticsMetadata(inputPath, finalOutputPath, convertResult, true));
|
|
246
|
+
process.exit(1);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (failOnWarn && warnings.length > 0) {
|
|
250
|
+
process.stderr.write("\nConversion completed with WARNINGS (fail-on-warn mode)\n\n");
|
|
251
|
+
await outputDiagnostics(allDiagnostics, diagnosticsMode, verbose, getDiagPath(), finalOutputPath, buildDiagnosticsMetadata(inputPath, finalOutputPath, convertResult, errors.length > 0));
|
|
252
|
+
process.exit(1);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (!convertResult.bundle) {
|
|
256
|
+
process.stderr.write("\nConversion FAILED: no bundle generated\n\n");
|
|
257
|
+
await outputDiagnostics(allDiagnostics, diagnosticsMode, verbose, getDiagPath(), finalOutputPath, {
|
|
258
|
+
inputPath,
|
|
259
|
+
outputPath: finalOutputPath,
|
|
260
|
+
totalItemsFound: 0,
|
|
261
|
+
convertedFiles: [],
|
|
262
|
+
failedFiles: []
|
|
263
|
+
});
|
|
264
|
+
process.exit(1);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
process.stderr.write(`Writing ${isZipOutput ? "ZIP" : "directory"} package... `);
|
|
268
|
+
const writeResult = await writeLearnosityBundle(convertResult.bundle, {
|
|
269
|
+
outDir: finalOutputPath,
|
|
270
|
+
isZipOutput
|
|
271
|
+
});
|
|
272
|
+
allDiagnostics.push(...writeResult.diagnostics);
|
|
273
|
+
if (writeResult.diagnostics.some((d) => d.level === "error")) {
|
|
274
|
+
process.stderr.write("FAILED\n\n");
|
|
275
|
+
await outputDiagnostics(allDiagnostics, diagnosticsMode, verbose, getDiagPath(), outputPath, buildDiagnosticsMetadata(inputPath, outputPath, convertResult, true));
|
|
276
|
+
process.exit(1);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
process.stderr.write("✓\n");
|
|
280
|
+
const successMetadata = buildDiagnosticsMetadata(inputPath, finalOutputPath, convertResult, false);
|
|
281
|
+
if (diagnosticsMode === "file" || diagnosticsMode === "both") {
|
|
282
|
+
const diagnosticsPath = getDiagPath();
|
|
283
|
+
process.stderr.write(`Writing diagnostics to ${diagnosticsPath}... `);
|
|
284
|
+
await outputDiagnostics(allDiagnostics, "file", verbose, diagnosticsPath, finalOutputPath, successMetadata);
|
|
285
|
+
process.stderr.write("✓\n");
|
|
286
|
+
}
|
|
287
|
+
if (diagnosticsMode === "stderr" || diagnosticsMode === "both") await outputDiagnostics(allDiagnostics, "stderr", verbose, getDiagPath(), finalOutputPath, successMetadata);
|
|
288
|
+
const elapsedTime = ((Date.now() - startTime) / 1e3).toFixed(1);
|
|
289
|
+
process.stderr.write(`\nCompleted in ${elapsedTime}s\n`);
|
|
290
|
+
const failedFiles = convertResult.failedSourceFiles || [];
|
|
291
|
+
if (failedFiles.length > 0) process.stderr.write(`\nPackage written with ${failedFiles.length} item(s) skipped due to errors\n`);
|
|
292
|
+
process.exit(0);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
if (error instanceof Error && error.name === "ExitPromptError") process.exit(130);
|
|
295
|
+
console.error("\n" + (error instanceof Error ? error.message : "Unknown error"));
|
|
296
|
+
process.exit(1);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Execute batch QTI package to Learnosity conversion for multiple subdirectories
|
|
301
|
+
*/
|
|
302
|
+
async function executeBatchQtiPackageToLearnosity(opts) {
|
|
303
|
+
const { inputPath, outputPath, organisationId, mediaVault, customAssetUrl, itemReferenceSource, itemFilenameSource, truncateTags, diagnosticsMode, failOnWarn, verbose, quiet, version, concurrency } = opts;
|
|
304
|
+
if (concurrency > 1) {
|
|
305
|
+
await processBatchParallel({
|
|
306
|
+
inputPath,
|
|
307
|
+
outputPath,
|
|
308
|
+
packageType: "qti",
|
|
309
|
+
direction: "qti-to-learnosity",
|
|
310
|
+
options: {
|
|
311
|
+
organisationId,
|
|
312
|
+
mediaVault,
|
|
313
|
+
customAssetUrl,
|
|
314
|
+
itemReferenceSource,
|
|
315
|
+
itemFilenameSource,
|
|
316
|
+
truncateTags,
|
|
317
|
+
version
|
|
318
|
+
},
|
|
319
|
+
concurrency,
|
|
320
|
+
quiet
|
|
321
|
+
});
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
displayConfiguration([
|
|
325
|
+
configField("Input:", inputPath),
|
|
326
|
+
configField("Output:", outputPath),
|
|
327
|
+
configField("Format:", "directory"),
|
|
328
|
+
configField("Diagnostics:", diagnosticsMode),
|
|
329
|
+
configField("Org ID:", organisationId),
|
|
330
|
+
configField("Media vault:", mediaVault),
|
|
331
|
+
configField("Item ref src:", itemReferenceSource ?? "sourceFilename (default)"),
|
|
332
|
+
configField("Item filename:", itemFilenameSource ?? "same as item ref src"),
|
|
333
|
+
configField("Truncate tags:", truncateTags),
|
|
334
|
+
configField("Recursive:", true),
|
|
335
|
+
configField("Verbose:", verbose),
|
|
336
|
+
configField("Fail on warn:", failOnWarn)
|
|
337
|
+
], { quiet });
|
|
338
|
+
if (!quiet) {
|
|
339
|
+
console.log("🔄 Batch Processing Mode");
|
|
340
|
+
console.log(`Scanning: ${inputPath}\n`);
|
|
341
|
+
}
|
|
342
|
+
await processBatch({
|
|
343
|
+
inputPath,
|
|
344
|
+
outputPath,
|
|
345
|
+
packageType: "qti",
|
|
346
|
+
options: opts,
|
|
347
|
+
quiet,
|
|
348
|
+
processPackage: (pkg, packageOutputPath, options) => processQtiPackageToLearnosity(pkg, packageOutputPath, options, quiet)
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
//#endregion
|
|
352
|
+
export { registerQtiPackageToLearnosityCommand };
|
|
353
|
+
|
|
354
|
+
//# sourceMappingURL=qtiPackageToLearnosity-0rkZKKOK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qtiPackageToLearnosity-0rkZKKOK.js","names":["input"],"sources":["../src/commands/qtiPackageToLearnosity.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Command } from 'commander';\nimport type {\n Diagnostic,\n ItemFilenameSource,\n ItemReferenceSource,\n} from '@learnosity/converter-core';\nimport {\n convertQtiPackageToLearnosityBundle,\n writeLearnosityBundle,\n loadPackageDirectory,\n nodeFileAccess,\n} from '@learnosity/converter-core/node';\nimport { existsSync, statSync, readFileSync } from 'fs';\nimport { input } from '@inquirer/prompts';\nimport { writeDiagnostics, type WriteDiagnosticsOptions } from '../io/writeDiagnostics.js';\nimport { showBanner } from '../ux/banner.js';\nimport { formatDiagnosticsTable } from '../ux/table.js';\nimport type { CliOptions } from '../options/types.js';\nimport { loadConfig } from '../options/loadConfig.js';\nimport { expandTilde } from '../utils/pathUtils.js';\nimport { processBatch, processBatchParallel } from '../utils/batchProcessing.js';\nimport { processQtiPackageToLearnosity } from '../utils/batchProcessors.js';\nimport { displayConfiguration, configField } from '../utils/configOutput.js';\n\n/**\n * Register qti-package-to-learnosity command\n */\nexport function registerQtiPackageToLearnosityCommand(program: Command, version: string): void {\n program\n .command('qti-package-to-learnosity')\n .alias('convert qti-package')\n .description('Convert a QTI Content Package to a Learnosity bundle')\n .option('--in <path>', 'Input package path (.zip or directory)')\n .option('--out <path>', 'Output bundle path (.zip or directory)')\n .option(\n '--format <type>',\n 'Output format: zip or dir (default: auto-detect from --out path)'\n )\n .option(\n '--organisation_id <number>',\n 'Organisation ID for Learnosity CDN asset URLs',\n parseInt\n )\n .option('--org_id <number>', 'Alias for --organisation_id', parseInt)\n .option('--mediavault', 'Use media-vault subdomain instead of assets (default: false)')\n .option(\n '--custom-asset-url <url>',\n 'Custom asset URL prefix to override default Learnosity CDN'\n )\n .option(\n '--item-reference-source <source>',\n 'How to generate item references: sourceFilename (default), qti (identifier), or uuid'\n )\n .option(\n '--item-filename-source <source>',\n 'How to name output JSON files: sourceFilename or qti (default: same as --item-reference-source)'\n )\n .option(\n '--truncate-tags',\n 'Truncate tag types and names to 255 characters instead of failing (default: false)'\n )\n .option('--recursive', 'Process all subdirectories in the input path (default: false)')\n .option(\n '--concurrency <number>',\n 'Worker threads for --recursive batch conversion (default: 1 = serial)',\n parseInt\n )\n .option('--diagnostics <mode>', 'Diagnostics output (stderr|file|both|none, default: file)')\n .option('--fail-on-warn', 'Exit with error code 1 if warnings exist (default: false)')\n .option('--config <path>', 'Path to config file')\n .option('--no-config', 'Disable config file loading')\n .option('-i, --interactive', 'Enable interactive prompts (default: false)')\n .option('--verbose', 'Show INFO level diagnostics in table (default: false)')\n .option('-q, --quiet', 'Suppress non-essential output (default: false)')\n .action(async (opts: CliOptions) => {\n await executeQtiPackageToLearnosity(opts, version);\n });\n}\n\n/**\n * Write diagnostics to file and/or stderr depending on mode\n */\nasync function outputDiagnostics(\n allDiagnostics: Diagnostic[],\n diagnosticsMode: string,\n verbose: boolean,\n diagnosticsPath: string,\n outputPath: string,\n metadata: WriteDiagnosticsOptions\n): Promise<void> {\n if (diagnosticsMode === 'file' || diagnosticsMode === 'both') {\n await writeDiagnostics(\n allDiagnostics,\n 'file',\n diagnosticsPath,\n outputPath,\n false,\n metadata\n );\n }\n\n if (diagnosticsMode === 'stderr' || diagnosticsMode === 'both') {\n const table = formatDiagnosticsTable(allDiagnostics, verbose);\n\n if (table) {\n console.error(table);\n }\n }\n}\n\n/**\n * Resolve an interactive or CLI-provided path option\n * Returns the expanded path or exits with an error.\n */\nasync function resolvePathOption(\n value: string | undefined,\n interactive: boolean,\n promptMessage: string,\n errorMessage: string\n): Promise<string> {\n let resolved = value;\n\n if (!resolved && interactive) {\n resolved = await input({ message: promptMessage });\n }\n\n if (!resolved) {\n console.error(errorMessage);\n process.exit(1);\n }\n\n return expandTilde(resolved);\n}\n\n/**\n * Parse the --diagnostics CLI option into mode and optional custom path\n */\nfunction resolveDiagnosticsConfig(diagnosticsOpt: string | undefined): {\n mode: 'file' | 'stderr' | 'both' | 'none';\n customPath?: string;\n} {\n const validModes = ['stderr', 'file', 'both', 'none'] as const;\n\n if (!diagnosticsOpt || validModes.includes(diagnosticsOpt as any)) {\n return { mode: (diagnosticsOpt as (typeof validModes)[number]) ?? 'file' };\n }\n\n return { mode: 'file', customPath: diagnosticsOpt };\n}\n\n/**\n * Resolve organisation ID from CLI options with optional interactive prompt\n */\nasync function resolveOrganisationId(\n cliOpts: CliOptions,\n interactive: boolean,\n configOrgId?: number\n): Promise<number> {\n let organisationId = (cliOpts as any).organisation_id ?? (cliOpts as any).org_id ?? configOrgId;\n\n if (organisationId === undefined && interactive) {\n const orgIdInput = await input({\n message: 'Organisation ID for Learnosity CDN asset URLs:',\n });\n\n organisationId = orgIdInput ? parseInt(orgIdInput, 10) : undefined;\n }\n\n if (organisationId === undefined || organisationId === null) {\n console.error(\n 'Error: --organisation_id is required. Use -i or --interactive for prompts or specify --organisation_id <number>'\n );\n process.exit(1);\n }\n\n return organisationId;\n}\n\n/**\n * Validate input path exists and determine its type\n */\nfunction validateInputPath(inputPath: string): { isZipInput: boolean } {\n if (!existsSync(inputPath)) {\n console.error(`Error: Input not found: ${inputPath}`);\n process.exit(1);\n }\n\n const isZipInput = inputPath.toLowerCase().endsWith('.zip');\n\n if (!isZipInput && !statSync(inputPath).isDirectory()) {\n console.error(`Error: Input must be a directory or .zip file: ${inputPath}`);\n process.exit(1);\n }\n\n return { isZipInput };\n}\n\n/**\n * Resolve output format (zip or directory) from path and explicit format option\n */\nfunction resolveOutputFormat(\n outputPath: string,\n formatOption?: string\n): { isZipOutput: boolean; finalOutputPath: string } {\n if (formatOption) {\n const fmt = formatOption.toLowerCase();\n\n if (fmt !== 'zip' && fmt !== 'dir') {\n console.error('Error: --format must be \"zip\" or \"dir\"');\n process.exit(1);\n }\n\n const isZipOutput = fmt === 'zip';\n const finalOutputPath =\n isZipOutput && !outputPath.toLowerCase().endsWith('.zip')\n ? `${outputPath}.zip`\n : outputPath;\n\n return { isZipOutput, finalOutputPath };\n }\n\n return {\n isZipOutput: outputPath.toLowerCase().endsWith('.zip'),\n finalOutputPath: outputPath,\n };\n}\n\n/**\n * Display conversion progress for activities and items\n */\nfunction displayConversionProgress(convertResult: any): void {\n const convertedActivityFiles = convertResult.convertedActivityFiles || [];\n\n if (convertedActivityFiles.length > 0) {\n process.stderr.write(' Assessment tests:\\n');\n convertedActivityFiles.forEach((sourceFile: string, index: number) => {\n process.stderr.write(\n ` [${index + 1}/${convertedActivityFiles.length}] ${sourceFile} \\x1b[32m✓\\x1b[0m\\n`\n );\n });\n process.stderr.write('\\n');\n }\n\n const convertedFiles = convertResult.convertedSourceFiles || [];\n const failedFiles = convertResult.failedSourceFiles || [];\n const totalFiles = convertedFiles.length + failedFiles.length;\n\n if (totalFiles > 0) {\n process.stderr.write(' Assessment items:\\n');\n const successSet = new Set(convertedFiles);\n const allFiles = [...convertedFiles, ...failedFiles].sort();\n\n allFiles.forEach((sourceFile: string, index: number) => {\n const isSuccess = successSet.has(sourceFile);\n const status = isSuccess ? '\\x1b[32m✓\\x1b[0m' : '\\x1b[31m✗\\x1b[0m';\n\n process.stderr.write(` [${index + 1}/${totalFiles}] ${sourceFile} ${status}\\n`);\n });\n\n if (failedFiles.length > 0) {\n process.stderr.write(\n `\\nConversion completed with ERRORS (${convertedFiles.length} succeeded, ${failedFiles.length} failed)\\n`\n );\n process.stderr.write(\n `Proceeding with ${convertedFiles.length} successfully converted items...\\n\\n`\n );\n } else {\n process.stderr.write(`\\nConverted ${convertedFiles.length} items ✓\\n\\n`);\n }\n }\n}\n\n/**\n * Build metadata object for diagnostics output\n */\nfunction buildDiagnosticsMetadata(\n inputPath: string,\n outputPath: string,\n convertResult: any,\n failed: boolean\n): WriteDiagnosticsOptions {\n const convertedFiles = convertResult.convertedSourceFiles || [];\n const failedFiles = convertResult.failedSourceFiles || [];\n const convertedActivityFiles = convertResult.convertedActivityFiles || [];\n const itemRefs = convertResult.bundle\n ? (Array.from(convertResult.bundle.items.keys()) as string[])\n : [];\n\n return {\n inputPath,\n outputPath,\n totalItemsFound: failed ? itemRefs.length : convertedFiles.length + failedFiles.length,\n totalActivitiesFound: convertedActivityFiles.length,\n convertedFiles: failed ? [] : convertedFiles,\n failedFiles: failed ? itemRefs.map((ref: string) => `items/${ref}.xml`) : failedFiles,\n convertedActivities: convertedActivityFiles,\n };\n}\n\n/**\n * Execute qti-package-to-learnosity conversion\n */\nasync function executeQtiPackageToLearnosity(cliOpts: CliOptions, version: string): Promise<void> {\n const allDiagnostics: Diagnostic[] = [];\n const startTime = Date.now();\n const quiet = cliOpts.quiet ?? false;\n\n try {\n showBanner('qti-package-to-learnosity', version, quiet);\n\n const interactive = cliOpts.interactive ?? false;\n\n // Load config file (CLI flags take precedence over config values)\n const { config, diagnostics: configDiagnostics } = await loadConfig(\n cliOpts.config,\n cliOpts.noConfig\n );\n\n allDiagnostics.push(...configDiagnostics);\n\n if (configDiagnostics.some((d) => d.level === 'error')) {\n console.log('\\n' + formatDiagnosticsTable(configDiagnostics));\n process.exit(1);\n\n return;\n }\n\n const inputPath = await resolvePathOption(\n cliOpts.in,\n interactive,\n 'Input QTI package path (.zip or directory):',\n 'Error: --in is required. Use -i or --interactive for prompts or specify --in <path>'\n );\n\n const outputPath = await resolvePathOption(\n cliOpts.out,\n interactive,\n 'Output bundle path (.zip or directory):',\n 'Error: --out is required. Use -i or --interactive for prompts or specify --out <path>'\n );\n\n const failOnWarn = cliOpts.failOnWarn ?? false;\n const verbose = cliOpts.verbose ?? config?.verbose ?? false;\n const { mode: diagnosticsMode, customPath: customDiagnosticsPath } =\n resolveDiagnosticsConfig(cliOpts.diagnostics ?? config?.diagnostics);\n const organisationId = await resolveOrganisationId(\n cliOpts,\n interactive,\n config?.organisationId\n );\n const mediaVault = (cliOpts as any).mediavault ?? config?.mediaVault ?? false;\n const customAssetUrl = (cliOpts as any).customAssetUrl ?? config?.customAssetUrl;\n const itemReferenceSource =\n (cliOpts as any).itemReferenceSource ?? config?.itemReferenceSource;\n const itemFilenameSource =\n (cliOpts as any).itemFilenameSource ?? config?.itemFilenameSource;\n const truncateTags = (cliOpts as any).truncateTags ?? config?.truncateTags ?? false;\n\n const { isZipInput } = validateInputPath(inputPath);\n\n // Handle recursive batch processing\n if ((cliOpts as any).recursive) {\n if (isZipInput) {\n console.error(\n 'Error: --recursive flag cannot be used with ZIP input. Please provide a directory containing subdirectories.'\n );\n process.exit(1);\n\n return;\n }\n\n await executeBatchQtiPackageToLearnosity({\n inputPath,\n outputPath,\n organisationId,\n mediaVault,\n customAssetUrl,\n itemReferenceSource,\n itemFilenameSource,\n truncateTags,\n diagnosticsMode,\n failOnWarn,\n verbose,\n quiet,\n version,\n concurrency: cliOpts.concurrency ?? 1,\n });\n\n return;\n }\n\n const { isZipOutput, finalOutputPath } = resolveOutputFormat(outputPath, cliOpts.format);\n\n if (!quiet) {\n displayConfiguration(\n [\n configField('Input:', inputPath),\n configField('Output:', finalOutputPath),\n configField('Format:', isZipOutput ? 'ZIP' : 'directory'),\n configField('Diagnostics:', diagnosticsMode),\n configField('Org ID:', organisationId),\n configField('Media vault:', mediaVault),\n configField('Item ref src:', itemReferenceSource ?? 'sourceFilename (default)'),\n configField('Item filename:', itemFilenameSource ?? 'same as item ref src'),\n configField('Verbose:', verbose),\n configField('Fail on warn:', failOnWarn),\n ],\n { quiet }\n );\n }\n\n // Step 1: Convert package to bundle model\n process.stderr.write('Converting QTI package...\\n');\n\n const convertOpts = {\n organisationId,\n mediaVault,\n customAssetUrl,\n itemReferenceSource,\n itemFilenameSource,\n truncateTags,\n packageVersion: version,\n };\n let convertResult;\n\n if (isZipInput) {\n convertResult = convertQtiPackageToLearnosityBundle(\n { zipBytes: new Uint8Array(readFileSync(inputPath)) },\n convertOpts\n );\n } else {\n const loaded = loadPackageDirectory(inputPath);\n\n convertResult = loaded.entries\n ? convertQtiPackageToLearnosityBundle(\n { entries: loaded.entries },\n { ...convertOpts, sourceDir: inputPath, fileAccess: nodeFileAccess }\n )\n : { diagnostics: loaded.diagnostics };\n }\n\n allDiagnostics.push(...convertResult.diagnostics);\n\n displayConversionProgress(convertResult);\n\n const getDiagPath = () =>\n customDiagnosticsPath ||\n (isZipOutput\n ? finalOutputPath.replace(/\\.zip$/i, '-diagnostics.json')\n : `${finalOutputPath.replace(/\\/$/, '')}/diagnostics.json`);\n\n // Check for critical errors\n const errors = allDiagnostics.filter((d) => d.level === 'error');\n const warnings = allDiagnostics.filter((d) => d.level === 'warning');\n const hasValidBundle = convertResult.bundle && convertResult.bundle.items.size > 0;\n\n if (errors.length > 0 && !hasValidBundle) {\n process.stderr.write('\\nConversion FAILED with errors\\n\\n');\n await outputDiagnostics(\n allDiagnostics,\n diagnosticsMode,\n verbose,\n getDiagPath(),\n finalOutputPath,\n buildDiagnosticsMetadata(inputPath, finalOutputPath, convertResult, true)\n );\n process.exit(1);\n\n return;\n }\n\n if (failOnWarn && warnings.length > 0) {\n process.stderr.write('\\nConversion completed with WARNINGS (fail-on-warn mode)\\n\\n');\n await outputDiagnostics(\n allDiagnostics,\n diagnosticsMode,\n verbose,\n getDiagPath(),\n finalOutputPath,\n buildDiagnosticsMetadata(\n inputPath,\n finalOutputPath,\n convertResult,\n errors.length > 0\n )\n );\n process.exit(1);\n\n return;\n }\n\n if (!convertResult.bundle) {\n process.stderr.write('\\nConversion FAILED: no bundle generated\\n\\n');\n await outputDiagnostics(\n allDiagnostics,\n diagnosticsMode,\n verbose,\n getDiagPath(),\n finalOutputPath,\n {\n inputPath,\n outputPath: finalOutputPath,\n totalItemsFound: 0,\n convertedFiles: [],\n failedFiles: [],\n }\n );\n process.exit(1);\n\n return;\n }\n\n // Step 2: Write bundle to directory or ZIP\n process.stderr.write(`Writing ${isZipOutput ? 'ZIP' : 'directory'} package... `);\n const writeResult = await writeLearnosityBundle(convertResult.bundle, {\n outDir: finalOutputPath,\n isZipOutput,\n });\n\n allDiagnostics.push(...writeResult.diagnostics);\n\n if (writeResult.diagnostics.some((d) => d.level === 'error')) {\n process.stderr.write('FAILED\\n\\n');\n await outputDiagnostics(\n allDiagnostics,\n diagnosticsMode,\n verbose,\n getDiagPath(),\n outputPath,\n buildDiagnosticsMetadata(inputPath, outputPath, convertResult, true)\n );\n process.exit(1);\n\n return;\n }\n\n process.stderr.write('✓\\n');\n\n // Step 3: Write final diagnostics on success\n const successMetadata = buildDiagnosticsMetadata(\n inputPath,\n finalOutputPath,\n convertResult,\n false\n );\n\n if (diagnosticsMode === 'file' || diagnosticsMode === 'both') {\n const diagnosticsPath = getDiagPath();\n\n process.stderr.write(`Writing diagnostics to ${diagnosticsPath}... `);\n await outputDiagnostics(\n allDiagnostics,\n 'file',\n verbose,\n diagnosticsPath,\n finalOutputPath,\n successMetadata\n );\n process.stderr.write('✓\\n');\n }\n\n if (diagnosticsMode === 'stderr' || diagnosticsMode === 'both') {\n await outputDiagnostics(\n allDiagnostics,\n 'stderr',\n verbose,\n getDiagPath(),\n finalOutputPath,\n successMetadata\n );\n }\n\n const elapsedTime = ((Date.now() - startTime) / 1000).toFixed(1);\n\n process.stderr.write(`\\nCompleted in ${elapsedTime}s\\n`);\n\n const failedFiles = convertResult.failedSourceFiles || [];\n\n if (failedFiles.length > 0) {\n process.stderr.write(\n `\\nPackage written with ${failedFiles.length} item(s) skipped due to errors\\n`\n );\n }\n\n process.exit(0);\n } catch (error) {\n if (error instanceof Error && error.name === 'ExitPromptError') {\n process.exit(130);\n }\n console.error('\\n' + (error instanceof Error ? error.message : 'Unknown error'));\n process.exit(1);\n }\n}\n\n/**\n * Execute batch QTI package to Learnosity conversion for multiple subdirectories\n */\nasync function executeBatchQtiPackageToLearnosity(opts: {\n inputPath: string;\n outputPath: string;\n organisationId: number;\n mediaVault: boolean;\n customAssetUrl?: string;\n itemReferenceSource?: ItemReferenceSource;\n itemFilenameSource?: ItemFilenameSource;\n truncateTags: boolean;\n diagnosticsMode: string;\n failOnWarn: boolean;\n verbose: boolean;\n quiet: boolean;\n version: string;\n concurrency: number;\n}): Promise<void> {\n const {\n inputPath,\n outputPath,\n organisationId,\n mediaVault,\n customAssetUrl,\n itemReferenceSource,\n itemFilenameSource,\n truncateTags,\n diagnosticsMode,\n failOnWarn,\n verbose,\n quiet,\n version,\n concurrency,\n } = opts;\n\n if (concurrency > 1) {\n await processBatchParallel({\n inputPath,\n outputPath,\n packageType: 'qti',\n direction: 'qti-to-learnosity',\n options: {\n organisationId,\n mediaVault,\n customAssetUrl,\n itemReferenceSource,\n itemFilenameSource,\n truncateTags,\n version,\n },\n concurrency,\n quiet,\n });\n\n return;\n }\n\n // Display configuration\n displayConfiguration(\n [\n configField('Input:', inputPath),\n configField('Output:', outputPath),\n configField('Format:', 'directory'),\n configField('Diagnostics:', diagnosticsMode),\n configField('Org ID:', organisationId),\n configField('Media vault:', mediaVault),\n configField('Item ref src:', itemReferenceSource ?? 'sourceFilename (default)'),\n configField('Item filename:', itemFilenameSource ?? 'same as item ref src'),\n configField('Truncate tags:', truncateTags),\n configField('Recursive:', true),\n configField('Verbose:', verbose),\n configField('Fail on warn:', failOnWarn),\n ],\n { quiet }\n );\n\n if (!quiet) {\n console.log('🔄 Batch Processing Mode');\n console.log(`Scanning: ${inputPath}\\n`);\n }\n\n // Use generic batch processor\n await processBatch({\n inputPath,\n outputPath,\n packageType: 'qti',\n options: opts,\n quiet,\n processPackage: (pkg, packageOutputPath, options) =>\n processQtiPackageToLearnosity(pkg, packageOutputPath, options, quiet),\n });\n}\n"],"mappings":";;;;;;;;;;AA6BA,SAAgB,sCAAsC,SAAkB,SAAuB;CAC3F,QACK,QAAQ,2BAA2B,CAAC,CACpC,MAAM,qBAAqB,CAAC,CAC5B,YAAY,sDAAsD,CAAC,CACnE,OAAO,eAAe,wCAAwC,CAAC,CAC/D,OAAO,gBAAgB,wCAAwC,CAAC,CAChE,OACG,mBACA,kEACJ,CAAC,CACA,OACG,8BACA,iDACA,QACJ,CAAC,CACA,OAAO,qBAAqB,+BAA+B,QAAQ,CAAC,CACpE,OAAO,gBAAgB,8DAA8D,CAAC,CACtF,OACG,4BACA,4DACJ,CAAC,CACA,OACG,oCACA,sFACJ,CAAC,CACA,OACG,mCACA,iGACJ,CAAC,CACA,OACG,mBACA,oFACJ,CAAC,CACA,OAAO,eAAe,+DAA+D,CAAC,CACtF,OACG,0BACA,yEACA,QACJ,CAAC,CACA,OAAO,wBAAwB,2DAA2D,CAAC,CAC3F,OAAO,kBAAkB,2DAA2D,CAAC,CACrF,OAAO,mBAAmB,qBAAqB,CAAC,CAChD,OAAO,eAAe,6BAA6B,CAAC,CACpD,OAAO,qBAAqB,6CAA6C,CAAC,CAC1E,OAAO,aAAa,uDAAuD,CAAC,CAC5E,OAAO,eAAe,gDAAgD,CAAC,CACvE,OAAO,OAAO,SAAqB;EAChC,MAAM,8BAA8B,MAAM,OAAO;CACrD,CAAC;AACT;;;;AAKA,eAAe,kBACX,gBACA,iBACA,SACA,iBACA,YACA,UACa;CACb,IAAI,oBAAoB,UAAU,oBAAoB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K,GAAG;EAEpB,QAAQ,MAAM,QAAQ,iBAAiB,QAAQ,MAAM,UAAU,gBAAgB;EAC/E,QAAQ,KAAK,CAAC;CAClB;AACJ;;;;AAKA,eAAe,mCAAmC,MAehC;CACd,MAAM,EACF,WACA,YACA,gBACA,YACA,gBACA,qBACA,oBACA,cACA,iBACA,YACA,SACA,OACA,SACA,gBACA;CAEJ,IAAI,cAAc,GAAG;EACjB,MAAM,qBAAqB;GACvB;GACA;GACA,aAAa;GACb,WAAW;GACX,SAAS;IACL;IACA;IACA;IACA;IACA;IACA;IACA;GACJ;GACA;GACA;EACJ,CAAC;EAED;CACJ;CAGA,qBACI;EACI,YAAY,UAAU,SAAS;EAC/B,YAAY,WAAW,UAAU;EACjC,YAAY,WAAW,WAAW;EAClC,YAAY,gBAAgB,eAAe;EAC3C,YAAY,WAAW,cAAc;EACrC,YAAY,gBAAgB,UAAU;EACtC,YAAY,iBAAiB,uBAAuB,0BAA0B;EAC9E,YAAY,kBAAkB,sBAAsB,sBAAsB;EAC1E,YAAY,kBAAkB,YAAY;EAC1C,YAAY,cAAc,IAAI;EAC9B,YAAY,YAAY,OAAO;EAC/B,YAAY,iBAAiB,UAAU;CAC3C,GACA,EAAE,MAAM,CACZ;CAEA,IAAI,CAAC,OAAO;EACR,QAAQ,IAAI,0BAA0B;EACtC,QAAQ,IAAI,aAAa,UAAU,GAAG;CAC1C;CAGA,MAAM,aAAa;EACf;EACA;EACA,aAAa;EACb,SAAS;EACT;EACA,iBAAiB,KAAK,mBAAmB,YACrC,8BAA8B,KAAK,mBAAmB,SAAS,KAAK;CAC5E,CAAC;AACL"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { n as loadConfig, r as showBanner } from "./pathUtils-CwZnJ55s.js";
|
|
2
|
+
import { r as formatDiagnosticsTable, s as writeDiagnostics, t as countErrors } from "./table-DYcNeyJ_.js";
|
|
3
|
+
import { c as convertQtiToLearnosity, i as writeOutput, n as ProgressTracker, o as readInput, r as showResolvedOptions, t as resolveOptions } from "./resolveOptions-gH_YAxxc.js";
|
|
4
|
+
import { nodeFileAccess } from "@learnosity/converter-core/node";
|
|
5
|
+
//#region src/commands/qtiToLearnosity.ts
|
|
6
|
+
/**
|
|
7
|
+
* Register qti-to-learnosity command
|
|
8
|
+
*/
|
|
9
|
+
function registerQtiToLearnosityCommand(program, version) {
|
|
10
|
+
program.command("qti-to-learnosity").description("Convert a single QTI file to Learnosity JSON").option("--in <path>", "Input file path or \"-\" for stdin").option("--out <path>", "Output file path or \"-\" for stdout").option("--qti-version <version>", "QTI version (2.1 or 2.2, default: 2.2)").option("--output-format <format>", "Output format (dir|zip|stdout, default: auto-detect from output path)").option("--diagnostics <mode>", "Diagnostics output (stderr|file|both|none, default: file for file output, stderr for stdout)").option("--organisation_id <number>", "Organisation ID for Learnosity CDN asset URLs", parseInt).option("--org_id <number>", "Alias for --organisation_id", parseInt).option("--mediavault", "Use media-vault subdomain instead of assets (default: false)").option("--custom-asset-url <url>", "Custom asset URL prefix to override default Learnosity CDN").option("--item-reference-source <source>", "How to generate item references: sourceFilename (default), qti (identifier), or uuid").option("--truncate-tags", "Truncate tag types and names to 255 characters instead of failing (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("--verbose", "Verbose output (default: false)").option("--pretty", "Pretty-print JSON output (default: false)").option("-q, --quiet", "Suppress non-essential output (default: false)").action(async (opts) => {
|
|
11
|
+
await executeQtiToLearnosity(opts, version);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
async function resolveOutputFilePath(outputPath, itemReference) {
|
|
15
|
+
if (outputPath === "-" || !itemReference) return outputPath;
|
|
16
|
+
const fs = await import("fs/promises");
|
|
17
|
+
try {
|
|
18
|
+
if ((await fs.stat(outputPath)).isDirectory()) return `${outputPath}/${itemReference}.json`;
|
|
19
|
+
} catch {
|
|
20
|
+
if (outputPath.endsWith("/") || !outputPath.includes(".")) return `${outputPath}${outputPath.endsWith("/") ? "" : "/"}${itemReference}.json`;
|
|
21
|
+
}
|
|
22
|
+
return outputPath;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Execute qti-to-learnosity conversion
|
|
26
|
+
*/
|
|
27
|
+
async function executeQtiToLearnosity(cliOpts, version) {
|
|
28
|
+
const allDiagnostics = [];
|
|
29
|
+
const quiet = cliOpts.quiet ?? false;
|
|
30
|
+
try {
|
|
31
|
+
showBanner("qti-to-learnosity", version, quiet);
|
|
32
|
+
const { config, diagnostics: configDiagnostics, configPath } = await loadConfig(cliOpts.config, cliOpts.noConfig);
|
|
33
|
+
allDiagnostics.push(...configDiagnostics);
|
|
34
|
+
if (configDiagnostics.filter((d) => d.level === "error").length > 0) {
|
|
35
|
+
console.log("\n" + formatDiagnosticsTable(configDiagnostics));
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
const { options: resolved, diagnostics: resolveDiagnostics, withSources } = await resolveOptions(cliOpts, config, false, configPath);
|
|
39
|
+
allDiagnostics.push(...resolveDiagnostics);
|
|
40
|
+
showResolvedOptions(resolved, withSources, quiet);
|
|
41
|
+
const progress = new ProgressTracker(resolved.verbose);
|
|
42
|
+
progress.startStage("Reading input...");
|
|
43
|
+
const input = await readInput(resolved.inputPath);
|
|
44
|
+
progress.succeedStage("Input read");
|
|
45
|
+
progress.startStage("Converting QTI to Learnosity...");
|
|
46
|
+
const conversionOpts = {
|
|
47
|
+
qtiVersion: resolved.qtiVersion,
|
|
48
|
+
outputFormat: resolved.outputFormat,
|
|
49
|
+
diagnostics: resolved.diagnostics,
|
|
50
|
+
verbose: resolved.verbose,
|
|
51
|
+
pretty: resolved.pretty,
|
|
52
|
+
inputPath: resolved.inputPath,
|
|
53
|
+
organisationId: resolved.organisationId,
|
|
54
|
+
mediaVault: resolved.mediaVault,
|
|
55
|
+
customAssetUrl: resolved.customAssetUrl,
|
|
56
|
+
itemReferenceSource: resolved.itemReferenceSource,
|
|
57
|
+
truncateTags: resolved.truncateTags,
|
|
58
|
+
fileAccess: nodeFileAccess
|
|
59
|
+
};
|
|
60
|
+
const result = await convertQtiToLearnosity(input, conversionOpts);
|
|
61
|
+
const inputFilename = resolved.inputPath.split("/").pop() ?? resolved.inputPath;
|
|
62
|
+
const prefixedDiagnostics = result.diagnostics.map((d) => ({
|
|
63
|
+
...d,
|
|
64
|
+
file: inputFilename
|
|
65
|
+
}));
|
|
66
|
+
allDiagnostics.push(...prefixedDiagnostics);
|
|
67
|
+
progress.succeedStage("Conversion complete");
|
|
68
|
+
const itemReference = result.output.reference;
|
|
69
|
+
const finalOutputPath = await resolveOutputFilePath(resolved.outputPath, itemReference);
|
|
70
|
+
progress.startStage("Writing output...");
|
|
71
|
+
await writeOutput(finalOutputPath, result.output, resolved.pretty);
|
|
72
|
+
progress.succeedStage("Output written");
|
|
73
|
+
if (resolved.diagnostics !== "none") {
|
|
74
|
+
progress.startStage("Writing diagnostics...");
|
|
75
|
+
const hasErrors = allDiagnostics.some((d) => d.level === "error");
|
|
76
|
+
await writeDiagnostics(allDiagnostics, resolved.diagnostics, resolved.diagnosticsPath, resolved.outputPath, resolved.verbose, {
|
|
77
|
+
inputPath: resolved.inputPath,
|
|
78
|
+
outputPath: resolved.outputPath,
|
|
79
|
+
totalItemsFound: 1,
|
|
80
|
+
convertedFiles: hasErrors ? [] : [inputFilename],
|
|
81
|
+
failedFiles: hasErrors ? [inputFilename] : []
|
|
82
|
+
});
|
|
83
|
+
progress.succeedStage("Diagnostics written");
|
|
84
|
+
}
|
|
85
|
+
if (resolved.diagnostics === "stderr" || resolved.diagnostics === "both") console.log("\n" + formatDiagnosticsTable(allDiagnostics));
|
|
86
|
+
const errorCount = countErrors(allDiagnostics);
|
|
87
|
+
process.exit(errorCount > 0 ? 1 : 0);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (error instanceof Error && error.name === "ExitPromptError") process.exit(130);
|
|
90
|
+
console.error("\n" + (error instanceof Error ? error.message : "Unknown error"));
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { registerQtiToLearnosityCommand };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=qtiToLearnosity-jiFTBiQU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qtiToLearnosity-jiFTBiQU.js","names":[],"sources":["../src/commands/qtiToLearnosity.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Command } from 'commander';\nimport type { ConversionOptions, Diagnostic } from '@learnosity/converter-core';\nimport { convertQtiToLearnosity } from '@learnosity/converter-core';\nimport { nodeFileAccess } from '@learnosity/converter-core/node';\nimport { readInput } from '../io/readInput.js';\nimport { writeOutput } from '../io/writeOutput.js';\nimport { writeDiagnostics } from '../io/writeDiagnostics.js';\nimport { showBanner } from '../ux/banner.js';\nimport { showResolvedOptions } from '../ux/resolvedOptions.js';\nimport { ProgressTracker } from '../ux/progress.js';\nimport { formatDiagnosticsTable, countErrors } from '../ux/table.js';\nimport { loadConfig } from '../options/loadConfig.js';\nimport { resolveOptions } from '../options/resolveOptions.js';\nimport type { CliOptions } from '../options/types.js';\n\n/**\n * Register qti-to-learnosity command\n */\nexport function registerQtiToLearnosityCommand(program: Command, version: string): void {\n program\n .command('qti-to-learnosity')\n .description('Convert a single QTI file to Learnosity JSON')\n .option('--in <path>', 'Input file path or \"-\" for stdin')\n .option('--out <path>', 'Output file path or \"-\" for stdout')\n .option('--qti-version <version>', 'QTI version (2.1 or 2.2, default: 2.2)')\n .option(\n '--output-format <format>',\n 'Output format (dir|zip|stdout, default: auto-detect from output path)'\n )\n .option(\n '--diagnostics <mode>',\n 'Diagnostics output (stderr|file|both|none, default: file for file output, stderr for stdout)'\n )\n .option(\n '--organisation_id <number>',\n 'Organisation ID for Learnosity CDN asset URLs',\n parseInt\n )\n .option('--org_id <number>', 'Alias for --organisation_id', parseInt)\n .option('--mediavault', 'Use media-vault subdomain instead of assets (default: false)')\n .option(\n '--custom-asset-url <url>',\n 'Custom asset URL prefix to override default Learnosity CDN'\n )\n .option(\n '--item-reference-source <source>',\n 'How to generate item references: sourceFilename (default), qti (identifier), or uuid'\n )\n .option(\n '--truncate-tags',\n 'Truncate tag types and names to 255 characters instead of failing (default: false)'\n )\n .option('--config <path>', 'Path to config file')\n .option('--no-config', 'Disable config file loading')\n .option('-i, --interactive', 'Enable interactive prompts (default: false)')\n .option('--verbose', 'Verbose output (default: false)')\n .option('--pretty', 'Pretty-print JSON output (default: false)')\n .option('-q, --quiet', 'Suppress non-essential output (default: false)')\n .action(async (opts: CliOptions) => {\n await executeQtiToLearnosity(opts, version);\n });\n}\n\nasync function resolveOutputFilePath(outputPath: string, itemReference?: string): Promise<string> {\n if (outputPath === '-' || !itemReference) {\n return outputPath;\n }\n\n const fs = await import('fs/promises');\n\n try {\n const stat = await fs.stat(outputPath);\n\n if (stat.isDirectory()) {\n return `${outputPath}/${itemReference}.json`;\n }\n } catch {\n if (outputPath.endsWith('/') || !outputPath.includes('.')) {\n return `${outputPath}${outputPath.endsWith('/') ? '' : '/'}${itemReference}.json`;\n }\n }\n\n return outputPath;\n}\n\n/**\n * Execute qti-to-learnosity conversion\n */\nasync function executeQtiToLearnosity(cliOpts: CliOptions, version: string): Promise<void> {\n const allDiagnostics: Diagnostic[] = [];\n const quiet = cliOpts.quiet ?? false;\n\n try {\n showBanner('qti-to-learnosity', version, quiet);\n\n // Load config\n const {\n config,\n diagnostics: configDiagnostics,\n configPath,\n } = await loadConfig(cliOpts.config, cliOpts.noConfig);\n\n allDiagnostics.push(...configDiagnostics);\n\n // Check for config errors\n const configErrors = configDiagnostics.filter((d) => d.level === 'error');\n\n if (configErrors.length > 0) {\n console.log('\\n' + formatDiagnosticsTable(configDiagnostics));\n process.exit(1);\n }\n\n // Resolve options\n const {\n options: resolved,\n diagnostics: resolveDiagnostics,\n withSources,\n } = await resolveOptions(cliOpts, config, false, configPath);\n\n allDiagnostics.push(...resolveDiagnostics);\n\n // Show resolved options\n showResolvedOptions(resolved, withSources, quiet);\n\n const progress = new ProgressTracker(resolved.verbose);\n\n // Read input\n progress.startStage('Reading input...');\n const input = await readInput(resolved.inputPath);\n\n progress.succeedStage('Input read');\n\n // Convert\n progress.startStage('Converting QTI to Learnosity...');\n const conversionOpts: ConversionOptions = {\n qtiVersion: resolved.qtiVersion,\n outputFormat: resolved.outputFormat,\n diagnostics: resolved.diagnostics,\n verbose: resolved.verbose,\n pretty: resolved.pretty,\n inputPath: resolved.inputPath,\n organisationId: resolved.organisationId, // TASK 030\n mediaVault: resolved.mediaVault,\n customAssetUrl: resolved.customAssetUrl,\n itemReferenceSource: resolved.itemReferenceSource,\n truncateTags: resolved.truncateTags,\n fileAccess: nodeFileAccess,\n };\n const result = await convertQtiToLearnosity(input, conversionOpts);\n\n // Set diagnostics file to input filename only\n const inputFilename = resolved.inputPath.split('/').pop() ?? resolved.inputPath;\n const prefixedDiagnostics = result.diagnostics.map((d) => ({\n ...d,\n file: inputFilename,\n }));\n\n allDiagnostics.push(...prefixedDiagnostics);\n progress.succeedStage('Conversion complete');\n\n // Determine output path - use MD5-based filename if output is a directory\n const itemReference = (result.output as any).reference;\n const finalOutputPath = await resolveOutputFilePath(resolved.outputPath, itemReference);\n\n // Write output\n progress.startStage('Writing output...');\n await writeOutput(finalOutputPath, result.output, resolved.pretty);\n progress.succeedStage('Output written');\n\n // Write diagnostics\n if (resolved.diagnostics !== 'none') {\n progress.startStage('Writing diagnostics...');\n const hasErrors = allDiagnostics.some((d) => d.level === 'error');\n\n await writeDiagnostics(\n allDiagnostics,\n resolved.diagnostics,\n resolved.diagnosticsPath,\n resolved.outputPath,\n resolved.verbose,\n {\n inputPath: resolved.inputPath,\n outputPath: resolved.outputPath,\n totalItemsFound: 1,\n convertedFiles: hasErrors ? [] : [inputFilename],\n failedFiles: hasErrors ? [inputFilename] : [],\n }\n );\n progress.succeedStage('Diagnostics written');\n }\n\n // Display diagnostics table only if mode is stderr or both\n if (resolved.diagnostics === 'stderr' || resolved.diagnostics === 'both') {\n console.log('\\n' + formatDiagnosticsTable(allDiagnostics));\n }\n\n const errorCount = countErrors(allDiagnostics);\n\n process.exit(errorCount > 0 ? 1 : 0);\n } catch (error) {\n if (error instanceof Error && error.name === 'ExitPromptError') {\n process.exit(130);\n }\n console.error('\\n' + (error instanceof Error ? error.message : 'Unknown error'));\n process.exit(1);\n }\n}\n"],"mappings":";;;;;;;;AAoBA,SAAgB,+BAA+B,SAAkB,SAAuB;CACpF,QACK,QAAQ,mBAAmB,CAAC,CAC5B,YAAY,8CAA8C,CAAC,CAC3D,OAAO,eAAe,oCAAkC,CAAC,CACzD,OAAO,gBAAgB,sCAAoC,CAAC,CAC5D,OAAO,2BAA2B,wCAAwC,CAAC,CAC3E,OACG,4BACA,uEACJ,CAAC,CACA,OACG,wBACA,8FACJ,CAAC,CACA,OACG,8BACA,iDACA,QACJ,CAAC,CACA,OAAO,qBAAqB,+BAA+B,QAAQ,CAAC,CACpE,OAAO,gBAAgB,8DAA8D,CAAC,CACtF,OACG,4BACA,4DACJ,CAAC,CACA,OACG,oCACA,sFACJ,CAAC,CACA,OACG,mBACA,oFACJ,CAAC,CACA,OAAO,mBAAmB,qBAAqB,CAAC,CAChD,OAAO,eAAe,6BAA6B,CAAC,CACpD,OAAO,qBAAqB,6CAA6C,CAAC,CAC1E,OAAO,aAAa,iCAAiC,CAAC,CACtD,OAAO,YAAY,2CAA2C,CAAC,CAC/D,OAAO,eAAe,gDAAgD,CAAC,CACvE,OAAO,OAAO,SAAqB;EAChC,MAAM,uBAAuB,MAAM,OAAO;CAC9C,CAAC;AACT;AAEA,eAAe,sBAAsB,YAAoB,eAAyC;CAC9F,IAAI,eAAe,OAAO,CAAC,eACvB,OAAO;CAGX,MAAM,KAAK,MAAM,OAAO;CAExB,IAAI;EAGA,KAAI,MAFe,GAAG,KAAK,UAAU,EAAA,CAE5B,YAAY,GACjB,OAAO,GAAG,WAAW,GAAG,cA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