@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.
Files changed (34) hide show
  1. package/README.md +9 -3
  2. package/docs/GETTING_STARTED.md +10 -4
  3. package/docs/TAGS_TO_QTI_METADATA.md +291 -0
  4. package/docs/_sidebar.md +10 -9
  5. package/package.json +9 -9
  6. package/packages/cli/dist/batchProcessors-BfmvnTQ5.js +215 -0
  7. package/packages/cli/dist/batchProcessors-BfmvnTQ5.js.map +1 -0
  8. package/packages/cli/dist/batchWorker.js +1 -1
  9. package/packages/cli/dist/configOutput-FwkFyQmk.js +399 -0
  10. package/packages/cli/dist/configOutput-FwkFyQmk.js.map +1 -0
  11. package/packages/cli/dist/create-prompt-DU9wLVhI.js +1392 -0
  12. package/packages/cli/dist/create-prompt-DU9wLVhI.js.map +1 -0
  13. package/packages/cli/dist/dist-DjpU2mIj.js +278 -0
  14. package/packages/cli/dist/dist-DjpU2mIj.js.map +1 -0
  15. package/packages/cli/dist/learnosityToQti-B0PoimXr.js +102 -0
  16. package/packages/cli/dist/learnosityToQti-B0PoimXr.js.map +1 -0
  17. package/packages/cli/dist/learnosityToQtiPackage-RyClxvZj.js +632 -0
  18. package/packages/cli/dist/learnosityToQtiPackage-RyClxvZj.js.map +1 -0
  19. package/packages/cli/dist/main.js +32 -37131
  20. package/packages/cli/dist/main.js.map +1 -1
  21. package/packages/cli/dist/pathUtils-CwZnJ55s.js +2386 -0
  22. package/packages/cli/dist/pathUtils-CwZnJ55s.js.map +1 -0
  23. package/packages/cli/dist/qtiPackageToLearnosity-0rkZKKOK.js +354 -0
  24. package/packages/cli/dist/qtiPackageToLearnosity-0rkZKKOK.js.map +1 -0
  25. package/packages/cli/dist/qtiToLearnosity-jiFTBiQU.js +97 -0
  26. package/packages/cli/dist/qtiToLearnosity-jiFTBiQU.js.map +1 -0
  27. package/packages/cli/dist/resolveOptions-gH_YAxxc.js +31578 -0
  28. package/packages/cli/dist/resolveOptions-gH_YAxxc.js.map +1 -0
  29. package/packages/cli/dist/rolldown-runtime-B4iAMlE-.js +35 -0
  30. package/packages/cli/dist/{batchProcessors-B8EQvMbH.js → table-DYcNeyJ_.js} +906 -1150
  31. package/packages/cli/dist/table-DYcNeyJ_.js.map +1 -0
  32. package/packages/core/dist/index.js +162 -144
  33. package/packages/core/dist/node.js +162 -144
  34. package/packages/cli/dist/batchProcessors-B8EQvMbH.js.map +0 -1
package/README.md CHANGED
@@ -36,6 +36,12 @@ pnpm install
36
36
  pnpm run build
37
37
  ```
38
38
 
39
+ After building, run the CLI directly via the local wrapper (no `npx` overhead):
40
+
41
+ ```bash
42
+ node bin/lcon.js -i
43
+ ```
44
+
39
45
  Some development tasks need tools that are not npm dependencies: Python 3 with `lxml` for [QTI validation](#qti-validation-not-bundled), and the Trivy and Semgrep CLIs for [security scanning](#security-scanning-external-tools-required).
40
46
 
41
47
  ## Quick Start
@@ -44,10 +50,10 @@ Some development tasks need tools that are not npm dependencies: Python 3 with `
44
50
 
45
51
  ```bash
46
52
  # Convert single QTI item to Learnosity
47
- npx lcon qti-to-learnosity --in item.xml --out item.json --pretty
53
+ npm run lcon qti-to-learnosity --in item.xml --out item.json --pretty
48
54
 
49
55
  # Convert single Learnosity item to QTI
50
- npx lcon learnosity-to-qti --in item.json --out item.xml
56
+ npm run lcon learnosity-to-qti --in item.json --out item.xml
51
57
  ```
52
58
 
53
59
  ### Library Usage
@@ -132,7 +138,7 @@ The CLI provides four main conversion commands:
132
138
 
