@tryghost/app-sdk 0.1.0-alpha.7 → 0.1.0-alpha.8
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 +37 -11
- package/build/bin.d.ts +1 -0
- package/build/bin.js +139 -0
- package/build/bin.js.map +1 -0
- package/build/chunks/sign-BhNJAPta.js +1130 -0
- package/build/chunks/sign-BhNJAPta.js.map +1 -0
- package/build/index.js +1 -1
- package/build/tooling.js +2 -1129
- package/dist/app-sdk.js +1 -1
- package/package.json +6 -2
- package/build/tooling.js.map +0 -1
package/README.md
CHANGED
|
@@ -11,7 +11,8 @@ its route in sync with Admin's URL, and send the publisher elsewhere in Admin.
|
|
|
11
11
|
| --------------------------- | -------------------------- | ----------------------------------------------------------------------------- |
|
|
12
12
|
| `@tryghost/app-sdk` | The app's page | Talking to Admin (below) |
|
|
13
13
|
| `@tryghost/app-sdk/backend` | Any platform with web APIs | [Answering Ghost's challenge and serving the manifest](#the-backend) |
|
|
14
|
-
| `@tryghost/app-sdk/tooling` | Node 22.
|
|
14
|
+
| `@tryghost/app-sdk/tooling` | Node 22.12 or later | [Creating keys, and signing and checking the manifest](#signing-the-manifest) |
|
|
15
|
+
| `ghost-app` | Node 22.12 or later | [The same tooling on the command line](#the-ghost-app-cli) |
|
|
15
16
|
|
|
16
17
|
The page's entry point loads none of the others' code.
|
|
17
18
|
|
|
@@ -297,10 +298,9 @@ Each mode has its own identity key and backend key, as two pairs of private
|
|
|
297
298
|
Ed25519 JWKs, in files only their owner can read:
|
|
298
299
|
|
|
299
300
|
- `.ghost-app/development/identity.json` and `backend.json`, for apps on this
|
|
300
|
-
machine, such as on `my-app.localhost
|
|
301
|
-
- `.ghost-app/production/identity.json` and `backend.json
|
|
302
|
-
|
|
303
|
-
`createKeys({ root, mode })` creates them.
|
|
301
|
+
machine, such as on `my-app.localhost`, which `ghost-app keys` creates;
|
|
302
|
+
- `.ghost-app/production/identity.json` and `backend.json`, which only
|
|
303
|
+
`ghost-app keys --production` creates.
|
|
304
304
|
|
|
305
305
|
Only the owner can read a key on macOS and Linux. On Windows, a key gets the
|
|
306
306
|
permissions of the folder it's in, so keep the project in a folder only you can
|
|
@@ -320,13 +320,38 @@ development identity key must share its backend key too: a new backend key
|
|
|
320
320
|
retires the old one on every site that reads the new manifest.
|
|
321
321
|
|
|
322
322
|
In CI, set `GHOST_APP_IDENTITY_KEY` to the production identity key and
|
|
323
|
-
`GHOST_APP_BACKEND_KEY` to the backend key's public half,
|
|
324
|
-
|
|
325
|
-
the backend's private key.
|
|
323
|
+
`GHOST_APP_BACKEND_KEY` to the backend key's public half, which
|
|
324
|
+
`ghost-app backend-key --production --public` prints, in place of the files. CI
|
|
325
|
+
only signs, so it never needs the backend's private key.
|
|
326
|
+
|
|
327
|
+
### The ghost-app CLI
|
|
328
|
+
|
|
329
|
+
```sh
|
|
330
|
+
ghost-app keys [--production]
|
|
331
|
+
ghost-app sign --url <manifest URL> [--production] [--out <file>] [--manifest <file>]
|
|
332
|
+
ghost-app check <manifest URL>
|
|
333
|
+
ghost-app backend-key [--production] [--public | --check]
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
- `keys` creates the mode's keys, keeping any that exist.
|
|
337
|
+
- `sign` prints the signed manifest, or writes it to `--out`.
|
|
338
|
+
- `check` checks an app as Ghost does before installing it, with `checkApp`
|
|
339
|
+
(below), and prints Ghost's own code and what exactly was wrong.
|
|
340
|
+
- `backend-key` prints the mode's private backend key, for a host's secret
|
|
341
|
+
store. It's the only command that prints a private key. `--public` prints
|
|
342
|
+
only its public half, for CI. `--check` prints nothing, and exits with 0
|
|
343
|
+
only if the key is there and usable, with the reason on stderr otherwise,
|
|
344
|
+
so a script can stop before piping nothing into a secret store, in any shell:
|
|
345
|
+
|
|
346
|
+
```sh
|
|
347
|
+
ghost-app backend-key --production --check && ghost-app backend-key --production | wrangler secret put GHOST_APP_BACKEND_KEY
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
`--dir` points any of them at another project directory.
|
|
326
351
|
|
|
327
352
|
### From code
|
|
328
353
|
|
|
329
|
-
`@tryghost/app-sdk/tooling`
|
|
354
|
+
`@tryghost/app-sdk/tooling` is what the CLI is built on, to sign and check from code:
|
|
330
355
|
|
|
331
356
|
| Export | What it does |
|
|
332
357
|
| -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -420,7 +445,7 @@ This is a workspace package in the Ghost monorepo. From the package directory:
|
|
|
420
445
|
```bash
|
|
421
446
|
pnpm build # the package to build/ and the browser bundle to dist/, with Vite
|
|
422
447
|
pnpm test # type-check + unit tests (jsdom for the page, with a fake Admin on a real
|
|
423
|
-
# MessageChannel; Node for the backend and
|
|
448
|
+
# MessageChannel; Node for the backend, tooling and CLI), which build both
|
|
424
449
|
# afresh to check what they import, and pack build/ and dist/ to use them from an
|
|
425
450
|
# app outside the workspace (after pnpm build; Nx runs it)
|
|
426
451
|
pnpm lint # lint source and tests
|
|
@@ -440,7 +465,8 @@ per entry point, which share chunks:
|
|
|
440
465
|
- `index.js` loads only `@quilted/threads`, never `jose`, `zod` or a Node
|
|
441
466
|
builtin;
|
|
442
467
|
- `backend.js` loads only `jose` and `zod`, and no Node builtin;
|
|
443
|
-
- `tooling.js` loads Node builtins, `jose` and `zod
|
|
468
|
+
- `tooling.js` loads Node builtins, `jose` and `zod`, and `bin.js` those and
|
|
469
|
+
`commander`;
|
|
444
470
|
- each entry point's declarations, emitted by TypeScript 7 and bundled by
|
|
445
471
|
`rolldown-plugin-dts`, import nothing;
|
|
446
472
|
- `dist/` imports nothing at all.
|
package/build/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/build/bin.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { a as signProject, c as KEYS_DIRECTORY, f as keyFile, g as checkApp, l as KEY_NAMES, m as readBackendKey, p as publicKeyOf, r as serialiseSigned, u as createKeys } from "./chunks/sign-BhNJAPta.js";
|
|
3
|
+
import { r as formatErrors } from "./chunks/manifest-DX1GTozy.js";
|
|
4
|
+
import { lstatSync, readlinkSync, realpathSync } from "node:fs";
|
|
5
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
6
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
7
|
+
import { Command, CommanderError } from "commander";
|
|
8
|
+
//#region src/tooling/paths.ts
|
|
9
|
+
/** Whether `child` is `parent` or anything inside it. Both are absolute. */
|
|
10
|
+
function isWithin(parent, child) {
|
|
11
|
+
const path = relative(parent, child);
|
|
12
|
+
return path === "" || path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path);
|
|
13
|
+
}
|
|
14
|
+
var realpath = (path) => {
|
|
15
|
+
try {
|
|
16
|
+
return realpathSync.native(path);
|
|
17
|
+
} catch {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var MAX_LINKS = 40;
|
|
22
|
+
/**
|
|
23
|
+
* Where writing to `path` really lands: through every link, as far as the path exists, and
|
|
24
|
+
* along a chain of dangling links to where its last one points, as writing follows them all. A
|
|
25
|
+
* path that doesn't exist yet lands in its directory, wherever that really is.
|
|
26
|
+
*/
|
|
27
|
+
function canonicalPath(path, links = 0) {
|
|
28
|
+
const existing = realpath(path);
|
|
29
|
+
if (existing) return existing;
|
|
30
|
+
if (links < MAX_LINKS && lstatSync(path, { throwIfNoEntry: false })?.isSymbolicLink()) return canonicalPath(resolve(dirname(path), readlinkSync(path)), links + 1);
|
|
31
|
+
const parent = dirname(path);
|
|
32
|
+
return join(parent === path ? parent : canonicalPath(parent, links), basename(path));
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/cli.ts
|
|
36
|
+
var modeOf = (production) => production ? "production" : "development";
|
|
37
|
+
async function keys(root, mode, io) {
|
|
38
|
+
const { created, kept } = await createKeys({
|
|
39
|
+
root,
|
|
40
|
+
mode
|
|
41
|
+
});
|
|
42
|
+
for (const name of created) io.err(`Created ${keyFile(mode, name)}`);
|
|
43
|
+
for (const name of kept) io.err(`Kept ${keyFile(mode, name)}, which already exists`);
|
|
44
|
+
if (mode === "production" && created.includes("identity")) io.err("\nKeep a copy of the production identity key somewhere safe, such as a password manager. Sites that install the app keep its identity key, and an app signed with another key is another app.");
|
|
45
|
+
}
|
|
46
|
+
var MODES = ["development", "production"];
|
|
47
|
+
/** Throws if writing to `written` would overwrite the manifest it's signed from, or a key. */
|
|
48
|
+
function refuseToOverwrite(root, written, manifestFile) {
|
|
49
|
+
const lands = canonicalPath(written);
|
|
50
|
+
if (lands === canonicalPath(resolve(root, manifestFile))) throw new Error(`Refusing to write the signed manifest over ${manifestFile}, which it's signed from`);
|
|
51
|
+
const keysDirectory = join(root, KEYS_DIRECTORY);
|
|
52
|
+
const keyFiles = MODES.flatMap((mode) => KEY_NAMES.map((name) => canonicalPath(join(root, keyFile(mode, name)))));
|
|
53
|
+
if (isWithin(keysDirectory, written) || isWithin(canonicalPath(keysDirectory), lands) || keyFiles.includes(lands)) throw new Error(`Refusing to write the signed manifest into ${KEYS_DIRECTORY}/, which holds the keys`);
|
|
54
|
+
}
|
|
55
|
+
async function sign(root, { url, production, out, manifest }, io) {
|
|
56
|
+
const manifestFile = manifest ?? "ghost-app.json";
|
|
57
|
+
const written = out === void 0 ? void 0 : resolve(root, out);
|
|
58
|
+
if (written) refuseToOverwrite(root, written, manifestFile);
|
|
59
|
+
const result = await signProject({
|
|
60
|
+
root,
|
|
61
|
+
mode: modeOf(production),
|
|
62
|
+
manifestUrl: url,
|
|
63
|
+
manifestFile
|
|
64
|
+
});
|
|
65
|
+
if (!result.success) {
|
|
66
|
+
io.err(`${result.code}: ${manifestFile} can't be signed:\n${formatErrors(result.errors)}`);
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
const text = serialiseSigned(result.signed);
|
|
70
|
+
if (written) {
|
|
71
|
+
await mkdir(dirname(written), { recursive: true });
|
|
72
|
+
await writeFile(written, text);
|
|
73
|
+
io.err(`Wrote ${written}, signed for ${String(result.manifest.manifest_url)}`);
|
|
74
|
+
} else io.out(text);
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
async function check(url, io) {
|
|
78
|
+
const result = await checkApp(url);
|
|
79
|
+
if (!result.success) {
|
|
80
|
+
io.err(`${result.code}: ${result.message}`);
|
|
81
|
+
io.err(result.errors ? formatErrors(result.errors) : result.detail);
|
|
82
|
+
return 1;
|
|
83
|
+
}
|
|
84
|
+
const { manifest } = result;
|
|
85
|
+
io.out(`OK: ${manifest.name} (${manifest.id}) at ${result.manifestUrl} is signed with the identity key it names, and its origin answered the challenge with its backend key.`);
|
|
86
|
+
if (manifest.development) io.out("It is a development build, which Admin labels as one.");
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
async function backendKey(root, { production, public: publicHalf, check: checkOnly }, io) {
|
|
90
|
+
const key = await readBackendKey({
|
|
91
|
+
root,
|
|
92
|
+
mode: modeOf(production)
|
|
93
|
+
});
|
|
94
|
+
if (!checkOnly) io.out(JSON.stringify(publicHalf ? publicKeyOf(key) : key));
|
|
95
|
+
}
|
|
96
|
+
/** Runs the CLI with its arguments (without `node` and the script), resolving with the exit code. */
|
|
97
|
+
async function run(args, io) {
|
|
98
|
+
let exitCode = 0;
|
|
99
|
+
const program = new Command("ghost-app").description("Creates an app's keys, signs its manifest, and checks it as Ghost does.").option("--dir <directory>", "the project's directory", ".").showHelpAfterError().exitOverride().configureOutput({
|
|
100
|
+
writeOut: io.out,
|
|
101
|
+
writeErr: io.err
|
|
102
|
+
});
|
|
103
|
+
const root = () => resolve(program.opts().dir);
|
|
104
|
+
program.command("keys").description("Creates the mode's identity and backend keys in .ghost-app/, keeping any that exist").option("--production", "the production keys instead of the development ones").action(async ({ production }) => {
|
|
105
|
+
await keys(root(), modeOf(production), io);
|
|
106
|
+
});
|
|
107
|
+
program.command("sign").description("Signs ghost-app.json for the address it will be served from").requiredOption("--url <manifest URL>", "the address the signed manifest will be served from").option("--production", "with the production keys instead of the development ones").option("--out <file>", "write it to a file in the project's directory instead of printing it").option("--manifest <file>", "sign another file than ghost-app.json").action(async (options) => {
|
|
108
|
+
exitCode = await sign(root(), options, io);
|
|
109
|
+
});
|
|
110
|
+
program.command("check").description("Checks an app as Ghost does before installing it").argument("<manifest URL>", "the address of its signed manifest").action(async (url) => {
|
|
111
|
+
exitCode = await check(url, io);
|
|
112
|
+
});
|
|
113
|
+
program.command("backend-key").description("Prints the mode's private backend key, to pipe into a secret store: ghost-app backend-key --production --check && ghost-app backend-key --production | wrangler secret put GHOST_APP_BACKEND_KEY").option("--production", "the production key instead of the development one").option("--public", "print only its public half, which is all CI needs to sign").option("--check", "print nothing, and exit 0 only if the key is there and usable").action(async (options) => {
|
|
114
|
+
await backendKey(root(), options, io);
|
|
115
|
+
});
|
|
116
|
+
try {
|
|
117
|
+
await program.parseAsync(args, { from: "user" });
|
|
118
|
+
return exitCode;
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (error instanceof CommanderError) return error.exitCode === 0 ? 0 : 2;
|
|
121
|
+
io.err(error instanceof Error ? error.message : String(error));
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/bin.ts
|
|
127
|
+
var line = (text) => text.endsWith("\n") ? text : `${text}\n`;
|
|
128
|
+
run(process.argv.slice(2), {
|
|
129
|
+
out: (text) => process.stdout.write(line(text)),
|
|
130
|
+
err: (text) => process.stderr.write(line(text))
|
|
131
|
+
}).then((code) => {
|
|
132
|
+
process.exitCode = code;
|
|
133
|
+
}, (error) => {
|
|
134
|
+
process.stderr.write(line(error instanceof Error ? error.message : String(error)));
|
|
135
|
+
process.exitCode = 1;
|
|
136
|
+
});
|
|
137
|
+
//#endregion
|
|
138
|
+
|
|
139
|
+
//# sourceMappingURL=bin.js.map
|
package/build/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","names":[],"sources":["../src/tooling/paths.ts","../src/cli.ts","../src/bin.ts"],"sourcesContent":["import { lstatSync, readlinkSync, realpathSync } from 'node:fs';\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';\n\n/** Whether `child` is `parent` or anything inside it. Both are absolute. */\nexport function isWithin(parent: string, child: string): boolean {\n const path = relative(parent, child);\n // Only `..` as a whole segment climbs out: `..signed.json` is a file inside.\n return path === '' || (path !== '..' && !path.startsWith(`..${sep}`) && !isAbsolute(path));\n}\n\nconst realpath = (path: string) => {\n try {\n // The native one gives the case the path has on disk, where the filesystem ignores case.\n return realpathSync.native(path);\n } catch {\n return undefined;\n }\n};\n\n// As many links as Linux follows before it gives up with ELOOP.\nconst MAX_LINKS = 40;\n\n/**\n * Where writing to `path` really lands: through every link, as far as the path exists, and\n * along a chain of dangling links to where its last one points, as writing follows them all. A\n * path that doesn't exist yet lands in its directory, wherever that really is.\n */\nexport function canonicalPath(path: string, links = 0): string {\n const existing = realpath(path);\n if (existing) {\n return existing;\n }\n if (links < MAX_LINKS && lstatSync(path, { throwIfNoEntry: false })?.isSymbolicLink()) {\n return canonicalPath(resolve(dirname(path), readlinkSync(path)), links + 1);\n }\n const parent = dirname(path);\n return join(parent === path ? parent : canonicalPath(parent, links), basename(path));\n}\n","import { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, join, resolve } from 'node:path';\n\nimport { Command, CommanderError } from 'commander';\n\nimport { checkApp } from './tooling/check.ts';\nimport {\n KEYS_DIRECTORY,\n KEY_NAMES,\n createKeys,\n keyFile,\n publicKeyOf,\n readBackendKey,\n type Mode,\n} from './tooling/keys.ts';\nimport { canonicalPath, isWithin } from './tooling/paths.ts';\nimport { formatErrors } from './shared/manifest.ts';\nimport { MANIFEST_FILE, serialiseSigned, signProject } from './tooling/sign.ts';\n\nexport interface Io {\n out: (text: string) => void;\n err: (text: string) => void;\n}\n\nconst modeOf = (production: boolean | undefined): Mode =>\n production ? 'production' : 'development';\n\nasync function keys(root: string, mode: Mode, io: Io) {\n const { created, kept } = await createKeys({ root, mode });\n for (const name of created) {\n io.err(`Created ${keyFile(mode, name)}`);\n }\n for (const name of kept) {\n io.err(`Kept ${keyFile(mode, name)}, which already exists`);\n }\n if (mode === 'production' && created.includes('identity')) {\n io.err(\n '\\nKeep a copy of the production identity key somewhere safe, such as a password manager. ' +\n 'Sites that install the app keep its identity key, and an app signed with another key is another app.',\n );\n }\n}\n\nconst MODES: readonly Mode[] = ['development', 'production'];\n\n/** Throws if writing to `written` would overwrite the manifest it's signed from, or a key. */\nfunction refuseToOverwrite(root: string, written: string, manifestFile: string) {\n // Where the write would really land, through every link.\n const lands = canonicalPath(written);\n if (lands === canonicalPath(resolve(root, manifestFile))) {\n throw new Error(\n `Refusing to write the signed manifest over ${manifestFile}, which it's signed from`,\n );\n }\n // Refused by the path as written, by where it really lands, and by where each key really is,\n // so neither a link out of .ghost-app/ nor a key that is itself a link lets it reach a key.\n const keysDirectory = join(root, KEYS_DIRECTORY);\n const keyFiles = MODES.flatMap((mode) =>\n KEY_NAMES.map((name) => canonicalPath(join(root, keyFile(mode, name)))),\n );\n if (\n isWithin(keysDirectory, written) ||\n isWithin(canonicalPath(keysDirectory), lands) ||\n keyFiles.includes(lands)\n ) {\n throw new Error(\n `Refusing to write the signed manifest into ${KEYS_DIRECTORY}/, which holds the keys`,\n );\n }\n}\n\nasync function sign(\n root: string,\n {\n url,\n production,\n out,\n manifest,\n }: { url: string; production?: boolean; out?: string; manifest?: string },\n io: Io,\n) {\n const manifestFile = manifest ?? MANIFEST_FILE;\n // Against the project's directory, like --manifest and the keys.\n const written = out === undefined ? undefined : resolve(root, out);\n if (written) {\n refuseToOverwrite(root, written, manifestFile);\n }\n const result = await signProject({\n root,\n mode: modeOf(production),\n manifestUrl: url,\n manifestFile,\n });\n if (!result.success) {\n io.err(`${result.code}: ${manifestFile} can't be signed:\\n${formatErrors(result.errors)}`);\n return 1;\n }\n const text = serialiseSigned(result.signed);\n if (written) {\n await mkdir(dirname(written), { recursive: true });\n await writeFile(written, text);\n io.err(`Wrote ${written}, signed for ${String(result.manifest.manifest_url)}`);\n } else {\n io.out(text);\n }\n return 0;\n}\n\nasync function check(url: string, io: Io) {\n const result = await checkApp(url);\n if (!result.success) {\n io.err(`${result.code}: ${result.message}`);\n io.err(result.errors ? formatErrors(result.errors) : result.detail);\n return 1;\n }\n const { manifest } = result;\n io.out(\n `OK: ${manifest.name} (${manifest.id}) at ${result.manifestUrl} is signed with the identity key it names, and its origin answered the challenge with its backend key.`,\n );\n if (manifest.development) {\n io.out('It is a development build, which Admin labels as one.');\n }\n return 0;\n}\n\nasync function backendKey(\n root: string,\n {\n production,\n public: publicHalf,\n check: checkOnly,\n }: { production?: boolean; public?: boolean; check?: boolean },\n io: Io,\n) {\n // Reading the key checks it, and fails with what's wrong, never with the key.\n const key = await readBackendKey({ root, mode: modeOf(production) });\n if (!checkOnly) {\n io.out(JSON.stringify(publicHalf ? publicKeyOf(key) : key));\n }\n}\n\n/** Runs the CLI with its arguments (without `node` and the script), resolving with the exit code. */\nexport async function run(args: string[], io: Io): Promise<number> {\n let exitCode = 0;\n const program = new Command('ghost-app')\n .description(\"Creates an app's keys, signs its manifest, and checks it as Ghost does.\")\n .option('--dir <directory>', \"the project's directory\", '.')\n .showHelpAfterError()\n // Thrown rather than exiting, so `run` resolves with the code, and prints through `io`.\n .exitOverride()\n .configureOutput({ writeOut: io.out, writeErr: io.err });\n const root = () => resolve(program.opts<{ dir: string }>().dir);\n\n program\n .command('keys')\n .description(\n \"Creates the mode's identity and backend keys in .ghost-app/, keeping any that exist\",\n )\n .option('--production', 'the production keys instead of the development ones')\n .action(async ({ production }: { production?: boolean }) => {\n await keys(root(), modeOf(production), io);\n });\n\n program\n .command('sign')\n .description('Signs ghost-app.json for the address it will be served from')\n .requiredOption('--url <manifest URL>', 'the address the signed manifest will be served from')\n .option('--production', 'with the production keys instead of the development ones')\n .option('--out <file>', \"write it to a file in the project's directory instead of printing it\")\n .option('--manifest <file>', 'sign another file than ghost-app.json')\n .action(async (options: Parameters<typeof sign>[1]) => {\n exitCode = await sign(root(), options, io);\n });\n\n program\n .command('check')\n .description('Checks an app as Ghost does before installing it')\n .argument('<manifest URL>', 'the address of its signed manifest')\n .action(async (url: string) => {\n exitCode = await check(url, io);\n });\n\n program\n .command('backend-key')\n .description(\n \"Prints the mode's private backend key, to pipe into a secret store: ghost-app backend-key --production --check && ghost-app backend-key --production | wrangler secret put GHOST_APP_BACKEND_KEY\",\n )\n .option('--production', 'the production key instead of the development one')\n .option('--public', 'print only its public half, which is all CI needs to sign')\n .option('--check', 'print nothing, and exit 0 only if the key is there and usable')\n .action(async (options: Parameters<typeof backendKey>[1]) => {\n await backendKey(root(), options, io);\n });\n\n try {\n await program.parseAsync(args, { from: 'user' });\n return exitCode;\n } catch (error) {\n // Commander has already printed help, or the mistake and the help: 0 for asking for help,\n // and 2 for a mistake in how the CLI was called.\n if (error instanceof CommanderError) {\n return error.exitCode === 0 ? 0 : 2;\n }\n io.err(error instanceof Error ? error.message : String(error));\n return 1;\n }\n}\n","#!/usr/bin/env node\nimport { run } from './cli.ts';\n\nconst line = (text: string) => (text.endsWith('\\n') ? text : `${text}\\n`);\n\nrun(process.argv.slice(2), {\n out: (text) => process.stdout.write(line(text)),\n err: (text) => process.stderr.write(line(text)),\n}).then(\n (code) => {\n process.exitCode = code;\n },\n // run reports its own failures, so this is a bug: say what, without a stack trace.\n (error: unknown) => {\n process.stderr.write(line(error instanceof Error ? error.message : String(error)));\n process.exitCode = 1;\n },\n);\n"],"mappings":";;;;;;;;;AAIA,SAAgB,SAAS,QAAgB,OAAwB;CAC/D,MAAM,OAAO,SAAS,QAAQ,KAAK;CAEnC,OAAO,SAAS,MAAO,SAAS,QAAQ,CAAC,KAAK,WAAW,KAAK,KAAK,KAAK,CAAC,WAAW,IAAI;AAC1F;AAEA,IAAM,YAAY,SAAiB;CACjC,IAAI;EAEF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