document-cli 4.0.3 → 5.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 +19 -12
- package/dist/index.cjs +17 -10
- package/dist/index.js +19 -12
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -99,7 +99,7 @@ document-cli convert report.docx - --to pdf > report.pdf
|
|
|
99
99
|
|
|
100
100
|
**`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`, `outline`).
|
|
101
101
|
|
|
102
|
-
**`from-package <input> [output]`** — reads back a `
|
|
102
|
+
**`from-package <input> [output]`** — reads back a `DocumentTree` 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.
|
|
103
103
|
|
|
104
104
|
```sh
|
|
105
105
|
document-cli docx-to-pdf report.docx report.pdf --dump-package report.package.json
|
|
@@ -168,7 +168,7 @@ document-cli set-metadata report.docx report.docx --set-title "Q3 Report" --set-
|
|
|
168
168
|
document-cli set-metadata report.docx report.odt --set-keywords "draft,internal"
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
-
**`outline <input>`** — prints a document's outline: the table-of-contents projection over the tree-form `
|
|
171
|
+
**`outline <input>`** — prints a document's outline: the table-of-contents projection over the tree-form `DocumentTree` a conversion of that document builds — headings nested by heading level, list items nested under their heading or slide, one group per slide (labelled `Slide N`), sheet (labelled with the sheet's own name), or draw page (labelled `Page N`) — rendered as indented text, two spaces per nesting depth. Leaves render their own text (a paragraph's runs, a table's cell text, an image's alt text, a formula's LaTeX) or their kind in brackets when they carry none (`[page-break]`, `[vector]`, `[embeddedObject]`). Works on any of the twelve readable formats: the command runs the cheapest conversion that still leaves a package behind — a PDF-bypassing bridge to a sibling format, so no layout engine runs (`docx`→`odt`, `markdown`→`docx`, `ods`→`xlsx`, ...); `pdf` reconstructs through `pdf-to-docx` and `odf` renders through `odf-to-pdf`, the one conversion each of those formats has — and projects that package's tree through [`document-outline.js`](../document-outline.js/README.md)'s own `buildOutline`, this command being that package's first real consumer. `--json` emits the outline tree itself — groups as `{ text, level, children }`, leaves as the package leaves they are — rather than a CLI-private shape; the internal conversion's diagnostics (a pdf reconstruction's parse warnings, say) reach stderr exactly as they would on the matching conversion command. `--from <format>` names the source format when the input path carries no recognised extension to infer it from — the only way to outline a document read from stdin (`-`), which otherwise has no extension to read at all. Heading nesting depends on the source document actually carrying a heading-level signal on disk (`w:outlineLvl` for docx, `text:outline-level` for odt) — present in anything authored by Word or LibreOffice, and always present for a markdown source, whose own reader parses `#`/`##` headings directly; a docx or odt this ecosystem's own writers produce does not currently stamp that signal even though the paragraph still carries its `Heading1`/`Heading2`-style reference, so outlining a docx/odt generated by this CLI's own conversions loses heading nesting specifically (list nesting and slide/sheet/page grouping are unaffected):
|
|
172
172
|
|
|
173
173
|
```sh
|
|
174
174
|
document-cli outline report.docx
|
|
@@ -191,7 +191,7 @@ The explicit conversions, `convert`, `odm-to-pdf`, `odb-to-xlsx`, `odb-to-csv`,
|
|
|
191
191
|
|
|
192
192
|
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:
|
|
193
193
|
|
|
194
|
-
`--dump-package <file>` is one flag further, registered only on the explicit conversions and `convert` — it writes the intermediate `
|
|
194
|
+
`--dump-package <file>` is one flag further, registered only on the explicit conversions and `convert` — it writes the intermediate `DocumentTree` (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; `outline` takes the shared flags except `--out` (it prints to stdout and writes no file), plus its own `--from <format>` for a source format extension inference can't resolve — it runs a conversion internally to obtain the package it projects, so its diagnostics and `--timeout` behave like any conversion's; `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.
|
|
195
195
|
|
|
196
196
|
### Real fonts
|
|
197
197
|
|
package/dist/cli.js
CHANGED
|
@@ -3,9 +3,9 @@ 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,
|
|
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, documentTreeWithSchema, encodeCsvText, encodeSvgText, evaluateSelect, extractSourceFontsForFormat, 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
|
-
import {
|
|
8
|
+
import { flattenTree } from "document-schema.js";
|
|
9
9
|
import { buildOutline, isOutlineNode, outlineLeafText } from "document-outline.js";
|
|
10
10
|
//#region src/runtime/abort.ts
|
|
11
11
|
function combineSignals(a, b) {
|
|
@@ -191,8 +191,8 @@ function buildConversionAction(source, target) {
|
|
|
191
191
|
});
|
|
192
192
|
for (const diagnostic of result.diagnostics) reporter.report(diagnostic);
|
|
193
193
|
if (options.dumpPackage !== void 0) {
|
|
194
|
-
if (result.package === void 0) process.stderr.write(`[${command}] this conversion does not produce an intermediate
|
|
195
|
-
else await writeFile(options.dumpPackage, JSON.stringify(
|
|
194
|
+
if (result.package === void 0) process.stderr.write(`[${command}] this conversion does not produce an intermediate DocumentTree\n`);
|
|
195
|
+
else await writeFile(options.dumpPackage, JSON.stringify(documentTreeWithSchema(result.package), void 0, 2));
|
|
196
196
|
}
|
|
197
197
|
reporter.summarize({
|
|
198
198
|
output: resolvedOutput,
|
|
@@ -224,7 +224,7 @@ function addVerboseOption(command) {
|
|
|
224
224
|
return command.option("--verbose", "include a full stack trace when the run fails", false);
|
|
225
225
|
}
|
|
226
226
|
function addDumpPackageOption(command) {
|
|
227
|
-
return command.option("--dump-package <file>", "write the intermediate
|
|
227
|
+
return command.option("--dump-package <file>", "write the intermediate DocumentTree (the tree form: container-grouped content carrying per-node rendered frames, plus page sizes) this conversion built to a JSON file");
|
|
228
228
|
}
|
|
229
229
|
function collectFontFile(value, previous) {
|
|
230
230
|
return [...previous, value];
|
|
@@ -407,6 +407,9 @@ function isSchemaVersionMismatchError(error) {
|
|
|
407
407
|
function isLayoutSchemaDemotedError(error) {
|
|
408
408
|
return error instanceof Error && error.name === "LayoutSchemaDemotedError";
|
|
409
409
|
}
|
|
410
|
+
function isDocumentPackageRenamedError(error) {
|
|
411
|
+
return error instanceof Error && error.name === "DocumentPackageRenamedError";
|
|
412
|
+
}
|
|
410
413
|
async function runFromPackage(input, output, options) {
|
|
411
414
|
const command = "from-package";
|
|
412
415
|
if (output !== void 0 && options.out !== void 0 && output !== options.out) {
|
|
@@ -431,11 +434,11 @@ async function runFromPackage(input, output, options) {
|
|
|
431
434
|
return 1;
|
|
432
435
|
}
|
|
433
436
|
const result = documentFromJson(parsed);
|
|
434
|
-
if (result.kind !== "
|
|
435
|
-
process.stderr.write(`[${command}] '${input}' is a ${result.kind}, not a
|
|
437
|
+
if (result.kind !== "DocumentTree") {
|
|
438
|
+
process.stderr.write(`[${command}] '${input}' is a ${result.kind}, not a DocumentTree -- only a file written by --dump-package can be read back by this command\n`);
|
|
436
439
|
return 2;
|
|
437
440
|
}
|
|
438
|
-
const content =
|
|
441
|
+
const content = flattenTree(result.value);
|
|
439
442
|
const bytes = target.format === "csv" ? encodeCsvText(buildCsvText(content, {
|
|
440
443
|
delimiter: options.delimiter,
|
|
441
444
|
sheet: options.sheet
|
|
@@ -457,19 +460,23 @@ async function runFromPackage(input, output, options) {
|
|
|
457
460
|
return 1;
|
|
458
461
|
}
|
|
459
462
|
if (isSchemaVersionMismatchError(error)) {
|
|
460
|
-
process.stderr.write(`[${command}] '${input}' is a
|
|
463
|
+
process.stderr.write(`[${command}] '${input}' is a DocumentTree 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 DocumentTree (ExaDev/document-schema.js#20); re-run the source conversion with --dump-package to write a current dump\n`);
|
|
461
464
|
return 1;
|
|
462
465
|
}
|
|
463
466
|
if (isLayoutSchemaDemotedError(error)) {
|
|
464
467
|
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`);
|
|
465
468
|
return 1;
|
|
466
469
|
}
|
|
470
|
+
if (isDocumentPackageRenamedError(error)) {
|
|
471
|
+
process.stderr.write(`[${command}] '${input}' is a document-package dump -- DocumentPackage was renamed to DocumentTree in document-schema.js 5.0.0 (ExaDev/documents.js#661); re-run the source conversion with --dump-package to write a current tree-form DocumentTree dump\n`);
|
|
472
|
+
return 1;
|
|
473
|
+
}
|
|
467
474
|
process.stderr.write(`${formatError(error, options.verbose)}\n`);
|
|
468
475
|
return mapErrorToExit(error, getAbortReason());
|
|
469
476
|
}
|
|
470
477
|
}
|
|
471
478
|
function registerFromPackageCommand(program) {
|
|
472
|
-
const command = program.command("from-package <input> [output]").description("read a
|
|
479
|
+
const command = program.command("from-package <input> [output]").description("read a DocumentTree previously written by --dump-package and export it to a real target format");
|
|
473
480
|
addOutOption(command);
|
|
474
481
|
addTimeoutOption(command);
|
|
475
482
|
addJsonOption(command);
|
|
@@ -1030,7 +1037,7 @@ async function runOutline(input, options) {
|
|
|
1030
1037
|
images: createFilesystemMarkdownImageResolver(input === "-" ? "." : dirname(resolve(input)))
|
|
1031
1038
|
});
|
|
1032
1039
|
for (const diagnostic of result.diagnostics) reporter.report(diagnostic);
|
|
1033
|
-
if (result.package === void 0) throw new Error(`the ${source.format}-to-${target} conversion produced no intermediate
|
|
1040
|
+
if (result.package === void 0) throw new Error(`the ${source.format}-to-${target} conversion produced no intermediate DocumentTree`);
|
|
1034
1041
|
const outline = buildOutline(result.package);
|
|
1035
1042
|
if (options.json) {
|
|
1036
1043
|
process.stdout.write(`${JSON.stringify(outline, void 0, 2)}\n`);
|
|
@@ -1204,7 +1211,7 @@ function registerSetMetadataCommand(program) {
|
|
|
1204
1211
|
}
|
|
1205
1212
|
//#endregion
|
|
1206
1213
|
//#region package.json
|
|
1207
|
-
var version = "
|
|
1214
|
+
var version = "5.0.0";
|
|
1208
1215
|
//#endregion
|
|
1209
1216
|
//#region src/program.ts
|
|
1210
1217
|
function createProgram() {
|
package/dist/index.cjs
CHANGED
|
@@ -309,8 +309,8 @@ function buildConversionAction(source, target) {
|
|
|
309
309
|
});
|
|
310
310
|
for (const diagnostic of result.diagnostics) reporter.report(diagnostic);
|
|
311
311
|
if (options.dumpPackage !== void 0) {
|
|
312
|
-
if (result.package === void 0) process.stderr.write(`[${command}] this conversion does not produce an intermediate
|
|
313
|
-
else await (0, node_fs_promises.writeFile)(options.dumpPackage, JSON.stringify((0, documents_js.
|
|
312
|
+
if (result.package === void 0) process.stderr.write(`[${command}] this conversion does not produce an intermediate DocumentTree\n`);
|
|
313
|
+
else await (0, node_fs_promises.writeFile)(options.dumpPackage, JSON.stringify((0, documents_js.documentTreeWithSchema)(result.package), void 0, 2));
|
|
314
314
|
}
|
|
315
315
|
reporter.summarize({
|
|
316
316
|
output: resolvedOutput,
|
|
@@ -342,7 +342,7 @@ function addVerboseOption(command) {
|
|
|
342
342
|
return command.option("--verbose", "include a full stack trace when the run fails", false);
|
|
343
343
|
}
|
|
344
344
|
function addDumpPackageOption(command) {
|
|
345
|
-
return command.option("--dump-package <file>", "write the intermediate
|
|
345
|
+
return command.option("--dump-package <file>", "write the intermediate DocumentTree (the tree form: container-grouped content carrying per-node rendered frames, plus page sizes) this conversion built to a JSON file");
|
|
346
346
|
}
|
|
347
347
|
function collectFontFile(value, previous) {
|
|
348
348
|
return [...previous, value];
|
|
@@ -589,6 +589,9 @@ function isSchemaVersionMismatchError(error) {
|
|
|
589
589
|
function isLayoutSchemaDemotedError(error) {
|
|
590
590
|
return error instanceof Error && error.name === "LayoutSchemaDemotedError";
|
|
591
591
|
}
|
|
592
|
+
function isDocumentPackageRenamedError(error) {
|
|
593
|
+
return error instanceof Error && error.name === "DocumentPackageRenamedError";
|
|
594
|
+
}
|
|
592
595
|
async function runFromPackage(input, output, options) {
|
|
593
596
|
const command = "from-package";
|
|
594
597
|
if (output !== void 0 && options.out !== void 0 && output !== options.out) {
|
|
@@ -613,11 +616,11 @@ async function runFromPackage(input, output, options) {
|
|
|
613
616
|
return 1;
|
|
614
617
|
}
|
|
615
618
|
const result = (0, documents_js.documentFromJson)(parsed);
|
|
616
|
-
if (result.kind !== "
|
|
617
|
-
process.stderr.write(`[${command}] '${input}' is a ${result.kind}, not a
|
|
619
|
+
if (result.kind !== "DocumentTree") {
|
|
620
|
+
process.stderr.write(`[${command}] '${input}' is a ${result.kind}, not a DocumentTree -- only a file written by --dump-package can be read back by this command\n`);
|
|
618
621
|
return 2;
|
|
619
622
|
}
|
|
620
|
-
const content = (0, document_schema_js.
|
|
623
|
+
const content = (0, document_schema_js.flattenTree)(result.value);
|
|
621
624
|
const bytes = target.format === "csv" ? (0, documents_js.encodeCsvText)((0, documents_js.buildCsvText)(content, {
|
|
622
625
|
delimiter: options.delimiter,
|
|
623
626
|
sheet: options.sheet
|
|
@@ -639,19 +642,23 @@ async function runFromPackage(input, output, options) {
|
|
|
639
642
|
return 1;
|
|
640
643
|
}
|
|
641
644
|
if (isSchemaVersionMismatchError(error)) {
|
|
642
|
-
process.stderr.write(`[${command}] '${input}' is a
|
|
645
|
+
process.stderr.write(`[${command}] '${input}' is a DocumentTree 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 DocumentTree (ExaDev/document-schema.js#20); re-run the source conversion with --dump-package to write a current dump\n`);
|
|
643
646
|
return 1;
|
|
644
647
|
}
|
|
645
648
|
if (isLayoutSchemaDemotedError(error)) {
|
|
646
649
|
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`);
|
|
647
650
|
return 1;
|
|
648
651
|
}
|
|
652
|
+
if (isDocumentPackageRenamedError(error)) {
|
|
653
|
+
process.stderr.write(`[${command}] '${input}' is a document-package dump -- DocumentPackage was renamed to DocumentTree in document-schema.js 5.0.0 (ExaDev/documents.js#661); re-run the source conversion with --dump-package to write a current tree-form DocumentTree dump\n`);
|
|
654
|
+
return 1;
|
|
655
|
+
}
|
|
649
656
|
process.stderr.write(`${formatError(error, options.verbose)}\n`);
|
|
650
657
|
return mapErrorToExit(error, getAbortReason());
|
|
651
658
|
}
|
|
652
659
|
}
|
|
653
660
|
function registerFromPackageCommand(program) {
|
|
654
|
-
const command = program.command("from-package <input> [output]").description("read a
|
|
661
|
+
const command = program.command("from-package <input> [output]").description("read a DocumentTree previously written by --dump-package and export it to a real target format");
|
|
655
662
|
addOutOption(command);
|
|
656
663
|
addTimeoutOption(command);
|
|
657
664
|
addJsonOption(command);
|
|
@@ -1368,7 +1375,7 @@ async function runOutline(input, options) {
|
|
|
1368
1375
|
images: createFilesystemMarkdownImageResolver(input === "-" ? "." : (0, node_path.dirname)((0, node_path.resolve)(input)))
|
|
1369
1376
|
});
|
|
1370
1377
|
for (const diagnostic of result.diagnostics) reporter.report(diagnostic);
|
|
1371
|
-
if (result.package === void 0) throw new Error(`the ${source.format}-to-${target} conversion produced no intermediate
|
|
1378
|
+
if (result.package === void 0) throw new Error(`the ${source.format}-to-${target} conversion produced no intermediate DocumentTree`);
|
|
1372
1379
|
const outline = (0, document_outline_js.buildOutline)(result.package);
|
|
1373
1380
|
if (options.json) {
|
|
1374
1381
|
process.stdout.write(`${JSON.stringify(outline, void 0, 2)}\n`);
|
|
@@ -1542,7 +1549,7 @@ function registerSetMetadataCommand(program) {
|
|
|
1542
1549
|
}
|
|
1543
1550
|
//#endregion
|
|
1544
1551
|
//#region package.json
|
|
1545
|
-
var version = "
|
|
1552
|
+
var version = "5.0.0";
|
|
1546
1553
|
//#endregion
|
|
1547
1554
|
//#region src/program.ts
|
|
1548
1555
|
function createProgram() {
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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,
|
|
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, documentTreeWithSchema, encodeCsvText, encodeSvgText, evaluateSelect, extractSourceFontsForFormat, 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
|
-
import {
|
|
6
|
+
import { flattenTree } from "document-schema.js";
|
|
7
7
|
import { buildOutline, isOutlineNode, outlineLeafText } from "document-outline.js";
|
|
8
8
|
//#region src/format.ts
|
|
9
9
|
const EXTENSION_TO_FORMAT = {
|
|
@@ -308,8 +308,8 @@ function buildConversionAction(source, target) {
|
|
|
308
308
|
});
|
|
309
309
|
for (const diagnostic of result.diagnostics) reporter.report(diagnostic);
|
|
310
310
|
if (options.dumpPackage !== void 0) {
|
|
311
|
-
if (result.package === void 0) process.stderr.write(`[${command}] this conversion does not produce an intermediate
|
|
312
|
-
else await writeFile(options.dumpPackage, JSON.stringify(
|
|
311
|
+
if (result.package === void 0) process.stderr.write(`[${command}] this conversion does not produce an intermediate DocumentTree\n`);
|
|
312
|
+
else await writeFile(options.dumpPackage, JSON.stringify(documentTreeWithSchema(result.package), void 0, 2));
|
|
313
313
|
}
|
|
314
314
|
reporter.summarize({
|
|
315
315
|
output: resolvedOutput,
|
|
@@ -341,7 +341,7 @@ function addVerboseOption(command) {
|
|
|
341
341
|
return command.option("--verbose", "include a full stack trace when the run fails", false);
|
|
342
342
|
}
|
|
343
343
|
function addDumpPackageOption(command) {
|
|
344
|
-
return command.option("--dump-package <file>", "write the intermediate
|
|
344
|
+
return command.option("--dump-package <file>", "write the intermediate DocumentTree (the tree form: container-grouped content carrying per-node rendered frames, plus page sizes) this conversion built to a JSON file");
|
|
345
345
|
}
|
|
346
346
|
function collectFontFile(value, previous) {
|
|
347
347
|
return [...previous, value];
|
|
@@ -588,6 +588,9 @@ function isSchemaVersionMismatchError(error) {
|
|
|
588
588
|
function isLayoutSchemaDemotedError(error) {
|
|
589
589
|
return error instanceof Error && error.name === "LayoutSchemaDemotedError";
|
|
590
590
|
}
|
|
591
|
+
function isDocumentPackageRenamedError(error) {
|
|
592
|
+
return error instanceof Error && error.name === "DocumentPackageRenamedError";
|
|
593
|
+
}
|
|
591
594
|
async function runFromPackage(input, output, options) {
|
|
592
595
|
const command = "from-package";
|
|
593
596
|
if (output !== void 0 && options.out !== void 0 && output !== options.out) {
|
|
@@ -612,11 +615,11 @@ async function runFromPackage(input, output, options) {
|
|
|
612
615
|
return 1;
|
|
613
616
|
}
|
|
614
617
|
const result = documentFromJson(parsed);
|
|
615
|
-
if (result.kind !== "
|
|
616
|
-
process.stderr.write(`[${command}] '${input}' is a ${result.kind}, not a
|
|
618
|
+
if (result.kind !== "DocumentTree") {
|
|
619
|
+
process.stderr.write(`[${command}] '${input}' is a ${result.kind}, not a DocumentTree -- only a file written by --dump-package can be read back by this command\n`);
|
|
617
620
|
return 2;
|
|
618
621
|
}
|
|
619
|
-
const content =
|
|
622
|
+
const content = flattenTree(result.value);
|
|
620
623
|
const bytes = target.format === "csv" ? encodeCsvText(buildCsvText(content, {
|
|
621
624
|
delimiter: options.delimiter,
|
|
622
625
|
sheet: options.sheet
|
|
@@ -638,19 +641,23 @@ async function runFromPackage(input, output, options) {
|
|
|
638
641
|
return 1;
|
|
639
642
|
}
|
|
640
643
|
if (isSchemaVersionMismatchError(error)) {
|
|
641
|
-
process.stderr.write(`[${command}] '${input}' is a
|
|
644
|
+
process.stderr.write(`[${command}] '${input}' is a DocumentTree 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 DocumentTree (ExaDev/document-schema.js#20); re-run the source conversion with --dump-package to write a current dump\n`);
|
|
642
645
|
return 1;
|
|
643
646
|
}
|
|
644
647
|
if (isLayoutSchemaDemotedError(error)) {
|
|
645
648
|
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`);
|
|
646
649
|
return 1;
|
|
647
650
|
}
|
|
651
|
+
if (isDocumentPackageRenamedError(error)) {
|
|
652
|
+
process.stderr.write(`[${command}] '${input}' is a document-package dump -- DocumentPackage was renamed to DocumentTree in document-schema.js 5.0.0 (ExaDev/documents.js#661); re-run the source conversion with --dump-package to write a current tree-form DocumentTree dump\n`);
|
|
653
|
+
return 1;
|
|
654
|
+
}
|
|
648
655
|
process.stderr.write(`${formatError(error, options.verbose)}\n`);
|
|
649
656
|
return mapErrorToExit(error, getAbortReason());
|
|
650
657
|
}
|
|
651
658
|
}
|
|
652
659
|
function registerFromPackageCommand(program) {
|
|
653
|
-
const command = program.command("from-package <input> [output]").description("read a
|
|
660
|
+
const command = program.command("from-package <input> [output]").description("read a DocumentTree previously written by --dump-package and export it to a real target format");
|
|
654
661
|
addOutOption(command);
|
|
655
662
|
addTimeoutOption(command);
|
|
656
663
|
addJsonOption(command);
|
|
@@ -1367,7 +1374,7 @@ async function runOutline(input, options) {
|
|
|
1367
1374
|
images: createFilesystemMarkdownImageResolver(input === "-" ? "." : dirname(resolve(input)))
|
|
1368
1375
|
});
|
|
1369
1376
|
for (const diagnostic of result.diagnostics) reporter.report(diagnostic);
|
|
1370
|
-
if (result.package === void 0) throw new Error(`the ${source.format}-to-${target} conversion produced no intermediate
|
|
1377
|
+
if (result.package === void 0) throw new Error(`the ${source.format}-to-${target} conversion produced no intermediate DocumentTree`);
|
|
1371
1378
|
const outline = buildOutline(result.package);
|
|
1372
1379
|
if (options.json) {
|
|
1373
1380
|
process.stdout.write(`${JSON.stringify(outline, void 0, 2)}\n`);
|
|
@@ -1541,7 +1548,7 @@ function registerSetMetadataCommand(program) {
|
|
|
1541
1548
|
}
|
|
1542
1549
|
//#endregion
|
|
1543
1550
|
//#region package.json
|
|
1544
|
-
var version = "
|
|
1551
|
+
var version = "5.0.0";
|
|
1545
1552
|
//#endregion
|
|
1546
1553
|
//#region src/program.ts
|
|
1547
1554
|
function createProgram() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.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": {
|
|
@@ -90,9 +90,9 @@
|
|
|
90
90
|
"packageManager": "pnpm@11.6.0",
|
|
91
91
|
"dependencies": {
|
|
92
92
|
"commander": "^15.0.0",
|
|
93
|
-
"document-outline.js": "^
|
|
94
|
-
"document-schema.js": "^
|
|
95
|
-
"documents.js": "^
|
|
93
|
+
"document-outline.js": "^3.0.0",
|
|
94
|
+
"document-schema.js": "^5.0.0",
|
|
95
|
+
"documents.js": "^6.0.0",
|
|
96
96
|
"ink": "^7.1.1",
|
|
97
97
|
"ink-text-input": "^6.0.0",
|
|
98
98
|
"react": "^19.2.8"
|
|
@@ -114,8 +114,8 @@
|
|
|
114
114
|
"husky": "^9.1.7",
|
|
115
115
|
"ink-testing-library": "^4.0.0",
|
|
116
116
|
"lint-staged": "^17.3.0",
|
|
117
|
-
"odf.js": "^
|
|
118
|
-
"pdf-codec": "^3.4.
|
|
117
|
+
"odf.js": "^6.0.0",
|
|
118
|
+
"pdf-codec": "^3.4.4",
|
|
119
119
|
"publint": "^0.3.22",
|
|
120
120
|
"semantic-release": "^25.0.8",
|
|
121
121
|
"tsdown": "^0.22.14",
|