@learnosity/lib-qti-converter 0.12.0 → 0.12.2

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 +7 -7
  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-COXnAzFl.js +1387 -0
  12. package/packages/cli/dist/create-prompt-COXnAzFl.js.map +1 -0
  13. package/packages/cli/dist/dist-CVD-X-DZ.js +278 -0
  14. package/packages/cli/dist/dist-CVD-X-DZ.js.map +1 -0
  15. package/packages/cli/dist/learnosityToQti-sKxcj5Hi.js +102 -0
  16. package/packages/cli/dist/learnosityToQti-sKxcj5Hi.js.map +1 -0
  17. package/packages/cli/dist/learnosityToQtiPackage-Ij4cM39M.js +632 -0
  18. package/packages/cli/dist/learnosityToQtiPackage-Ij4cM39M.js.map +1 -0
  19. package/packages/cli/dist/main.js +32 -37155
  20. package/packages/cli/dist/main.js.map +1 -1
  21. package/packages/cli/dist/pathUtils-Cz2GpPEb.js +2386 -0
  22. package/packages/cli/dist/pathUtils-Cz2GpPEb.js.map +1 -0
  23. package/packages/cli/dist/qtiPackageToLearnosity-CvXdmwsb.js +354 -0
  24. package/packages/cli/dist/qtiPackageToLearnosity-CvXdmwsb.js.map +1 -0
  25. package/packages/cli/dist/qtiToLearnosity-CkD0r1q0.js +97 -0
  26. package/packages/cli/dist/qtiToLearnosity-CkD0r1q0.js.map +1 -0
  27. package/packages/cli/dist/resolveOptions-CfXUqGkd.js +31562 -0
  28. package/packages/cli/dist/resolveOptions-CfXUqGkd.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 +389 -411
  33. package/packages/core/dist/node.js +389 -411
  34. package/packages/cli/dist/batchProcessors-B8EQvMbH.js.map +0 -1
