pulpweaver4-cli 0.0.0-stage → 0.0.91

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.
Files changed (78) hide show
  1. package/dist/bridge.d.ts +25 -0
  2. package/dist/bridge.js +109 -0
  3. package/dist/bridge.js.map +1 -0
  4. package/dist/build.d.ts +12 -0
  5. package/dist/build.js +95 -0
  6. package/dist/build.js.map +1 -0
  7. package/dist/chromium.d.ts +83 -0
  8. package/dist/chromium.js +213 -0
  9. package/dist/chromium.js.map +1 -0
  10. package/dist/commands.d.ts +217 -0
  11. package/dist/commands.js +162 -0
  12. package/dist/commands.js.map +1 -0
  13. package/dist/csl.d.ts +8 -0
  14. package/dist/csl.js +53 -0
  15. package/dist/csl.js.map +1 -0
  16. package/dist/index.d.ts +28 -0
  17. package/dist/index.js +135 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/lint.d.ts +13 -0
  20. package/dist/lint.js +80 -0
  21. package/dist/lint.js.map +1 -0
  22. package/dist/new.d.ts +12 -0
  23. package/dist/new.js +92 -0
  24. package/dist/new.js.map +1 -0
  25. package/dist/node-fs.d.ts +17 -0
  26. package/dist/node-fs.js +78 -0
  27. package/dist/node-fs.js.map +1 -0
  28. package/dist/page/host.d.ts +111 -0
  29. package/dist/page/host.js +202 -0
  30. package/dist/page/host.js.map +1 -0
  31. package/dist/page/test-setup.d.ts +11 -0
  32. package/dist/page/test-setup.js +24 -0
  33. package/dist/page/test-setup.js.map +1 -0
  34. package/dist/paint-corpus.d.ts +8 -0
  35. package/dist/paint-corpus.js +89 -0
  36. package/dist/paint-corpus.js.map +1 -0
  37. package/dist/plugin-commands.d.ts +26 -0
  38. package/dist/plugin-commands.js +49 -0
  39. package/dist/plugin-commands.js.map +1 -0
  40. package/dist/plugins.d.ts +23 -0
  41. package/dist/plugins.js +85 -0
  42. package/dist/plugins.js.map +1 -0
  43. package/dist/problems.d.ts +29 -0
  44. package/dist/problems.js +28 -0
  45. package/dist/problems.js.map +1 -0
  46. package/dist/profiles.d.ts +37 -0
  47. package/dist/profiles.js +224 -0
  48. package/dist/profiles.js.map +1 -0
  49. package/dist/pw.d.ts +2 -0
  50. package/dist/pw.js +4 -0
  51. package/dist/pw.js.map +1 -0
  52. package/dist/spike.d.ts +27 -0
  53. package/dist/spike.js +79 -0
  54. package/dist/spike.js.map +1 -0
  55. package/dist/test.d.ts +35 -0
  56. package/dist/test.js +228 -0
  57. package/dist/test.js.map +1 -0
  58. package/docs/README.md +9 -0
  59. package/docs/reference/commands/build.md +40 -0
  60. package/docs/reference/commands/index.md +42 -0
  61. package/docs/reference/commands/lint.md +35 -0
  62. package/docs/reference/commands/new.md +34 -0
  63. package/docs/reference/commands/preflight.md +35 -0
  64. package/docs/reference/commands/profiles.md +57 -0
  65. package/docs/reference/commands/spike.md +30 -0
  66. package/docs/reference/commands/test.md +47 -0
  67. package/package.json +40 -4
  68. package/template/chapters/01-beginning.dj +14 -0
  69. package/template/chapters/02-writing.dj +16 -0
  70. package/template/fonts/CrimsonPro-Italic-VF.ttf +0 -0
  71. package/template/fonts/CrimsonPro-VF.ttf +0 -0
  72. package/template/fonts/NotoSansSymbols2-Boxes.ttf +0 -0
  73. package/template/fonts/OFL.txt +94 -0
  74. package/template/gitignore +2 -0
  75. package/template/pulpweaver4.toml +23 -0
  76. package/template/styles/book.css +109 -0
  77. package/template/tests/book.test.ts +23 -0
  78. package/README.md +0 -3
