latex-kit 0.2.0 → 0.3.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/build.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { Engine } from '@latex-kit/render';
2
+ import { Diagnostic, Variant } from '@latex-kit/template';
3
+ import { Project } from './project';
4
+ export interface BuildOptions {
5
+ variant?: Variant;
6
+ /** Fail on missing values even in drafts. Default: on when CI=true. */
7
+ strict?: boolean;
8
+ engine?: Engine;
9
+ backend?: 'docker' | 'local';
10
+ image?: string;
11
+ platform?: string | null;
12
+ /** Build twice and fail unless the PDFs are byte-identical. */
13
+ verify?: boolean;
14
+ /** Stop after writing the .tex (no TeX run). */
15
+ texOnly?: boolean;
16
+ onOutput?: (chunk: string) => void;
17
+ }
18
+ export interface BuildResult {
19
+ name: string;
20
+ variant: Variant;
21
+ tex: string;
22
+ pdf: string | null;
23
+ sha256: string | null;
24
+ docId: string | null;
25
+ /** The ID was minted by this build and written to the record. */
26
+ minted: boolean;
27
+ sourceDateEpoch: number;
28
+ reproducible: boolean;
29
+ verified?: boolean;
30
+ diagnostics: Diagnostic[];
31
+ }
32
+ export declare class BuildError extends Error {
33
+ readonly diagnostics: Diagnostic[];
34
+ constructor(message: string, diagnostics: Diagnostic[]);
35
+ }
36
+ /** Build one document record. */
37
+ export declare function buildDocument(project: Project, file: string, options?: BuildOptions): Promise<BuildResult>;
38
+ /** Build a template as a blank form, without a record. */
39
+ export declare function buildBlank(project: Project, templateName: string, options?: BuildOptions): Promise<BuildResult>;
package/build.js ADDED
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuildError = void 0;
4
+ exports.buildDocument = buildDocument;
5
+ exports.buildBlank = buildBlank;
6
+ const render_1 = require("@latex-kit/render");
7
+ const schema_1 = require("@latex-kit/schema");
8
+ const template_1 = require("@latex-kit/template");
9
+ const child_process_1 = require("child_process");
10
+ const crypto_1 = require("crypto");
11
+ const fs_1 = require("fs");
12
+ const path_1 = require("path");
13
+ class BuildError extends Error {
14
+ diagnostics;
15
+ constructor(message, diagnostics) {
16
+ super(message);
17
+ this.diagnostics = diagnostics;
18
+ this.name = 'BuildError';
19
+ }
20
+ }
21
+ exports.BuildError = BuildError;
22
+ const sha256 = (data) => (0, crypto_1.createHash)('sha256').update(data).digest('hex');
23
+ function isCI() {
24
+ return process.env.CI === 'true' || process.env.CI === '1';
25
+ }
26
+ /**
27
+ * The build date: SOURCE_DATE_EPOCH if set, else the newest commit among
28
+ * every input file. Same commit → same date → same PDF bytes.
29
+ */
30
+ function buildEpoch(files) {
31
+ const env = process.env.SOURCE_DATE_EPOCH;
32
+ if (env && /^\d+$/.test(env.trim()))
33
+ return { epoch: Number(env.trim()), reproducible: true };
34
+ let newest = -1;
35
+ let allCommitted = true;
36
+ for (const f of files) {
37
+ const t = (0, render_1.gitCommitTime)(f);
38
+ if (t && /^\d+$/.test(t))
39
+ newest = Math.max(newest, Number(t));
40
+ else
41
+ allCommitted = false;
42
+ }
43
+ if (newest < 0)
44
+ return { epoch: Math.floor(Date.now() / 1000), reproducible: false };
45
+ return { epoch: newest, reproducible: allCommitted };
46
+ }
47
+ function gitShortHead(cwd) {
48
+ try {
49
+ return (0, child_process_1.execFileSync)('git', ['rev-parse', '--short', 'HEAD'], { cwd, stdio: ['ignore', 'pipe', 'ignore'], encoding: 'utf8' }).trim();
50
+ }
51
+ catch {
52
+ return 'no-git';
53
+ }
54
+ }
55
+ async function run(job) {
56
+ const { project, template, variant, options } = job;
57
+ const diagnostics = job.diagnostics;
58
+ // 1. fill the template
59
+ const snippets = new Set();
60
+ const loadSnippet = (name, from) => {
61
+ const s = project.loadSnippet(name, from);
62
+ if (s)
63
+ snippets.add((0, path_1.resolve)(s.file));
64
+ return s;
65
+ };
66
+ const strict = options.strict ?? isCI();
67
+ const files = [...job.inputs, template.texFile, ...(template.schemaFile ? [template.schemaFile] : [])];
68
+ const { epoch, reproducible } = buildEpoch(files);
69
+ let docId = job.docId;
70
+ let minted = false;
71
+ if (!docId && job.mintInto) {
72
+ docId = (0, schema_1.mintDocId)({ prefix: template.meta.docIdPrefix ?? template.name, epoch: Math.floor(Date.now() / 1000) });
73
+ minted = true;
74
+ }
75
+ const evaluated = (0, template_1.evaluateTemplate)(template.compiled, {
76
+ data: job.data,
77
+ variant,
78
+ locale: job.locale,
79
+ docId,
80
+ template: template.name,
81
+ allowMissing: variant === 'draft' ? !strict : undefined,
82
+ loadSnippet,
83
+ });
84
+ diagnostics.push(...evaluated.diagnostics);
85
+ if ((0, template_1.hasErrors)(diagnostics))
86
+ throw new BuildError(`${job.name}: cannot build ${variant}`, diagnostics);
87
+ // snippets count as inputs for the build date too
88
+ const finalEpoch = snippets.size ? buildEpoch([...files, ...snippets]) : { epoch, reproducible };
89
+ // 2. write the .tex next to latex-kit.sty
90
+ const outDir = (0, path_1.join)(project.outDir, job.name);
91
+ (0, fs_1.mkdirSync)(outDir, { recursive: true });
92
+ const job_ = variant === 'final' ? job.name : `${job.name}-${variant}`;
93
+ const texPath = (0, path_1.join)(outDir, `${job_}.tex`);
94
+ const stamp = `${new Date(finalEpoch.epoch * 1000).toISOString().slice(0, 10)} ${gitShortHead(project.root)}`;
95
+ const tex = (0, template_1.wrapDocument)(evaluated.tex, { variant, stamp });
96
+ (0, fs_1.writeFileSync)(texPath, tex);
97
+ (0, fs_1.writeFileSync)((0, path_1.join)(outDir, 'latex-kit.sty'), template_1.LATEX_KIT_STY);
98
+ const result = {
99
+ name: job.name,
100
+ variant,
101
+ tex: texPath,
102
+ pdf: null,
103
+ sha256: null,
104
+ docId: docId ?? null,
105
+ minted: false,
106
+ sourceDateEpoch: finalEpoch.epoch,
107
+ reproducible: finalEpoch.reproducible,
108
+ diagnostics,
109
+ };
110
+ if (options.texOnly)
111
+ return result;
112
+ // 3. render
113
+ const engine = options.engine ?? template.meta.engine ?? project.config.engine ?? 'lualatex';
114
+ const renderOpts = {
115
+ file: texPath,
116
+ root: project.root,
117
+ engine,
118
+ backend: options.backend ?? project.config.backend,
119
+ image: options.image ?? project.config.image,
120
+ platform: options.platform !== undefined ? options.platform : project.config.platform,
121
+ sourceDateEpoch: finalEpoch.epoch,
122
+ texInputs: [(0, path_1.relative)(project.root, outDir) || '.', (0, path_1.relative)(project.root, template.dir) || '.'],
123
+ onOutput: options.onOutput,
124
+ };
125
+ let rendered;
126
+ try {
127
+ rendered = await (0, render_1.render)({ ...renderOpts, outDir: (0, path_1.relative)(project.root, outDir) });
128
+ }
129
+ catch (e) {
130
+ if (e instanceof render_1.RenderError) {
131
+ throw new BuildError(`${job.name}: ${e.message}`, [
132
+ ...diagnostics,
133
+ ...e.diagnostics.map((d) => (0, template_1.diag)(d.severity, d.message, d.file ? { file: project.rel((0, path_1.join)(outDir, (0, path_1.basename)(d.file))), line: d.line ?? 0, column: 0 } : undefined)),
134
+ ]);
135
+ }
136
+ throw e;
137
+ }
138
+ result.pdf = rendered.pdf;
139
+ result.sha256 = rendered.sha256;
140
+ if (options.verify) {
141
+ const verifyDir = `${outDir}.verify`;
142
+ const again = await (0, render_1.render)({ ...renderOpts, outDir: (0, path_1.relative)(project.root, verifyDir) });
143
+ result.verified = again.sha256 === rendered.sha256;
144
+ (0, fs_1.rmSync)(verifyDir, { recursive: true, force: true });
145
+ }
146
+ // 4. keep the ID: only after a successful final build
147
+ if (minted && job.mintInto) {
148
+ (0, schema_1.writeDocId)(job.mintInto, docId);
149
+ result.minted = true;
150
+ }
151
+ // 5. manifest: what went in, what came out
152
+ const inputFiles = [...new Set([...files, ...snippets])].filter(fs_1.existsSync).sort();
153
+ (0, fs_1.writeFileSync)((0, path_1.join)(outDir, `${job_}.manifest.json`), JSON.stringify({
154
+ document: job.name,
155
+ template: template.name,
156
+ variant,
157
+ docId: docId ?? null,
158
+ locale: job.locale,
159
+ engine,
160
+ image: rendered.image,
161
+ sourceDateEpoch: finalEpoch.epoch,
162
+ inputs: inputFiles.map((f) => ({ file: (0, path_1.relative)(project.root, f), sha256: sha256((0, fs_1.readFileSync)(f)) })),
163
+ tex: { file: (0, path_1.relative)(project.root, texPath), sha256: sha256(tex) },
164
+ pdf: { file: (0, path_1.relative)(project.root, rendered.pdf), sha256: rendered.sha256 },
165
+ fields: evaluated.fields.map((f) => ({ path: f.path, missing: f.missing })),
166
+ }, null, 2) + '\n');
167
+ return result;
168
+ }
169
+ /** Build one document record. */
170
+ async function buildDocument(project, file, options = {}) {
171
+ const variant = options.variant ?? 'draft';
172
+ const diagnostics = [];
173
+ const doc = await (0, schema_1.loadDocument)(file, { dataDir: project.dataDir });
174
+ const template = await project.template(doc.record.template);
175
+ const at = { file: project.rel(file), line: 1, column: 1 };
176
+ let data = doc.data;
177
+ if (template.schema) {
178
+ const v = (0, schema_1.validate)(template.schema, doc.data);
179
+ if (v.ok) {
180
+ data = v.value;
181
+ }
182
+ else {
183
+ const sev = variant === 'final' || variant === 'signed' ? 'error' : 'warning';
184
+ for (const i of v.issues)
185
+ diagnostics.push((0, template_1.diag)(sev, `data.${i.path}: ${i.message}`, at));
186
+ }
187
+ }
188
+ const needsId = (variant === 'final' || variant === 'signed') && !doc.record.docId;
189
+ if (needsId && !['.json', '.yaml', '.yml'].includes((0, path_1.extname)(file).toLowerCase())) {
190
+ const suggestion = (0, schema_1.mintDocId)({ prefix: template.meta.docIdPrefix ?? template.name, epoch: Math.floor(Date.now() / 1000) });
191
+ diagnostics.push((0, template_1.diag)('error', `a ${variant} build needs a document ID, and latex-kit does not edit code. Add: docId: '${suggestion}'`, at));
192
+ throw new BuildError(`${doc.record.template}: no document ID`, diagnostics);
193
+ }
194
+ return run({
195
+ project,
196
+ template,
197
+ name: project.documentName(file),
198
+ variant,
199
+ data,
200
+ locale: doc.record.locale ?? template.meta.locale ?? project.config.locale,
201
+ docId: doc.record.docId,
202
+ inputs: [file, ...doc.refFiles],
203
+ diagnostics,
204
+ options,
205
+ mintInto: needsId ? file : undefined,
206
+ });
207
+ }
208
+ /** Build a template as a blank form, without a record. */
209
+ async function buildBlank(project, templateName, options = {}) {
210
+ const template = await project.template(templateName);
211
+ return run({
212
+ project,
213
+ template,
214
+ name: `${templateName}`,
215
+ variant: 'blank',
216
+ data: {},
217
+ locale: template.meta.locale ?? project.config.locale,
218
+ inputs: [],
219
+ diagnostics: [],
220
+ options: { ...options, variant: 'blank' },
221
+ });
222
+ }
package/check.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { Diagnostic, FieldRef } from '@latex-kit/template';
2
+ import { Project } from './project';
3
+ export interface CheckResult {
4
+ diagnostics: Diagnostic[];
5
+ templates: string[];
6
+ documents: string[];
7
+ }
8
+ /**
9
+ * Everything that can be checked without TeX: template syntax, field names
10
+ * against each schema, every document's data, references, and duplicate IDs.
11
+ */
12
+ export declare function checkProject(project: Project): Promise<CheckResult>;
13
+ /** Every field a template reads, including through snippets. */
14
+ export declare function templateFields(project: Project, name: string): Promise<{
15
+ fields: FieldRef[];
16
+ diagnostics: Diagnostic[];
17
+ }>;
package/check.js ADDED
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkProject = checkProject;
4
+ exports.templateFields = templateFields;
5
+ const schema_1 = require("@latex-kit/schema");
6
+ const template_1 = require("@latex-kit/template");
7
+ /**
8
+ * Everything that can be checked without TeX: template syntax, field names
9
+ * against each schema, every document's data, references, and duplicate IDs.
10
+ */
11
+ async function checkProject(project) {
12
+ const diagnostics = [];
13
+ const templates = project.templateNames();
14
+ for (const name of templates) {
15
+ try {
16
+ const t = await project.template(name);
17
+ if (!t.jsonSchema) {
18
+ diagnostics.push((0, template_1.diag)('warning', `template ${name} has no schema.ts, so field names are not checked`, { file: t.compiled.file, line: 1, column: 1 }));
19
+ }
20
+ diagnostics.push(...(0, template_1.analyzeTemplate)(t.compiled, { schema: t.jsonSchema ?? undefined, loadSnippet: project.loadSnippet }).diagnostics);
21
+ }
22
+ catch (e) {
23
+ diagnostics.push((0, template_1.diag)('error', e.message, { file: project.rel(project.path(project.config.templates, name)), line: 1, column: 1 }));
24
+ }
25
+ }
26
+ const files = project.documentFiles();
27
+ const ids = new Map();
28
+ for (const file of files) {
29
+ const at = { file: project.rel(file), line: 1, column: 1 };
30
+ try {
31
+ const doc = await (0, schema_1.loadDocument)(file, { dataDir: project.dataDir });
32
+ if (doc.record.docId) {
33
+ const prev = ids.get(doc.record.docId);
34
+ if (prev)
35
+ diagnostics.push((0, template_1.diag)('error', `document ID ${doc.record.docId} is also used by ${prev}; never reuse an ID`, at));
36
+ else
37
+ ids.set(doc.record.docId, project.rel(file));
38
+ }
39
+ const t = await project.template(doc.record.template);
40
+ if (t.schema) {
41
+ const v = (0, schema_1.validate)(t.schema, doc.data);
42
+ if (!v.ok)
43
+ for (const i of v.issues)
44
+ diagnostics.push((0, template_1.diag)('error', `data.${i.path}: ${i.message}`, at));
45
+ }
46
+ }
47
+ catch (e) {
48
+ diagnostics.push((0, template_1.diag)('error', e.message.replace(`${file}: `, ''), at));
49
+ }
50
+ }
51
+ return { diagnostics, templates, documents: files.map((f) => project.rel(f)) };
52
+ }
53
+ /** Every field a template reads, including through snippets. */
54
+ async function templateFields(project, name) {
55
+ const t = await project.template(name);
56
+ const r = (0, template_1.analyzeTemplate)(t.compiled, { schema: t.jsonSchema ?? undefined, loadSnippet: project.loadSnippet });
57
+ return { fields: r.fields, diagnostics: r.diagnostics };
58
+ }
package/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/cli.js ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const inquirerer_1 = require("inquirerer");
5
+ const commands_1 = require("./commands");
6
+ const app = new inquirerer_1.CLI(commands_1.commands, {
7
+ noTty: !process.stdin.isTTY,
8
+ // inquirerer answers --version itself; make it report latex-kit
9
+ version: (0, commands_1.version)(),
10
+ minimistOpts: {
11
+ alias: { h: 'help', v: 'version', o: 'out', e: 'engine' },
12
+ boolean: ['help', 'version', 'local', 'verify', 'json', 'final', 'strict', 'tex-only'],
13
+ string: ['out', 'engine', 'image', 'root', 'platform', 'source-date-epoch', 'variant', 'template'],
14
+ default: { strict: undefined },
15
+ },
16
+ });
17
+ app.run().catch((error) => {
18
+ console.error(error instanceof Error ? error.message : error);
19
+ process.exit(1);
20
+ });
package/commands.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { CLIOptions, Inquirerer } from 'inquirerer';
2
2
  import type { ParsedArgs } from 'minimist';