@@ -0,0 +1,102 @@
1
+ import { n as loadConfig, r as showBanner } from "./pathUtils-Cz2GpPEb.js";
2
+ import { r as formatDiagnosticsTable, s as writeDiagnostics, t as countErrors } from "./table-DYcNeyJ_.js";
3
+ import { a as parseJsonInput, i as writeOutput, n as ProgressTracker, o as readInput, r as showResolvedOptions, s as convertLearnosityToQti, t as resolveOptions } from "./resolveOptions-CfXUqGkd.js";
4
+ import { copyFile, mkdir } from "fs/promises";
5
+ import { basename, dirname, join } from "path";
6
+ //#region src/commands/learnosityToQti.ts
7
+ /**
8
+ * Register learnosity-to-qti command
9
+ */
10
+ function registerLearnosityToQtiCommand(program, version) {
11
+ program.command("learnosity-to-qti").description("Convert a single Learnosity item to QTI").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("--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", "Verbose output (default: false)").option("--pretty", "Pretty-print JSON output (default: false)").option("-q, --quiet", "Suppress non-essential output (default: false)").option("--include-learnosity-source", "Copy input file to source/ folder alongside output (default: false)").action(async (opts) => {
12
+ await executeLearnosityToQti(opts, version);
13
+ });
14
+ }
15
+ async function copySourceFile(inputPath, outputPath) {
16
+ const outputDir = dirname(outputPath);
17
+ const sourceDir = join(outputDir, "source");
18
+ await mkdir(sourceDir, { recursive: true });
19
+ await copyFile(inputPath, join(sourceDir, basename(inputPath)));
20
+ }
21
+ /**
22
+ * Execute learnosity-to-qti conversion
23
+ */
24
+ async function executeLearnosityToQti(cliOpts, version) {
25
+ const allDiagnostics = [];
26
+ const quiet = cliOpts.quiet ?? false;
27
+ try {
28
+ showBanner("learnosity-to-qti", version, quiet);
29
+ const { config, diagnostics: configDiagnostics, configPath } = await loadConfig(cliOpts.config, cliOpts.noConfig);
30
+ allDiagnostics.push(...configDiagnostics);
31
+ if (configDiagnostics.filter((d) => d.level === "error").length > 0) {
32
+ console.log("\n" + formatDiagnosticsTable(configDiagnostics));
33
+ process.exit(1);
34
+ }
35
+ const { options: resolved, diagnostics: resolveDiagnostics, withSources } = await resolveOptions(cliOpts, config, false, configPath);
36
+ allDiagnostics.push(...resolveDiagnostics);
37
+ showResolvedOptions(resolved, withSources, quiet);
38
+ const progress = new ProgressTracker(resolved.verbose);
39
+ progress.startStage("Reading input...");
40
+ const inputText = await readInput(resolved.inputPath);
41
+ const input = parseJsonInput(inputText);
42
+ progress.succeedStage("Input read");
43
+ progress.startStage("Converting Learnosity to QTI...");
44
+ const conversionOpts = {
45
+ qtiVersion: resolved.qtiVersion,
46
+ outputFormat: resolved.outputFormat,
47
+ diagnostics: resolved.diagnostics,
48
+ verbose: resolved.verbose,
49
+ pretty: resolved.pretty
50
+ };
51
+ const result = await convertLearnosityToQti(input, conversionOpts);
52
+ const inputFilename = resolved.inputPath.split("/").pop() ?? resolved.inputPath;
53
+ const prefixedDiagnostics = result.diagnostics.map((d) => ({
54
+ ...d,
55
+ file: inputFilename
56
+ }));
57
+ allDiagnostics.push(...prefixedDiagnostics);
58
+ progress.succeedStage("Conversion complete");
59
+ if (countErrors(allDiagnostics) > 0) {
60
+ progress.failStage("Conversion failed");
61
+ console.log("\n" + formatDiagnosticsTable(allDiagnostics));
62
+ process.exit(1);
63
+ }
64
+ if (result.output) {
65
+ progress.startStage("Writing output...");
66
+ await writeOutput(resolved.outputPath, result.output, resolved.pretty);
67
+ progress.succeedStage("Output written");
68
+ }
69
+ if (cliOpts.includeLearnositySource && resolved.inputPath !== "-" && resolved.outputPath !== "-") {
70
+ progress.startStage("Copying source file...");
71
+ await copySourceFile(resolved.inputPath, resolved.outputPath);
72
+ progress.succeedStage("Source file copied");
73
+ }
74
+ if (resolved.diagnostics !== "none") {
75
+ progress.startStage("Writing diagnostics...");
76
+ const hasErrors = allDiagnostics.some((d) => d.level === "error");
77
+ await writeDiagnostics(allDiagnostics, resolved.diagnostics, resolved.diagnosticsPath, resolved.outputPath, resolved.verbose, {
78
+ inputPath: resolved.inputPath,
79
+ outputPath: resolved.outputPath,
80
+ totalItemsFound: 1,
81
+ convertedFiles: hasErrors ? [] : [inputFilename],
82
+ failedFiles: hasErrors ? [inputFilename] : []
83
+ });
84
+ progress.succeedStage("Diagnostics written");
85
+ }
86
+ if (resolved.diagnostics === "stderr" || resolved.diagnostics === "both") console.log("\n" + formatDiagnosticsTable(allDiagnostics));
87
+ const warningCount = allDiagnostics.filter((d) => d.level === "warning").length;
88
+ if (warningCount > 0 && cliOpts.failOnWarn) {
89
+ process.stderr.write(`\n${warningCount} warning(s) found - exiting with error (--fail-on-warn)\n`);
90
+ process.exit(1);
91
+ }
92
+ process.exit(0);
93
+ } catch (error) {
94
+ if (error instanceof Error && error.name === "ExitPromptError") process.exit(130);
95
+ console.error("\n" + (error instanceof Error ? error.message : "Unknown error"));
96
+ process.exit(1);
97
+ }
98
+ }
99
+ //#endregion
100
+ export { registerLearnosityToQtiCommand };
101
+
102
+ //# sourceMappingURL=learnosityToQti-sKxcj5Hi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learnosityToQti-sKxcj5Hi.js","names":[],"sources":["../src/commands/learnosityToQti.ts"],"sourcesContent":["import type { Command } from 'commander';\nimport type { ConversionOptions, Diagnostic } from '@learnosity/converter-core';\nimport { convertLearnosityToQti } from '@learnosity/converter-core';\nimport { copyFile, mkdir } from 'fs/promises';\nimport { dirname, join, basename } from 'path';\nimport { readInput, parseJsonInput } 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 learnosity-to-qti command\n */\nexport function registerLearnosityToQtiCommand(program: Command, version: string): void {\n program\n .command('learnosity-to-qti')\n .description('Convert a single Learnosity item to QTI')\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('--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', 'Verbose output (default: false)')\n .option('--pretty', 'Pretty-print JSON output (default: false)')\n .option('-q, --quiet', 'Suppress non-essential output (default: false)')\n .option(\n '--include-learnosity-source',\n 'Copy input file to source/ folder alongside output (default: false)'\n )\n .action(async (opts: CliOptions) => {\n await executeLearnosityToQti(opts, version);\n });\n}\n\nasync function copySourceFile(inputPath: string, outputPath: string): Promise<void> {\n const outputDir = dirname(outputPath);\n\n // Both paths are CLI arguments the operator chose. 'source' is a literal and\n // basename() strips any directory part of inputPath, so the copy stays inside\n // the requested output directory.\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n const sourceDir = join(outputDir, 'source');\n\n await mkdir(sourceDir, { recursive: true });\n // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal, javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal\n await copyFile(inputPath, join(sourceDir, basename(inputPath)));\n}\n\n/**\n * Execute learnosity-to-qti conversion\n */\nasync function executeLearnosityToQti(cliOpts: CliOptions, version: string): Promise<void> {\n const allDiagnostics: Diagnostic[] = [];\n const quiet = cliOpts.quiet ?? false;\n\n try {\n showBanner('learnosity-to-qti', 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 and parse input\n progress.startStage('Reading input...');\n const inputText = await readInput(resolved.inputPath);\n const input = parseJsonInput(inputText);\n\n progress.succeedStage('Input read');\n\n // Convert\n progress.startStage('Converting Learnosity to QTI...');\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 };\n const result = await convertLearnosityToQti(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 // Check for errors before writing output\n const errorCount = countErrors(allDiagnostics);\n\n if (errorCount > 0) {\n progress.failStage('Conversion failed');\n console.log('\\n' + formatDiagnosticsTable(allDiagnostics));\n process.exit(1);\n }\n\n // Write output only if no errors\n if (result.output) {\n progress.startStage('Writing output...');\n await writeOutput(resolved.outputPath, result.output, resolved.pretty);\n progress.succeedStage('Output written');\n }\n\n // Copy source file if requested\n if (\n cliOpts.includeLearnositySource &&\n resolved.inputPath !== '-' &&\n resolved.outputPath !== '-'\n ) {\n progress.startStage('Copying source file...');\n await copySourceFile(resolved.inputPath, resolved.outputPath);\n progress.succeedStage('Source file copied');\n }\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 // Check for warnings if fail-on-warn\n const warningCount = allDiagnostics.filter((d) => d.level === 'warning').length;\n\n if (warningCount > 0 && cliOpts.failOnWarn) {\n process.stderr.write(\n `\\n${warningCount} warning(s) found - exiting with error (--fail-on-warn)\\n`\n );\n process.exit(1);\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"],"mappings":";;;;;;;;;AAmBA,SAAgB,+BAA+B,SAAkB,SAAuB;CACpF,QACK,QAAQ,mBAAmB,CAAC,CAC5B,YAAY,yCAAyC,CAAC,CACtD,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,OAAO,kBAAkB,2DAA2D,CAAC,CACrF,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,OACG,+BACA,qEACJ,CAAC,CACA,OAAO,OAAO,SAAqB;EAChC,MAAM,uBAAuB,MAAM,OAAO;CAC9C,CAAC;AACT;AAEA,eAAe,eAAe,WAAmB,YAAmC;CAChF,MAAM,YAAY,QAAQ,UAAU;CAMpC,MAAM,YAAY,KAAK,WAAW,QAAQ;CAE1C,MAAM,MAAM,WAAW,EAAE,WAAW,KAAK,CAAC;CAE1C,MAAM,SAAS,WAAW,KAAK,WAAW,SAAS,SAAS,CAAC,CAAC;AAClE;;;;AAKA,eAAe,uBAAuB,SAAqB,SAAgC;CACvF,MAAM,iBAA+B,CAAC;CACtC,MAAM,QAAQ,QAAQ,SAAS;CAE/B,IAAI;EACA,WAAW,qBAAqB,SAAS,KAAK;EAG9C,MAAM,EACF,QACA,aAAa,mBACb,eACA,MAAM,WAAW,QAAQ,QAAQ,QAAQ,QAAQ;EAErD,eAAe,KAAK,GAAG,iBAAiB;EAKxC,IAFqB,kBAAkB,QAAQ,MAAM,EAAE,UAAU,OAElD,CAAC,CAA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