@cenk1cenk2/md-printer 3.4.0 → 3.5.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
CHANGED
|
@@ -93,7 +93,7 @@ Markdown files take YAML front-matter. For YAML input the same keys are top-leve
|
|
|
93
93
|
| Key | Description |
|
|
94
94
|
| ----------------- | --------------------------------------------------------------------------------------------- |
|
|
95
95
|
| `template` | Built-in template name, path to a template directory or an object, see [Template sources](#template-sources). |
|
|
96
|
-
| `dest` | Output file, relative to the current directory, not to the input file.
|
|
96
|
+
| `dest` | Output file, relative to the current directory, not to the input file. Also an object, see [Output destination](#output-destination). |
|
|
97
97
|
| `outputFiletype` | `pdf` (default) or `html`. |
|
|
98
98
|
| `language` | Language for template translations. |
|
|
99
99
|
| `continuous` | `true` renders one page per part, each as tall as its content, split only at page breaks. |
|
|
@@ -128,6 +128,19 @@ pdfOptions:
|
|
|
128
128
|
---
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
+
### Output destination
|
|
132
|
+
|
|
133
|
+
`dest` is a file path, or an object that splits it into a `directory` and a `filename`. Both keys are optional: `directory` defaults to the current directory and `filename` to `<input name>.<pdf|html>`, so a document can pick a folder and keep its own name. Without an input file (stdin) the object needs a `filename`.
|
|
134
|
+
|
|
135
|
+
```yaml
|
|
136
|
+
---
|
|
137
|
+
dest:
|
|
138
|
+
directory: ./out
|
|
139
|
+
---
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`document.md` with the front-matter above is written to `./out/document.pdf`. The output argument still wins over `dest` in either form.
|
|
143
|
+
|
|
131
144
|
### Precedence
|
|
132
145
|
|
|
133
146
|
- General: flags > front-matter > template `settings.json` > defaults. `pdfOptions` are merged key by key in the order defaults, `settings.json`, front-matter.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// src/services/printer.schema.ts
|
|
3
|
+
const DestSchema = z.strictObject({
|
|
4
|
+
directory: z.string().min(1).optional(),
|
|
5
|
+
filename: z.string().min(1).optional()
|
|
6
|
+
}, { error: (issue) => issue.code === "invalid_type" ? "Use a string or an object with a directory and a filename." : void 0 });
|
|
7
|
+
export { DestSchema };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { I18nService } from "./i18n.service.mjs";
|
|
2
2
|
import { MarkdownService } from "./markdown.service.mjs";
|
|
3
3
|
import { PdfService } from "./pdf/pdf.service.mjs";
|
|
4
|
+
import { DestSchema } from "./printer.schema.mjs";
|
|
4
5
|
import { RendererService } from "./renderer/renderer.service.mjs";
|
|
5
6
|
import { SignatureVerificationError } from "./signature/cms.mjs";
|
|
6
7
|
import { SignatureService } from "./signature/signature.service.mjs";
|
|
@@ -13,7 +14,7 @@ import { OutputFileType } from "../constants/file.constants.mjs";
|
|
|
13
14
|
import __decorateMetadata from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/decorateMetadata.mjs";
|
|
14
15
|
import __decorate from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/decorate.mjs";
|
|
15
16
|
import { Injectable } from "@nestjs/common";
|
|
16
|
-
import { basename, dirname, extname, resolve } from "path";
|
|
17
|
+
import { basename, dirname, extname, join, resolve } from "path";
|
|
17
18
|
import { ConfigService, FileSystemService, LoggerService } from "@cenk1cenk2/oclif-common";
|
|
18
19
|
import { cloneDeep, mergeWith, uniq } from "es-toolkit";
|
|
19
20
|
import { parse } from "yaml";
|
|
@@ -70,7 +71,7 @@ let PrinterService = class PrinterService {
|
|
|
70
71
|
const { directory: template, settings, files } = await this.template.resolve(source, input.directory);
|
|
71
72
|
const output = flags.outputFiletype ?? data.outputFiletype ?? "pdf";
|
|
72
73
|
if (!Object.values(OutputFileType).includes(output)) throw new Error(`Output file type is not supported: ${output}, use one of ${Object.values(OutputFileType).join(", ")}.`);
|
|
73
|
-
const dest = flags.stdout ? void 0 : flags.output ?? data.dest
|
|
74
|
+
const dest = flags.stdout ? void 0 : flags.output ?? this.dest(data.dest, input.file && `${basename(input.file, extname(input.file))}.${output}`);
|
|
74
75
|
return {
|
|
75
76
|
template,
|
|
76
77
|
files,
|
|
@@ -175,6 +176,14 @@ let PrinterService = class PrinterService {
|
|
|
175
176
|
if (!success) throw new Error(`Template is invalid: ${issues(error)}`);
|
|
176
177
|
return data;
|
|
177
178
|
}
|
|
179
|
+
dest(value, filename) {
|
|
180
|
+
if (value === void 0 || value === null) return filename;
|
|
181
|
+
if (typeof value === "string") return value;
|
|
182
|
+
const { success, data, error } = DestSchema.safeParse(value);
|
|
183
|
+
if (!success) throw new Error(`Dest is invalid: ${issues(error)}`);
|
|
184
|
+
if (!data.filename && !filename) throw new Error("Dest needs a filename when there is no input file to name the output after.");
|
|
185
|
+
return join(data.directory ?? ".", data.filename ?? filename);
|
|
186
|
+
}
|
|
178
187
|
attachments(value) {
|
|
179
188
|
if (value === void 0 || value === null) return [];
|
|
180
189
|
if (!Array.isArray(value)) throw new Error("Front-matter attachments must be a list of { file, position, compress }.");
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cenk1cenk2/md-printer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Render markdown or yaml through Svelte templates into PDF or HTML with Puppeteer.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"@cenk1cenk2/md-printer-template-invoice": "^1.0.0",
|
|
55
55
|
"@cenk1cenk2/md-printer-template-kilic.dev": "1.1.0",
|
|
56
56
|
"@cenk1cenk2/md-printer-template-mail": "1.1.0",
|
|
57
|
-
"@cenk1cenk2/oclif-common": "^8.0.
|
|
58
|
-
"@listr2/manager": "^4.3.
|
|
57
|
+
"@cenk1cenk2/oclif-common": "^8.0.4",
|
|
58
|
+
"@listr2/manager": "^4.3.4",
|
|
59
59
|
"@nestjs/common": "^12.3.2",
|
|
60
60
|
"@oclif/core": "^5.1.11",
|
|
61
61
|
"@oclif/plugin-help": "^7.0.6",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"highlight.js": "^11.12.0",
|
|
76
76
|
"i18next": "^26.7.1",
|
|
77
77
|
"lightningcss": "^1.33.0",
|
|
78
|
-
"listr2": "^11.4.
|
|
78
|
+
"listr2": "^11.4.1",
|
|
79
79
|
"lowlight": "^3.3.0",
|
|
80
80
|
"mime": "^4.1.2",
|
|
81
81
|
"mupdf": "^1.28.1",
|