133
139
  **Batch Processing:** The package conversion commands (`qti-package-to-learnosity` and `learnosity-to-qti-package`) support a `--recursive` flag to convert multiple packages in subdirectories with a single command, plus an opt-in `--concurrency <n>` flag to convert them in parallel across worker threads (default `1` = serial). See [Examples - Batch Processing](https://learnosity.github.io/lib-qti-converter/#/EXAMPLES?id=10-batch-processing-with-recursive-flag) for details.
134
140
 
135
- Run `npx lcon <command> --help` for detailed options, or see [Examples](https://learnosity.github.io/lib-qti-converter/#/EXAMPLES) for usage scenarios.
141
+ Run `lcon <command> --help` for detailed options, or see [Examples](https://learnosity.github.io/lib-qti-converter/#/EXAMPLES) for usage scenarios.
136
142
 
137
143
  ## QTI Validation (not bundled)
138
144
 
@@ -24,12 +24,18 @@ pnpm install
24
24
  pnpm run build
25
25
  ```
26
26
 
27
+ After building, you can run the CLI directly via the local wrapper (no `npx` overhead):
28
+
29
+ ```bash
30
+ node bin/lcon.js -i
31
+ ```
32
+
27
33
  ## Quick Start — CLI
28
34
 
29
35
  ### Convert a Single QTI Item to Learnosity
30
36
 
31
37
  ```bash
32
- npx lcon qti-to-learnosity \
38
+ lcon qti-to-learnosity \
33
39
  --in path/to/item.xml \
34
40
  --out path/to/output.json \
35
41
  --pretty
@@ -38,7 +44,7 @@ npx lcon qti-to-learnosity \
38
44
  ### Convert a Learnosity Item to QTI
39
45
 
40
46
  ```bash
41
- npx lcon learnosity-to-qti \
47
+ lcon learnosity-to-qti \
42
48
  --in path/to/item.json \
43
49
  --out path/to/output.xml \
44
50
  --qti-version 2.2
@@ -49,9 +55,9 @@ npx lcon learnosity-to-qti \
49
55
  If you prefer prompts for options:
50
56
 
51
57
  ```bash
52
- npx lcon qti-to-learnosity --interactive
58
+ lcon qti-to-learnosity --interactive
53
59
  # or
54
- npx lcon -i
60
+ lcon -i
55
61
  ```
56
62
 
57
63
  Interactive mode will prompt you for:
@@ -0,0 +1,291 @@
1
+ # Learnosity Tags to QTI Metadata
2
+
3
+ When converting Learnosity bundles to QTI Content Packages, the converter automatically converts Learnosity tags to IMS LOM (Learning Object Metadata) XML files.
4
+
5
+ ## Overview
6
+
7
+ The converter supports one metadata output format:
8
+
9
+ - **LOM (Learning Object Metadata)** - IMS standard metadata format (v1.2)
10
+
11
+ Each Learnosity item's `tags` object is converted to a standalone `.lom.xml` file included in the output package.
12
+
13
+ > **Note:** Common Cartridge Curriculum Standards Metadata is **not** generated in the export direction. Tags are only serialized as LOM classifications.
14
+
15
+ ## Tag Input Format
16
+
17
+ The converter accepts Learnosity tags in the **object format** — a JSON object where keys are tag types and values are arrays of tag names:
18
+
19
+ ```json
20
+ {
21
+ "reference": "item_001",
22
+ "tags": {
23
+ "subject": ["Mathematics", "Algebra"],
24
+ "grade-level": ["Grade 5"],
25
+ "difficulty": ["Easy"]
26
+ }
27
+ }
28
+ ```
29
+
30
+ ### Tag Normalization
31
+
32
+ During parsing, the following normalization is applied:
33
+
34
+ - Empty or whitespace-only tag names are filtered out
35
+ - Tag names are trimmed of leading/trailing whitespace
36
+ - Tag names are **de-duplicated** within each type
37
+ - Tag types with no valid tag names after filtering are omitted
38
+
39
+ ## LOM Output Format
40
+
41
+ ### Standalone LOM File
42
+
43
+ For each item with tags, a standalone file is generated at `metadata/<item-reference>.lom.xml`:
44
+
45
+ ```xml
46
+ <?xml version="1.0" encoding="UTF-8"?>
47
+ <imsmd:lom
48
+ xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
49
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
50
+
51
+ <imsmd:general>
52
+ <imsmd:catalogentry>
53
+ <imsmd:catalog>learnosity</imsmd:catalog>
54
+ <imsmd:entry>
55
+ <imsmd:langstring xml:lang="en">item_001</imsmd:langstring>
56
+ </imsmd:entry>
57
+ </imsmd:catalogentry>
58
+ </imsmd:general>
59
+
60
+ <imsmd:classification>
61
+ <imsmd:taxonpath>
62
+ <imsmd:source>
63
+ <imsmd:langstring xml:lang="en">difficulty</imsmd:langstring>
64
+ </imsmd:source>
65
+ <imsmd:taxon>
66
+ <imsmd:entry>
67
+ <imsmd:langstring xml:lang="en">Easy</imsmd:langstring>
68
+ </imsmd:entry>
69
+ </imsmd:taxon>
70
+ </imsmd:taxonpath>
71
+ </imsmd:classification>
72
+
73
+ <imsmd:classification>
74
+ <imsmd:taxonpath>
75
+ <imsmd:source>
76
+ <imsmd:langstring xml:lang="en">grade-level</imsmd:langstring>
77
+ </imsmd:source>
78
+ <imsmd:taxon>
79
+ <imsmd:entry>
80
+ <imsmd:langstring xml:lang="en">Grade 5</imsmd:langstring>
81
+ </imsmd:entry>
82
+ </imsmd:taxon>
83
+ </imsmd:taxonpath>
84
+ </imsmd:classification>
85
+
86
+ <imsmd:classification>
87
+ <imsmd:taxonpath>
88
+ <imsmd:source>
89
+ <imsmd:langstring xml:lang="en">subject</imsmd:langstring>
90
+ </imsmd:source>
91
+ <imsmd:taxon>
92
+ <imsmd:entry>
93
+ <imsmd:langstring xml:lang="en">Algebra</imsmd:langstring>
94
+ </imsmd:entry>
95
+ </imsmd:taxon>
96
+ <imsmd:taxon>
97
+ <imsmd:entry>
98
+ <imsmd:langstring xml:lang="en">Mathematics</imsmd:langstring>
99
+ </imsmd:entry>
100
+ </imsmd:taxon>
101
+ </imsmd:taxonpath>
102
+ </imsmd:classification>
103
+
104
+ </imsmd:lom>
105
+ ```
106
+
107
+ ### Manifest Reference
108
+
109
+ The LOM file is referenced in `imsmanifest.xml` within the item's `<resource>` element:
110
+
111
+ ```xml
112
+ <resource identifier="item_item_001" type="imsqti_item_xmlv2p2" href="items/item_001.xml">
113
+ <file href="items/item_001.xml"/>
114
+ <file href="metadata/item_001.lom.xml"/>
115
+ </resource>
116
+ ```
117
+
118
+ The LOM content is **not** embedded inline in the manifest — it is stored as a separate file.
119
+
120
+ ## Mapping
121
+
122
+ | Learnosity | QTI LOM |
123
+ | ---------------------- | ----------------------------------------------------------------------- |
124
+ | Tag type (object key) | `<imsmd:source>/<imsmd:langstring>` |
125
+ | Tag name (array value) | `<imsmd:taxon>/<imsmd:entry>/<imsmd:langstring>` |
126
+ | Item reference | `<imsmd:general>/<imsmd:catalogentry>/<imsmd:entry>/<imsmd:langstring>` |
127
+
128
+ ### Structure
129
+
130
+ - One `<imsmd:classification>` element per tag type
131
+ - One `<imsmd:taxon>` element per tag name within a classification
132
+ - The `<imsmd:general>` section identifies the item via a `<imsmd:catalogentry>` with catalog `learnosity`
133
+
134
+ ## Sorting and Determinism
135
+
136
+ The converter produces **deterministic output** by sorting:
137
+
138
+ - **Tag types** are sorted lexicographically (e.g., `difficulty` before `grade-level` before `subject`)
139
+ - **Tag names** within each type are sorted alphabetically (e.g., `Algebra` before `Mathematics`)
140
+
141
+ This ensures that the same input always produces identical output, regardless of the original key order in the JSON.
142
+
143
+ ## XML Formatting
144
+
145
+ - Uses IMS Metadata v1.2 namespace (`http://www.imsglobal.org/xsd/imsmd_v1p2`)
146
+ - Uses **lowercase** IMS MD v1.2 element names: `imsmd:taxonpath`, `imsmd:langstring`
147
+ - All `<imsmd:langstring>` elements include `xml:lang="en"`
148
+ - XML special characters in tag types and tag names are escaped (`&`, `<`, `>`, `"`, `'`)
149
+
150
+ ## Items Without Tags
151
+
152
+ If an item has no `tags` property, an empty tags object, or all tag names are empty/whitespace, **no LOM metadata file is generated** for that item and no metadata file reference appears in the manifest.
153
+
154
+ ## Tag Validation
155
+
156
+ Unlike the QTI-to-Learnosity direction, the Learnosity-to-QTI export does **not** enforce a maximum tag length or provide a truncation option. All tag types and tag names are written to LOM as-is (after trimming and de-duplication).
157
+
158
+ ## Complete Example
159
+
160
+ ### Input (Learnosity JSON)
161
+
162
+ ```json
163
+ {
164
+ "reference": "math_q1",
165
+ "tags": {
166
+ "standard": ["CCSS.MATH.CONTENT.HSA.REI.A.1", "CCSS.MATH.CONTENT.HSA.REI.B.3"],
167
+ "subject": ["Mathematics"],
168
+ "grade-level": ["Grade 9", "Grade 10"]
169
+ },
170
+ "questions": [...]
171
+ }
172
+ ```
173
+
174
+ ### Output: `metadata/math_q1.lom.xml`
175
+
176
+ ```xml
177
+ <?xml version="1.0" encoding="UTF-8"?>
178
+ <imsmd:lom
179
+ xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
180
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
181
+
182
+ <imsmd:general>
183
+ <imsmd:catalogentry>
184
+ <imsmd:catalog>learnosity</imsmd:catalog>
185
+ <imsmd:entry>
186
+ <imsmd:langstring xml:lang="en">math_q1</imsmd:langstring>
187
+ </imsmd:entry>
188
+ </imsmd:catalogentry>
189
+ </imsmd:general>
190
+
191
+ <imsmd:classification>
192
+ <imsmd:taxonpath>
193
+ <imsmd:source>
194
+ <imsmd:langstring xml:lang="en">grade-level</imsmd:langstring>
195
+ </imsmd:source>
196
+ <imsmd:taxon>
197
+ <imsmd:entry>
198
+ <imsmd:langstring xml:lang="en">Grade 10</imsmd:langstring>
199
+ </imsmd:entry>
200
+ </imsmd:taxon>
201
+ <imsmd:taxon>
202
+ <imsmd:entry>
203
+ <imsmd:langstring xml:lang="en">Grade 9</imsmd:langstring>
204
+ </imsmd:entry>
205
+ </imsmd:taxon>
206
+ </imsmd:taxonpath>
207
+ </imsmd:classification>
208
+
209
+ <imsmd:classification>
210
+ <imsmd:taxonpath>
211
+ <imsmd:source>
212
+ <imsmd:langstring xml:lang="en">standard</imsmd:langstring>
213
+ </imsmd:source>
214
+ <imsmd:taxon>
215
+ <imsmd:entry>
216
+ <imsmd:langstring xml:lang="en">CCSS.MATH.CONTENT.HSA.REI.A.1</imsmd:langstring>
217
+ </imsmd:entry>
218
+ </imsmd:taxon>
219
+ <imsmd:taxon>
220
+ <imsmd:entry>
221
+ <imsmd:langstring xml:lang="en">CCSS.MATH.CONTENT.HSA.REI.B.3</imsmd:langstring>
222
+ </imsmd:entry>
223
+ </imsmd:taxon>
224
+ </imsmd:taxonpath>
225
+ </imsmd:classification>
226
+
227
+ <imsmd:classification>
228
+ <imsmd:taxonpath>
229
+ <imsmd:source>
230
+ <imsmd:langstring xml:lang="en">subject</imsmd:langstring>
231
+ </imsmd:source>
232
+ <imsmd:taxon>
233
+ <imsmd:entry>
234
+ <imsmd:langstring xml:lang="en">Mathematics</imsmd:langstring>
235
+ </imsmd:entry>
236
+ </imsmd:taxon>
237
+ </imsmd:taxonpath>
238
+ </imsmd:classification>
239
+
240
+ </imsmd:lom>
241
+ ```
242
+
243
+ ### Output: `imsmanifest.xml` (resource entry)
244
+
245
+ ```xml
246
+ <resource identifier="item_math_q1" type="imsqti_item_xmlv2p2" href="items/math_q1.xml">
247
+ <file href="items/math_q1.xml"/>
248
+ <file href="metadata/math_q1.lom.xml"/>
249
+ </resource>
250
+ ```
251
+
252
+ ## Package Structure
253
+
254
+ A typical output package contains:
255
+
256
+ ```
257
+ output.zip/
258
+ imsmanifest.xml
259
+ assessmentTest.xml
260
+ items/
261
+ item_001.xml
262
+ item_002.xml
263
+ metadata/
264
+ item_001.lom.xml
265
+ item_002.lom.xml
266
+ assets/
267
+ image1.png
268
+ ```
269
+
270
+ The `metadata/` folder is only present when at least one item has tags.
271
+
272
+ ---
273
+
274
+ ## Differences from QTI-to-Learnosity Direction
275
+
276
+ | Aspect | QTI → Learnosity | Learnosity → QTI |
277
+ | --------------------- | ---------------------------------- | --------------------- |
278
+ | Formats supported | LOM + Common Cartridge | LOM only |
279
+ | Metadata location | Manifest inline + standalone files | Standalone files only |
280
+ | Tag length validation | 255-char limit enforced | No length validation |
281
+ | Truncation option | `--truncate-tags` available | Not applicable |
282
+ | Merge behavior | Manifest tags take priority | N/A (single source) |
283
+
284
+ ---
285
+
286
+ ## See Also
287
+
288
+ - [QTI Metadata to Learnosity Tags](./QTI_METADATA_TO_TAGS.md) - The reverse direction (QTI → Learnosity)
289
+ - [Supported Interactions](https://learnosity.github.io/lib-qti-converter/#/SUPPORTED_INTERACTIONS) - Complete list of QTI ↔ Learnosity interaction mappings
290
+ - [Getting Started](https://learnosity.github.io/lib-qti-converter/#/GETTING_STARTED) - Installation and basic usage
291
+ - [Examples](https://learnosity.github.io/lib-qti-converter/#/EXAMPLES) - Conversion examples
package/docs/_sidebar.md CHANGED
@@ -1,12 +1,13 @@
1
1
  - **Getting Started**
2
- - [Installation & Quick Start](GETTING_STARTED.md)
2
+ - [Installation & Quick Start](GETTING_STARTED.md)
3
3
  - **Reference**
4
- - [Supported Interactions](SUPPORTED_INTERACTIONS.md)
5
- - [QTI Structure](QTI_STRUCTURE.md)
6
- - [Learnosity Bundle Format](LEARNOSITY_BUNDLE_FORMAT.md)
7
- - [Learnosity Sections](LEARNOSITY_SECTIONS.md)
8
- - [QTI Metadata to Tags](QTI_METADATA_TO_TAGS.md)
9
- - [Diagnostics](DIAGNOSTICS.md)
4
+ - [Supported Interactions](SUPPORTED_INTERACTIONS.md)
5
+ - [QTI Structure](QTI_STRUCTURE.md)
6
+ - [Learnosity Bundle Format](LEARNOSITY_BUNDLE_FORMAT.md)
7
+ - [Learnosity Sections](LEARNOSITY_SECTIONS.md)
8
+ - [QTI Metadata to Tags](QTI_METADATA_TO_TAGS.md)
9
+ - [Tags to QTI Metadata](TAGS_TO_QTI_METADATA.md)
10
+ - [Diagnostics](DIAGNOSTICS.md)
10
11
  - **More**
11
- - [Examples](EXAMPLES.md)
12
- - [FAQ](FAQ.md)
12
+ - [Examples](EXAMPLES.md)
13
+ - [FAQ](FAQ.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@learnosity/lib-qti-converter",
3
- "version": "0.12.1",
3
+ "version": "0.12.3",
4
4
  "type": "module",
5
5
  "description": "QTI ↔ Learnosity JSON converter",
6
6
  "license": "MIT",
@@ -72,19 +72,19 @@
72
72
  },
73
73
  "devDependencies": {
74
74
  "@arethetypeswrong/cli": "^0.18.5",
75
- "@types/node": "^26.2.0",
76
- "@typescript-eslint/eslint-plugin": "^8.67.0",
77
- "@typescript-eslint/parser": "^8.67.0",
75
+ "@types/node": "^26.3.0",
76
+ "@typescript-eslint/eslint-plugin": "^8.68.0",
77
+ "@typescript-eslint/parser": "^8.68.0",
78
78
  "@typescript/native": "npm:typescript@^7.0.2",
79
- "@vitest/coverage-v8": "^4.1.10",
80
- "eslint": "^10.8.1",
79
+ "@vitest/coverage-v8": "^4.1.11",
80
+ "eslint": "^10.9.1",
81
81
  "glob": "^13.0.6",
82
- "publint": "^0.3.23",
82
+ "publint": "^0.3.24",
83
83
  "tsdown": "^0.22.14",
84
84
  "tsx": "^4.23.12",
85
85
  "typescript": "npm:@typescript/typescript6@^6.0.2",
86
- "vite": "^8.2.1",
87
- "vitest": "^4.1.10"
86
+ "vite": "^8.2.2",
87
+ "vitest": "^4.1.11"
88
88
  },
89
89
  "engines": {
90
90
  "node": ">=22.0.0"
@@ -0,0 +1,215 @@
1
+ import { n as formatDiagnosticsSummaryTable, s as writeDiagnostics } from "./table-DYcNeyJ_.js";
2
+ import { buildPackageFromActivity, convertActivity, convertQtiPackageToLearnosityBundle, ensureUniqueFolderName, loadLearnosityBundle, loadPackageDirectory, mergeActivityPackage, nodeFileAccess, sanitizeFolderName, saveQtiContentPackage, writeLearnosityBundle } from "@learnosity/converter-core/node";
3
+ //#region src/utils/batchProcessors.ts
4
+ /**
5
+ * Per-package conversion tasks, shared by the serial batch path
6
+ * (`processBatch`) and the parallel worker path (`processBatchParallel` via
7
+ * `batchWorker`). Extracting them here keeps a single implementation per
8
+ * direction — the same code runs inline or inside a worker thread.
9
+ */
10
+ /** Run one batch task in-process (used by the worker and directly in tests). */
11
+ async function runBatchTask(task, quiet = true) {
12
+ if (task.direction === "qti-to-learnosity") return processQtiPackageToLearnosity(task.pkg, task.packageOutputPath, task.options, quiet);
13
+ return processLearnosityToQtiPackage(task.pkg, task.packageOutputPath, task.options, quiet);
14
+ }
15
+ function displayDiagnosticsSummary(diagnostics, quiet) {
16
+ if (quiet) return;
17
+ const summaryTable = formatDiagnosticsSummaryTable(diagnostics);
18
+ if (summaryTable) {
19
+ console.log(" Diagnostics:");
20
+ console.log(summaryTable.split("\n").map((line) => " " + line).join("\n"));
21
+ console.log("");
22
+ }
23
+ }
24
+ /** Convert one QTI Content Package directory to a Learnosity bundle on disk. */
25
+ async function processQtiPackageToLearnosity(pkg, packageOutputPath, options, quiet) {
26
+ const loaded = loadPackageDirectory(pkg.path);
27
+ const convertResult = loaded.entries ? convertQtiPackageToLearnosityBundle({ entries: loaded.entries }, {
28
+ organisationId: options.organisationId,
29
+ mediaVault: options.mediaVault,
30
+ customAssetUrl: options.customAssetUrl,
31
+ itemReferenceSource: options.itemReferenceSource,
32
+ itemFilenameSource: options.itemFilenameSource,
33
+ truncateTags: options.truncateTags,
34
+ packageVersion: options.version,
35
+ sourceDir: pkg.path,
36
+ fileAccess: nodeFileAccess
37
+ }) : { diagnostics: loaded.diagnostics };
38
+ const errors = convertResult.diagnostics.filter((d) => d.level === "error");
39
+ const warnings = convertResult.diagnostics.filter((d) => d.level === "warning");
40
+ const hasValidBundle = convertResult.bundle && convertResult.bundle.items.size > 0;
41
+ const convertedFiles = convertResult.convertedSourceFiles || [];
42
+ const failedFiles = convertResult.failedSourceFiles || [];
43
+ const filesWithErrors = /* @__PURE__ */ new Set();
44
+ for (const d of convertResult.diagnostics) if (d.level === "error" && d.file) filesWithErrors.add(d.file);
45
+ const convertedWithErrors = convertedFiles.filter((f) => filesWithErrors.has(f)).length;
46
+ const erroredItemCount = failedFiles.length + convertedWithErrors;
47
+ const cleanItemCount = convertedFiles.length - convertedWithErrors;
48
+ if (errors.length > 0 && !hasValidBundle) return {
49
+ success: false,
50
+ errorCount: errors.length,
51
+ warningCount: warnings.length,
52
+ convertedItemCount: cleanItemCount,
53
+ failedItemCount: erroredItemCount,
54
+ message: "Conversion failed"
55
+ };
56
+ const writeResult = await writeLearnosityBundle(convertResult.bundle, {
57
+ outDir: packageOutputPath,
58
+ isZipOutput: false
59
+ });
60
+ const writeErrors = writeResult.diagnostics.filter((d) => d.level === "error");
61
+ if (writeErrors.length > 0) return {
62
+ success: false,
63
+ errorCount: errors.length + writeErrors.length,
64
+ warningCount: warnings.length,
65
+ convertedItemCount: cleanItemCount,
66
+ failedItemCount: erroredItemCount,
67
+ message: "Write failed"
68
+ };
69
+ const diagnosticsPath = `${packageOutputPath}/diagnostics.json`;
70
+ const allDiagnostics = [...convertResult.diagnostics, ...writeResult.diagnostics];
71
+ const convertedActivityFiles = convertResult.convertedActivityFiles || [];
72
+ await writeDiagnostics(allDiagnostics, "file", diagnosticsPath, packageOutputPath, false, {
73
+ inputPath: pkg.path,
74
+ outputPath: packageOutputPath,
75
+ totalItemsFound: convertedFiles.length + failedFiles.length,
76
+ totalActivitiesFound: convertedActivityFiles.length,
77
+ convertedFiles,
78
+ failedFiles,
79
+ convertedActivities: convertedActivityFiles
80
+ });
81
+ if (!quiet) {
82
+ const summaryTable = formatDiagnosticsSummaryTable(allDiagnostics);
83
+ if (summaryTable) {
84
+ console.log(" Diagnostics:");
85
+ console.log(summaryTable.split("\n").map((line) => " " + line).join("\n"));
86
+ console.log("");
87
+ }
88
+ }
89
+ return {
90
+ success: true,
91
+ errorCount: errors.length,
92
+ warningCount: warnings.length,
93
+ convertedItemCount: cleanItemCount,
94
+ failedItemCount: erroredItemCount
95
+ };
96
+ }
97
+ /** Convert one Learnosity bundle directory to a QTI Content Package on disk. */
98
+ async function processLearnosityToQtiPackage(pkg, packageOutputPath, options, quiet) {
99
+ const loadResult = loadLearnosityBundle(pkg.path);
100
+ if (!loadResult.bundle) {
101
+ const errorCount = loadResult.diagnostics.filter((d) => d.level === "error").length;
102
+ displayDiagnosticsSummary(loadResult.diagnostics, quiet);
103
+ return {
104
+ success: false,
105
+ errorCount,
106
+ warningCount: 0,
107
+ message: "Bundle load error"
108
+ };
109
+ }
110
+ const bundle = loadResult.bundle;
111
+ const allDiagnostics = [...loadResult.diagnostics];
112
+ const allConvertedActivities = [];
113
+ const usedFolderNames = /* @__PURE__ */ new Set();
114
+ const convertedItemRefs = /* @__PURE__ */ new Set();
115
+ const failedItemRefs = /* @__PURE__ */ new Set();
116
+ for (const activityRef of bundle.activityRefs) {
117
+ const convertResult = convertActivity(bundle, activityRef, {
118
+ pretty: options.pretty,
119
+ version: options.qtiVersion
120
+ });
121
+ allDiagnostics.push(...convertResult.diagnostics);
122
+ const itemRefs = bundle.activityItemRefs.get(activityRef) ?? [];
123
+ const successfulItemRefs = new Set(convertResult.items.map((item) => item.reference));
124
+ for (const itemRef of itemRefs) if (successfulItemRefs.has(itemRef)) convertedItemRefs.add(itemRef);
125
+ else failedItemRefs.add(itemRef);
126
+ if (convertResult.items.length > 0) {
127
+ const sanitizedName = sanitizeFolderName(activityRef, `activity_${allConvertedActivities.length + 1}`);
128
+ const folderName = ensureUniqueFolderName(sanitizedName, usedFolderNames);
129
+ allConvertedActivities.push({
130
+ activityRef,
131
+ folderName,
132
+ conversion: convertResult
133
+ });
134
+ }
135
+ }
136
+ for (const itemRef of convertedItemRefs) failedItemRefs.delete(itemRef);
137
+ const convertedFiles = itemRefsToFilenames(bundle, convertedItemRefs);
138
+ const failedFiles = itemRefsToFilenames(bundle, failedItemRefs);
139
+ const convertedActivityFiles = allConvertedActivities.map(({ activityRef }) => `activities/${activityRef}.json`);
140
+ const failedActivityFiles = bundle.activityRefs.filter((ref) => !allConvertedActivities.some((a) => a.activityRef === ref)).map((ref) => `activities/${ref}.json`);
141
+ const totalItemsConverted = convertedItemRefs.size;
142
+ const totalItemsFailed = failedItemRefs.size;
143
+ const writePackageDiagnostics = () => writeDiagnostics(allDiagnostics, "file", `${packageOutputPath}/diagnostics.json`, packageOutputPath, false, {
144
+ inputPath: pkg.path,
145
+ outputPath: packageOutputPath,
146
+ totalItemsFound: totalItemsConverted + totalItemsFailed,
147
+ totalActivitiesFound: bundle.activityRefs.length,
148
+ convertedFiles,
149
+ failedFiles,
150
+ convertedActivities: convertedActivityFiles,
151
+ failedActivities: failedActivityFiles
152
+ });
153
+ if (allConvertedActivities.length === 0) {
154
+ const errorCount = allDiagnostics.filter((d) => d.level === "error").length;
155
+ await writePackageDiagnostics();
156
+ return {
157
+ success: false,
158
+ errorCount,
159
+ warningCount: allDiagnostics.filter((d) => d.level === "warning").length,
160
+ convertedItemCount: 0,
161
+ failedItemCount: totalItemsFailed,
162
+ message: "No activities converted"
163
+ };
164
+ }
165
+ const pkgData = {
166
+ zipPath: "",
167
+ resources: [],
168
+ entries: /* @__PURE__ */ new Map(),
169
+ items: [],
170
+ assets: []
171
+ };
172
+ const addedResourceIds = /* @__PURE__ */ new Set();
173
+ for (const { activityRef, folderName, conversion } of allConvertedActivities) {
174
+ const packageResult = buildPackageFromActivity(conversion, {
175
+ bundleDir: pkg.path,
176
+ activityRef,
177
+ version: options.qtiVersion
178
+ });
179
+ allDiagnostics.push(...packageResult.diagnostics);
180
+ mergeActivityPackage(pkgData, folderName, packageResult, addedResourceIds);
181
+ }
182
+ const saveResult = saveQtiContentPackage(pkgData, packageOutputPath);
183
+ allDiagnostics.push(...saveResult.diagnostics);
184
+ const errors = allDiagnostics.filter((d) => d.level === "error");
185
+ const warnings = allDiagnostics.filter((d) => d.level === "warning");
186
+ await writePackageDiagnostics();
187
+ displayDiagnosticsSummary(allDiagnostics, quiet);
188
+ if (errors.length > 0) return {
189
+ success: false,
190
+ errorCount: errors.length,
191
+ warningCount: warnings.length,
192
+ convertedItemCount: totalItemsConverted,
193
+ failedItemCount: totalItemsFailed,
194
+ message: "Conversion failed"
195
+ };
196
+ return {
197
+ success: true,
198
+ errorCount: 0,
199
+ warningCount: warnings.length,
200
+ convertedItemCount: totalItemsConverted,
201
+ failedItemCount: totalItemsFailed
202
+ };
203
+ }
204
+ /**
205
+ * Map item references to the filenames they were loaded from, for the
206
+ * diagnostics report. Falls back to the reference when the bundle has no
207
+ * filename recorded, so counts always match the listed items.
208
+ */
209
+ function itemRefsToFilenames(bundle, itemRefs) {
210
+ return [...itemRefs].map((itemRef) => bundle.itemRefToFilename.get(itemRef) ?? itemRef);
211
+ }
212
+ //#endregion
213
+ export { processQtiPackageToLearnosity as n, runBatchTask as r, processLearnosityToQtiPackage as t };
214
+
215
+ //# sourceMappingURL=batchProcessors-BfmvnTQ5.js.map