manuscrio-pdf 1.0.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 +89 -0
- package/bin/manuscrio-pdf.js +4 -0
- package/package.json +39 -0
- package/src/main.js +134 -0
- package/src/plan.js +191 -0
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# manuscrio-pdf
|
|
2
|
+
|
|
3
|
+
**Professional PDFs from your documentation build.** Point it at a built Docusaurus, Starlight or
|
|
4
|
+
MkDocs site and it produces a complete, publication-quality manual: numbered, bookmarked, with a
|
|
5
|
+
contents table and the site's own logo on the cover.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx manuscrio-pdf inspect ./build # what manuals does this site contain?
|
|
9
|
+
npx manuscrio-pdf export ./build # one manual per documentation edition
|
|
10
|
+
npx manuscrio-pdf export ./build --scope section --theme lapis
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Documentation: **[manuscrio.com/docs](https://manuscrio.com/docs/)**
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- **Docker or Podman.** Rendering happens inside a published image; this package is the wrapper
|
|
18
|
+
that runs it. Nothing else is installed on your machine.
|
|
19
|
+
- **Node 20.19 or later**, only for this command. The engine itself contains no Java runtime.
|
|
20
|
+
|
|
21
|
+
The image is `ghcr.io/manuscrio/manuscrio-pdf`, pinned by digest so one version of this package always
|
|
22
|
+
renders through exactly one build of the engine. It is **public — no account, no login, no download
|
|
23
|
+
token.** Docker pulls it on first use.
|
|
24
|
+
|
|
25
|
+
## Licensing
|
|
26
|
+
|
|
27
|
+
Without a licence the exporter runs in **Evaluation Mode**: complete manuals at full rendering
|
|
28
|
+
quality, no page limit and no account, with a diagonal watermark and a footer line. An organization
|
|
29
|
+
licence removes both. Nothing calls home in either mode — the entitlement is a signed file you hold,
|
|
30
|
+
verified offline, so an export works in CI with no network egress at all.
|
|
31
|
+
|
|
32
|
+
See [licensing](https://manuscrio.com/docs/licensing/).
|
|
33
|
+
|
|
34
|
+
## Why a wrapper
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx manuscrio-pdf export ./build --logo brand/acme.svg
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The equivalent without it is four lines, two bind mounts and a `--user "$(id -u):$(id -g)"` that a
|
|
41
|
+
first-time evaluator has no reason to know is load-bearing.
|
|
42
|
+
|
|
43
|
+
## What it actually does
|
|
44
|
+
|
|
45
|
+
The wrapper is not a second command line. It recognises only the arguments that name a **host
|
|
46
|
+
path** — the Site Build positional, `--output-dir`, `--logo`, `--license`, and
|
|
47
|
+
`$MANUSCRIO_PDF_LICENSE_FILE` — because those are the ones the engine cannot see unless something
|
|
48
|
+
mounts them. Everything else is forwarded to the image verbatim as an opaque string, so a new
|
|
49
|
+
engine option needs no release here.
|
|
50
|
+
|
|
51
|
+
| You type | The container gets |
|
|
52
|
+
|---|---|
|
|
53
|
+
| `./build` | `/input`, mounted read-only |
|
|
54
|
+
| `--output-dir ./pdfs` | `/output`, created on the host first so it is yours, not the daemon's |
|
|
55
|
+
| *(no `--output-dir`)* | `manuscrio-output` beside the Site Build, matching the engine's default |
|
|
56
|
+
| `--logo brand/acme.svg` | `/brand/acme.svg`, read-only |
|
|
57
|
+
| `--license acme.manuscrio-pdf-license` | `/etc/manuscrio-pdf/license`, read-only |
|
|
58
|
+
| `$MANUSCRIO_PDF_LICENSE_FILE=./ci.license` | the same mount, with the variable rewritten to it |
|
|
59
|
+
| `$MANUSCRIO_PDF_LICENSE` | `-e MANUSCRIO_PDF_LICENSE` by **name** — never by value |
|
|
60
|
+
|
|
61
|
+
That last row is deliberate. A licence is a bearer token, and `-e MANUSCRIO_PDF_LICENSE=<text>` would
|
|
62
|
+
put it in `ps` output on a shared CI runner.
|
|
63
|
+
|
|
64
|
+
`--help`, `--version`, and any command the engine grows later are handed over untouched.
|
|
65
|
+
|
|
66
|
+
The run itself reproduces the invocation in
|
|
67
|
+
[container packaging](../../packaging/container/README.md): `--rm --init --ipc=host`, input
|
|
68
|
+
read-only, output writable, and the caller's UID/GID so the PDFs and a mode-0600 licence file both
|
|
69
|
+
work. Under rootless Podman it combines `--userns=keep-id` with the same `--user` value: the namespace
|
|
70
|
+
maps the caller's UID and GID, while the explicit user overrides the image's `USER pwuser`. Both are
|
|
71
|
+
required on Podman 5.4 for bind-mounted files to remain owned by the caller — without them the
|
|
72
|
+
export can fail on a restrictive output directory or leave files owned by a subordinate UID on a
|
|
73
|
+
more permissive one. Rootful Podman does not need `keep-id`, so the wrapper asks (`podman info
|
|
74
|
+
--format '{{.Host.Security.Rootless}}'`) rather than inferring from the runtime's name.
|
|
75
|
+
`$MANUSCRIO_USER` replaces the whole mapping.
|
|
76
|
+
|
|
77
|
+
## Environment
|
|
78
|
+
|
|
79
|
+
| Variable | Effect |
|
|
80
|
+
|---|---|
|
|
81
|
+
| `MANUSCRIO_RUNTIME` | container engine to use. Otherwise `docker`, then `podman` |
|
|
82
|
+
| `MANUSCRIO_IMAGE` | image to run, for testing against a local build |
|
|
83
|
+
| `MANUSCRIO_USER` | value for `--user`, overriding the rule above |
|
|
84
|
+
|
|
85
|
+
## Support
|
|
86
|
+
|
|
87
|
+
`contact@manuscrio.com`, or [troubleshooting](https://manuscrio.com/docs/troubleshooting/).
|
|
88
|
+
|
|
89
|
+
Development notes for this package live in the product repository, alongside the engine.
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "manuscrio-pdf",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Professional PDFs from your documentation build. Runs the Manuscrio image under Docker or Podman.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pdf",
|
|
7
|
+
"documentation",
|
|
8
|
+
"docusaurus",
|
|
9
|
+
"mkdocs",
|
|
10
|
+
"starlight",
|
|
11
|
+
"manual",
|
|
12
|
+
"technical-writing",
|
|
13
|
+
"docs-as-code"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://manuscrio.com",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://manuscrio.com/docs/troubleshooting/",
|
|
18
|
+
"email": "contact@manuscrio.com"
|
|
19
|
+
},
|
|
20
|
+
"license": "UNLICENSED",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"bin": {
|
|
23
|
+
"manuscrio-pdf": "bin/manuscrio-pdf.js"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"bin",
|
|
27
|
+
"src",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20.19"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"test": "node --test"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/main.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime half of the wrapper: find a container engine, check the paths the plan needs, run it.
|
|
3
|
+
* The translation itself lives in plan.js and is pure.
|
|
4
|
+
*/
|
|
5
|
+
import { mkdirSync, statSync } from 'node:fs';
|
|
6
|
+
import { spawnSync } from 'node:child_process';
|
|
7
|
+
import { DEFAULT_IMAGE, UsageError, plan } from './plan.js';
|
|
8
|
+
|
|
9
|
+
const RUNTIMES = ['docker', 'podman'];
|
|
10
|
+
|
|
11
|
+
class CliError extends Error {}
|
|
12
|
+
|
|
13
|
+
/** First runtime that answers `--version`. `--version` rather than a lookup on PATH, so a shim or
|
|
14
|
+
* an alias installed as something other than a file is found too. */
|
|
15
|
+
function findRuntime(env) {
|
|
16
|
+
const requested = env.MANUSCRIO_RUNTIME;
|
|
17
|
+
const candidates = requested ? [requested] : RUNTIMES;
|
|
18
|
+
for (const candidate of candidates) {
|
|
19
|
+
const probe = spawnSync(candidate, ['--version'], { stdio: 'ignore' });
|
|
20
|
+
if (!probe.error) {
|
|
21
|
+
return candidate;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
throw new CliError(
|
|
25
|
+
requested
|
|
26
|
+
? `${requested} is not runnable, and $MANUSCRIO_RUNTIME asks for it`
|
|
27
|
+
: 'no container engine found. Manuscrio renders inside its published image and needs '
|
|
28
|
+
+ 'Docker or Podman on PATH; set $MANUSCRIO_RUNTIME to name another.');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Whether this Podman is rootless, which decides whether `keep-id` is needed. Asked rather than
|
|
33
|
+
* inferred, because the runtime's name says nothing about it. A probe that cannot answer is a
|
|
34
|
+
* runtime failure, not a reason to guess at the ownership mapping.
|
|
35
|
+
*/
|
|
36
|
+
function isRootlessPodman(runtime) {
|
|
37
|
+
const probe = spawnSync(runtime, ['info', '--format', '{{.Host.Security.Rootless}}'],
|
|
38
|
+
{ encoding: 'utf8' });
|
|
39
|
+
if (probe.error) {
|
|
40
|
+
throw new CliError(`${runtime} could not report whether it is rootless: ${probe.error.message}`);
|
|
41
|
+
}
|
|
42
|
+
if (probe.status !== 0) {
|
|
43
|
+
const detail = (probe.stderr || '').trim();
|
|
44
|
+
throw new CliError(`${runtime} could not report whether it is rootless${detail ? `: ${detail}` : ''}`);
|
|
45
|
+
}
|
|
46
|
+
const answer = (probe.stdout || '').trim();
|
|
47
|
+
if (answer !== 'true' && answer !== 'false') {
|
|
48
|
+
throw new CliError(`${runtime} returned an unexpected rootless status: ${answer || '<empty>'}`);
|
|
49
|
+
}
|
|
50
|
+
return answer === 'true';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* How the container maps the caller who needs to read inputs and own outputs.
|
|
55
|
+
*
|
|
56
|
+
* Docker's daemon runs as root, so `--user` alone is enough. Rootless Podman needs both flags:
|
|
57
|
+
* `keep-id` maps the caller's UID and GID into the container, and the explicit `--user` overrides
|
|
58
|
+
* the image's own `USER pwuser` -- Podman honours that unless told otherwise, and files written
|
|
59
|
+
* under it land owned by a subuid rather than by the caller, which can fail a restrictive output
|
|
60
|
+
* mount or leave awkwardly owned files on a permissive one. Rootful Podman behaves like Docker and
|
|
61
|
+
* does not need `keep-id`, so it takes `--user` alone.
|
|
62
|
+
*/
|
|
63
|
+
export function containerIdentity(runtime, env, rootlessPodman = false) {
|
|
64
|
+
if (env.MANUSCRIO_USER) {
|
|
65
|
+
return { user: env.MANUSCRIO_USER, userns: null };
|
|
66
|
+
}
|
|
67
|
+
// No getuid on Windows; a remote client then has no local identity to map, and keep-id still
|
|
68
|
+
// maps the user Podman runs as on the other side.
|
|
69
|
+
const user = typeof process.getuid === 'function'
|
|
70
|
+
? `${process.getuid()}:${process.getgid()}` : null;
|
|
71
|
+
return { user, userns: rootlessPodman ? 'keep-id' : null };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function checkPaths(required) {
|
|
75
|
+
for (const { path, kind, source } of required) {
|
|
76
|
+
let stats;
|
|
77
|
+
try {
|
|
78
|
+
stats = statSync(path);
|
|
79
|
+
} catch {
|
|
80
|
+
throw new CliError(`${source} is not there: ${path}`);
|
|
81
|
+
}
|
|
82
|
+
if (kind === 'directory' && !stats.isDirectory()) {
|
|
83
|
+
throw new CliError(`${source} is not a directory: ${path}`);
|
|
84
|
+
}
|
|
85
|
+
if (kind === 'file' && !stats.isFile()) {
|
|
86
|
+
throw new CliError(`${source} is not a file: ${path}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function main(argv, env = process.env) {
|
|
92
|
+
try {
|
|
93
|
+
const runtime = findRuntime(env);
|
|
94
|
+
const identity = containerIdentity(runtime, env,
|
|
95
|
+
!env.MANUSCRIO_USER && runtime.includes('podman') && isRootlessPodman(runtime));
|
|
96
|
+
const run = plan({
|
|
97
|
+
argv,
|
|
98
|
+
env,
|
|
99
|
+
cwd: process.cwd(),
|
|
100
|
+
runtime,
|
|
101
|
+
image: env.MANUSCRIO_IMAGE || DEFAULT_IMAGE,
|
|
102
|
+
...identity,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
checkPaths(run.require);
|
|
106
|
+
for (const directory of run.create) {
|
|
107
|
+
// Ahead of the run, so the output directory is owned by whoever typed the command rather
|
|
108
|
+
// than created by the daemon.
|
|
109
|
+
mkdirSync(directory, { recursive: true });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const result = spawnSync(run.runtime, run.args, { stdio: 'inherit' });
|
|
113
|
+
if (result.error) {
|
|
114
|
+
throw new CliError(`${run.runtime} could not be started: ${result.error.message}`);
|
|
115
|
+
}
|
|
116
|
+
if (result.signal) {
|
|
117
|
+
throw new CliError(`${run.runtime} was killed by ${result.signal}`);
|
|
118
|
+
}
|
|
119
|
+
if (result.status === 0 && run.create.length > 0) {
|
|
120
|
+
// The engine reports the container's own /output, which nobody typed. Name the host
|
|
121
|
+
// directory the PDFs are actually in. On stderr, so piped stdout stays the engine's.
|
|
122
|
+
process.stderr.write(`manuscrio-pdf: PDFs written to ${run.create[0]}\n`);
|
|
123
|
+
}
|
|
124
|
+
return result.status ?? 1;
|
|
125
|
+
} catch (failure) {
|
|
126
|
+
if (failure instanceof CliError || failure instanceof UsageError) {
|
|
127
|
+
process.stderr.write(`manuscrio-pdf: ${failure.message}\n`);
|
|
128
|
+
// 2 for a command line the wrapper could not read, matching picocli's convention in the
|
|
129
|
+
// engine; 1 for a run that failed.
|
|
130
|
+
return failure instanceof UsageError ? 2 : 1;
|
|
131
|
+
}
|
|
132
|
+
throw failure;
|
|
133
|
+
}
|
|
134
|
+
}
|
package/src/plan.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translates a Manuscrio command line into a container run.
|
|
3
|
+
*
|
|
4
|
+
* The wrapper is not a second command line. It recognises only the arguments that name a *host*
|
|
5
|
+
* path -- the Site Build, `--output-dir`, `--logo`, `--license` -- because those are the ones the
|
|
6
|
+
* engine cannot see unless something mounts them; everything else is forwarded verbatim as an
|
|
7
|
+
* opaque string. Adding an engine option therefore needs no release here, as long as it does not
|
|
8
|
+
* name a path.
|
|
9
|
+
*
|
|
10
|
+
* Pure: it reads no filesystem and spawns nothing, so the translation is testable without a
|
|
11
|
+
* container engine. It reports the paths it needs back to the caller instead.
|
|
12
|
+
*/
|
|
13
|
+
import { basename, isAbsolute, relative, resolve } from 'node:path';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Published product image. GHCR rather than Docker Hub because Evaluation Mode is defined as an
|
|
17
|
+
* anonymous pull with no account or token, and Docker Hub rate-limits anonymous pulls per source
|
|
18
|
+
* IP -- a limit a customer's whole office shares behind one NAT, spent inside their release window.
|
|
19
|
+
* `MANUSCRIO_IMAGE` overrides it.
|
|
20
|
+
*
|
|
21
|
+
* Named by tag *and* digest. The tag is the version, so this file, the documentation, the engine
|
|
22
|
+
* pom and package.json all read 1.0.0 and stay in step. The digest is what actually resolves: a tag
|
|
23
|
+
* can be moved, and `npx manuscrio-pdf@1.0.0` rendering against different bytes than it shipped with
|
|
24
|
+
* would contradict the reproducibility the product sells. Docker rejects the reference outright if
|
|
25
|
+
* the two disagree, so the pairing cannot drift silently.
|
|
26
|
+
*
|
|
27
|
+
* Both halves move together at an image release; scripts/check-image-reference.mjs holds the
|
|
28
|
+
* documentation to the tag.
|
|
29
|
+
*/
|
|
30
|
+
export const DEFAULT_IMAGE =
|
|
31
|
+
'ghcr.io/manuscrio/manuscrio-pdf:1.0.0@sha256:5ef06180c165af3940cacb7416fb8af2fcd533859bdfa582e3988d52b3254e96';
|
|
32
|
+
|
|
33
|
+
export const CONTAINER_INPUT = '/input';
|
|
34
|
+
export const CONTAINER_OUTPUT = '/output';
|
|
35
|
+
export const CONTAINER_BRAND_DIR = '/brand';
|
|
36
|
+
/** The engine's own default licence location, so a mount alone is enough. */
|
|
37
|
+
export const CONTAINER_LICENSE = '/etc/manuscrio-pdf/license';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Engine options that consume the following argument. Needed only to tell an option's value from
|
|
41
|
+
* the Site Build positional: without it, `--scope section ./build` would read `section` as the
|
|
42
|
+
* build directory. `test/engine-options.test.js` reads the picocli annotations and fails when this
|
|
43
|
+
* drifts from the engine.
|
|
44
|
+
*/
|
|
45
|
+
export const VALUE_OPTIONS = new Set([
|
|
46
|
+
'--base-path',
|
|
47
|
+
'--concurrency',
|
|
48
|
+
'--edition',
|
|
49
|
+
'--exclude-edition',
|
|
50
|
+
'--framework',
|
|
51
|
+
'--license',
|
|
52
|
+
'--logo',
|
|
53
|
+
'--manual',
|
|
54
|
+
'--max-chapter-level',
|
|
55
|
+
'--output-dir',
|
|
56
|
+
'--scope',
|
|
57
|
+
'--theme',
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
/** Commands that name host paths. Anything else is handed to the image untouched. */
|
|
61
|
+
const TRANSLATED_COMMANDS = new Set(['inspect', 'export', 'license']);
|
|
62
|
+
|
|
63
|
+
const HELP_OPTIONS = new Set(['-h', '--help', '-V', '--version']);
|
|
64
|
+
|
|
65
|
+
export class UsageError extends Error {}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {object} input
|
|
69
|
+
* @param {string[]} input.argv arguments as the user typed them, without the program name
|
|
70
|
+
* @param {Record<string,string|undefined>} [input.env]
|
|
71
|
+
* @param {string} [input.cwd] base for relative host paths
|
|
72
|
+
* @param {string} input.runtime `docker` or `podman`, already resolved
|
|
73
|
+
* @param {string} input.image
|
|
74
|
+
* @param {string|null} [input.user] `uid:gid` for `--user`, or null to run as the image's user
|
|
75
|
+
* @param {string|null} [input.userns] user namespace mode, used for rootless Podman
|
|
76
|
+
* @returns {{args: string[], create: string[], require: {path: string, kind: string, source: string}[]}}
|
|
77
|
+
*/
|
|
78
|
+
export function plan({ argv, env = {}, cwd = process.cwd(), runtime, image, user = null, userns = null }) {
|
|
79
|
+
const run = ['run', '--rm', '--init', '--ipc=host'];
|
|
80
|
+
if (userns) {
|
|
81
|
+
run.push('--userns', userns);
|
|
82
|
+
}
|
|
83
|
+
if (user) {
|
|
84
|
+
run.push('--user', user);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const command = argv[0];
|
|
88
|
+
if (!TRANSLATED_COMMANDS.has(command) || argv.some((arg) => HELP_OPTIONS.has(arg))) {
|
|
89
|
+
// Usage, version, and any command added to the engine later. Nothing here names a host path,
|
|
90
|
+
// so translating would only be a way to get it wrong.
|
|
91
|
+
return { runtime, args: [...run, image, ...argv], create: [], require: [] };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const forwarded = [];
|
|
95
|
+
const mounts = [];
|
|
96
|
+
const envArgs = [];
|
|
97
|
+
const require = [];
|
|
98
|
+
let buildDir = null;
|
|
99
|
+
let outputDir = null;
|
|
100
|
+
let licensed = false;
|
|
101
|
+
|
|
102
|
+
for (let i = 0; i < argv.length; i++) {
|
|
103
|
+
const arg = argv[i];
|
|
104
|
+
const equals = arg.startsWith('--') ? arg.indexOf('=') : -1;
|
|
105
|
+
const name = equals > 0 ? arg.slice(0, equals) : arg;
|
|
106
|
+
const takesValue = VALUE_OPTIONS.has(name);
|
|
107
|
+
let value = null;
|
|
108
|
+
if (takesValue) {
|
|
109
|
+
value = equals > 0 ? arg.slice(equals + 1) : argv[++i];
|
|
110
|
+
if (value === undefined) {
|
|
111
|
+
throw new UsageError(`${name} needs a value`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
switch (name) {
|
|
116
|
+
case '--output-dir':
|
|
117
|
+
outputDir = resolve(cwd, value);
|
|
118
|
+
forwarded.push('--output-dir', CONTAINER_OUTPUT);
|
|
119
|
+
break;
|
|
120
|
+
case '--logo': {
|
|
121
|
+
const host = resolve(cwd, value);
|
|
122
|
+
const target = `${CONTAINER_BRAND_DIR}/${basename(host) || 'logo'}`;
|
|
123
|
+
mounts.push('-v', `${host}:${target}:ro`);
|
|
124
|
+
require.push({ path: host, kind: 'file', source: '--logo' });
|
|
125
|
+
forwarded.push('--logo', target);
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
case '--license': {
|
|
129
|
+
const host = resolve(cwd, value);
|
|
130
|
+
mounts.push('-v', `${host}:${CONTAINER_LICENSE}:ro`);
|
|
131
|
+
require.push({ path: host, kind: 'file', source: '--license' });
|
|
132
|
+
forwarded.push('--license', CONTAINER_LICENSE);
|
|
133
|
+
licensed = true;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
default:
|
|
137
|
+
if (takesValue) {
|
|
138
|
+
forwarded.push(name, value);
|
|
139
|
+
} else if (i > 0 && buildDir === null && arg[0] !== '-' && command !== 'license') {
|
|
140
|
+
buildDir = resolve(cwd, arg);
|
|
141
|
+
forwarded.push(CONTAINER_INPUT);
|
|
142
|
+
} else {
|
|
143
|
+
forwarded.push(arg);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (command !== 'license') {
|
|
149
|
+
if (buildDir === null) {
|
|
150
|
+
throw new UsageError(`${command} needs a Site Build directory`);
|
|
151
|
+
}
|
|
152
|
+
mounts.push('-v', `${buildDir}:${CONTAINER_INPUT}:ro`);
|
|
153
|
+
require.push({ path: buildDir, kind: 'directory', source: 'the Site Build' });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const create = [];
|
|
157
|
+
if (command === 'export') {
|
|
158
|
+
if (outputDir === null) {
|
|
159
|
+
// The engine defaults to manuscrio-output beside the Site Build. Resolve that here instead,
|
|
160
|
+
// because inside the container "beside the Site Build" is /manuscrio-output, which nothing
|
|
161
|
+
// is mounted on and which the caller would never see.
|
|
162
|
+
outputDir = resolve(buildDir, '..', 'manuscrio-output');
|
|
163
|
+
forwarded.push('--output-dir', CONTAINER_OUTPUT);
|
|
164
|
+
}
|
|
165
|
+
const inside = relative(buildDir, outputDir);
|
|
166
|
+
if (inside === '' || (!inside.startsWith('..') && !isAbsolute(inside))) {
|
|
167
|
+
// Docker would allow it -- the Site Build is mounted read-only, the output writable over
|
|
168
|
+
// part of it -- and the PDFs would land inside the tree the next site build wipes. The
|
|
169
|
+
// engine's own default sits beside the Site Build for the same reason.
|
|
170
|
+
throw new UsageError(`--output-dir is inside the Site Build, where the next build will erase it: ${outputDir}`);
|
|
171
|
+
}
|
|
172
|
+
mounts.push('-v', `${outputDir}:${CONTAINER_OUTPUT}`);
|
|
173
|
+
create.push(outputDir);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (env.MANUSCRIO_PDF_LICENSE) {
|
|
177
|
+
// By name: the value is the licence text, and a licence is a bearer token. Passing
|
|
178
|
+
// `-e NAME=<text>` would put it in `ps` output on a shared CI runner.
|
|
179
|
+
envArgs.push('-e', 'MANUSCRIO_PDF_LICENSE');
|
|
180
|
+
}
|
|
181
|
+
if (env.MANUSCRIO_PDF_LICENSE_FILE && !licensed) {
|
|
182
|
+
// A host path in an environment variable needs the same mount and rewrite as --license.
|
|
183
|
+
// Skipped when --license was given, which outranks it in the engine either way.
|
|
184
|
+
const host = resolve(cwd, env.MANUSCRIO_PDF_LICENSE_FILE);
|
|
185
|
+
mounts.push('-v', `${host}:${CONTAINER_LICENSE}:ro`);
|
|
186
|
+
require.push({ path: host, kind: 'file', source: '$MANUSCRIO_PDF_LICENSE_FILE' });
|
|
187
|
+
envArgs.push('-e', `MANUSCRIO_PDF_LICENSE_FILE=${CONTAINER_LICENSE}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return { runtime, args: [...run, ...envArgs, ...mounts, image, ...forwarded], create, require };
|
|
191
|
+
}
|