document-cli 2.1.5 → 3.0.0
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 +3 -3
- package/dist/cli.js +22 -14
- package/dist/index.cjs +21 -13
- package/dist/index.js +22 -14
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -95,7 +95,7 @@ document-cli convert report.docx - --to pdf > report.pdf
|
|
|
95
95
|
|
|
96
96
|
**`formats`** — lists every `source -> target` pair the commands above support (`--json` for a machine-readable array), plus a pointer to the commands not on that list because they don't fit the source/target shape (`odm-to-pdf`, `odb-to-csv`, `odb-to-xlsx`, `odb-tables`, `odb-forms`, `odb-reports`, `pdf-inspect`, `from-package`, `fonts`, `docx-extras`, `metadata`, `set-metadata`).
|
|
97
97
|
|
|
98
|
-
**`from-package <input> [output]`** — reads back a `DocumentPackage` JSON file a previous conversion wrote via `--dump-package` (below) and exports it to a real target format, closing the round trip `--dump-package` otherwise has no return path for. Target resolution matches `convert`: an output path's own extension, or `--to <format>` when it doesn't have one. `pdf` rebuilds the layout from the package's own recorded positions — each content node's `frames` plus the package's `pages` geometry (`layoutDocumentFromPackage` → `writePdf`; a package no longer carries a separate `layout` half at all); every other format builds a fresh package from the
|
|
98
|
+
**`from-package <input> [output]`** — reads back a `DocumentPackage` JSON file a previous conversion wrote via `--dump-package` (below) and exports it to a real target format, closing the round trip `--dump-package` otherwise has no return path for. Target resolution matches `convert`: an output path's own extension, or `--to <format>` when it doesn't have one. The package this command reads is the tree form since documents.js 3.0.0 — content grouped one group per container (section, slide, sheet, draw page) under `children`, with the minted `styles` table at the root — flattened once at this boundary, exactly as documents.js's own builders do. `pdf` rebuilds the layout from the package's own recorded positions — each content node's `frames` plus the package's `pages` geometry (`layoutDocumentFromPackage` → `writePdf`; a package no longer carries a separate `layout` half at all); every other format builds a fresh package from the flattened content through the identical `buildXPackage` function the matching `pdf-to-X`/bridge conversion already uses — `xlsx` included, via `ooxml.js`'s own `buildXlsxPackage`. `odf` is the one target rejected outright, since a standalone formula document has no write path from `ContentDocument` at all; a `csv` or `svg` target is written through the identical `buildCsvText`/`buildSvgText` functions the codec registry's own write wrappers call, so the `--delimiter`/`--sheet`/`--page` selection flags below reach it exactly as they do a live conversion. Only a file genuinely written by a current `--dump-package` round-trips here: the `$schema` URI a dump carries pins the document-schema.js release that wrote it, and any pre-4.0.0 dump — the flat `{ formatVersion, content, pages }` envelope documents.js 1.x/2.x wrote, whatever its `formatVersion` — is rejected with an error naming the pinned release, the flat-to-tree change, and the remedy, rather than a raw validation wall. A layout-document dump (a document-schema.js 3.x layout artefact, e.g. an old `pdf-inspect --full` output) gets its own pointer: that schema moved to pdf-codec.
|
|
99
99
|
|
|
100
100
|
```sh
|
|
101
101
|
document-cli docx-to-pdf report.docx report.pdf --dump-package report.package.json
|
|
@@ -132,7 +132,7 @@ document-cli odb-query sales.odb --query HighValueSales --json
|
|
|
132
132
|
document-cli odb-render-report sales.odb SalesByRegion.pdf --report SalesByRegion
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
**`pdf-inspect <input>`** — reports a PDF's page count, per-page size and item-kind histogram, document metadata, and embedded image formats, without converting it to anything. `--full` dumps the entire parsed `LayoutDocument` as JSON instead of the summary:
|
|
135
|
+
**`pdf-inspect <input>`** — reports a PDF's page count, per-page size and item-kind histogram, document metadata, and embedded image formats, without converting it to anything. `--full` dumps the entire parsed `LayoutDocument` as plain JSON (no `$schema` stamp — that family moved to pdf-codec at document-schema.js 4.0.0 and lost its schema-stamped envelope) instead of the summary:
|
|
136
136
|
|
|
137
137
|
```sh
|
|
138
138
|
document-cli pdf-inspect report.pdf
|
|
@@ -180,7 +180,7 @@ The explicit conversions, `convert`, `odm-to-pdf`, `odb-to-xlsx`, `odb-to-csv`,
|
|
|
180
180
|
|
|
181
181
|
Three further flags select what a csv or svg edge of a conversion works on, threaded straight into documents.js's own `ConversionOptions`: `--delimiter <char>` (the field delimiter a csv source reads with, or a csv target writes with — default `,`), `--sheet <name>` (the sheet a csv target writes, required when the source document has more than one), and `--page <index>` (the 0-based page an svg target draws, required when the source document has more than one). On the explicit commands they are registered only where the pair can reach the edge in question — `--delimiter` on any pair with a csv edge, `--sheet` on a csv target, `--page` on an svg target — and unconditionally on `convert` and `from-package`, whose target is only known once the output path or `--to` resolves at run time (the same registration reasoning the font flags below document). Leaving `--sheet` or `--page` unanswered on an ambiguous document fails with exit `3`, naming the sheets or page count to pick from:
|
|
182
182
|
|
|
183
|
-
`--dump-package <file>` is one flag further, registered only on the explicit conversions and `convert` — it writes the intermediate `DocumentPackage` (content carrying
|
|
183
|
+
`--dump-package <file>` is one flag further, registered only on the explicit conversions and `convert` — it writes the intermediate `DocumentPackage` (the tree form: content grouped one group per container, the content nodes carrying their own rendered `frames`, plus the `pages` geometry those frames index into and the minted `styles` table at the root) that conversion built to a JSON file, tagged with its own version-pinned `$schema` — the URI *is* the package's version — so `from-package` (above) can read it back in. Every conversion populates one, `odf-to-pdf` included — its dump carries a `formula`-kind content and the one A4 page it renders (the formula's glyphs travel through the PDF writer's own positioned-formula channel rather than as frame-stamped page content); every PDF-bypassing bridge (`ods-to-xlsx`, `docx-to-pptx`, `odg-to-svg`, and every other content-format pair above) populates one too, just with `pages` always absent, since a bridge never runs a layout engine. `odm-to-pdf`/`odb-*`/`set-metadata` don't expose the flag at all, since none of them goes through `DocumentConverter.convert` in the first place. `odb-tables`, `odb-forms`, `odb-reports`, `fonts`, `docx-extras`, `metadata`, `formats`, and `pdf-inspect` each take only their own `--json` (plus `pdf-inspect`'s own `--full`); `odb-query` takes `--sql <text>`/`--query <savedName>` (mutually exclusive) alongside its own `--json`, with none of the shared flags above since it only reads and writes nothing; `from-package` and `set-metadata` each take `--to <format>` alongside the shared flags in this table; `odb-render-report` takes `--report <name>` and `--to <format>` alongside the shared flags and the font flags below; `tui` takes no flags at all, only an optional positional file.
|
|
184
184
|
|
|
185
185
|
### Real fonts
|
|
186
186
|
|
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import { a as odbFormSummary, c as formatDocxExtrasLines, d as writeOutput, f as
|
|
|
3
3
|
import { Command, CommanderError, InvalidArgumentError } from "commander";
|
|
4
4
|
import { writeFile } from "node:fs/promises";
|
|
5
5
|
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
6
|
-
import { CsvSheetNotFoundError, CsvSheetNotSpecifiedError, HsqldbSqlEvaluationError, HsqldbSqlParseError, HsqldbSqlUnsupportedError, OdbNoEmbeddedDataSourceError, OdbReportNotSpecifiedError, OdbTableNotFoundError, OdbTableNotSpecifiedError, OdbUnsupportedFormatError, OdmUnresolvedSectionError, PdfEncryptedError, PdfParseError, SvgMultiPageNotSpecifiedError, SvgPageNotFoundError, UnrecognizedDocumentSchemaError, UnsupportedFontSourceFormatError, buildCsvText, buildDocumentBytes, buildSvgText, createLocalDocumentConverter, decodeOdbPackage, decodePackage, documentFromJson, documentPackageWithSchema,
|
|
6
|
+
import { CsvSheetNotFoundError, CsvSheetNotSpecifiedError, HsqldbSqlEvaluationError, HsqldbSqlParseError, HsqldbSqlUnsupportedError, OdbNoEmbeddedDataSourceError, OdbReportNotSpecifiedError, OdbTableNotFoundError, OdbTableNotSpecifiedError, OdbUnsupportedFormatError, OdmUnresolvedSectionError, PdfEncryptedError, PdfParseError, SvgMultiPageNotSpecifiedError, SvgPageNotFoundError, UnrecognizedDocumentSchemaError, UnsupportedFontSourceFormatError, buildCsvText, buildDocumentBytes, buildSvgText, createLocalDocumentConverter, decodeOdbPackage, decodePackage, documentFromJson, documentPackageWithSchema, encodeCsvText, encodeSvgText, evaluateSelect, extractSourceFontsForFormat, flattenPackage, hsqldbCellDisplayText, odbReportToDocx, odbReportToOdt, odbReportToPdf, odbToCsv, odbToXlsx, odmToPdf, parseSelect, readDocumentMetadata, readDocxExtras, readOdbForms, readOdbInventory, readOdbReportContent, readOdbReports, readOdbTables, readPdf, setDocumentMetadata } from "documents.js";
|
|
7
7
|
import { existsSync, readFileSync } from "node:fs";
|
|
8
8
|
//#region src/runtime/abort.ts
|
|
9
9
|
function combineSignals(a, b) {
|
|
@@ -220,7 +220,7 @@ function addVerboseOption(command) {
|
|
|
220
220
|
return command.option("--verbose", "include a full stack trace when the run fails", false);
|
|
221
221
|
}
|
|
222
222
|
function addDumpPackageOption(command) {
|
|
223
|
-
return command.option("--dump-package <file>", "write the intermediate DocumentPackage (content
|
|
223
|
+
return command.option("--dump-package <file>", "write the intermediate DocumentPackage (the tree form: container-grouped content carrying per-node rendered frames, plus page sizes) this conversion built to a JSON file");
|
|
224
224
|
}
|
|
225
225
|
function collectFontFile(value, previous) {
|
|
226
226
|
return [...previous, value];
|
|
@@ -395,10 +395,13 @@ function registerFormatsCommand(program) {
|
|
|
395
395
|
}
|
|
396
396
|
//#endregion
|
|
397
397
|
//#region src/commands/from-package.ts
|
|
398
|
-
function
|
|
399
|
-
if (
|
|
400
|
-
if (
|
|
401
|
-
return
|
|
398
|
+
function isSchemaVersionMismatchError(error) {
|
|
399
|
+
if (!(error instanceof Error)) return false;
|
|
400
|
+
if (error.name !== "SchemaVersionMismatchError") return false;
|
|
401
|
+
return "dumpVersion" in error && "installedVersion" in error;
|
|
402
|
+
}
|
|
403
|
+
function isLayoutSchemaDemotedError(error) {
|
|
404
|
+
return error instanceof Error && error.name === "LayoutSchemaDemotedError";
|
|
402
405
|
}
|
|
403
406
|
async function runFromPackage(input, output, options) {
|
|
404
407
|
const command = "from-package";
|
|
@@ -423,19 +426,16 @@ async function runFromPackage(input, output, options) {
|
|
|
423
426
|
process.stderr.write(`[${command}] '${input}' is not valid JSON: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
424
427
|
return 1;
|
|
425
428
|
}
|
|
426
|
-
if (documentSchemaKindOf(parsed) === "DocumentPackage" && isFormatVersionOneRecord(parsed)) {
|
|
427
|
-
process.stderr.write(`[${command}] '${input}' is a DocumentPackage dump at formatVersion 1 (the documents.js 1.x shape: content plus a separate layout half) -- documents.js 2.0.0 replaced it with formatVersion 2 (content carrying its own rendered frames, plus page sizes); re-run the source conversion with --dump-package to write a current dump\n`);
|
|
428
|
-
return 1;
|
|
429
|
-
}
|
|
430
429
|
const result = documentFromJson(parsed);
|
|
431
430
|
if (result.kind !== "DocumentPackage") {
|
|
432
431
|
process.stderr.write(`[${command}] '${input}' is a ${result.kind}, not a DocumentPackage -- only a file written by --dump-package can be read back by this command\n`);
|
|
433
432
|
return 2;
|
|
434
433
|
}
|
|
435
|
-
const
|
|
434
|
+
const content = flattenPackage(result.value);
|
|
435
|
+
const bytes = target.format === "csv" ? encodeCsvText(buildCsvText(content, {
|
|
436
436
|
delimiter: options.delimiter,
|
|
437
437
|
sheet: options.sheet
|
|
438
|
-
})) : target.format === "svg" ? encodeSvgText(buildSvgText(
|
|
438
|
+
})) : target.format === "svg" ? encodeSvgText(buildSvgText(content, { page: options.page })) : buildDocumentBytes(result.value, target.format);
|
|
439
439
|
await writeOutput(resolvedOutput, bytes);
|
|
440
440
|
createDiagnosticReporter({
|
|
441
441
|
json: options.json,
|
|
@@ -452,6 +452,14 @@ async function runFromPackage(input, output, options) {
|
|
|
452
452
|
process.stderr.write(`[${command}] '${input}' has no recognised $schema -- only a file written by --dump-package can be read back by this command\n`);
|
|
453
453
|
return 1;
|
|
454
454
|
}
|
|
455
|
+
if (isSchemaVersionMismatchError(error)) {
|
|
456
|
+
process.stderr.write(`[${command}] '${input}' is a DocumentPackage dump from document-schema.js@${error.dumpVersion}, but this CLI's documents.js reads only @${error.installedVersion}-major dumps -- 4.0.0 replaced the flat { formatVersion, content, pages } shape with the tree-form DocumentPackage (ExaDev/document-schema.js#20); re-run the source conversion with --dump-package to write a current dump\n`);
|
|
457
|
+
return 1;
|
|
458
|
+
}
|
|
459
|
+
if (isLayoutSchemaDemotedError(error)) {
|
|
460
|
+
process.stderr.write(`[${command}] '${input}' is a LayoutDocument dump -- LayoutDocument moved to pdf-codec in document-schema.js 4.0.0 and is no longer a schema-stamped input; re-run the source conversion with --dump-package and read that package back instead\n`);
|
|
461
|
+
return 1;
|
|
462
|
+
}
|
|
455
463
|
process.stderr.write(`${formatError(error, options.verbose)}\n`);
|
|
456
464
|
return mapErrorToExit(error, getAbortReason());
|
|
457
465
|
}
|
|
@@ -976,7 +984,7 @@ async function runPdfInspect(input, options) {
|
|
|
976
984
|
}
|
|
977
985
|
});
|
|
978
986
|
if (options.full) {
|
|
979
|
-
process.stdout.write(`${JSON.stringify(
|
|
987
|
+
process.stdout.write(`${JSON.stringify(layout, void 0, 2)}\n`);
|
|
980
988
|
return 0;
|
|
981
989
|
}
|
|
982
990
|
const imagesByFormat = countImagesByFormat(layout.images);
|
|
@@ -1095,7 +1103,7 @@ function registerSetMetadataCommand(program) {
|
|
|
1095
1103
|
}
|
|
1096
1104
|
//#endregion
|
|
1097
1105
|
//#region package.json
|
|
1098
|
-
var version = "
|
|
1106
|
+
var version = "3.0.0";
|
|
1099
1107
|
//#endregion
|
|
1100
1108
|
//#region src/program.ts
|
|
1101
1109
|
function createProgram() {
|
package/dist/index.cjs
CHANGED
|
@@ -338,7 +338,7 @@ function addVerboseOption(command) {
|
|
|
338
338
|
return command.option("--verbose", "include a full stack trace when the run fails", false);
|
|
339
339
|
}
|
|
340
340
|
function addDumpPackageOption(command) {
|
|
341
|
-
return command.option("--dump-package <file>", "write the intermediate DocumentPackage (content
|
|
341
|
+
return command.option("--dump-package <file>", "write the intermediate DocumentPackage (the tree form: container-grouped content carrying per-node rendered frames, plus page sizes) this conversion built to a JSON file");
|
|
342
342
|
}
|
|
343
343
|
function collectFontFile(value, previous) {
|
|
344
344
|
return [...previous, value];
|
|
@@ -571,10 +571,13 @@ function registerFormatsCommand(program) {
|
|
|
571
571
|
}
|
|
572
572
|
//#endregion
|
|
573
573
|
//#region src/commands/from-package.ts
|
|
574
|
-
function
|
|
575
|
-
if (
|
|
576
|
-
if (
|
|
577
|
-
return
|
|
574
|
+
function isSchemaVersionMismatchError(error) {
|
|
575
|
+
if (!(error instanceof Error)) return false;
|
|
576
|
+
if (error.name !== "SchemaVersionMismatchError") return false;
|
|
577
|
+
return "dumpVersion" in error && "installedVersion" in error;
|
|
578
|
+
}
|
|
579
|
+
function isLayoutSchemaDemotedError(error) {
|
|
580
|
+
return error instanceof Error && error.name === "LayoutSchemaDemotedError";
|
|
578
581
|
}
|
|
579
582
|
async function runFromPackage(input, output, options) {
|
|
580
583
|
const command = "from-package";
|
|
@@ -599,19 +602,16 @@ async function runFromPackage(input, output, options) {
|
|
|
599
602
|
process.stderr.write(`[${command}] '${input}' is not valid JSON: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
600
603
|
return 1;
|
|
601
604
|
}
|
|
602
|
-
if ((0, documents_js.documentSchemaKindOf)(parsed) === "DocumentPackage" && isFormatVersionOneRecord(parsed)) {
|
|
603
|
-
process.stderr.write(`[${command}] '${input}' is a DocumentPackage dump at formatVersion 1 (the documents.js 1.x shape: content plus a separate layout half) -- documents.js 2.0.0 replaced it with formatVersion 2 (content carrying its own rendered frames, plus page sizes); re-run the source conversion with --dump-package to write a current dump\n`);
|
|
604
|
-
return 1;
|
|
605
|
-
}
|
|
606
605
|
const result = (0, documents_js.documentFromJson)(parsed);
|
|
607
606
|
if (result.kind !== "DocumentPackage") {
|
|
608
607
|
process.stderr.write(`[${command}] '${input}' is a ${result.kind}, not a DocumentPackage -- only a file written by --dump-package can be read back by this command\n`);
|
|
609
608
|
return 2;
|
|
610
609
|
}
|
|
611
|
-
const
|
|
610
|
+
const content = (0, documents_js.flattenPackage)(result.value);
|
|
611
|
+
const bytes = target.format === "csv" ? (0, documents_js.encodeCsvText)((0, documents_js.buildCsvText)(content, {
|
|
612
612
|
delimiter: options.delimiter,
|
|
613
613
|
sheet: options.sheet
|
|
614
|
-
})) : target.format === "svg" ? (0, documents_js.encodeSvgText)((0, documents_js.buildSvgText)(
|
|
614
|
+
})) : target.format === "svg" ? (0, documents_js.encodeSvgText)((0, documents_js.buildSvgText)(content, { page: options.page })) : (0, documents_js.buildDocumentBytes)(result.value, target.format);
|
|
615
615
|
await writeOutput(resolvedOutput, bytes);
|
|
616
616
|
createDiagnosticReporter({
|
|
617
617
|
json: options.json,
|
|
@@ -628,6 +628,14 @@ async function runFromPackage(input, output, options) {
|
|
|
628
628
|
process.stderr.write(`[${command}] '${input}' has no recognised $schema -- only a file written by --dump-package can be read back by this command\n`);
|
|
629
629
|
return 1;
|
|
630
630
|
}
|
|
631
|
+
if (isSchemaVersionMismatchError(error)) {
|
|
632
|
+
process.stderr.write(`[${command}] '${input}' is a DocumentPackage dump from document-schema.js@${error.dumpVersion}, but this CLI's documents.js reads only @${error.installedVersion}-major dumps -- 4.0.0 replaced the flat { formatVersion, content, pages } shape with the tree-form DocumentPackage (ExaDev/document-schema.js#20); re-run the source conversion with --dump-package to write a current dump\n`);
|
|
633
|
+
return 1;
|
|
634
|
+
}
|
|
635
|
+
if (isLayoutSchemaDemotedError(error)) {
|
|
636
|
+
process.stderr.write(`[${command}] '${input}' is a LayoutDocument dump -- LayoutDocument moved to pdf-codec in document-schema.js 4.0.0 and is no longer a schema-stamped input; re-run the source conversion with --dump-package and read that package back instead\n`);
|
|
637
|
+
return 1;
|
|
638
|
+
}
|
|
631
639
|
process.stderr.write(`${formatError(error, options.verbose)}\n`);
|
|
632
640
|
return mapErrorToExit(error, getAbortReason());
|
|
633
641
|
}
|
|
@@ -1308,7 +1316,7 @@ async function runPdfInspect(input, options) {
|
|
|
1308
1316
|
}
|
|
1309
1317
|
});
|
|
1310
1318
|
if (options.full) {
|
|
1311
|
-
process.stdout.write(`${JSON.stringify(
|
|
1319
|
+
process.stdout.write(`${JSON.stringify(layout, void 0, 2)}\n`);
|
|
1312
1320
|
return 0;
|
|
1313
1321
|
}
|
|
1314
1322
|
const imagesByFormat = countImagesByFormat(layout.images);
|
|
@@ -1427,7 +1435,7 @@ function registerSetMetadataCommand(program) {
|
|
|
1427
1435
|
}
|
|
1428
1436
|
//#endregion
|
|
1429
1437
|
//#region package.json
|
|
1430
|
-
var version = "
|
|
1438
|
+
var version = "3.0.0";
|
|
1431
1439
|
//#endregion
|
|
1432
1440
|
//#region src/program.ts
|
|
1433
1441
|
function createProgram() {
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
3
|
-
import { CsvSheetNotFoundError, CsvSheetNotSpecifiedError, HsqldbSqlEvaluationError, HsqldbSqlParseError, HsqldbSqlUnsupportedError, OdbNoEmbeddedDataSourceError, OdbReportNotSpecifiedError, OdbTableNotFoundError, OdbTableNotSpecifiedError, OdbUnsupportedFormatError, OdmUnresolvedSectionError, PdfEncryptedError, PdfParseError, SvgMultiPageNotSpecifiedError, SvgPageNotFoundError, UnrecognizedDocumentSchemaError, UnsupportedFontSourceFormatError, buildCsvText, buildDocumentBytes, buildSvgText, createLocalDocumentConverter, decodeOdbPackage, decodePackage, describeFontFace, documentFromJson, documentPackageWithSchema,
|
|
3
|
+
import { CsvSheetNotFoundError, CsvSheetNotSpecifiedError, HsqldbSqlEvaluationError, HsqldbSqlParseError, HsqldbSqlUnsupportedError, OdbNoEmbeddedDataSourceError, OdbReportNotSpecifiedError, OdbTableNotFoundError, OdbTableNotSpecifiedError, OdbUnsupportedFormatError, OdmUnresolvedSectionError, PdfEncryptedError, PdfParseError, SvgMultiPageNotSpecifiedError, SvgPageNotFoundError, UnrecognizedDocumentSchemaError, UnsupportedFontSourceFormatError, buildCsvText, buildDocumentBytes, buildSvgText, createLocalDocumentConverter, decodeOdbPackage, decodePackage, describeFontFace, documentFromJson, documentPackageWithSchema, encodeCsvText, encodeSvgText, evaluateSelect, extractSourceFontsForFormat, flattenPackage, hsqldbCellDisplayText, odbReportToDocx, odbReportToOdt, odbReportToPdf, odbToCsv, odbToXlsx, odmToPdf, parseSelect, readDocumentMetadata, readDocxExtras, readOdbForms, readOdbInventory, readOdbReportContent, readOdbReports, readOdbTables, readPdf, setDocumentMetadata } from "documents.js";
|
|
4
4
|
import { existsSync, readFileSync } from "node:fs";
|
|
5
5
|
import { Command, InvalidArgumentError } from "commander";
|
|
6
6
|
//#region src/format.ts
|
|
@@ -337,7 +337,7 @@ function addVerboseOption(command) {
|
|
|
337
337
|
return command.option("--verbose", "include a full stack trace when the run fails", false);
|
|
338
338
|
}
|
|
339
339
|
function addDumpPackageOption(command) {
|
|
340
|
-
return command.option("--dump-package <file>", "write the intermediate DocumentPackage (content
|
|
340
|
+
return command.option("--dump-package <file>", "write the intermediate DocumentPackage (the tree form: container-grouped content carrying per-node rendered frames, plus page sizes) this conversion built to a JSON file");
|
|
341
341
|
}
|
|
342
342
|
function collectFontFile(value, previous) {
|
|
343
343
|
return [...previous, value];
|
|
@@ -570,10 +570,13 @@ function registerFormatsCommand(program) {
|
|
|
570
570
|
}
|
|
571
571
|
//#endregion
|
|
572
572
|
//#region src/commands/from-package.ts
|
|
573
|
-
function
|
|
574
|
-
if (
|
|
575
|
-
if (
|
|
576
|
-
return
|
|
573
|
+
function isSchemaVersionMismatchError(error) {
|
|
574
|
+
if (!(error instanceof Error)) return false;
|
|
575
|
+
if (error.name !== "SchemaVersionMismatchError") return false;
|
|
576
|
+
return "dumpVersion" in error && "installedVersion" in error;
|
|
577
|
+
}
|
|
578
|
+
function isLayoutSchemaDemotedError(error) {
|
|
579
|
+
return error instanceof Error && error.name === "LayoutSchemaDemotedError";
|
|
577
580
|
}
|
|
578
581
|
async function runFromPackage(input, output, options) {
|
|
579
582
|
const command = "from-package";
|
|
@@ -598,19 +601,16 @@ async function runFromPackage(input, output, options) {
|
|
|
598
601
|
process.stderr.write(`[${command}] '${input}' is not valid JSON: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
599
602
|
return 1;
|
|
600
603
|
}
|
|
601
|
-
if (documentSchemaKindOf(parsed) === "DocumentPackage" && isFormatVersionOneRecord(parsed)) {
|
|
602
|
-
process.stderr.write(`[${command}] '${input}' is a DocumentPackage dump at formatVersion 1 (the documents.js 1.x shape: content plus a separate layout half) -- documents.js 2.0.0 replaced it with formatVersion 2 (content carrying its own rendered frames, plus page sizes); re-run the source conversion with --dump-package to write a current dump\n`);
|
|
603
|
-
return 1;
|
|
604
|
-
}
|
|
605
604
|
const result = documentFromJson(parsed);
|
|
606
605
|
if (result.kind !== "DocumentPackage") {
|
|
607
606
|
process.stderr.write(`[${command}] '${input}' is a ${result.kind}, not a DocumentPackage -- only a file written by --dump-package can be read back by this command\n`);
|
|
608
607
|
return 2;
|
|
609
608
|
}
|
|
610
|
-
const
|
|
609
|
+
const content = flattenPackage(result.value);
|
|
610
|
+
const bytes = target.format === "csv" ? encodeCsvText(buildCsvText(content, {
|
|
611
611
|
delimiter: options.delimiter,
|
|
612
612
|
sheet: options.sheet
|
|
613
|
-
})) : target.format === "svg" ? encodeSvgText(buildSvgText(
|
|
613
|
+
})) : target.format === "svg" ? encodeSvgText(buildSvgText(content, { page: options.page })) : buildDocumentBytes(result.value, target.format);
|
|
614
614
|
await writeOutput(resolvedOutput, bytes);
|
|
615
615
|
createDiagnosticReporter({
|
|
616
616
|
json: options.json,
|
|
@@ -627,6 +627,14 @@ async function runFromPackage(input, output, options) {
|
|
|
627
627
|
process.stderr.write(`[${command}] '${input}' has no recognised $schema -- only a file written by --dump-package can be read back by this command\n`);
|
|
628
628
|
return 1;
|
|
629
629
|
}
|
|
630
|
+
if (isSchemaVersionMismatchError(error)) {
|
|
631
|
+
process.stderr.write(`[${command}] '${input}' is a DocumentPackage dump from document-schema.js@${error.dumpVersion}, but this CLI's documents.js reads only @${error.installedVersion}-major dumps -- 4.0.0 replaced the flat { formatVersion, content, pages } shape with the tree-form DocumentPackage (ExaDev/document-schema.js#20); re-run the source conversion with --dump-package to write a current dump\n`);
|
|
632
|
+
return 1;
|
|
633
|
+
}
|
|
634
|
+
if (isLayoutSchemaDemotedError(error)) {
|
|
635
|
+
process.stderr.write(`[${command}] '${input}' is a LayoutDocument dump -- LayoutDocument moved to pdf-codec in document-schema.js 4.0.0 and is no longer a schema-stamped input; re-run the source conversion with --dump-package and read that package back instead\n`);
|
|
636
|
+
return 1;
|
|
637
|
+
}
|
|
630
638
|
process.stderr.write(`${formatError(error, options.verbose)}\n`);
|
|
631
639
|
return mapErrorToExit(error, getAbortReason());
|
|
632
640
|
}
|
|
@@ -1307,7 +1315,7 @@ async function runPdfInspect(input, options) {
|
|
|
1307
1315
|
}
|
|
1308
1316
|
});
|
|
1309
1317
|
if (options.full) {
|
|
1310
|
-
process.stdout.write(`${JSON.stringify(
|
|
1318
|
+
process.stdout.write(`${JSON.stringify(layout, void 0, 2)}\n`);
|
|
1311
1319
|
return 0;
|
|
1312
1320
|
}
|
|
1313
1321
|
const imagesByFormat = countImagesByFormat(layout.images);
|
|
@@ -1426,7 +1434,7 @@ function registerSetMetadataCommand(program) {
|
|
|
1426
1434
|
}
|
|
1427
1435
|
//#endregion
|
|
1428
1436
|
//#region package.json
|
|
1429
|
-
var version = "
|
|
1437
|
+
var version = "3.0.0";
|
|
1430
1438
|
//#endregion
|
|
1431
1439
|
//#region src/program.ts
|
|
1432
1440
|
function createProgram() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "CLI and interactive Ink TUI for documents.js: every docx/pptx/odt/odp/ods/odg/odf/pdf/odm/odb/xlsx/csv/svg/markdown conversion, bridge, and editor as a scriptable command or a terminal app.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"packageManager": "pnpm@11.6.0",
|
|
89
89
|
"dependencies": {
|
|
90
90
|
"commander": "^15.0.0",
|
|
91
|
-
"documents.js": "^
|
|
91
|
+
"documents.js": "^3.0.1",
|
|
92
92
|
"ink": "^7.1.1",
|
|
93
93
|
"ink-text-input": "^6.0.0",
|
|
94
94
|
"react": "^19.2.8"
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"ink-testing-library": "^4.0.0",
|
|
112
112
|
"lint-staged": "^17.3.0",
|
|
113
113
|
"odf.js": "^4.0.0",
|
|
114
|
-
"pdf-codec": "^
|
|
114
|
+
"pdf-codec": "^3.0.0",
|
|
115
115
|
"publint": "^0.3.22",
|
|
116
116
|
"semantic-release": "^25.0.8",
|
|
117
117
|
"tsdown": "^0.22.14",
|