latex-kit 0.5.0 → 0.6.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 +1 -1
- package/boilerplates.d.ts +14 -1
- package/boilerplates.js +200 -2
- package/build.d.ts +12 -1
- package/build.js +16 -3
- package/cli.js +2 -2
- package/config.d.ts +8 -1
- package/esm/boilerplates.d.ts +14 -1
- package/esm/boilerplates.js +196 -1
- package/esm/build.d.ts +12 -1
- package/esm/build.js +16 -3
- package/esm/cli.js +2 -2
- package/esm/config.d.ts +8 -1
- package/esm/form.d.ts +30 -0
- package/esm/form.js +39 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/paper-style.d.ts +10 -0
- package/esm/paper-style.js +10 -0
- package/esm/project-commands.js +19 -2
- package/esm/scaffold.d.ts +2 -1
- package/esm/scaffold.js +1 -1
- package/esm/usage.js +18 -3
- package/form.d.ts +30 -0
- package/form.js +43 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +6 -6
- package/paper-style.d.ts +10 -0
- package/paper-style.js +13 -0
- package/project-commands.js +18 -1
- package/scaffold.d.ts +2 -1
- package/scaffold.js +1 -1
- package/usage.js +18 -3
package/esm/build.js
CHANGED
|
@@ -6,6 +6,7 @@ import { createHash } from 'crypto';
|
|
|
6
6
|
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs';
|
|
7
7
|
import { homedir } from 'os';
|
|
8
8
|
import { basename, extname, isAbsolute, join, posix, relative, resolve, sep } from 'path';
|
|
9
|
+
import { writeFormJson } from './form';
|
|
9
10
|
export class BuildError extends Error {
|
|
10
11
|
diagnostics;
|
|
11
12
|
constructor(message, diagnostics) {
|
|
@@ -94,7 +95,8 @@ async function run(job) {
|
|
|
94
95
|
snippets.add(resolve(s.file));
|
|
95
96
|
return s;
|
|
96
97
|
};
|
|
97
|
-
|
|
98
|
+
// asking for blanks where values are missing means missing values are expected
|
|
99
|
+
const strict = options.strict ?? (options.missing === 'blank' ? false : isCI());
|
|
98
100
|
const files = [...job.inputs, template.texFile, ...(template.schemaFile ? [template.schemaFile] : [])];
|
|
99
101
|
const { epoch, reproducible } = buildEpoch(files);
|
|
100
102
|
let docId = job.docId;
|
|
@@ -104,7 +106,11 @@ async function run(job) {
|
|
|
104
106
|
minted = true;
|
|
105
107
|
}
|
|
106
108
|
const outDir = options.outDir ?? join(project.outDir, job.name);
|
|
107
|
-
const
|
|
109
|
+
const blanks = variant === 'blank' ? (options.blanks ?? project.config.blanks) : undefined;
|
|
110
|
+
// the names view is its own file, so it can sit next to the form to fill in
|
|
111
|
+
const highlight = variant === 'draft' && Boolean(options.highlight);
|
|
112
|
+
const missingAs = variant === 'draft' ? options.missing : undefined;
|
|
113
|
+
const job_ = variant === 'final' ? job.name : blanks === 'names' ? `${job.name}-names` : highlight ? `${job.name}-highlight` : `${job.name}-${variant}`;
|
|
108
114
|
// signed builds: copy signature images next to the .tex for this build only
|
|
109
115
|
const stageDir = join(outDir, 'lk-signatures');
|
|
110
116
|
const staged = [];
|
|
@@ -150,6 +156,7 @@ async function run(job) {
|
|
|
150
156
|
docId,
|
|
151
157
|
template: template.name,
|
|
152
158
|
allowMissing: variant === 'draft' ? !strict : undefined,
|
|
159
|
+
markValues: highlight,
|
|
153
160
|
loadSnippet,
|
|
154
161
|
loadClause: project.loadClause,
|
|
155
162
|
components: project.components,
|
|
@@ -168,7 +175,7 @@ async function run(job) {
|
|
|
168
175
|
mkdirSync(outDir, { recursive: true });
|
|
169
176
|
const texPath = join(outDir, `${job_}.tex`);
|
|
170
177
|
const stamp = `${new Date(finalEpoch.epoch * 1000).toISOString().slice(0, 10)} ${gitShortHead(project.root)}`;
|
|
171
|
-
const tex = wrapDocument(evaluated.tex, { variant, stamp });
|
|
178
|
+
const tex = wrapDocument(evaluated.tex, { variant, stamp, blanks, missing: missingAs });
|
|
172
179
|
writeFileSync(texPath, tex);
|
|
173
180
|
writeFileSync(join(outDir, 'latex-kit.sty'), LATEX_KIT_STY);
|
|
174
181
|
const result = {
|
|
@@ -185,6 +192,7 @@ async function run(job) {
|
|
|
185
192
|
engine: null,
|
|
186
193
|
engineReason: null,
|
|
187
194
|
cached: false,
|
|
195
|
+
form: null,
|
|
188
196
|
diagnostics,
|
|
189
197
|
};
|
|
190
198
|
if (options.texOnly)
|
|
@@ -226,6 +234,7 @@ async function run(job) {
|
|
|
226
234
|
const keyInputs = [...filesUnder(template.dir), ...staged].map((f) => [posixRel(project.root, f), sha256(readFileSync(f))]);
|
|
227
235
|
const cacheKey = sha256(JSON.stringify({ v: 1, tex: sha256(tex), sty: sha256(LATEX_KIT_STY), engine, backend, image: backend === 'docker' ? (image ?? 'default') : null, platform: platform ?? null, epoch: finalEpoch.epoch, inputs: keyInputs }));
|
|
228
236
|
const manifestPath = join(outDir, `${job_}.manifest.json`);
|
|
237
|
+
const formBase = join(outDir, job_);
|
|
229
238
|
const pdfPath = join(outDir, `${job_}.pdf`);
|
|
230
239
|
if (!options.force && !options.verify && existsSync(manifestPath) && existsSync(pdfPath)) {
|
|
231
240
|
try {
|
|
@@ -235,6 +244,7 @@ async function run(job) {
|
|
|
235
244
|
result.pdf = pdfPath;
|
|
236
245
|
result.sha256 = pdfSha;
|
|
237
246
|
result.cached = true;
|
|
247
|
+
result.form = existsSync(formBase + '.form.json') ? formBase + '.form.json' : null;
|
|
238
248
|
return result;
|
|
239
249
|
}
|
|
240
250
|
}
|
|
@@ -242,6 +252,8 @@ async function run(job) {
|
|
|
242
252
|
// an unreadable manifest just means a rebuild
|
|
243
253
|
}
|
|
244
254
|
}
|
|
255
|
+
// TeX writes marked spots to <job>.form; a file from an earlier run must not survive
|
|
256
|
+
rmSync(formBase + '.form', { force: true });
|
|
245
257
|
let rendered;
|
|
246
258
|
try {
|
|
247
259
|
rendered = await render({ ...renderOpts, outDir: relative(project.root, outDir) });
|
|
@@ -257,6 +269,7 @@ async function run(job) {
|
|
|
257
269
|
}
|
|
258
270
|
result.pdf = rendered.pdf;
|
|
259
271
|
result.sha256 = rendered.sha256;
|
|
272
|
+
result.form = writeFormJson(formBase);
|
|
260
273
|
if (options.verify) {
|
|
261
274
|
// same output path: some tools (Ghostscript) hash the path into the PDF ID
|
|
262
275
|
const again = await render({ ...renderOpts, outDir: relative(project.root, outDir) });
|
package/esm/cli.js
CHANGED
|
@@ -18,8 +18,8 @@ const app = new CLI(commands, {
|
|
|
18
18
|
version: version(),
|
|
19
19
|
minimistOpts: {
|
|
20
20
|
alias: { h: 'help', v: 'version', o: 'out', e: 'engine' },
|
|
21
|
-
boolean: ['help', 'version', 'local', 'verify', 'json', 'final', 'strict', 'tex-only', 'force', 'schema', 'paper', 'check'],
|
|
22
|
-
string: ['out', 'engine', 'image', 'root', 'platform', 'source-date-epoch', 'variant', 'template', 'name', 'against', 'only', 'locale', 'signatures'],
|
|
21
|
+
boolean: ['help', 'version', 'local', 'verify', 'json', 'final', 'strict', 'tex-only', 'force', 'schema', 'paper', 'check', 'highlight'],
|
|
22
|
+
string: ['out', 'engine', 'image', 'root', 'platform', 'source-date-epoch', 'variant', 'template', 'name', 'against', 'only', 'locale', 'signatures', 'preset', 'blanks', 'missing'],
|
|
23
23
|
default: { strict: undefined, schema: true },
|
|
24
24
|
},
|
|
25
25
|
});
|
package/esm/config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Backend, EngineChoice } from '@latex-kit/render';
|
|
2
|
+
import type { BlankStyle } from '@latex-kit/template';
|
|
2
3
|
/** latex-kit.config.ts (or .js, .mjs, .cjs, .json) at the project root. */
|
|
3
4
|
export interface LatexKitConfig {
|
|
4
5
|
/** One folder per template: `<templates>/<name>/template.tex` and optional `schema.ts`. Default `templates`. */
|
|
@@ -25,11 +26,17 @@ export interface LatexKitConfig {
|
|
|
25
26
|
* override it. A leading ~ is the home folder.
|
|
26
27
|
*/
|
|
27
28
|
signatures?: string;
|
|
29
|
+
/**
|
|
30
|
+
* How blanks print in blank builds: `labelled` (default, the field's name on
|
|
31
|
+
* a line), `lines` (an empty line to write on) or `names` (the name in
|
|
32
|
+
* brackets). `--blanks` overrides it.
|
|
33
|
+
*/
|
|
34
|
+
blanks?: BlankStyle;
|
|
28
35
|
backend?: Backend;
|
|
29
36
|
image?: string;
|
|
30
37
|
platform?: string | null;
|
|
31
38
|
}
|
|
32
|
-
export type ResolvedConfig = Required<Pick<LatexKitConfig, 'templates' | 'snippets' | 'clauses' | 'components' | 'data' | 'documents' | 'out' | 'locale'>> & Pick<LatexKitConfig, 'engine' | 'backend' | 'image' | 'platform' | 'signatures'> & {
|
|
39
|
+
export type ResolvedConfig = Required<Pick<LatexKitConfig, 'templates' | 'snippets' | 'clauses' | 'components' | 'data' | 'documents' | 'out' | 'locale'>> & Pick<LatexKitConfig, 'engine' | 'backend' | 'image' | 'platform' | 'signatures' | 'blanks'> & {
|
|
33
40
|
file: string | null;
|
|
34
41
|
};
|
|
35
42
|
export declare function defineConfig(config: LatexKitConfig): LatexKitConfig;
|
package/esm/form.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A spot in a built PDF for someone to fill in: where a signing or form tool
|
|
3
|
+
* should put its box. Lengths are PDF points (1/72 inch); `x` and `y` are the
|
|
4
|
+
* box's bottom-left corner, measured from the bottom-left corner of the page.
|
|
5
|
+
*/
|
|
6
|
+
export interface FormField {
|
|
7
|
+
/** signature, date, initials, text, or whatever the template called it. */
|
|
8
|
+
type: string;
|
|
9
|
+
/** The party that fills it in, as the template named it. */
|
|
10
|
+
who: string;
|
|
11
|
+
/** What to type here, when the template said (`label={Printed name}`). */
|
|
12
|
+
label?: string;
|
|
13
|
+
/** From 1. */
|
|
14
|
+
page: number;
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Read what `\formfield` and `\signature` wrote while TeX ran: one line per
|
|
22
|
+
* spot, `type who page x y width height raise [label]`, lengths in scaled points.
|
|
23
|
+
* Lines that are not that shape are skipped.
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseFormFile(text: string): FormField[];
|
|
26
|
+
/**
|
|
27
|
+
* Turn `<base>.form` into `<base>.form.json`. Returns the JSON file, or null
|
|
28
|
+
* when the document marked no spots (a stale JSON file is then removed).
|
|
29
|
+
*/
|
|
30
|
+
export declare function writeFormJson(base: string): string | null;
|
package/esm/form.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { existsSync, readFileSync, rmSync, writeFileSync } from 'fs';
|
|
2
|
+
/** TeX's scaled points (65536 to a TeX point, 72.27 TeX points to an inch) to PDF points. */
|
|
3
|
+
const bp = (sp) => Math.round((sp / 65536) * (72 / 72.27) * 100) / 100;
|
|
4
|
+
/**
|
|
5
|
+
* Read what `\formfield` and `\signature` wrote while TeX ran: one line per
|
|
6
|
+
* spot, `type who page x y width height raise [label]`, lengths in scaled points.
|
|
7
|
+
* Lines that are not that shape are skipped.
|
|
8
|
+
*/
|
|
9
|
+
export function parseFormFile(text) {
|
|
10
|
+
const fields = [];
|
|
11
|
+
for (const line of text.split('\n')) {
|
|
12
|
+
const parts = line.trim().split(/\s+/);
|
|
13
|
+
if (parts.length < 8)
|
|
14
|
+
continue;
|
|
15
|
+
const [type, who, ...rest] = parts;
|
|
16
|
+
const n = rest.slice(0, 6).map(Number);
|
|
17
|
+
const label = rest.slice(6).join(' ');
|
|
18
|
+
if (!n.every(Number.isFinite) || n[0] < 1)
|
|
19
|
+
continue;
|
|
20
|
+
const [page, x, y, width, height, raise] = n;
|
|
21
|
+
fields.push({ type, who: who === '-' ? '' : who, ...(label ? { label } : {}), page, x: bp(x), y: bp(y + raise), width: bp(width), height: bp(height) });
|
|
22
|
+
}
|
|
23
|
+
return fields;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Turn `<base>.form` into `<base>.form.json`. Returns the JSON file, or null
|
|
27
|
+
* when the document marked no spots (a stale JSON file is then removed).
|
|
28
|
+
*/
|
|
29
|
+
export function writeFormJson(base) {
|
|
30
|
+
const raw = `${base}.form`;
|
|
31
|
+
const out = `${base}.form.json`;
|
|
32
|
+
const fields = existsSync(raw) ? parseFormFile(readFileSync(raw, 'utf8')) : [];
|
|
33
|
+
if (!fields.length) {
|
|
34
|
+
rmSync(out, { force: true });
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
writeFileSync(out, JSON.stringify(fields, null, 2) + '\n');
|
|
38
|
+
return out;
|
|
39
|
+
}
|
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Constructive whitepaper style, from constructive-io/rls-whitepaper and
|
|
3
|
+
* hyperweb-whitepaper (tex/headers/): the code colour palette and the
|
|
4
|
+
* TypeScript listings style, copied verbatim so new papers look like ours.
|
|
5
|
+
* Regenerate from those files rather than editing here.
|
|
6
|
+
*/
|
|
7
|
+
/** tex/headers/colors.tex */
|
|
8
|
+
export declare const WHITEPAPER_COLORS_TEX = "% Define colors for code highlighting\n\\definecolor{lightpurple}{rgb}{0.85, 0.85, 1}\n\\definecolor{white}{rgb}{1, 1, 1}\n\\definecolor{codegray}{gray}{0.9}\n\\definecolor{codeblue}{rgb}{0,0,0.6}\n\\definecolor{codegreen}{rgb}{0,0.6,0}\n\\definecolor{codepurple}{rgb}{0.58,0,0.82}\n\\definecolor{codebackground}{rgb}{0.95,0.95,0.95}\n\\definecolor{codeorange}{rgb}{1, 0.6, 0.2}\n\\definecolor{codered}{rgb}{0.8, 0, 0}\n\\definecolor{codeyellow}{rgb}{0.9, 0.9, 0.4}\n\\definecolor{codeteal}{rgb}{0, 0.5, 0.5}\n\\definecolor{codepink}{rgb}{1, 0.5, 0.7}\n\\definecolor{codebrown}{rgb}{0.6, 0.4, 0.2}\n\\definecolor{codelightblue}{rgb}{0.7, 0.85, 1}\n\\definecolor{codelightgreen}{rgb}{0.7, 1, 0.7}\n\\definecolor{codedarkblue}{rgb}{0, 0.2, 0.5}\n\\definecolor{codedarkpurple}{rgb}{0.4, 0.2, 0.6}\n\\definecolor{black}{rgb}{0, 0, 0}\n\\pagecolor{white}";
|
|
9
|
+
/** tex/headers/typescript.tex */
|
|
10
|
+
export declare const WHITEPAPER_TYPESCRIPT_TEX = "% Code style definition\n\\lstdefinelanguage{typescript}{\n keywords={abstract, arguments, await, boolean, break, byte, case, catch,\n class, const, continue, debugger, default, delete, do, double, else,\n enum, eval, export, extends, false, final, finally, float, for,\n function, goto, if, implements, import, in, instanceof, int, interface,\n let, long, native, new, null, package, private, protected, public,\n return, short, static, super, switch, synchronized, this, throw,\n throws, transient, true, try, typeof, var, void, volatile, while, with,\n yield, async, from, of},\n keywordstyle=\\color{codeblue},\n sensitive=true,\n comment=[l]{//},\n morecomment=[s]{/*}{*/},\n commentstyle=\\color{codegreen},\n stringstyle=\\color{codepurple},\n morestring=[b]',\n morestring=[b]\"\n}\n\n% Enhanced Code Style Definition for TypeScript and JavaScript\n\\lstdefinestyle{typescript}{\n language=typescript,\n backgroundcolor=\\color{white},\n basicstyle=\\ttfamily\\footnotesize,\n breakatwhitespace=false,\n breaklines=true,\n captionpos=b,\n keepspaces=true,\n numbers=left,\n numbersep=5pt,\n showspaces=false,\n showstringspaces=false,\n showtabs=false,\n tabsize=2,\n numberstyle=\\tiny\\color{black},\n % Additional TypeScript-specific highlighting\n moredelim=[is][\\textcolor{codepurple}]{\\#\\{}{\\}}, % Template literals\n moredelim=[is][\\textcolor{codeblue}]{<}{>}, % Generic types\n literate=\n {=>}{{\\textcolor{codeblue}{=>}}}2 \n {interface}{{\\textcolor{codeblue}{interface}}}9\n {type}{{\\textcolor{codered}{type}}}4\n {export}{{\\textcolor{codegreen}{export}}}6\n {import}{{\\textcolor{codeorange}{import}}}6\n {from}{{\\textcolor{codeblue}{from}}}4\n {return}{{\\textcolor{codeteal}{return}}}6 \n {function}{{\\textcolor{codeblue}{function}}}8\n {string}{{\\textcolor{codepink}{string}}}6 \n {let}{{\\textcolor{codered}{let}}}3 \n% {const}{{\\textcolor{codedarkpurple}{const}}}5 \n {var}{{\\textcolor{codelightblue}{var}}}3 \n {while}{{\\textcolor{codered}{while}}}5 \n {if}{{\\textcolor{codeorange}{if}}}2 \n {else}{{\\textcolor{codeyellow}{else}}}4\n\t{@onlyOwner}{{\\textcolor{codered}{@onlyOwner}}}9\n\t{@instantiate}{{\\textcolor{codered}{@instantiate}}}{10}\n}\n\n";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Constructive whitepaper style, from constructive-io/rls-whitepaper and
|
|
3
|
+
* hyperweb-whitepaper (tex/headers/): the code colour palette and the
|
|
4
|
+
* TypeScript listings style, copied verbatim so new papers look like ours.
|
|
5
|
+
* Regenerate from those files rather than editing here.
|
|
6
|
+
*/
|
|
7
|
+
/** tex/headers/colors.tex */
|
|
8
|
+
export const WHITEPAPER_COLORS_TEX = '% Define colors for code highlighting\n\\definecolor{lightpurple}{rgb}{0.85, 0.85, 1}\n\\definecolor{white}{rgb}{1, 1, 1}\n\\definecolor{codegray}{gray}{0.9}\n\\definecolor{codeblue}{rgb}{0,0,0.6}\n\\definecolor{codegreen}{rgb}{0,0.6,0}\n\\definecolor{codepurple}{rgb}{0.58,0,0.82}\n\\definecolor{codebackground}{rgb}{0.95,0.95,0.95}\n\\definecolor{codeorange}{rgb}{1, 0.6, 0.2}\n\\definecolor{codered}{rgb}{0.8, 0, 0}\n\\definecolor{codeyellow}{rgb}{0.9, 0.9, 0.4}\n\\definecolor{codeteal}{rgb}{0, 0.5, 0.5}\n\\definecolor{codepink}{rgb}{1, 0.5, 0.7}\n\\definecolor{codebrown}{rgb}{0.6, 0.4, 0.2}\n\\definecolor{codelightblue}{rgb}{0.7, 0.85, 1}\n\\definecolor{codelightgreen}{rgb}{0.7, 1, 0.7}\n\\definecolor{codedarkblue}{rgb}{0, 0.2, 0.5}\n\\definecolor{codedarkpurple}{rgb}{0.4, 0.2, 0.6}\n\\definecolor{black}{rgb}{0, 0, 0}\n\\pagecolor{white}';
|
|
9
|
+
/** tex/headers/typescript.tex */
|
|
10
|
+
export const WHITEPAPER_TYPESCRIPT_TEX = "% Code style definition\n\\lstdefinelanguage{typescript}{\n keywords={abstract, arguments, await, boolean, break, byte, case, catch,\n class, const, continue, debugger, default, delete, do, double, else,\n enum, eval, export, extends, false, final, finally, float, for,\n function, goto, if, implements, import, in, instanceof, int, interface,\n let, long, native, new, null, package, private, protected, public,\n return, short, static, super, switch, synchronized, this, throw,\n throws, transient, true, try, typeof, var, void, volatile, while, with,\n yield, async, from, of},\n keywordstyle=\\color{codeblue},\n sensitive=true,\n comment=[l]{//},\n morecomment=[s]{/*}{*/},\n commentstyle=\\color{codegreen},\n stringstyle=\\color{codepurple},\n morestring=[b]',\n morestring=[b]\"\n}\n\n% Enhanced Code Style Definition for TypeScript and JavaScript\n\\lstdefinestyle{typescript}{\n language=typescript,\n backgroundcolor=\\color{white},\n basicstyle=\\ttfamily\\footnotesize,\n breakatwhitespace=false,\n breaklines=true,\n captionpos=b,\n keepspaces=true,\n numbers=left,\n numbersep=5pt,\n showspaces=false,\n showstringspaces=false,\n showtabs=false,\n tabsize=2,\n numberstyle=\\tiny\\color{black},\n % Additional TypeScript-specific highlighting\n moredelim=[is][\\textcolor{codepurple}]{\\#\\{}{\\}}, % Template literals\n moredelim=[is][\\textcolor{codeblue}]{<}{>}, % Generic types\n literate=\n {=>}{{\\textcolor{codeblue}{=>}}}2 \n {interface}{{\\textcolor{codeblue}{interface}}}9\n {type}{{\\textcolor{codered}{type}}}4\n {export}{{\\textcolor{codegreen}{export}}}6\n {import}{{\\textcolor{codeorange}{import}}}6\n {from}{{\\textcolor{codeblue}{from}}}4\n {return}{{\\textcolor{codeteal}{return}}}6 \n {function}{{\\textcolor{codeblue}{function}}}8\n {string}{{\\textcolor{codepink}{string}}}6 \n {let}{{\\textcolor{codered}{let}}}3 \n% {const}{{\\textcolor{codedarkpurple}{const}}}5 \n {var}{{\\textcolor{codelightblue}{var}}}3 \n {while}{{\\textcolor{codered}{while}}}5 \n {if}{{\\textcolor{codeorange}{if}}}2 \n {else}{{\\textcolor{codeyellow}{else}}}4\n\t{@onlyOwner}{{\\textcolor{codered}{@onlyOwner}}}9\n\t{@instantiate}{{\\textcolor{codered}{@instantiate}}}{10}\n}\n\n";
|
package/esm/project-commands.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ENGINES } from '@latex-kit/render';
|
|
2
2
|
import { documentJsonSchema, generateTypes, loadDocument } from '@latex-kit/schema';
|
|
3
|
-
import { formatDiagnostic, LATEX_KIT_STY, VARIANTS } from '@latex-kit/template';
|
|
3
|
+
import { BLANK_STYLES, formatDiagnostic, LATEX_KIT_STY, VARIANTS } from '@latex-kit/template';
|
|
4
4
|
import { existsSync, mkdirSync, rmSync, watch as fsWatch, writeFileSync } from 'fs';
|
|
5
5
|
import { isAbsolute, join, relative } from 'path';
|
|
6
6
|
import chalk from 'yanse';
|
|
7
7
|
import { UsageError } from './args';
|
|
8
|
+
import { PAPER_PRESETS } from './boilerplates';
|
|
8
9
|
import { buildBlank, buildDocument, BuildError } from './build';
|
|
9
10
|
import { checkProject, templateFields } from './check';
|
|
10
11
|
import { version } from './commands';
|
|
@@ -48,6 +49,14 @@ export async function buildCommand(argv) {
|
|
|
48
49
|
throw new UsageError(`--engine must be auto or one of ${ENGINES.join(', ')}`);
|
|
49
50
|
if (argv.signatures !== undefined && variant !== 'signed')
|
|
50
51
|
throw new UsageError('--signatures only applies to --variant signed');
|
|
52
|
+
if (argv.blanks !== undefined && !BLANK_STYLES.includes(argv.blanks))
|
|
53
|
+
throw new UsageError(`--blanks must be one of ${BLANK_STYLES.join(', ')}`);
|
|
54
|
+
if (argv.blanks !== undefined && variant !== 'blank')
|
|
55
|
+
throw new UsageError('--blanks only applies to --variant blank');
|
|
56
|
+
if (argv.missing !== undefined && !['marker', 'blank'].includes(argv.missing))
|
|
57
|
+
throw new UsageError('--missing must be marker or blank');
|
|
58
|
+
if ((argv.highlight || argv.missing !== undefined) && variant !== 'draft')
|
|
59
|
+
throw new UsageError('--highlight and --missing only apply to drafts');
|
|
51
60
|
const only = onlyMatcher(argv.only);
|
|
52
61
|
const project = await Project.open(argv.root);
|
|
53
62
|
const options = {
|
|
@@ -62,6 +71,9 @@ export async function buildCommand(argv) {
|
|
|
62
71
|
locale: checkLocale(argv.locale),
|
|
63
72
|
force: Boolean(argv.force),
|
|
64
73
|
signatures: argv.signatures,
|
|
74
|
+
blanks: argv.blanks,
|
|
75
|
+
highlight: Boolean(argv.highlight),
|
|
76
|
+
missing: argv.missing,
|
|
65
77
|
};
|
|
66
78
|
const json = Boolean(argv.json);
|
|
67
79
|
const log = (s) => !json && console.error(s);
|
|
@@ -283,7 +295,12 @@ export async function lockCommand(argv) {
|
|
|
283
295
|
}
|
|
284
296
|
export async function initCommand(argv) {
|
|
285
297
|
const dir = join(process.cwd(), argv._?.[0] ? String(argv._[0]) : '.');
|
|
286
|
-
const
|
|
298
|
+
const preset = (argv.preset ?? 'whitepaper');
|
|
299
|
+
if (!PAPER_PRESETS.includes(preset))
|
|
300
|
+
throw new UsageError(`--preset must be one of ${PAPER_PRESETS.join(', ')}`);
|
|
301
|
+
if (argv.preset && !argv.paper)
|
|
302
|
+
throw new UsageError('--preset only applies to init --paper');
|
|
303
|
+
const r = initProject(dir, { paper: Boolean(argv.paper), preset, force: Boolean(argv.force), version: version() });
|
|
287
304
|
if (!argv.paper && !existsSync(join(dir, LOCK_FILE))) {
|
|
288
305
|
writeLock(dir);
|
|
289
306
|
r.written.push(join(dir, LOCK_FILE));
|
package/esm/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/esm/scaffold.js
CHANGED
|
@@ -27,7 +27,7 @@ export function initProject(dir, options) {
|
|
|
27
27
|
if (existing)
|
|
28
28
|
throw new Error(`${join(dir, existing)} already exists; use --force to add the starter files anyway`);
|
|
29
29
|
}
|
|
30
|
-
return writeFiles(dir, options.paper ? paperFiles() : projectFiles(options.version), options.force);
|
|
30
|
+
return writeFiles(dir, options.paper ? paperFiles(options.preset) : projectFiles(options.version), options.force);
|
|
31
31
|
}
|
|
32
32
|
export function newTemplate(project, name, force = false) {
|
|
33
33
|
if (!/^[a-z0-9][a-z0-9_-]*$/.test(name))
|
package/esm/usage.js
CHANGED
|
@@ -5,7 +5,10 @@ Usage
|
|
|
5
5
|
|
|
6
6
|
Start
|
|
7
7
|
init [dir] A new project: a letter template, data and a record
|
|
8
|
-
init [dir] --paper A paper
|
|
8
|
+
init [dir] --paper A paper in the Constructive whitepaper style (TikZ,
|
|
9
|
+
PSTricks, highlighted TypeScript listings, IEEE
|
|
10
|
+
references) with CI and release-on-tag; --preset plain
|
|
11
|
+
for a minimal LuaLaTeX paper
|
|
9
12
|
new template <name> A template folder with template.tex and schema.ts
|
|
10
13
|
new document <name> --template <t>
|
|
11
14
|
A record with every required field, linked to its schema
|
|
@@ -44,7 +47,7 @@ Options
|
|
|
44
47
|
-o, --out <dir> Output directory, relative to --root (default: out)
|
|
45
48
|
-e, --engine <name> auto (default), lualatex, xelatex, pdflatex or pdfps
|
|
46
49
|
--root <dir> Directory TeX can see (default: current directory)
|
|
47
|
-
--image <ref> Docker image (default: pinned
|
|
50
|
+
--image <ref> Docker image (default: pinned constructiveio/latex-kit)
|
|
48
51
|
--platform <os/arch> Docker --platform (default: native)
|
|
49
52
|
--local Use latexmk on PATH instead of Docker (not pinned)
|
|
50
53
|
--source-date-epoch <s> Build timestamp in seconds since 1970
|
|
@@ -80,18 +83,30 @@ Options
|
|
|
80
83
|
comma-separated, * matches anything: --only 'nda-*'
|
|
81
84
|
--locale <tag> Build in another locale (dates, numbers, bilingual
|
|
82
85
|
order); writes <document>-<tag>.pdf
|
|
86
|
+
--blanks <style> How a blank prints, for --variant blank:
|
|
87
|
+
labelled (default) the field's name on a line
|
|
88
|
+
lines an empty line to write on
|
|
89
|
+
names the name in brackets; writes <name>-names.pdf
|
|
90
|
+
--highlight Drafts: print every filled-in value in red, to review
|
|
91
|
+
what came from the record; writes <name>-highlight.pdf
|
|
92
|
+
--missing <how> Drafts: a missing value prints as a red marker
|
|
93
|
+
(default) or as a blank to fill in: --missing blank
|
|
83
94
|
--signatures <dir> Signature images for --variant signed
|
|
84
95
|
--strict Fail on missing values in drafts too
|
|
85
96
|
--force Rebuild even if the PDF is up to date
|
|
86
97
|
-e, --engine <name> auto (default), lualatex, xelatex, pdflatex or pdfps
|
|
87
98
|
--local Use latexmk on PATH instead of Docker
|
|
88
99
|
--image <ref> Docker image (default: latex-kit.lock, else the pinned
|
|
89
|
-
|
|
100
|
+
constructiveio/latex-kit on Docker Hub)
|
|
90
101
|
--verify Build twice and fail unless the PDFs are identical
|
|
91
102
|
--tex-only Write the .tex without running TeX
|
|
92
103
|
--json JSON results on stdout
|
|
93
104
|
--root <dir> Project folder (default: current directory)
|
|
94
105
|
|
|
106
|
+
When a template marks spots to sign or fill in (\\signature blocks do, and
|
|
107
|
+
\\formfield[type=…,who=…]{…} marks your own), the build also writes
|
|
108
|
+
<document>.form.json: each spot's page and position, for signing tools.
|
|
109
|
+
|
|
95
110
|
A build is skipped ("unchanged") when the last PDF came from exactly the
|
|
96
111
|
same .tex, template folder, engine, image and build date.
|
|
97
112
|
`;
|
package/form.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A spot in a built PDF for someone to fill in: where a signing or form tool
|
|
3
|
+
* should put its box. Lengths are PDF points (1/72 inch); `x` and `y` are the
|
|
4
|
+
* box's bottom-left corner, measured from the bottom-left corner of the page.
|
|
5
|
+
*/
|
|
6
|
+
export interface FormField {
|
|
7
|
+
/** signature, date, initials, text, or whatever the template called it. */
|
|
8
|
+
type: string;
|
|
9
|
+
/** The party that fills it in, as the template named it. */
|
|
10
|
+
who: string;
|
|
11
|
+
/** What to type here, when the template said (`label={Printed name}`). */
|
|
12
|
+
label?: string;
|
|
13
|
+
/** From 1. */
|
|
14
|
+
page: number;
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Read what `\formfield` and `\signature` wrote while TeX ran: one line per
|
|
22
|
+
* spot, `type who page x y width height raise [label]`, lengths in scaled points.
|
|
23
|
+
* Lines that are not that shape are skipped.
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseFormFile(text: string): FormField[];
|
|
26
|
+
/**
|
|
27
|
+
* Turn `<base>.form` into `<base>.form.json`. Returns the JSON file, or null
|
|
28
|
+
* when the document marked no spots (a stale JSON file is then removed).
|
|
29
|
+
*/
|
|
30
|
+
export declare function writeFormJson(base: string): string | null;
|
package/form.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseFormFile = parseFormFile;
|
|
4
|
+
exports.writeFormJson = writeFormJson;
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
/** TeX's scaled points (65536 to a TeX point, 72.27 TeX points to an inch) to PDF points. */
|
|
7
|
+
const bp = (sp) => Math.round((sp / 65536) * (72 / 72.27) * 100) / 100;
|
|
8
|
+
/**
|
|
9
|
+
* Read what `\formfield` and `\signature` wrote while TeX ran: one line per
|
|
10
|
+
* spot, `type who page x y width height raise [label]`, lengths in scaled points.
|
|
11
|
+
* Lines that are not that shape are skipped.
|
|
12
|
+
*/
|
|
13
|
+
function parseFormFile(text) {
|
|
14
|
+
const fields = [];
|
|
15
|
+
for (const line of text.split('\n')) {
|
|
16
|
+
const parts = line.trim().split(/\s+/);
|
|
17
|
+
if (parts.length < 8)
|
|
18
|
+
continue;
|
|
19
|
+
const [type, who, ...rest] = parts;
|
|
20
|
+
const n = rest.slice(0, 6).map(Number);
|
|
21
|
+
const label = rest.slice(6).join(' ');
|
|
22
|
+
if (!n.every(Number.isFinite) || n[0] < 1)
|
|
23
|
+
continue;
|
|
24
|
+
const [page, x, y, width, height, raise] = n;
|
|
25
|
+
fields.push({ type, who: who === '-' ? '' : who, ...(label ? { label } : {}), page, x: bp(x), y: bp(y + raise), width: bp(width), height: bp(height) });
|
|
26
|
+
}
|
|
27
|
+
return fields;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Turn `<base>.form` into `<base>.form.json`. Returns the JSON file, or null
|
|
31
|
+
* when the document marked no spots (a stale JSON file is then removed).
|
|
32
|
+
*/
|
|
33
|
+
function writeFormJson(base) {
|
|
34
|
+
const raw = `${base}.form`;
|
|
35
|
+
const out = `${base}.form.json`;
|
|
36
|
+
const fields = (0, fs_1.existsSync)(raw) ? parseFormFile((0, fs_1.readFileSync)(raw, 'utf8')) : [];
|
|
37
|
+
if (!fields.length) {
|
|
38
|
+
(0, fs_1.rmSync)(out, { force: true });
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
(0, fs_1.writeFileSync)(out, JSON.stringify(fields, null, 2) + '\n');
|
|
42
|
+
return out;
|
|
43
|
+
}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __exportStar(require("./build"), exports);
|
|
|
27
27
|
__exportStar(require("./check"), exports);
|
|
28
28
|
__exportStar(require("./config"), exports);
|
|
29
29
|
__exportStar(require("./diff"), exports);
|
|
30
|
+
__exportStar(require("./form"), exports);
|
|
30
31
|
__exportStar(require("./import"), exports);
|
|
31
32
|
__exportStar(require("./lock"), exports);
|
|
32
33
|
__exportStar(require("./project"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "latex-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Build typed, reproducible LaTeX documents from the command line",
|
|
5
5
|
"author": "Constructive <developers@constructive.io>",
|
|
6
6
|
"main": "index.js",
|
|
@@ -44,13 +44,13 @@
|
|
|
44
44
|
"latex-kit": "cli.js"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@latex-kit/components": "0.
|
|
48
|
-
"@latex-kit/render": "0.5.
|
|
49
|
-
"@latex-kit/schema": "0.4.
|
|
50
|
-
"@latex-kit/template": "0.
|
|
47
|
+
"@latex-kit/components": "0.3.0",
|
|
48
|
+
"@latex-kit/render": "0.5.1",
|
|
49
|
+
"@latex-kit/schema": "0.4.1",
|
|
50
|
+
"@latex-kit/template": "0.5.0",
|
|
51
51
|
"inquirerer": "^4.9.5",
|
|
52
52
|
"minimist": "^1.2.8",
|
|
53
53
|
"yanse": "^0.2.3"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "a117e69246e80a133c7ec027dd626b3815e6e45c"
|
|
56
56
|
}
|
package/paper-style.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Constructive whitepaper style, from constructive-io/rls-whitepaper and
|
|
3
|
+
* hyperweb-whitepaper (tex/headers/): the code colour palette and the
|
|
4
|
+
* TypeScript listings style, copied verbatim so new papers look like ours.
|
|
5
|
+
* Regenerate from those files rather than editing here.
|
|
6
|
+
*/
|
|
7
|
+
/** tex/headers/colors.tex */
|
|
8
|
+
export declare const WHITEPAPER_COLORS_TEX = "% Define colors for code highlighting\n\\definecolor{lightpurple}{rgb}{0.85, 0.85, 1}\n\\definecolor{white}{rgb}{1, 1, 1}\n\\definecolor{codegray}{gray}{0.9}\n\\definecolor{codeblue}{rgb}{0,0,0.6}\n\\definecolor{codegreen}{rgb}{0,0.6,0}\n\\definecolor{codepurple}{rgb}{0.58,0,0.82}\n\\definecolor{codebackground}{rgb}{0.95,0.95,0.95}\n\\definecolor{codeorange}{rgb}{1, 0.6, 0.2}\n\\definecolor{codered}{rgb}{0.8, 0, 0}\n\\definecolor{codeyellow}{rgb}{0.9, 0.9, 0.4}\n\\definecolor{codeteal}{rgb}{0, 0.5, 0.5}\n\\definecolor{codepink}{rgb}{1, 0.5, 0.7}\n\\definecolor{codebrown}{rgb}{0.6, 0.4, 0.2}\n\\definecolor{codelightblue}{rgb}{0.7, 0.85, 1}\n\\definecolor{codelightgreen}{rgb}{0.7, 1, 0.7}\n\\definecolor{codedarkblue}{rgb}{0, 0.2, 0.5}\n\\definecolor{codedarkpurple}{rgb}{0.4, 0.2, 0.6}\n\\definecolor{black}{rgb}{0, 0, 0}\n\\pagecolor{white}";
|
|
9
|
+
/** tex/headers/typescript.tex */
|
|
10
|
+
export declare const WHITEPAPER_TYPESCRIPT_TEX = "% Code style definition\n\\lstdefinelanguage{typescript}{\n keywords={abstract, arguments, await, boolean, break, byte, case, catch,\n class, const, continue, debugger, default, delete, do, double, else,\n enum, eval, export, extends, false, final, finally, float, for,\n function, goto, if, implements, import, in, instanceof, int, interface,\n let, long, native, new, null, package, private, protected, public,\n return, short, static, super, switch, synchronized, this, throw,\n throws, transient, true, try, typeof, var, void, volatile, while, with,\n yield, async, from, of},\n keywordstyle=\\color{codeblue},\n sensitive=true,\n comment=[l]{//},\n morecomment=[s]{/*}{*/},\n commentstyle=\\color{codegreen},\n stringstyle=\\color{codepurple},\n morestring=[b]',\n morestring=[b]\"\n}\n\n% Enhanced Code Style Definition for TypeScript and JavaScript\n\\lstdefinestyle{typescript}{\n language=typescript,\n backgroundcolor=\\color{white},\n basicstyle=\\ttfamily\\footnotesize,\n breakatwhitespace=false,\n breaklines=true,\n captionpos=b,\n keepspaces=true,\n numbers=left,\n numbersep=5pt,\n showspaces=false,\n showstringspaces=false,\n showtabs=false,\n tabsize=2,\n numberstyle=\\tiny\\color{black},\n % Additional TypeScript-specific highlighting\n moredelim=[is][\\textcolor{codepurple}]{\\#\\{}{\\}}, % Template literals\n moredelim=[is][\\textcolor{codeblue}]{<}{>}, % Generic types\n literate=\n {=>}{{\\textcolor{codeblue}{=>}}}2 \n {interface}{{\\textcolor{codeblue}{interface}}}9\n {type}{{\\textcolor{codered}{type}}}4\n {export}{{\\textcolor{codegreen}{export}}}6\n {import}{{\\textcolor{codeorange}{import}}}6\n {from}{{\\textcolor{codeblue}{from}}}4\n {return}{{\\textcolor{codeteal}{return}}}6 \n {function}{{\\textcolor{codeblue}{function}}}8\n {string}{{\\textcolor{codepink}{string}}}6 \n {let}{{\\textcolor{codered}{let}}}3 \n% {const}{{\\textcolor{codedarkpurple}{const}}}5 \n {var}{{\\textcolor{codelightblue}{var}}}3 \n {while}{{\\textcolor{codered}{while}}}5 \n {if}{{\\textcolor{codeorange}{if}}}2 \n {else}{{\\textcolor{codeyellow}{else}}}4\n\t{@onlyOwner}{{\\textcolor{codered}{@onlyOwner}}}9\n\t{@instantiate}{{\\textcolor{codered}{@instantiate}}}{10}\n}\n\n";
|
package/paper-style.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The Constructive whitepaper style, from constructive-io/rls-whitepaper and
|
|
4
|
+
* hyperweb-whitepaper (tex/headers/): the code colour palette and the
|
|
5
|
+
* TypeScript listings style, copied verbatim so new papers look like ours.
|
|
6
|
+
* Regenerate from those files rather than editing here.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.WHITEPAPER_TYPESCRIPT_TEX = exports.WHITEPAPER_COLORS_TEX = void 0;
|
|
10
|
+
/** tex/headers/colors.tex */
|
|
11
|
+
exports.WHITEPAPER_COLORS_TEX = '% Define colors for code highlighting\n\\definecolor{lightpurple}{rgb}{0.85, 0.85, 1}\n\\definecolor{white}{rgb}{1, 1, 1}\n\\definecolor{codegray}{gray}{0.9}\n\\definecolor{codeblue}{rgb}{0,0,0.6}\n\\definecolor{codegreen}{rgb}{0,0.6,0}\n\\definecolor{codepurple}{rgb}{0.58,0,0.82}\n\\definecolor{codebackground}{rgb}{0.95,0.95,0.95}\n\\definecolor{codeorange}{rgb}{1, 0.6, 0.2}\n\\definecolor{codered}{rgb}{0.8, 0, 0}\n\\definecolor{codeyellow}{rgb}{0.9, 0.9, 0.4}\n\\definecolor{codeteal}{rgb}{0, 0.5, 0.5}\n\\definecolor{codepink}{rgb}{1, 0.5, 0.7}\n\\definecolor{codebrown}{rgb}{0.6, 0.4, 0.2}\n\\definecolor{codelightblue}{rgb}{0.7, 0.85, 1}\n\\definecolor{codelightgreen}{rgb}{0.7, 1, 0.7}\n\\definecolor{codedarkblue}{rgb}{0, 0.2, 0.5}\n\\definecolor{codedarkpurple}{rgb}{0.4, 0.2, 0.6}\n\\definecolor{black}{rgb}{0, 0, 0}\n\\pagecolor{white}';
|
|
12
|
+
/** tex/headers/typescript.tex */
|
|
13
|
+
exports.WHITEPAPER_TYPESCRIPT_TEX = "% Code style definition\n\\lstdefinelanguage{typescript}{\n keywords={abstract, arguments, await, boolean, break, byte, case, catch,\n class, const, continue, debugger, default, delete, do, double, else,\n enum, eval, export, extends, false, final, finally, float, for,\n function, goto, if, implements, import, in, instanceof, int, interface,\n let, long, native, new, null, package, private, protected, public,\n return, short, static, super, switch, synchronized, this, throw,\n throws, transient, true, try, typeof, var, void, volatile, while, with,\n yield, async, from, of},\n keywordstyle=\\color{codeblue},\n sensitive=true,\n comment=[l]{//},\n morecomment=[s]{/*}{*/},\n commentstyle=\\color{codegreen},\n stringstyle=\\color{codepurple},\n morestring=[b]',\n morestring=[b]\"\n}\n\n% Enhanced Code Style Definition for TypeScript and JavaScript\n\\lstdefinestyle{typescript}{\n language=typescript,\n backgroundcolor=\\color{white},\n basicstyle=\\ttfamily\\footnotesize,\n breakatwhitespace=false,\n breaklines=true,\n captionpos=b,\n keepspaces=true,\n numbers=left,\n numbersep=5pt,\n showspaces=false,\n showstringspaces=false,\n showtabs=false,\n tabsize=2,\n numberstyle=\\tiny\\color{black},\n % Additional TypeScript-specific highlighting\n moredelim=[is][\\textcolor{codepurple}]{\\#\\{}{\\}}, % Template literals\n moredelim=[is][\\textcolor{codeblue}]{<}{>}, % Generic types\n literate=\n {=>}{{\\textcolor{codeblue}{=>}}}2 \n {interface}{{\\textcolor{codeblue}{interface}}}9\n {type}{{\\textcolor{codered}{type}}}4\n {export}{{\\textcolor{codegreen}{export}}}6\n {import}{{\\textcolor{codeorange}{import}}}6\n {from}{{\\textcolor{codeblue}{from}}}4\n {return}{{\\textcolor{codeteal}{return}}}6 \n {function}{{\\textcolor{codeblue}{function}}}8\n {string}{{\\textcolor{codepink}{string}}}6 \n {let}{{\\textcolor{codered}{let}}}3 \n% {const}{{\\textcolor{codedarkpurple}{const}}}5 \n {var}{{\\textcolor{codelightblue}{var}}}3 \n {while}{{\\textcolor{codered}{while}}}5 \n {if}{{\\textcolor{codeorange}{if}}}2 \n {else}{{\\textcolor{codeyellow}{else}}}4\n\t{@onlyOwner}{{\\textcolor{codered}{@onlyOwner}}}9\n\t{@instantiate}{{\\textcolor{codered}{@instantiate}}}{10}\n}\n\n";
|
package/project-commands.js
CHANGED
|
@@ -23,6 +23,7 @@ const fs_1 = require("fs");
|
|
|
23
23
|
const path_1 = require("path");
|
|
24
24
|
const yanse_1 = __importDefault(require("yanse"));
|
|
25
25
|
const args_1 = require("./args");
|
|
26
|
+
const boilerplates_1 = require("./boilerplates");
|
|
26
27
|
const build_1 = require("./build");
|
|
27
28
|
const check_1 = require("./check");
|
|
28
29
|
const commands_1 = require("./commands");
|
|
@@ -66,6 +67,14 @@ async function buildCommand(argv) {
|
|
|
66
67
|
throw new args_1.UsageError(`--engine must be auto or one of ${render_1.ENGINES.join(', ')}`);
|
|
67
68
|
if (argv.signatures !== undefined && variant !== 'signed')
|
|
68
69
|
throw new args_1.UsageError('--signatures only applies to --variant signed');
|
|
70
|
+
if (argv.blanks !== undefined && !template_1.BLANK_STYLES.includes(argv.blanks))
|
|
71
|
+
throw new args_1.UsageError(`--blanks must be one of ${template_1.BLANK_STYLES.join(', ')}`);
|
|
72
|
+
if (argv.blanks !== undefined && variant !== 'blank')
|
|
73
|
+
throw new args_1.UsageError('--blanks only applies to --variant blank');
|
|
74
|
+
if (argv.missing !== undefined && !['marker', 'blank'].includes(argv.missing))
|
|
75
|
+
throw new args_1.UsageError('--missing must be marker or blank');
|
|
76
|
+
if ((argv.highlight || argv.missing !== undefined) && variant !== 'draft')
|
|
77
|
+
throw new args_1.UsageError('--highlight and --missing only apply to drafts');
|
|
69
78
|
const only = onlyMatcher(argv.only);
|
|
70
79
|
const project = await project_1.Project.open(argv.root);
|
|
71
80
|
const options = {
|
|
@@ -80,6 +89,9 @@ async function buildCommand(argv) {
|
|
|
80
89
|
locale: checkLocale(argv.locale),
|
|
81
90
|
force: Boolean(argv.force),
|
|
82
91
|
signatures: argv.signatures,
|
|
92
|
+
blanks: argv.blanks,
|
|
93
|
+
highlight: Boolean(argv.highlight),
|
|
94
|
+
missing: argv.missing,
|
|
83
95
|
};
|
|
84
96
|
const json = Boolean(argv.json);
|
|
85
97
|
const log = (s) => !json && console.error(s);
|
|
@@ -301,7 +313,12 @@ async function lockCommand(argv) {
|
|
|
301
313
|
}
|
|
302
314
|
async function initCommand(argv) {
|
|
303
315
|
const dir = (0, path_1.join)(process.cwd(), argv._?.[0] ? String(argv._[0]) : '.');
|
|
304
|
-
const
|
|
316
|
+
const preset = (argv.preset ?? 'whitepaper');
|
|
317
|
+
if (!boilerplates_1.PAPER_PRESETS.includes(preset))
|
|
318
|
+
throw new args_1.UsageError(`--preset must be one of ${boilerplates_1.PAPER_PRESETS.join(', ')}`);
|
|
319
|
+
if (argv.preset && !argv.paper)
|
|
320
|
+
throw new args_1.UsageError('--preset only applies to init --paper');
|
|
321
|
+
const r = (0, scaffold_1.initProject)(dir, { paper: Boolean(argv.paper), preset, force: Boolean(argv.force), version: (0, commands_1.version)() });
|
|
305
322
|
if (!argv.paper && !(0, fs_1.existsSync)((0, path_1.join)(dir, lock_1.LOCK_FILE))) {
|
|
306
323
|
(0, lock_1.writeLock)(dir);
|
|
307
324
|
r.written.push((0, path_1.join)(dir, lock_1.LOCK_FILE));
|
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))
|