3
+ /** The package version, from package.json next to the built files. */
3
4
  export declare function version(): string;
4
5
  export declare const commands: (argv: Partial<ParsedArgs>, prompter: Inquirerer, _options: CLIOptions) => Promise<Partial<ParsedArgs>>;
package/commands.js CHANGED
@@ -1,14 +1,38 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.commands = void 0;
4
7
  exports.version = version;
5
8
  const fs_1 = require("fs");
9
+ const path_1 = require("path");
10
+ const yanse_1 = __importDefault(require("yanse"));
11
+ const args_1 = require("./args");
6
12
  const doctor_1 = require("./doctor");
13
+ const project_commands_1 = require("./project-commands");
7
14
  const render_1 = require("./render");
8
15
  const usage_1 = require("./usage");
16
+ /** The package version, from package.json next to the built files. */
9
17
  function version() {
10
- return JSON.parse((0, fs_1.readFileSync)(require.resolve('../package.json'), 'utf8')).version;
18
+ for (const p of [(0, path_1.join)(__dirname, 'package.json'), (0, path_1.join)(__dirname, '..', 'package.json')]) {
19
+ if ((0, fs_1.existsSync)(p)) {
20
+ const pkg = JSON.parse((0, fs_1.readFileSync)(p, 'utf8'));
21
+ if (pkg.name === 'latex-kit')
22
+ return pkg.version;
23
+ }
24
+ }
25
+ return 'unknown';
11
26
  }