@@ -0,0 +1,217 @@
1
+ import type { PluginCommand } from './plugin-commands.js';
2
+ /** A positional argument. */
3
+ export interface CommandArgument {
4
+ /** As the usage line writes it, without brackets: `<dir>`. */
5
+ readonly name: string;
6
+ readonly optional?: boolean;
7
+ /** What it is, in a sentence of Markdown. */
8
+ readonly description: string;
9
+ }
10
+ /** An option. */
11
+ export interface CommandOption {
12
+ /** `--edition`. */
13
+ readonly name: string;
14
+ /** Another name for it: `-u`. */
15
+ readonly alias?: string;
16
+ /** Its value, if it takes one, as the usage line writes it: `<name>|all`. */
17
+ readonly value?: string;
18
+ /** What it does, in a sentence of Markdown. */
19
+ readonly description: string;
20
+ }
21
+ /** A command of `pw`'s own. */
22
+ export interface Command {
23
+ readonly name: string;
24
+ /** What it does, in a line, for `pw --help` and the reference's tables. */
25
+ readonly summary: string;
26
+ /** What it does, more fully, in Markdown, for its page in the reference. */
27
+ readonly description: string;
28
+ readonly arguments: readonly CommandArgument[];
29
+ readonly options: readonly CommandOption[];
30
+ /** Command lines that use it, each with what it does. */
31
+ readonly examples: readonly {
32
+ readonly command: string;
33
+ readonly description: string;
34
+ }[];
35
+ /** Its own commands (`pw profiles get`), if it has them, each with its arguments and options rather than its own. */
36
+ readonly subcommands?: readonly Command[];
37
+ }
38
+ /** An environment variable `pw` reads. */
39
+ export interface EnvironmentVariable {
40
+ readonly name: string;
41
+ readonly description: string;
42
+ }
43
+ /** `pw`'s commands, in the order `pw --help` lists them. */
44
+ export declare const COMMANDS: readonly [{
45
+ readonly name: 'new';
46
+ readonly summary: 'start a project in a new folder: pulpweaver4.toml, a chapter, a stylesheet, fonts and a test';
47
+ readonly description: 'Makes a new project in a folder, which must be new or empty: a `pulpweaver4.toml` titled after the folder (`my-first-book` is “My First Book”) with a web, a paperback, a letter and a text edition, two chapters in Djot, `styles/book.css`, Crimson Pro in roman and italic (under the SIL Open Font License, with its licence), a test in `tests/`, and a `.gitignore`. Everything in it but the fonts is CC0, so you may do anything with it.';
48
+ readonly arguments: readonly [{
49
+ readonly name: '<dir>';
50
+ readonly description: 'The folder to make the project in.';
51
+ }];
52
+ readonly options: readonly [{
53
+ readonly name: '--theme';
54
+ readonly value: 'book';
55
+ readonly description: 'The project’s look: `book`, the one theme so far, and the default.';
56
+ }];
57
+ readonly examples: readonly [{
58
+ readonly command: 'pw new my-first-book';
59
+ readonly description: 'Start “My First Book” in `my-first-book/`.';
60
+ }];
61
+ }, {
62
+ readonly name: 'build';
63
+ readonly summary: 'write each edition, or the one named, to dist/<edition>/: the web edition\'s site, a print edition\'s PDF, the text edition\'s file';
64
+ readonly description: 'Builds the project’s editions, each into `dist/<edition>/`, emptied first: a web edition’s site, a print edition’s PDF (`dist/<edition>/<edition>.pdf`), a text edition’s file, or what a plugin’s output writes. The book is laid out in the pinned Chromium, headless, so a build gives the same bytes on any machine. Each edition’s `html` and `layout` lint rules run over the built book, and every problem is printed with its place in the source, as a compiler prints them; any error fails the build, with exit status 1.';
65
+ readonly arguments: readonly [{
66
+ readonly name: '<dir>';
67
+ readonly optional: true;
68
+ readonly description: 'The project’s folder, the one with `pulpweaver4.toml`; the current folder by default.';
69
+ }];
70
+ readonly options: readonly [{
71
+ readonly name: '--edition';
72
+ readonly value: '<name>|all';
73
+ readonly description: 'The edition to build, by its name in `pulpweaver4.toml`; give it more than once for several. `all`, or no `--edition`, builds every edition.';
74
+ }];
75
+ readonly examples: readonly [{
76
+ readonly command: 'pw build';
77
+ readonly description: 'Build every edition of the project in this folder.';
78
+ }, {
79
+ readonly command: 'pw build --edition paperback';
80
+ readonly description: 'Build the paperback’s PDF alone.';
81
+ }];
82
+ }, {
83
+ readonly name: 'test';
84
+ readonly summary: 'run the project\'s tests (tests/**/*.test.ts) in headless Chromium, and with --update, write their snapshots anew';
85
+ readonly description: 'Runs the project’s tests, `tests/**/*.test.ts` (and `.test.js`), with Vitest in the pinned Chromium, headless, as the core’s own tests run: with the test API’s globals (`build`, `expect`, `test`) and its matchers, and `build()` building the project as `pw build` does, with its plugins. Snapshots are kept beside the tests. The project needs nothing installed but `pw`. A failing test fails it, with exit status 1.';
86
+ readonly arguments: readonly [{
87
+ readonly name: '<dir>';
88
+ readonly optional: true;
89
+ readonly description: 'The project’s folder, if the first argument is one (it has `pulpweaver4.toml`); the current folder by default.';
90
+ }, {
91
+ readonly name: '<filter>…';
92
+ readonly optional: true;
93
+ readonly description: 'Run only the test files whose paths contain one of these, as Vitest’s filters do; in a project’s folder, `pw test layout` runs `tests/layout.test.ts`.';
94
+ }];
95
+ readonly options: readonly [{
96
+ readonly name: '--update';
97
+ readonly alias: '-u';
98
+ readonly description: 'Write the snapshots anew rather than comparing with them, for a change you meant to make: look at what changed before you commit it.';
99
+ }];
100
+ readonly examples: readonly [{
101
+ readonly command: 'pw test';
102
+ readonly description: 'Run every test of the project in this folder.';
103
+ }, {
104
+ readonly command: 'pw test layout';
105
+ readonly description: 'Run the tests whose paths contain `layout`.';
106
+ }, {
107
+ readonly command: 'pw test my-book chapters --update';
108
+ readonly description: 'Rewrite the snapshots of the tests in `my-book/` whose paths contain `chapters`.';
109
+ }];
110
+ }, {
111
+ readonly name: 'lint';
112
+ readonly summary: 'run the project\'s lint rules as the edition\'s settings turn them on (its first by default), building it in headless Chromium for its html and layout rules, and with --fix, apply what the source rules can fix';
113
+ readonly description: 'Runs the project’s lint rules as the edition’s `[lint]` settings over the project’s turn them on, and prints what they report: the `source` rules over its chapters and bibliography, and, where an `html` or `layout` rule is on, the rules over the edition’s HTML and, in print, its pages, which it builds in headless Chromium as `pw build` does, with the same plugins. `pw build` reports the same lint problems for each edition it builds. Any error gives exit status 1.';
114
+ readonly arguments: readonly [{
115
+ readonly name: '<project>';
116
+ readonly optional: true;
117
+ readonly description: 'The project’s folder; the current folder by default.';
118
+ }];
119
+ readonly options: readonly [{
120
+ readonly name: '--fix';
121
+ readonly description: 'Apply the fixes the source rules give (straight quotes made curly, and so on) to the sources, pass after pass, and report what is left.';
122
+ }, {
123
+ readonly name: '--edition';
124
+ readonly value: '<name>';
125
+ readonly description: 'Lint as this edition’s settings have it; the first edition in `pulpweaver4.toml` by default.';
126
+ }];
127
+ readonly examples: readonly [{
128
+ readonly command: 'pw lint --fix';
129
+ readonly description: 'Fix what can be fixed in the project in this folder, and list the rest.';
130
+ }];
131
+ }, {
132
+ readonly name: 'preflight';
133
+ readonly summary: `check a PDF against our PDF/X rules: the standard the file says it is, or the one named (${string}), requiring an output intent in that colour space`;
134
+ readonly description: `Checks a PDF against pulpweaver4’s PDF/X rules, from ISO 15930, and lists each violation with its rule and page, and what it couldn’t check. It checks the standard the file claims, or the one \`--standard\` names (${string}). Any violation gives exit status 1. It reads any PDF, not only pulpweaver4’s, but it is no substitute for a commercial preflight before a book goes to press.`;
135
+ readonly arguments: readonly [{
136
+ readonly name: '<file.pdf>';
137
+ readonly description: 'The PDF to check.';
138
+ }];
139
+ readonly options: readonly [{
140
+ readonly name: '--standard';
141
+ readonly value: '<pdf/x-…>';
142
+ readonly description: 'The standard to check against, whatever the file claims.';
143
+ }, {
144
+ readonly name: '--output';
145
+ readonly value: 'CMYK|RGB|GRAY';
146
+ readonly description: 'Require an output intent in this colour space, as a printer asking for CMYK would.';
147
+ }];
148
+ readonly examples: readonly [{
149
+ readonly command: 'pw preflight dist/paperback/paperback.pdf --output CMYK';
150
+ readonly description: 'Check the paperback’s PDF, and that it is for a CMYK press.';
151
+ }];
152
+ }, {
153
+ readonly name: 'spike';
154
+ readonly summary: 'lay out phase 0\'s spike page in headless Chromium, and print its lines as JSON, or paint it to a PDF: sRGB, or CMYK PDF/X-4 for GRACoL 2013';
155
+ readonly description: 'Lays out the spike page, the test page pulpweaver4’s first phase was measured by, in headless Chromium, and prints its lines as JSON, or paints it to a PDF. It is for pulpweaver4’s own tests, which hold every build to the same page.';
156
+ readonly arguments: readonly [];
157
+ readonly options: readonly [{
158
+ readonly name: '--fonts';
159
+ readonly value: '<dir>';
160
+ readonly description: 'The folder with the spike page’s font. Required.';
161
+ }, {
162
+ readonly name: '--pdf';
163
+ readonly value: '<file>';
164
+ readonly description: 'Paint the page to this PDF, in sRGB, rather than print its lines.';
165
+ }, {
166
+ readonly name: '--cmyk';
167
+ readonly value: '<GRACoL2013_CRPC6.icc>';
168
+ readonly description: 'With `--pdf`, paint it in CMYK as PDF/X-4, through this GRACoL 2013 profile.';
169
+ }];
170
+ readonly examples: readonly [{
171
+ readonly command: 'pw spike --fonts tests/fonts --pdf spike.pdf';
172
+ readonly description: 'Paint the spike page to `spike.pdf`.';
173
+ }];
174
+ }, {
175
+ readonly name: 'profiles';
176
+ readonly summary: 'put the standard output intents\' ICC profiles in pw\'s cache, where builds find them, or list them';
177
+ readonly description: 'Manages the standard output intents’ ICC profiles in `pw`’s cache (`$XDG_CACHE_HOME/pulpweaver4/icc`, else `~/.cache/pulpweaver4/icc`), where `pw build` finds them. A build fetches a shareable profile from the ICC’s registry itself; one whose owner forbids redistribution but lets each user download it (FOGRA51’s, `PSOcoated_v3.icc`, from ECI) is fetched only by `pw profiles get`, from the owner’s own file, once you accept the owner’s licence. pulpweaver4 never hosts or ships it.';
178
+ readonly arguments: readonly [];
179
+ readonly options: readonly [];
180
+ readonly examples: readonly [{
181
+ readonly command: 'pw profiles get FOGRA51';
182
+ readonly description: 'Show ECI’s licence, and once you accept it, put FOGRA51’s profile in the cache.';
183
+ }, {
184
+ readonly command: 'pw profiles list';
185
+ readonly description: 'List the standard output intents’ profiles, and which are in the cache.';
186
+ }];
187
+ readonly subcommands: readonly [{
188
+ readonly name: 'get';
189
+ readonly summary: 'put a standard output intent\'s ICC profile in pw\'s cache, where builds find it, checked by its hash: FOGRA51\'s from ECI, once you accept ECI\'s licence (--accept-licence, for CI)';
190
+ readonly description: 'Fetches each named output intent’s profile into the cache and checks it against the hash pulpweaver4 registers for it. For a profile its owner gives only to each user, it shows the owner’s licence and asks you to accept it, unless `--accept-licence` says you have.';
191
+ readonly arguments: readonly [{
192
+ readonly name: '<name>…';
193
+ readonly description: 'The output intents whose profiles to get, by their names in `pulpweaver4.toml`’s `output-intent`: `FOGRA51`, `GRACoL2013`, and so on.';
194
+ }];
195
+ readonly options: readonly [{
196
+ readonly name: '--accept-licence';
197
+ readonly alias: '--accept-license';
198
+ readonly description: 'Accept the owner’s licence without being asked, as CI must, having read it yourself.';
199
+ }];
200
+ readonly examples: readonly [];
201
+ }, {
202
+ readonly name: 'list';
203
+ readonly summary: 'the standard output intents\' profiles, and which are in the cache';
204
+ readonly description: 'Lists each standard output intent with its profile’s file, how `pw` gets it, and where it is in the cache, if it is (and whether it is the registered profile).';
205
+ readonly arguments: readonly [];
206
+ readonly options: readonly [];
207
+ readonly examples: readonly [];
208
+ }];
209
+ }];
210
+ /** A command's name. */
211
+ export type CommandName = (typeof COMMANDS)[number]['name'];
212
+ /** The environment variables `pw` reads. */
213
+ export declare const ENVIRONMENT: readonly EnvironmentVariable[];
214
+ /** A command's usage line: `pw build [<dir>] [--edition <name>|all]`; a subcommand's after its command's name. */
215
+ export declare function usageLine(command: Command, parent?: Command): string;
216
+ /** `pw --help`: each command's usage and summary, the project's plugins' commands (`plugins`), then the environment. */
217
+ export declare function helpText(name: string, plugins?: readonly PluginCommand[]): string;
@@ -0,0 +1,162 @@
1
+ /**
2
+ * `pw`'s commands, as data (https://plans.inkylabs.com/pulpweaver#commands):
3
+ * what each takes and does, which `pw --help` prints and the reference's
4
+ * pages are made from (https://plans.inkylabs.com/pulpweaver#the-documentation-site),
5
+ * so a command and its documentation change together. `main` (`index.ts`)
6
+ * runs them, one handler per name here, and in a project, any other name
7
+ * a plugin's command (`plugin-commands.ts`); `//:reference_test` fails on a
8
+ * command, argument, option or variable without a description.
9
+ */
10
+ import { PDF_X_STANDARDS } from 'pulpweaver4';
11
+ import { CHROMIUM } from './chromium.js';
12
+ /** `pw`'s commands, in the order `pw --help` lists them. */
13
+ export const COMMANDS = [
14
+ {
15
+ name: 'new',
16
+ summary: 'start a project in a new folder: pulpweaver4.toml, a chapter, a stylesheet, fonts and a test',
17
+ description: 'Makes a new project in a folder, which must be new or empty: a `pulpweaver4.toml` titled after the folder (`my-first-book` is “My First Book”) with a web, a paperback, a letter and a text edition, two chapters in Djot, `styles/book.css`, Crimson Pro in roman and italic (under the SIL Open Font License, with its licence), a test in `tests/`, and a `.gitignore`. Everything in it but the fonts is CC0, so you may do anything with it.',
18
+ arguments: [{ name: '<dir>', description: 'The folder to make the project in.' }],
19
+ options: [{ name: '--theme', value: 'book', description: 'The project’s look: `book`, the one theme so far, and the default.' }],
20
+ examples: [{ command: 'pw new my-first-book', description: 'Start “My First Book” in `my-first-book/`.' }],
21
+ },
22
+ {
23
+ name: 'build',
24
+ summary: 'write each edition, or the one named, to dist/<edition>/: the web edition\'s site, a print edition\'s PDF, the text edition\'s file',
25
+ description: 'Builds the project’s editions, each into `dist/<edition>/`, emptied first: a web edition’s site, a print edition’s PDF (`dist/<edition>/<edition>.pdf`), a text edition’s file, or what a plugin’s output writes. The book is laid out in the pinned Chromium, headless, so a build gives the same bytes on any machine. Each edition’s `html` and `layout` lint rules run over the built book, and every problem is printed with its place in the source, as a compiler prints them; any error fails the build, with exit status 1.',
26
+ arguments: [{ name: '<dir>', optional: true, description: 'The project’s folder, the one with `pulpweaver4.toml`; the current folder by default.' }],
27
+ options: [{ name: '--edition', value: '<name>|all', description: 'The edition to build, by its name in `pulpweaver4.toml`; give it more than once for several. `all`, or no `--edition`, builds every edition.' }],
28
+ examples: [
29
+ { command: 'pw build', description: 'Build every edition of the project in this folder.' },
30
+ { command: 'pw build --edition paperback', description: 'Build the paperback’s PDF alone.' },
31
+ ],
32
+ },
33
+ {
34
+ name: 'test',
35
+ summary: 'run the project\'s tests (tests/**/*.test.ts) in headless Chromium, and with --update, write their snapshots anew',
36
+ description: 'Runs the project’s tests, `tests/**/*.test.ts` (and `.test.js`), with Vitest in the pinned Chromium, headless, as the core’s own tests run: with the test API’s globals (`build`, `expect`, `test`) and its matchers, and `build()` building the project as `pw build` does, with its plugins. Snapshots are kept beside the tests. The project needs nothing installed but `pw`. A failing test fails it, with exit status 1.',
37
+ arguments: [
38
+ { name: '<dir>', optional: true, description: 'The project’s folder, if the first argument is one (it has `pulpweaver4.toml`); the current folder by default.' },
39
+ { name: '<filter>…', optional: true, description: 'Run only the test files whose paths contain one of these, as Vitest’s filters do; in a project’s folder, `pw test layout` runs `tests/layout.test.ts`.' },
40
+ ],
41
+ options: [{ name: '--update', alias: '-u', description: 'Write the snapshots anew rather than comparing with them, for a change you meant to make: look at what changed before you commit it.' }],
42
+ examples: [
43
+ { command: 'pw test', description: 'Run every test of the project in this folder.' },
44
+ { command: 'pw test layout', description: 'Run the tests whose paths contain `layout`.' },
45
+ { command: 'pw test my-book chapters --update', description: 'Rewrite the snapshots of the tests in `my-book/` whose paths contain `chapters`.' },
46
+ ],
47
+ },
48
+ {
49
+ name: 'lint',
50
+ summary: 'run the project\'s lint rules as the edition\'s settings turn them on (its first by default), building it in headless Chromium for its html and layout rules, and with --fix, apply what the source rules can fix',
51
+ description: 'Runs the project’s lint rules as the edition’s `[lint]` settings over the project’s turn them on, and prints what they report: the `source` rules over its chapters and bibliography, and, where an `html` or `layout` rule is on, the rules over the edition’s HTML and, in print, its pages, which it builds in headless Chromium as `pw build` does, with the same plugins. `pw build` reports the same lint problems for each edition it builds. Any error gives exit status 1.',
52
+ arguments: [{ name: '<project>', optional: true, description: 'The project’s folder; the current folder by default.' }],
53
+ options: [
54
+ { name: '--fix', description: 'Apply the fixes the source rules give (straight quotes made curly, and so on) to the sources, pass after pass, and report what is left.' },
55
+ { name: '--edition', value: '<name>', description: 'Lint as this edition’s settings have it; the first edition in `pulpweaver4.toml` by default.' },
56
+ ],
57
+ examples: [{ command: 'pw lint --fix', description: 'Fix what can be fixed in the project in this folder, and list the rest.' }],
58
+ },
59
+ {
60
+ name: 'preflight',
61
+ summary: `check a PDF against our PDF/X rules: the standard the file says it is, or the one named (${PDF_X_STANDARDS.join(', ')}), requiring an output intent in that colour space`,
62
+ description: `Checks a PDF against pulpweaver4’s PDF/X rules, from ISO 15930, and lists each violation with its rule and page, and what it couldn’t check. It checks the standard the file claims, or the one \`--standard\` names (${PDF_X_STANDARDS.map((s) => `\`${s}\``).join(', ')}). Any violation gives exit status 1. It reads any PDF, not only pulpweaver4’s, but it is no substitute for a commercial preflight before a book goes to press.`,
63
+ arguments: [{ name: '<file.pdf>', description: 'The PDF to check.' }],
64
+ options: [
65
+ { name: '--standard', value: '<pdf/x-…>', description: 'The standard to check against, whatever the file claims.' },
66
+ { name: '--output', value: 'CMYK|RGB|GRAY', description: 'Require an output intent in this colour space, as a printer asking for CMYK would.' },
67
+ ],
68
+ examples: [{ command: 'pw preflight dist/paperback/paperback.pdf --output CMYK', description: 'Check the paperback’s PDF, and that it is for a CMYK press.' }],
69
+ },
70
+ {
71
+ name: 'spike',
72
+ summary: 'lay out phase 0\'s spike page in headless Chromium, and print its lines as JSON, or paint it to a PDF: sRGB, or CMYK PDF/X-4 for GRACoL 2013',
73
+ description: 'Lays out the spike page, the test page pulpweaver4’s first phase was measured by, in headless Chromium, and prints its lines as JSON, or paints it to a PDF. It is for pulpweaver4’s own tests, which hold every build to the same page.',
74
+ arguments: [],
75
+ options: [
76
+ { name: '--fonts', value: '<dir>', description: 'The folder with the spike page’s font. Required.' },
77
+ { name: '--pdf', value: '<file>', description: 'Paint the page to this PDF, in sRGB, rather than print its lines.' },
78
+ { name: '--cmyk', value: '<GRACoL2013_CRPC6.icc>', description: 'With `--pdf`, paint it in CMYK as PDF/X-4, through this GRACoL 2013 profile.' },
79
+ ],
80
+ examples: [{ command: 'pw spike --fonts tests/fonts --pdf spike.pdf', description: 'Paint the spike page to `spike.pdf`.' }],
81
+ },
82
+ {
83
+ name: 'profiles',
84
+ summary: 'put the standard output intents\' ICC profiles in pw\'s cache, where builds find them, or list them',
85
+ description: 'Manages the standard output intents’ ICC profiles in `pw`’s cache (`$XDG_CACHE_HOME/pulpweaver4/icc`, else `~/.cache/pulpweaver4/icc`), where `pw build` finds them. A build fetches a shareable profile from the ICC’s registry itself; one whose owner forbids redistribution but lets each user download it (FOGRA51’s, `PSOcoated_v3.icc`, from ECI) is fetched only by `pw profiles get`, from the owner’s own file, once you accept the owner’s licence. pulpweaver4 never hosts or ships it.',
86
+ arguments: [],
87
+ options: [],
88
+ examples: [
89
+ { command: 'pw profiles get FOGRA51', description: 'Show ECI’s licence, and once you accept it, put FOGRA51’s profile in the cache.' },
90
+ { command: 'pw profiles list', description: 'List the standard output intents’ profiles, and which are in the cache.' },
91
+ ],
92
+ subcommands: [
93
+ {
94
+ name: 'get',
95
+ summary: 'put a standard output intent\'s ICC profile in pw\'s cache, where builds find it, checked by its hash: FOGRA51\'s from ECI, once you accept ECI\'s licence (--accept-licence, for CI)',
96
+ description: 'Fetches each named output intent’s profile into the cache and checks it against the hash pulpweaver4 registers for it. For a profile its owner gives only to each user, it shows the owner’s licence and asks you to accept it, unless `--accept-licence` says you have.',
97
+ arguments: [{ name: '<name>…', description: 'The output intents whose profiles to get, by their names in `pulpweaver4.toml`’s `output-intent`: `FOGRA51`, `GRACoL2013`, and so on.' }],
98
+ options: [{ name: '--accept-licence', alias: '--accept-license', description: 'Accept the owner’s licence without being asked, as CI must, having read it yourself.' }],
99
+ examples: [],
100
+ },
101
+ {
102
+ name: 'list',
103
+ summary: 'the standard output intents\' profiles, and which are in the cache',
104
+ description: 'Lists each standard output intent with its profile’s file, how `pw` gets it, and where it is in the cache, if it is (and whether it is the registered profile).',
105
+ arguments: [],
106
+ options: [],
107
+ examples: [],
108
+ },
109
+ ],
110
+ },
111
+ ];
112
+ /** The environment variables `pw` reads. */
113
+ export const ENVIRONMENT = [
114
+ {
115
+ name: 'SOURCE_DATE_EPOCH',
116
+ description: 'The date PDFs are stamped with, in seconds since 1970 UTC, when the project sets none (`date` in `pulpweaver4.toml`); never the clock’s, so a build is reproducible (https://reproducible-builds.org/specs/source-date-epoch/).',
117
+ },
118
+ {
119
+ name: 'PW_ANY_CHROMIUM',
120
+ description: `Set (to anything but \`0\` or nothing) to lay out in a Chromium other than ${CHROMIUM.version} (Playwright ${CHROMIUM.playwright}’s), with a warning: another Chromium may break lines and pages differently.`,
121
+ },
122
+ ];
123
+ /** A command's usage line: `pw build [<dir>] [--edition <name>|all]`; a subcommand's after its command's name. */
124
+ export function usageLine(command, parent) {
125
+ const args = command.arguments.map((a) => (a.optional ? `[${a.name}]` : a.name));
126
+ const options = command.options.map((o) => {
127
+ const option = o.value ? `${o.name} ${o.value}` : o.name;
128
+ // The spike's fonts are required.
129
+ return command.name === 'spike' && o.name === '--fonts' ? option : `[${option}]`;
130
+ });
131
+ return ['pw', ...(parent ? [parent.name] : []), command.name, ...args, ...options].join(' ');
132
+ }
133
+ /** Text without its Markdown: `pw --help` is plain text. */
134
+ function plain(text) {
135
+ return text.replaceAll('`', '');
136
+ }
137
+ /** `pw --help`: each command's usage and summary, the project's plugins' commands (`plugins`), then the environment. */
138
+ export function helpText(name, plugins = []) {
139
+ const wrap = (text, indent) => {
140
+ const lines = [];
141
+ let line = '';
142
+ for (const word of text.split(' ')) {
143
+ if (line && indent.length + line.length + 1 + word.length > 100) {
144
+ lines.push(indent + line);
145
+ line = word;
146
+ }
147
+ else
148
+ line = line ? `${line} ${word}` : word;
149
+ }
150
+ return [...lines, indent + line].join('\n');
151
+ };
152
+ const width = Math.max(...ENVIRONMENT.map((v) => v.name.length)) + 2;
153
+ return [
154
+ `usage: pw <command>\n\n${name}'s command line.\n`,
155
+ ...COMMANDS.flatMap((c) => (c.subcommands ?? [undefined]).map((sub) => ` ${sub ? usageLine(sub, c) : usageLine(c)}\n${wrap((sub ?? c).summary, ' ')}`)),
156
+ ...(plugins.length ? ['\nThe project\'s plugins\' commands:'] : []),
157
+ ...plugins.map((c) => ` ${['pw', c.name, ...(c.usage ? [c.usage] : [])].join(' ')}\n${wrap(`${c.description} (${c.plugin})`, ' ')}`),
158
+ '\nEnvironment:',
159
+ ...ENVIRONMENT.map((v) => wrap(plain(v.description).replace(/ \(https:[^)]*\)/, ''), ' '.repeat(width + 2)).replace(' '.repeat(width + 2), ` ${v.name.padEnd(width)}`)),
160
+ ].join('\n');
161
+ }
162
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AA6CxC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB;QACE,IAAI,E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-0,0 +1,8 @@
1
+ /** Where the cache keeps a file of the CSL repositories, by its URL; `undefined` for a URL that isn't one. */
2
+ export declare function cachedCslPath(url: string, env?: NodeJS.ProcessEnv): string | undefined;
3
+ /**
4
+ * A style's or locale's text, from pw's cache or fetched into it;
5
+ * `undefined` if the repository has no such file. Rejects, saying so, when
6
+ * it isn't in the cache and can't be fetched.
7
+ */
8
+ export declare function cslText(url: string, env?: NodeJS.ProcessEnv, fetcher?: typeof fetch): Promise<string | undefined>;
package/dist/csl.js ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The CSL project's styles and locales for a build
3
+ * (https://plans.inkylabs.com/pulpweaver#citations): a style or locale a
4
+ * project names by id that the core doesn't bundle is fetched from the CSL
5
+ * repositories at the commit the core pins (`CSL_COMMITS`), once, into pw's
6
+ * cache (`~/.cache/pulpweaver4/csl/<repository>/<commit>/`), where later
7
+ * builds find it with no network. A file at a commit never changes, so what
8
+ * the cache has is what the network would give, and that a file isn't
9
+ * there is kept too (`<file>.missing`): a dependent style is looked for
10
+ * among the independent ones first. They are CC BY-SA 3.0, fetched for the
11
+ * user whose project names one, and never shipped with pw.
12
+ */
13
+ import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
14
+ import { dirname, join } from 'node:path';
15
+ import { cslFetcher, cslFile } from 'pulpweaver4';
16
+ import { cacheDir } from './profiles.js';
17
+ /** Where the cache keeps a file of the CSL repositories, by its URL; `undefined` for a URL that isn't one. */
18
+ export function cachedCslPath(url, env = process.env) {
19
+ const file = cslFile(url);
20
+ return file && join(cacheDir(env), 'csl', file.repository, file.commit, file.path);
21
+ }
22
+ async function keep(path, text) {
23
+ await mkdir(dirname(path), { recursive: true });
24
+ const partial = `${path}.${process.pid}.part`;
25
+ await writeFile(partial, text);
26
+ await rename(partial, path);
27
+ }
28
+ /**
29
+ * A style's or locale's text, from pw's cache or fetched into it;
30
+ * `undefined` if the repository has no such file. Rejects, saying so, when
31
+ * it isn't in the cache and can't be fetched.
32
+ */
33
+ export async function cslText(url, env = process.env, fetcher = fetch) {
34
+ const path = cachedCslPath(url, env);
35
+ if (path === undefined)
36
+ throw new Error(`${url} isn't a file of the CSL repositories at the pinned commit`);
37
+ const have = await readFile(path, 'utf8').catch(() => undefined);
38
+ if (have !== undefined)
39
+ return have;
40
+ if (await readFile(`${path}.missing`).then(() => true, () => false))
41
+ return undefined;
42
+ let text;
43
+ try {
44
+ text = await cslFetcher(fetcher)(url);
45
+ }
46
+ catch (e) {
47
+ const cause = e.cause;
48
+ throw new Error(`${url} isn't in pw's cache (${path}) and couldn't be fetched: ${e.message}${cause ? ` (${String(cause)})` : ''}`);
49
+ }
50
+ await keep(text === undefined ? `${path}.missing` : path, text ?? '');
51
+ return text;
52
+ }
53
+ //# sourceMappingURL=csl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csl.js","sourceRoot":"","sources":["../src/csl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACrE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,8GAA8G;AAC9G,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,GAAG,GAAsB,OAAO,CAAC,GAAG;IAC7E,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IACzB,OAAO,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;AACpF,CAAC;AAED,KAAK,UAAU,IAAI,CAAC,IAAY,EAAE,IAAY;IAC5C,MAAM,KAAK,CAAC,O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C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IAC/I,CAAC;IACD,MAAM,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,CAAA;IACrE,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { type ChromiumHostOptions } from './chromium.js';
2
+ export { buildProject, parseBuildArgs } from './build.js';
3
+ export { lintProjectIn, parseLintArgs } from './lint.js';
4
+ export { COMMANDS, ENVIRONMENT, helpText, usageLine, type Command, type CommandArgument, type CommandName, type CommandOption, type EnvironmentVariable } from './commands.js';
5
+ export { exposeProject, PAGE_HOST_MODULE, pluginRoutes } from './bridge.js';
6
+ export { cacheDir, cachedProfile, cachedProfilePath, getProfile, profilesCommand, type GetProfileOptions } from './profiles.js';
7
+ export { newProject, TEMPLATE_DIR } from './new.js';
8
+ export { CHROMIUM, checkChromium, ChromiumError, ChromiumHost, PAGE_LOCALE, PAGE_TIME_ZONE, type ChromiumHostOptions } from './chromium.js';
9
+ export { NodeFS } from './node-fs.js';
10
+ export { printProblems, useColour, type ColourEnvironment } from './problems.js';
11
+ export { nodePluginImporter, packageDir, packageEntry } from './plugins.js';
12
+ export { loadProjectPlugins, pluginCommands, runPluginCommand, type PluginCommand, type ProjectPlugins } from './plugin-commands.js';
13
+ export { spikePdfs, spikeSignature, type SpikePdfOptions } from './spike.js';
14
+ /** The environment pw reads. */
15
+ export interface PwEnvironment {
16
+ /** The build's date when the project has none (https://reproducible-builds.org/specs/source-date-epoch/). */
17
+ SOURCE_DATE_EPOCH?: string | undefined;
18
+ /** Set (to anything but `0` or nothing) to lay out in a Chromium other than the pinned one, with a warning. */
19
+ PW_ANY_CHROMIUM?: string | undefined;
20
+ [name: string]: string | undefined;
21
+ }
22
+ /**
23
+ * Runs pw with its arguments, writing to `out`, and returns the exit status.
24
+ * `host` says where the core is, for running from its sources, `env`
25
+ * is the environment, `process.env` by default, and `cwd` the folder it
26
+ * runs in, whose project's plugins' commands it knows.
27
+ */
28
+ export declare function main(args: readonly string[], out: (line: string) => void, host?: ChromiumHostOptions, env?: PwEnvironment, cwd?: string): Promise<number>;
package/dist/index.js ADDED
@@ -0,0 +1,135 @@
1
+ /** pw, pulpweaver4's command line: the core, hosted on Node. */
2
+ import { buildDate, NAME, PDF_X_STANDARDS, pdfXStandard, preflightPdfX, } from 'pulpweaver4';
3
+ import { readFile, writeFile } from 'node:fs/promises';
4
+ import { buildCommand } from './build.js';
5
+ import { helpText } from './commands.js';
6
+ import { CHROMIUM, ChromiumError } from './chromium.js';
7
+ import { lintCommand } from './lint.js';
8
+ import { newCommand } from './new.js';
9
+ import { loadProjectPlugins, pluginCommands, runPluginCommand } from './plugin-commands.js';
10
+ import { profilesCommand } from './profiles.js';
11
+ import { spikePdfs, spikeSignature } from './spike.js';
12
+ export { buildProject, parseBuildArgs } from './build.js';
13
+ export { lintProjectIn, parseLintArgs } from './lint.js';
14
+ export { COMMANDS, ENVIRONMENT, helpText, usageLine } from './commands.js';
15
+ export { exposeProject, PAGE_HOST_MODULE, pluginRoutes } from './bridge.js';
16
+ export { cacheDir, cachedProfile, cachedProfilePath, getProfile, profilesCommand } from './profiles.js';
17
+ export { newProject, TEMPLATE_DIR } from './new.js';
18
+ export { CHROMIUM, checkChromium, ChromiumError, ChromiumHost, PAGE_LOCALE, PAGE_TIME_ZONE } from './chromium.js';
19
+ export { NodeFS } from './node-fs.js';
20
+ export { printProblems, useColour } from './problems.js';
21
+ export { nodePluginImporter, packageDir, packageEntry } from './plugins.js';
22
+ export { loadProjectPlugins, pluginCommands, runPluginCommand } from './plugin-commands.js';
23
+ export { spikePdfs, spikeSignature } from './spike.js';
24
+ /**
25
+ * Runs pw with its arguments, writing to `out`, and returns the exit status.
26
+ * `host` says where the core is, for running from its sources, `env`
27
+ * is the environment, `process.env` by default, and `cwd` the folder it
28
+ * runs in, whose project's plugins' commands it knows.
29
+ */
30
+ export async function main(args, out, host = {}, env = process.env, cwd = process.cwd()) {
31
+ try {
32
+ return await run(args, out, { anyChromium: env.PW_ANY_CHROMIUM !== undefined && env.PW_ANY_CHROMIUM !== '' && env.PW_ANY_CHROMIUM !== '0', ...host }, env, cwd);
33
+ }
34
+ catch (e) {
35
+ if (!(e instanceof ChromiumError))
36
+ throw e;
37
+ out(`pw: ${e.message}`);
38
+ return 1;
39
+ }
40
+ }
41
+ async function run(args, out, host, env, cwd) {
42
+ const option = (name) => {
43
+ const i = args.indexOf(name);
44
+ return i >= 0 ? args[i + 1] : undefined;
45
+ };
46
+ if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
47
+ const loaded = await loadProjectPlugins(cwd);
48
+ out(helpText(NAME, loaded ? pluginCommands(loaded.registry) : []));
49
+ return 0;
50
+ }
51
+ // One handler for each of COMMANDS, which documents them.
52
+ const handlers = {
53
+ new: () => newCommand(args.slice(1), out),
54
+ build: () => buildCommand(args.slice(1), out, host, env),
55
+ // Vitest loads only for the tests.
56
+ test: async () => (await import('./test.js')).testCommand(args.slice(1), out, host, env),
57
+ spike: () => spikeCommand(option, out, host, env),
58
+ preflight: () => preflightCommand(args, option, out),
59
+ lint: () => lintCommand(args.slice(1), out, host, env),
60
+ profiles: () => profilesCommand(args.slice(1), out, env),
61
+ };
62
+ const command = args[0];
63
+ if (Object.hasOwn(handlers, command))
64
+ return handlers[command]();
65
+ // Else a command of the project's plugins.
66
+ const loaded = await loadProjectPlugins(cwd);
67
+ const status = loaded && await runPluginCommand(loaded, command, args.slice(1), out, env);
68
+ if (status !== undefined)
69
+ return status;
70
+ out(`pw: unknown command ${JSON.stringify(command)}`);
71
+ return 2;
72
+ }
73
+ /** `pw spike`: phase 0's spike page, as its lines in JSON or painted to a PDF. */
74
+ async function spikeCommand(option, out, host, env) {
75
+ const fontsDir = option('--fonts');
76
+ if (!fontsDir) {
77
+ out('pw spike: --fonts <dir> names the directory with the spike page\'s font');
78
+ return 2;
79
+ }
80
+ const pdf = option('--pdf');
81
+ const cmyk = option('--cmyk');
82
+ if (cmyk && !pdf) {
83
+ out('pw spike: --cmyk needs --pdf');
84
+ return 2;
85
+ }
86
+ if (pdf) {
87
+ let date;
88
+ try {
89
+ date = buildDate({ sourceDateEpoch: env.SOURCE_DATE_EPOCH });
90
+ }
91
+ catch (e) {
92
+ if (!(e instanceof RangeError))
93
+ throw e;
94
+ out(`pw: ${e.message}`);
95
+ return 2;
96
+ }
97
+ const profile = cmyk ? new Uint8Array(await readFile(cmyk)) : undefined;
98
+ await writeFile(pdf, (await spikePdfs({ ...host, fontsDir }, { ...(profile ? { cmyk: profile } : {}), ...(date ? { date } : {}) })).ours);
99
+ return 0;
100
+ }
101
+ out(JSON.stringify(await spikeSignature({ ...host, fontsDir }), null, 1));
102
+ return 0;
103
+ }
104
+ /** `pw preflight`: a PDF against our PDF/X rules. */
105
+ async function preflightCommand(args, option, out) {
106
+ const file = args[1];
107
+ if (!file) {
108
+ out('pw preflight: name the PDF to check');
109
+ return 2;
110
+ }
111
+ const name = option('--standard');
112
+ const standard = name === undefined ? undefined : pdfXStandard(name);
113
+ if (name !== undefined && !standard) {
114
+ out(`pw preflight: unknown standard ${JSON.stringify(name)}; one of ${PDF_X_STANDARDS.join(', ')}`);
115
+ return 2;
116
+ }
117
+ const output = option('--output')?.toUpperCase();
118
+ if (output !== undefined && output !== 'CMYK' && output !== 'RGB' && output !== 'GRAY') {
119
+ out('pw preflight: --output is CMYK, RGB or GRAY');
120
+ return 2;
121
+ }
122
+ const report = preflightPdfX(new Uint8Array(await readFile(file)), {
123
+ ...(standard ? { standard } : {}),
124
+ ...(output ? { outputColourSpace: output } : {}),
125
+ });
126
+ const at = (page) => (page ? `page ${page}: ` : '');
127
+ for (const v of report.violations)
128
+ out(`${file}: ${v.rule}: ${at(v.page)}${v.message}`);
129
+ for (const n of report.notices)
130
+ out(`${file}: not checked: ${n.rule}: ${at(n.page)}${n.message}`);
131
+ const n = report.violations.length;
132
+ out(`${file}: ${n ? `${n} ${report.standard} violation${n === 1 ? '' : 's'}` : `no ${report.standard} violations`}`);
133
+ return report.violations.length ? 1 : 0;
134
+ }
135
+ //# sourceMappingURL=index.js.map