latex-kit 0.4.1 → 0.5.1
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 +21 -2
- package/args.js +3 -3
- package/boilerplates.d.ts +14 -1
- package/boilerplates.js +200 -2
- package/build.d.ts +22 -2
- package/build.js +230 -95
- package/check.js +4 -3
- package/cli.js +2 -2
- package/commands.js +1 -0
- package/config.d.ts +13 -4
- package/config.js +1 -1
- package/diff.d.ts +2 -2
- package/diff.js +3 -3
- package/esm/args.js +3 -3
- package/esm/boilerplates.d.ts +14 -1
- package/esm/boilerplates.js +196 -1
- package/esm/build.d.ts +22 -2
- package/esm/build.js +231 -98
- package/esm/check.js +4 -3
- package/esm/cli.js +2 -2
- package/esm/commands.js +2 -1
- package/esm/config.d.ts +13 -4
- package/esm/config.js +1 -1
- package/esm/diff.d.ts +2 -2
- package/esm/diff.js +3 -3
- package/esm/import.js +1 -1
- package/esm/index.d.ts +6 -2
- package/esm/index.js +5 -2
- package/esm/lock.d.ts +24 -0
- package/esm/lock.js +50 -0
- package/esm/paper-style.d.ts +10 -0
- package/esm/paper-style.js +10 -0
- package/esm/project-commands.d.ts +4 -0
- package/esm/project-commands.js +76 -6
- package/esm/project.d.ts +18 -2
- package/esm/project.js +92 -5
- package/esm/render.js +4 -2
- package/esm/scaffold.d.ts +2 -1
- package/esm/scaffold.js +1 -1
- package/esm/usage.js +28 -7
- package/import.js +1 -1
- package/index.d.ts +6 -2
- package/index.js +24 -2
- package/lock.d.ts +24 -0
- package/lock.js +57 -0
- package/package.json +16 -17
- package/paper-style.d.ts +10 -0
- package/paper-style.js +13 -0
- package/project-commands.d.ts +4 -0
- package/project-commands.js +78 -6
- package/project.d.ts +18 -2
- package/project.js +90 -3
- package/render.js +4 -2
- package/scaffold.d.ts +2 -1
- package/scaffold.js +1 -1
- package/usage.js +28 -7
package/project.js
CHANGED
|
@@ -1,26 +1,110 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Project = void 0;
|
|
4
|
+
const components_1 = require("@latex-kit/components");
|
|
4
5
|
const schema_1 = require("@latex-kit/schema");
|
|
5
6
|
const template_1 = require("@latex-kit/template");
|
|
6
7
|
const fs_1 = require("fs");
|
|
7
8
|
const path_1 = require("path");
|
|
8
9
|
const config_1 = require("./config");
|
|
10
|
+
const lock_1 = require("./lock");
|
|
11
|
+
const CODE_EXTENSIONS = ['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs'];
|
|
12
|
+
/** Every code file under `dir`, as [name without extension, absolute path]. */
|
|
13
|
+
function codeFiles(dir) {
|
|
14
|
+
const out = [];
|
|
15
|
+
const walk = (d, prefix) => {
|
|
16
|
+
if (!(0, fs_1.existsSync)(d))
|
|
17
|
+
return;
|
|
18
|
+
for (const name of (0, fs_1.readdirSync)(d).sort()) {
|
|
19
|
+
if (name.startsWith('.') || name.startsWith('_'))
|
|
20
|
+
continue;
|
|
21
|
+
const p = (0, path_1.join)(d, name);
|
|
22
|
+
if ((0, fs_1.statSync)(p).isDirectory())
|
|
23
|
+
walk(p, `${prefix}${name}/`);
|
|
24
|
+
else if (CODE_EXTENSIONS.includes((0, path_1.extname)(name)) && !name.endsWith('.d.ts'))
|
|
25
|
+
out.push([`${prefix}${name.slice(0, -(0, path_1.extname)(name).length)}`, p]);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
walk(dir, '');
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
9
31
|
const SCHEMA_FILES = ['schema.ts', 'schema.mts', 'schema.js', 'schema.mjs', 'schema.cjs'];
|
|
10
32
|
/** A latex-kit project: a folder with templates, data and documents. */
|
|
11
33
|
class Project {
|
|
12
34
|
root;
|
|
13
35
|
config;
|
|
36
|
+
lock;
|
|
14
37
|
templates = new Map();
|
|
15
38
|
snippets = new Map();
|
|
16
39
|
clauses = new Map();
|
|
17
|
-
|
|
40
|
+
/** Clauses written in TypeScript, loaded when the project opens. */
|
|
41
|
+
codeClauses = new Map();
|
|
42
|
+
/** Built-in components, then the project's own (which win). */
|
|
43
|
+
components = { ...components_1.BUILTIN_COMPONENTS };
|
|
44
|
+
/** Source files of the project's components, by name. */
|
|
45
|
+
componentFiles = {};
|
|
46
|
+
/** Problems loading components/ and TypeScript clauses. */
|
|
47
|
+
codeDiagnostics = [];
|
|
48
|
+
constructor(root, config,
|
|
49
|
+
/** latex-kit.lock, when the project has one. */
|
|
50
|
+
lock) {
|
|
18
51
|
this.root = root;
|
|
19
52
|
this.config = config;
|
|
53
|
+
this.lock = lock;
|
|
20
54
|
}
|
|
21
55
|
static async open(root = process.cwd()) {
|
|
22
56
|
const abs = (0, path_1.resolve)(root);
|
|
23
|
-
|
|
57
|
+
const project = new Project(abs, await (0, config_1.loadConfig)(abs), (0, lock_1.readLock)(abs));
|
|
58
|
+
await project.loadCode();
|
|
59
|
+
return project;
|
|
60
|
+
}
|
|
61
|
+
/** The Docker image to build with: --image, then config, then latex-kit.lock. */
|
|
62
|
+
image(override) {
|
|
63
|
+
return override ?? this.config.image ?? this.lock?.image;
|
|
64
|
+
}
|
|
65
|
+
async loadCode() {
|
|
66
|
+
for (const [name, file] of codeFiles(this.path(this.config.components))) {
|
|
67
|
+
const at = { file: this.rel(file), line: 1, column: 1 };
|
|
68
|
+
this.componentFiles[name] = file;
|
|
69
|
+
try {
|
|
70
|
+
const mod = await (0, schema_1.loadModule)(file);
|
|
71
|
+
const fn = mod.default;
|
|
72
|
+
if (typeof fn !== 'function')
|
|
73
|
+
throw new Error('the default export must be a component function (use defineComponent)');
|
|
74
|
+
this.components[name] = fn;
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
this.codeDiagnostics.push((0, template_1.diag)('error', `component ${name}: ${e.message}`, at));
|
|
78
|
+
const message = e.message;
|
|
79
|
+
this.components[name] = () => {
|
|
80
|
+
throw new Error(`failed to load: ${message}`);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const [id, file] of codeFiles(this.path(this.config.clauses))) {
|
|
85
|
+
const at = { file: this.rel(file), line: 1, column: 1 };
|
|
86
|
+
try {
|
|
87
|
+
const mod = await (0, schema_1.loadModule)(file);
|
|
88
|
+
const def = mod.default;
|
|
89
|
+
if (!def || typeof def !== 'object' || (typeof def.body !== 'string' && typeof def.render !== 'function')) {
|
|
90
|
+
throw new Error('the default export must be defineClause({ title, version, body | render })');
|
|
91
|
+
}
|
|
92
|
+
this.codeClauses.set(id, {
|
|
93
|
+
id,
|
|
94
|
+
title: def.title,
|
|
95
|
+
version: def.version === undefined ? undefined : String(def.version),
|
|
96
|
+
template: (0, template_1.compileTemplate)(def.body ?? '', this.rel(file)),
|
|
97
|
+
render: def.render,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
this.codeDiagnostics.push((0, template_1.diag)('error', `clause ${id}: ${e.message}`, at));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Names \\component can use. */
|
|
106
|
+
componentNames() {
|
|
107
|
+
return Object.keys(this.components).sort();
|
|
24
108
|
}
|
|
25
109
|
path(...parts) {
|
|
26
110
|
return (0, path_1.join)(this.root, ...parts);
|
|
@@ -122,7 +206,7 @@ class Project {
|
|
|
122
206
|
}
|
|
123
207
|
return null;
|
|
124
208
|
};
|
|
125
|
-
/** \\clause{id}: `clauses/<id>.tex` from the clause library. */
|
|
209
|
+
/** \\clause{id}: `clauses/<id>.tex` (or `.ts`) from the clause library. */
|
|
126
210
|
loadClause = (id) => {
|
|
127
211
|
if (this.clauses.has(id))
|
|
128
212
|
return this.clauses.get(id);
|
|
@@ -132,6 +216,9 @@ class Project {
|
|
|
132
216
|
const text = (0, fs_1.readFileSync)(file, 'utf8');
|
|
133
217
|
loaded = { id, template: (0, template_1.compileTemplate)(text, this.rel(file)), ...(0, template_1.parseClauseHeader)(text) };
|
|
134
218
|
}
|
|
219
|
+
else if (this.codeClauses.has(id)) {
|
|
220
|
+
loaded = this.codeClauses.get(id);
|
|
221
|
+
}
|
|
135
222
|
this.clauses.set(id, loaded);
|
|
136
223
|
return loaded;
|
|
137
224
|
};
|
package/render.js
CHANGED
|
@@ -13,6 +13,7 @@ function summary(r) {
|
|
|
13
13
|
pdf: (0, path_1.relative)(process.cwd(), r.pdf),
|
|
14
14
|
sha256: r.sha256,
|
|
15
15
|
engine: r.engine,
|
|
16
|
+
engineReason: r.engineReason,
|
|
16
17
|
backend: r.backend,
|
|
17
18
|
image: r.image,
|
|
18
19
|
sourceDateEpoch: r.sourceDateEpoch,
|
|
@@ -44,8 +45,9 @@ async function renderCommand(argv, prompter) {
|
|
|
44
45
|
console.error(s);
|
|
45
46
|
};
|
|
46
47
|
try {
|
|
47
|
-
log(yanse_1.default.dim(`rendering ${opts.file}
|
|
48
|
+
log(yanse_1.default.dim(`rendering ${opts.file} (${opts.backend})…`));
|
|
48
49
|
const first = await (0, render_1.render)({ ...opts, file: opts.file });
|
|
50
|
+
log(yanse_1.default.dim(` engine ${first.engine}${first.engineReason === 'chosen' ? '' : ` (${first.engineReason})`}`));
|
|
49
51
|
for (const d of first.diagnostics)
|
|
50
52
|
log(yanse_1.default.yellow((0, render_1.formatDiagnostic)(d)));
|
|
51
53
|
if (!first.reproducible) {
|
|
@@ -55,7 +57,7 @@ async function renderCommand(argv, prompter) {
|
|
|
55
57
|
if (argv.verify) {
|
|
56
58
|
// same output path: some tools (Ghostscript) hash the path into the PDF ID
|
|
57
59
|
log(yanse_1.default.dim('rendering again to check the output is byte-identical…'));
|
|
58
|
-
const second = await (0, render_1.render)({ ...opts, file: opts.file, sourceDateEpoch: first.sourceDateEpoch });
|
|
60
|
+
const second = await (0, render_1.render)({ ...opts, file: opts.file, engine: first.engine, sourceDateEpoch: first.sourceDateEpoch });
|
|
59
61
|
verified = second.sha256 === first.sha256;
|
|
60
62
|
}
|
|
61
63
|
if (argv.json) {
|
package/scaffold.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FileMap } from './boilerplates';
|
|
1
|
+
import { FileMap, PaperPreset } from './boilerplates';
|
|
2
2
|
import { Project } from './project';
|
|
3
3
|
export interface WriteResult {
|
|
4
4
|
written: string[];
|
|
@@ -9,6 +9,7 @@ export declare function writeFiles(dir: string, files: FileMap, force?: boolean)
|
|
|
9
9
|
/** Scaffold a latex-kit project (or a paper) in `dir`. */
|
|
10
10
|
export declare function initProject(dir: string, options: {
|
|
11
11
|
paper?: boolean;
|
|
12
|
+
preset?: PaperPreset;
|
|
12
13
|
force?: boolean;
|
|
13
14
|
version: string;
|
|
14
15
|
}): WriteResult;
|
package/scaffold.js
CHANGED
|
@@ -34,7 +34,7 @@ function initProject(dir, options) {
|
|
|
34
34
|
if (existing)
|
|
35
35
|
throw new Error(`${(0, path_1.join)(dir, existing)} already exists; use --force to add the starter files anyway`);
|
|
36
36
|
}
|
|
37
|
-
return writeFiles(dir, options.paper ? (0, boilerplates_1.paperFiles)() : (0, boilerplates_1.projectFiles)(options.version), options.force);
|
|
37
|
+
return writeFiles(dir, options.paper ? (0, boilerplates_1.paperFiles)(options.preset) : (0, boilerplates_1.projectFiles)(options.version), options.force);
|
|
38
38
|
}
|
|
39
39
|
function newTemplate(project, name, force = false) {
|
|
40
40
|
if (!/^[a-z0-9][a-z0-9_-]*$/.test(name))
|
package/usage.js
CHANGED
|
@@ -8,7 +8,10 @@ Usage
|
|
|
8
8
|
|
|
9
9
|
Start
|
|
10
10
|
init [dir] A new project: a letter template, data and a record
|
|
11
|
-
init [dir] --paper A paper
|
|
11
|
+
init [dir] --paper A paper in the Constructive whitepaper style (TikZ,
|
|
12
|
+
PSTricks, highlighted TypeScript listings, IEEE
|
|
13
|
+
references) with CI and release-on-tag; --preset plain
|
|
14
|
+
for a minimal LuaLaTeX paper
|
|
12
15
|
new template <name> A template folder with template.tex and schema.ts
|
|
13
16
|
new document <name> --template <t>
|
|
14
17
|
A record with every required field, linked to its schema
|
|
@@ -21,6 +24,7 @@ Project commands (run in a folder with templates/, data/, documents/)
|
|
|
21
24
|
fields <template> List every field a template reads
|
|
22
25
|
typegen Write JSON Schema and .d.ts for each template's data
|
|
23
26
|
sty [dir] Write latex-kit.sty so editors can preview templates
|
|
27
|
+
lock [--check] Pin the TeX and pandoc images in latex-kit.lock
|
|
24
28
|
import <file> Turn a Word/Markdown/HTML document (or an older .tex)
|
|
25
29
|
into a template; {{x}} and @GROUP@FIELD@ become \\field
|
|
26
30
|
diff <document> --against <ref>
|
|
@@ -44,16 +48,19 @@ always produces the same PDF bytes.
|
|
|
44
48
|
|
|
45
49
|
Options
|
|
46
50
|
-o, --out <dir> Output directory, relative to --root (default: out)
|
|
47
|
-
-e, --engine <name>
|
|
51
|
+
-e, --engine <name> auto (default), lualatex, xelatex, pdflatex or pdfps
|
|
48
52
|
--root <dir> Directory TeX can see (default: current directory)
|
|
49
|
-
--image <ref> Docker image (default: pinned
|
|
53
|
+
--image <ref> Docker image (default: pinned constructiveio/latex-kit)
|
|
50
54
|
--platform <os/arch> Docker --platform (default: native)
|
|
51
55
|
--local Use latexmk on PATH instead of Docker (not pinned)
|
|
52
56
|
--source-date-epoch <s> Build timestamp in seconds since 1970
|
|
53
57
|
--verify Build twice and fail if the PDFs differ
|
|
54
58
|
--json Print a JSON summary on stdout
|
|
55
59
|
|
|
56
|
-
|
|
60
|
+
auto reads the file: a "% !TEX program =" line wins; PSTricks packages
|
|
61
|
+
pick pdfps, xeCJK or ctex pick xelatex, CJK/CJKutf8 pick pdflatex, and
|
|
62
|
+
everything else uses lualatex, the only engine that is byte-reproducible in
|
|
63
|
+
the default image.
|
|
57
64
|
`;
|
|
58
65
|
const BUILD = `latex-kit build [documents…] [options]
|
|
59
66
|
|
|
@@ -65,20 +72,34 @@ Variants
|
|
|
65
72
|
as red markers (they fail instead when CI=true or --strict)
|
|
66
73
|
--variant final No marks. Missing values fail. Mints a document ID on the
|
|
67
74
|
--final first build and saves it in the record (JSON/YAML)
|
|
68
|
-
--variant signed Like final
|
|
75
|
+
--variant signed Like final, and \\signature blocks are signed: each signer's
|
|
76
|
+
image from --signatures (a folder outside the repo,
|
|
77
|
+
<name>.png|pdf|jpg or the signer's "signature" file),
|
|
78
|
+
else "/s/ Name"; dates come from the record:
|
|
79
|
+
signed: { discloser: { date: 2026-11-25 } }
|
|
69
80
|
--variant blank Every field is a labelled line. With no documents, builds
|
|
70
81
|
each template (or --template <name>) as an empty form
|
|
71
82
|
|
|
72
83
|
Options
|
|
73
84
|
--template <name> Only documents that use this template
|
|
85
|
+
--only <names> Only these documents (or templates, for blanks);
|
|
86
|
+
comma-separated, * matches anything: --only 'nda-*'
|
|
87
|
+
--locale <tag> Build in another locale (dates, numbers, bilingual
|
|
88
|
+
order); writes <document>-<tag>.pdf
|
|
89
|
+
--signatures <dir> Signature images for --variant signed
|
|
74
90
|
--strict Fail on missing values in drafts too
|
|
75
|
-
|
|
91
|
+
--force Rebuild even if the PDF is up to date
|
|
92
|
+
-e, --engine <name> auto (default), lualatex, xelatex, pdflatex or pdfps
|
|
76
93
|
--local Use latexmk on PATH instead of Docker
|
|
77
|
-
--image <ref> Docker image (default:
|
|
94
|
+
--image <ref> Docker image (default: latex-kit.lock, else the pinned
|
|
95
|
+
constructiveio/latex-kit on Docker Hub)
|
|
78
96
|
--verify Build twice and fail unless the PDFs are identical
|
|
79
97
|
--tex-only Write the .tex without running TeX
|
|
80
98
|
--json JSON results on stdout
|
|
81
99
|
--root <dir> Project folder (default: current directory)
|
|
100
|
+
|
|
101
|
+
A build is skipped ("unchanged") when the last PDF came from exactly the
|
|
102
|
+
same .tex, template folder, engine, image and build date.
|
|
82
103
|
`;
|
|
83
104
|
const DOCTOR = `latex-kit doctor [--image <ref>] [--json]
|
|
84
105
|
|