27
+ const COMMANDS = {
28
+ build: project_commands_1.buildCommand,
29
+ check: project_commands_1.checkCommand,
30
+ fields: project_commands_1.fieldsCommand,
31
+ typegen: project_commands_1.typegenCommand,
32
+ sty: project_commands_1.styCommand,
33
+ render: render_1.renderCommand,
34
+ doctor: doctor_1.doctorCommand,
35
+ };
12
36
  const commands = async (argv, prompter, _options) => {
13
37
  const [command, ...rest] = (argv._ ?? []).map(String);
14
38
  if (argv.version) {
@@ -19,21 +43,27 @@ const commands = async (argv, prompter, _options) => {
19
43
  (0, usage_1.help)(command === 'help' ? rest[0] : argv.help ? command : undefined);
20
44
  return argv;
21
45
  }
22
- let code;
23
- switch (command) {
24
- case 'render':
25
- code = await (0, render_1.renderCommand)({ ...argv, _: rest }, prompter);
26
- break;
27
- case 'doctor':
28
- code = await (0, doctor_1.doctorCommand)({ ...argv, _: rest });
29
- break;
30
- default:
31
- console.error(`unknown command: ${command}\n`);
32
- (0, usage_1.help)();
33
- code = 2;
46
+ const run = COMMANDS[command];
47
+ if (!run) {
48
+ console.error(`unknown command: ${command}\n`);
49
+ (0, usage_1.help)();
50
+ process.exitCode = 2;
51
+ return argv;
52
+ }
53
+ try {
54
+ const code = await run({ ...argv, _: rest }, prompter);
55
+ if (code !== 0)
56
+ process.exitCode = code;
57
+ }
58
+ catch (e) {
59
+ if (e instanceof args_1.UsageError) {
60
+ console.error(yanse_1.default.red(e.message));
61
+ process.exitCode = 2;
62
+ }
63
+ else {
64
+ throw e;
65
+ }
34
66
  }
35
- if (code !== 0)
36
- process.exitCode = code;
37
67
  return argv;
38
68
  };
39
69
  exports.commands = commands;
package/config.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { Backend, Engine } from '@latex-kit/render';
2
+ /** latex-kit.config.ts (or .js, .mjs, .cjs, .json) at the project root. */
3
+ export interface LatexKitConfig {
4
+ /** One folder per template: `<templates>/<name>/template.tex` and optional `schema.ts`. Default `templates`. */
5
+ templates?: string;
6
+ /** Shared pieces for \snippet{name}. Default `snippets`. */
7
+ snippets?: string;
8
+ /** Shared records that references point at: `<data>/<collection>/<id>.json`. Default `data`. */
9
+ data?: string;
10
+ /** Document records: `<documents>/<name>.json|yaml|ts`. Default `documents`. */
11
+ documents?: string;
12
+ /** Generated .tex and PDFs. Default `out`. */
13
+ out?: string;
14
+ /** Default locale for dates, numbers and money. Default `en-US`. */
15
+ locale?: string;
16
+ engine?: Engine;
17
+ backend?: Backend;
18
+ image?: string;
19
+ platform?: string | null;
20
+ }
21
+ export type ResolvedConfig = Required<Pick<LatexKitConfig, 'templates' | 'snippets' | 'data' | 'documents' | 'out' | 'locale'>> & Pick<LatexKitConfig, 'engine' | 'backend' | 'image' | 'platform'> & {
22
+ file: string | null;
23
+ };
24
+ export declare function defineConfig(config: LatexKitConfig): LatexKitConfig;
25
+ export declare const CONFIG_FILES: string[];
26
+ export declare function loadConfig(root: string): Promise<ResolvedConfig>;
package/config.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONFIG_FILES = void 0;
4
+ exports.defineConfig = defineConfig;
5
+ exports.loadConfig = loadConfig;
6
+ const schema_1 = require("@latex-kit/schema");
7
+ const fs_1 = require("fs");
8
+ const path_1 = require("path");
9
+ function defineConfig(config) {
10
+ return config;
11
+ }
12
+ exports.CONFIG_FILES = ['latex-kit.config.ts', 'latex-kit.config.mts', 'latex-kit.config.js', 'latex-kit.config.mjs', 'latex-kit.config.cjs', 'latex-kit.config.json'];
13
+ const DEFAULTS = { templates: 'templates', snippets: 'snippets', data: 'data', documents: 'documents', out: 'out', locale: 'en-US' };
14
+ async function loadConfig(root) {
15
+ for (const name of exports.CONFIG_FILES) {
16
+ const file = (0, path_1.join)((0, path_1.resolve)(root), name);
17
+ if (!(0, fs_1.existsSync)(file))
18
+ continue;
19
+ let config;
20
+ if (name.endsWith('.json')) {
21
+ config = JSON.parse((0, fs_1.readFileSync)(file, 'utf8'));
22
+ }
23
+ else {
24
+ const mod = await (0, schema_1.loadModule)(file);
25
+ config = (mod.default ?? mod);
26
+ }
27
+ return { ...DEFAULTS, ...config, file };
28
+ }
29
+ return { ...DEFAULTS, file: null };
30
+ }
package/esm/build.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { Engine } from '@latex-kit/render';
2
+ import { Diagnostic, Variant } from '@latex-kit/template';
3
+ import { Project } from './project';
4
+ export interface BuildOptions {
5
+ variant?: Variant;
6
+ /** Fail on missing values even in drafts. Default: on when CI=true. */
7
+ strict?: boolean;
8
+ engine?: Engine;
9
+ backend?: 'docker' | 'local';
10
+ image?: string;
11
+ platform?: string | null;
12
+ /** Build twice and fail unless the PDFs are byte-identical. */
13
+ verify?: boolean;
14
+ /** Stop after writing the .tex (no TeX run). */
15
+ texOnly?: boolean;
16
+ onOutput?: (chunk: string) => void;
17
+ }
18
+ export interface BuildResult {
19
+ name: string;
20
+ variant: Variant;
21
+ tex: string;
22
+ pdf: string | null;
23
+ sha256: string | null;
24
+ docId: string | null;
25
+ /** The ID was minted by this build and written to the record. */
26
+ minted: boolean;
27
+ sourceDateEpoch: number;
28
+ reproducible: boolean;
29
+ verified?: boolean;
30
+ diagnostics: Diagnostic[];
31
+ }
32
+ export declare class BuildError extends Error {
33
+ readonly diagnostics: Diagnostic[];
34
+ constructor(message: string, diagnostics: Diagnostic[]);
35
+ }
36
+ /** Build one document record. */
37
+ export declare function buildDocument(project: Project, file: string, options?: BuildOptions): Promise<BuildResult>;
38
+ /** Build a template as a blank form, without a record. */
39
+ export declare function buildBlank(project: Project, templateName: string, options?: BuildOptions): Promise<BuildResult>;