latex-kit 0.3.0 → 0.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 +22 -3
- package/args.js +3 -3
- package/boilerplates.d.ts +8 -0
- package/boilerplates.js +225 -0
- package/build.d.ts +28 -2
- package/build.js +233 -94
- package/check.js +4 -3
- package/cli.js +14 -3
- package/commands.js +7 -0
- package/config.d.ts +14 -3
- package/config.js +1 -1
- package/diff.d.ts +25 -0
- package/diff.js +112 -0
- package/esm/args.js +3 -3
- package/esm/boilerplates.d.ts +8 -0
- package/esm/boilerplates.js +220 -0
- package/esm/build.d.ts +28 -2
- package/esm/build.js +234 -97
- package/esm/check.js +4 -3
- package/esm/cli.js +14 -3
- package/esm/commands.js +8 -1
- package/esm/config.d.ts +14 -3
- package/esm/config.js +1 -1
- package/esm/diff.d.ts +25 -0
- package/esm/diff.js +108 -0
- package/esm/import.d.ts +24 -0
- package/esm/import.js +113 -0
- package/esm/index.d.ts +9 -2
- package/esm/index.js +8 -2
- package/esm/lock.d.ts +24 -0
- package/esm/lock.js +50 -0
- package/esm/project-commands.d.ts +14 -0
- package/esm/project-commands.js +232 -7
- package/esm/project.d.ts +20 -1
- package/esm/project.js +105 -4
- package/esm/render.js +6 -6
- package/esm/scaffold.d.ts +27 -0
- package/esm/scaffold.js +108 -0
- package/esm/usage.js +40 -7
- package/import.d.ts +24 -0
- package/import.js +118 -0
- package/index.d.ts +9 -2
- package/index.js +27 -2
- package/lock.d.ts +24 -0
- package/lock.js +57 -0
- package/package.json +6 -5
- package/project-commands.d.ts +14 -0
- package/project-commands.js +238 -5
- package/project.d.ts +20 -1
- package/project.js +103 -2
- package/render.js +5 -5
- package/scaffold.d.ts +27 -0
- package/scaffold.js +115 -0
- package/usage.js +40 -7
package/scaffold.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeFiles = writeFiles;
|
|
4
|
+
exports.initProject = initProject;
|
|
5
|
+
exports.newTemplate = newTemplate;
|
|
6
|
+
exports.skeleton = skeleton;
|
|
7
|
+
exports.newDocument = newDocument;
|
|
8
|
+
const schema_1 = require("@latex-kit/schema");
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const path_1 = require("path");
|
|
11
|
+
const boilerplates_1 = require("./boilerplates");
|
|
12
|
+
const config_1 = require("./config");
|
|
13
|
+
/** Write files under `dir`. Existing files are kept unless `force`. */
|
|
14
|
+
function writeFiles(dir, files, force = false) {
|
|
15
|
+
const written = [];
|
|
16
|
+
const skipped = [];
|
|
17
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
18
|
+
const file = (0, path_1.join)(dir, rel);
|
|
19
|
+
if ((0, fs_1.existsSync)(file) && !force) {
|
|
20
|
+
skipped.push(file);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
(0, fs_1.mkdirSync)((0, path_1.dirname)(file), { recursive: true });
|
|
24
|
+
(0, fs_1.writeFileSync)(file, content);
|
|
25
|
+
written.push(file);
|
|
26
|
+
}
|
|
27
|
+
return { written, skipped };
|
|
28
|
+
}
|
|
29
|
+
/** Scaffold a latex-kit project (or a paper) in `dir`. */
|
|
30
|
+
function initProject(dir, options) {
|
|
31
|
+
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
32
|
+
if (!options.paper && !options.force) {
|
|
33
|
+
const existing = config_1.CONFIG_FILES.find((f) => (0, fs_1.existsSync)((0, path_1.join)(dir, f)));
|
|
34
|
+
if (existing)
|
|
35
|
+
throw new Error(`${(0, path_1.join)(dir, existing)} already exists; use --force to add the starter files anyway`);
|
|
36
|
+
}
|
|
37
|
+
return writeFiles(dir, options.paper ? (0, boilerplates_1.paperFiles)() : (0, boilerplates_1.projectFiles)(options.version), options.force);
|
|
38
|
+
}
|
|
39
|
+
function newTemplate(project, name, force = false) {
|
|
40
|
+
if (!/^[a-z0-9][a-z0-9_-]*$/.test(name))
|
|
41
|
+
throw new Error(`invalid template name "${name}" (use lowercase letters, digits and -)`);
|
|
42
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(project.templatesDir, name)) && !force)
|
|
43
|
+
throw new Error(`template ${name} already exists`);
|
|
44
|
+
const files = (0, boilerplates_1.templateFiles)(name);
|
|
45
|
+
const mapped = {};
|
|
46
|
+
for (const [rel, content] of Object.entries(files))
|
|
47
|
+
mapped[(0, path_1.join)(project.config.templates, rel.replace(/^templates\//, ''))] = content;
|
|
48
|
+
return writeFiles(project.root, mapped, force);
|
|
49
|
+
}
|
|
50
|
+
/** A placeholder value for a JSON Schema: required fields only, typed. */
|
|
51
|
+
function skeleton(schema, root, depth = 0) {
|
|
52
|
+
if (!schema || depth > 12)
|
|
53
|
+
return '';
|
|
54
|
+
if (typeof schema.$ref === 'string') {
|
|
55
|
+
const m = /^#\/(\$defs|definitions)\/(.+)$/.exec(schema.$ref);
|
|
56
|
+
const target = m ? root[m[1]]?.[m[2]] : undefined;
|
|
57
|
+
return skeleton(target, root, depth + 1);
|
|
58
|
+
}
|
|
59
|
+
if ('default' in schema)
|
|
60
|
+
return schema.default;
|
|
61
|
+
if ('const' in schema)
|
|
62
|
+
return schema.const;
|
|
63
|
+
if (Array.isArray(schema.enum))
|
|
64
|
+
return schema.enum[0];
|
|
65
|
+
const alt = (schema.anyOf ?? schema.oneOf);
|
|
66
|
+
if (alt?.length)
|
|
67
|
+
return skeleton(alt.find((a) => a.type !== 'null') ?? alt[0], root, depth + 1);
|
|
68
|
+
const type = Array.isArray(schema.type) ? schema.type[0] : schema.type;
|
|
69
|
+
switch (type) {
|
|
70
|
+
case 'object': {
|
|
71
|
+
const props = (schema.properties ?? {});
|
|
72
|
+
const required = (schema.required ?? []);
|
|
73
|
+
const out = {};
|
|
74
|
+
for (const key of required)
|
|
75
|
+
out[key] = skeleton(props[key], root, depth + 1);
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
case 'array':
|
|
79
|
+
return [];
|
|
80
|
+
case 'number':
|
|
81
|
+
case 'integer':
|
|
82
|
+
return 0;
|
|
83
|
+
case 'boolean':
|
|
84
|
+
return false;
|
|
85
|
+
case 'string':
|
|
86
|
+
return typeof schema.pattern === 'string' && schema.pattern.includes('\\d{4}-\\d{2}-\\d{2}') ? '2026-01-01' : '';
|
|
87
|
+
default:
|
|
88
|
+
return '';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* documents/<name>.json for a template: every required field with a
|
|
93
|
+
* placeholder, and `$schema` pointing at the generated JSON Schema so editors
|
|
94
|
+
* autocomplete and validate it.
|
|
95
|
+
*/
|
|
96
|
+
async function newDocument(project, name, templateName, force = false) {
|
|
97
|
+
if (!/^[a-z0-9][a-z0-9_-]*$/.test(name))
|
|
98
|
+
throw new Error(`invalid document name "${name}" (use lowercase letters, digits and -)`);
|
|
99
|
+
const existing = (0, fs_1.existsSync)(project.documentsDir) ? (0, fs_1.readdirSync)(project.documentsDir).find((f) => f.replace(/\.[^.]+$/, '') === name) : undefined;
|
|
100
|
+
if (existing && !force)
|
|
101
|
+
throw new Error(`documents/${existing} already exists`);
|
|
102
|
+
const template = await project.template(templateName);
|
|
103
|
+
const file = (0, path_1.join)(project.documentsDir, `${name}.json`);
|
|
104
|
+
let schemaFile = null;
|
|
105
|
+
const record = {};
|
|
106
|
+
if (template.jsonSchema) {
|
|
107
|
+
schemaFile = (0, path_1.join)(template.dir, `${templateName}.schema.json`);
|
|
108
|
+
(0, fs_1.writeFileSync)(schemaFile, JSON.stringify((0, schema_1.documentJsonSchema)(templateName, template.jsonSchema), null, 2) + '\n');
|
|
109
|
+
record.$schema = (0, path_1.relative)(project.documentsDir, schemaFile).split('\\').join('/');
|
|
110
|
+
}
|
|
111
|
+
record.template = templateName;
|
|
112
|
+
record.data = template.jsonSchema ? skeleton(template.jsonSchema, template.jsonSchema) : {};
|
|
113
|
+
const r = writeFiles((0, path_1.dirname)(file), { [`${name}.json`]: JSON.stringify(record, null, 2) + '\n' }, force);
|
|
114
|
+
return { ...r, schemaFile };
|
|
115
|
+
}
|
package/usage.js
CHANGED
|
@@ -6,12 +6,28 @@ const MAIN = `latex-kit — build typed, reproducible LaTeX documents
|
|
|
6
6
|
Usage
|
|
7
7
|
latex-kit <command> [options]
|
|
8
8
|
|
|
9
|
+
Start
|
|
10
|
+
init [dir] A new project: a letter template, data and a record
|
|
11
|
+
init [dir] --paper A paper: main.tex, refs.bib and a GitHub Actions workflow
|
|
12
|
+
new template <name> A template folder with template.tex and schema.ts
|
|
13
|
+
new document <name> --template <t>
|
|
14
|
+
A record with every required field, linked to its schema
|
|
15
|
+
|
|
9
16
|
Project commands (run in a folder with templates/, data/, documents/)
|
|
10
17
|
build [documents…] Fill templates with records and build PDFs
|
|
18
|
+
watch [documents…] Rebuild drafts whenever a template, clause or record changes
|
|
19
|
+
clean Delete the out/ folder
|
|
11
20
|
check Check templates, schemas, records and IDs without TeX
|
|
12
21
|
fields <template> List every field a template reads
|
|
13
22
|
typegen Write JSON Schema and .d.ts for each template's data
|
|
14
23
|
sty [dir] Write latex-kit.sty so editors can preview templates
|
|
24
|
+
lock [--check] Pin the TeX and pandoc images in latex-kit.lock
|
|
25
|
+
import <file> Turn a Word/Markdown/HTML document (or an older .tex)
|
|
26
|
+
into a template; {{x}} and @GROUP@FIELD@ become \\field
|
|
27
|
+
diff <document> --against <ref>
|
|
28
|
+
Redline PDF of a document against an earlier commit
|
|
29
|
+
diff <old.tex> <new.tex>
|
|
30
|
+
Redline PDF of any two .tex files
|
|
15
31
|
|
|
16
32
|
Other commands
|
|
17
33
|
render <file.tex> Build a plain .tex file with latexmk in a pinned image
|
|
@@ -29,16 +45,19 @@ always produces the same PDF bytes.
|
|
|
29
45
|
|
|
30
46
|
Options
|
|
31
47
|
-o, --out <dir> Output directory, relative to --root (default: out)
|
|
32
|
-
-e, --engine <name>
|
|
48
|
+
-e, --engine <name> auto (default), lualatex, xelatex, pdflatex or pdfps
|
|
33
49
|
--root <dir> Directory TeX can see (default: current directory)
|
|
34
|
-
--image <ref> Docker image (default: pinned
|
|
35
|
-
--platform <os/arch> Docker --platform (default:
|
|
50
|
+
--image <ref> Docker image (default: pinned ghcr.io/constructive-io/latex-kit)
|
|
51
|
+
--platform <os/arch> Docker --platform (default: native)
|
|
36
52
|
--local Use latexmk on PATH instead of Docker (not pinned)
|
|
37
53
|
--source-date-epoch <s> Build timestamp in seconds since 1970
|
|
38
54
|
--verify Build twice and fail if the PDFs differ
|
|
39
55
|
--json Print a JSON summary on stdout
|
|
40
56
|
|
|
41
|
-
|
|
57
|
+
auto reads the file: a "% !TEX program =" line wins; PSTricks packages
|
|
58
|
+
pick pdfps, xeCJK or ctex pick xelatex, CJK/CJKutf8 pick pdflatex, and
|
|
59
|
+
everything else uses lualatex, the only engine that is byte-reproducible in
|
|
60
|
+
the default image.
|
|
42
61
|
`;
|
|
43
62
|
const BUILD = `latex-kit build [documents…] [options]
|
|
44
63
|
|
|
@@ -50,20 +69,34 @@ Variants
|
|
|
50
69
|
as red markers (they fail instead when CI=true or --strict)
|
|
51
70
|
--variant final No marks. Missing values fail. Mints a document ID on the
|
|
52
71
|
--final first build and saves it in the record (JSON/YAML)
|
|
53
|
-
--variant signed Like final
|
|
72
|
+
--variant signed Like final, and \\signature blocks are signed: each signer's
|
|
73
|
+
image from --signatures (a folder outside the repo,
|
|
74
|
+
<name>.png|pdf|jpg or the signer's "signature" file),
|
|
75
|
+
else "/s/ Name"; dates come from the record:
|
|
76
|
+
signed: { discloser: { date: 2026-11-25 } }
|
|
54
77
|
--variant blank Every field is a labelled line. With no documents, builds
|
|
55
78
|
each template (or --template <name>) as an empty form
|
|
56
79
|
|
|
57
80
|
Options
|
|
58
81
|
--template <name> Only documents that use this template
|
|
82
|
+
--only <names> Only these documents (or templates, for blanks);
|
|
83
|
+
comma-separated, * matches anything: --only 'nda-*'
|
|
84
|
+
--locale <tag> Build in another locale (dates, numbers, bilingual
|
|
85
|
+
order); writes <document>-<tag>.pdf
|
|
86
|
+
--signatures <dir> Signature images for --variant signed
|
|
59
87
|
--strict Fail on missing values in drafts too
|
|
60
|
-
|
|
88
|
+
--force Rebuild even if the PDF is up to date
|
|
89
|
+
-e, --engine <name> auto (default), lualatex, xelatex, pdflatex or pdfps
|
|
61
90
|
--local Use latexmk on PATH instead of Docker
|
|
62
|
-
--image <ref> Docker image (default: pinned
|
|
91
|
+
--image <ref> Docker image (default: latex-kit.lock, else the pinned
|
|
92
|
+
ghcr.io/constructive-io/latex-kit)
|
|
63
93
|
--verify Build twice and fail unless the PDFs are identical
|
|
64
94
|
--tex-only Write the .tex without running TeX
|
|
65
95
|
--json JSON results on stdout
|
|
66
96
|
--root <dir> Project folder (default: current directory)
|
|
97
|
+
|
|
98
|
+
A build is skipped ("unchanged") when the last PDF came from exactly the
|
|
99
|
+
same .tex, template folder, engine, image and build date.
|
|
67
100
|
`;
|
|
68
101
|
const DOCTOR = `latex-kit doctor [--image <ref>] [--json]
|
|
69
102
|
|