mnfst-publish 0.1.18 → 0.1.19
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 +13 -1
- package/manifest.publish.mjs +103 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,9 @@ endpoint from `.mcp.json`, renders the site if it's a prerendered ("website")
|
|
|
13
13
|
project, zips it gitignore-aware, uploads it, and prints the live URL.
|
|
14
14
|
|
|
15
15
|
Flags: `--staging` / `--production` (default), `--no-render`, `--promote`,
|
|
16
|
-
`--source render|spa` (auto-detected), `--key <key>`, `--mcp <url
|
|
16
|
+
`--list`, `--source render|spa` (auto-detected), `--key <key>`, `--mcp <url>`,
|
|
17
|
+
`--version`, `--help`. An unknown option is refused with exit code 1 and
|
|
18
|
+
nothing is published.
|
|
17
19
|
|
|
18
20
|
## Release scripts
|
|
19
21
|
|
|
@@ -21,6 +23,8 @@ Review a build at its own address before it reaches production, then ship
|
|
|
21
23
|
exactly that build:
|
|
22
24
|
|
|
23
25
|
```bash
|
|
26
|
+
npx mnfst-publish --list --json
|
|
27
|
+
# {"ok":true,"env":"production","live_deployment_id":"dep_…","deployments":[{"deployment_id":"dep_…","status":"ready","is_live":true,"held":false,"label":null,"preview_url":null,"published_at":"…","source":"render"},…]}
|
|
24
28
|
npx mnfst-publish --no-live --label "v2.4.0" --json
|
|
25
29
|
# {"ok":true,"env":"staging","deployment_id":"dep_…","live":false,"preview_url":"https://preview--….manifestx.ai",…}
|
|
26
30
|
npx mnfst-publish --promote --deployment dep_… --expect-live dep_… --json
|
|
@@ -33,7 +37,15 @@ npx mnfst-publish --promote --deployment dep_… --expect-live dep_… --json
|
|
|
33
37
|
staging is unchanged. Without `--deployment`, promotes what staging serves.
|
|
34
38
|
- `--expect-live <id>`: with `--promote`, refuses unless production is serving
|
|
35
39
|
that deployment, checked in the same step as the switch.
|
|
40
|
+
- `--list`: recent deployments and which one is live (production, or staging
|
|
41
|
+
with `--staging`). Publishes nothing.
|
|
36
42
|
- `--json`: the result as one JSON object on stdout; progress goes to stderr.
|
|
43
|
+
A failure is `{"ok":false,"error":"<code>","message":"…"}` with exit code 1.
|
|
44
|
+
Promote refusals use the server's codes: `unknown_deployment`, `not_staging`,
|
|
45
|
+
`not_ready`, `live_moved`, `nothing_on_staging`, `promote_in_progress`,
|
|
46
|
+
`promote_failed`. The CLI adds `usage` (bad options), `no_api_key`,
|
|
47
|
+
`unsupported_server` (the server lacks a flag you passed; nothing changed)
|
|
48
|
+
and `promoted_other`. A server older than these codes reports `refused`.
|
|
37
49
|
|
|
38
50
|
Against a server that doesn't support these yet, mnfst-publish stops before
|
|
39
51
|
uploading or promoting anything.
|
package/manifest.publish.mjs
CHANGED
|
@@ -20,8 +20,13 @@ let jsonMode = false;
|
|
|
20
20
|
function log(msg) {
|
|
21
21
|
(jsonMode ? process.stderr : process.stdout).write(msg + '\n');
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
// Our codes are lowercase snake_case; Node's (ENOENT, ERR_…) are reported as "failed".
|
|
24
|
+
function publicCode(code) {
|
|
25
|
+
return typeof code === 'string' && /^[a-z][a-z_]*$/.test(code) ? code : 'failed';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function fail(msg, code) {
|
|
29
|
+
if (jsonMode) process.stdout.write(JSON.stringify({ ok: false, error: publicCode(code), message: msg }) + '\n');
|
|
25
30
|
console.error('mnfst-publish: ' + msg);
|
|
26
31
|
process.exit(1);
|
|
27
32
|
}
|
|
@@ -30,8 +35,24 @@ export const LABEL_MAX_LENGTH = 200;
|
|
|
30
35
|
// C0/C1 controls, DEL, line/paragraph separators, zero-width and bidi override/isolate characters.
|
|
31
36
|
const NON_PRINTABLE = new RegExp('[\\u0000-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2066-\\u2069\\ufeff]');
|
|
32
37
|
|
|
33
|
-
/**
|
|
38
|
+
/** An Error with a machine-readable code (the `error` field under --json). */
|
|
39
|
+
export function codedError(code, message) {
|
|
40
|
+
const err = new Error(message);
|
|
41
|
+
err.code = code;
|
|
42
|
+
return err;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Parse argv; throws an Error with a user-facing message on an unknown option or a bad combination. */
|
|
34
46
|
export function parseArgs(argv) {
|
|
47
|
+
try {
|
|
48
|
+
return parseArgsInner(argv);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (!e.code) e.code = 'usage';
|
|
51
|
+
throw e;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function parseArgsInner(argv) {
|
|
35
56
|
const out = { env: 'production', render: undefined, promote: false };
|
|
36
57
|
let envGiven = false;
|
|
37
58
|
const value = (flag, i) => {
|
|
@@ -57,10 +78,19 @@ export function parseArgs(argv) {
|
|
|
57
78
|
else if (a === '--key') out.key = value(a, ++i);
|
|
58
79
|
else if (a === '--mcp') out.mcp = value(a, ++i);
|
|
59
80
|
else if (a === '--root') out.root = value(a, ++i);
|
|
81
|
+
else if (a === '--list') out.list = true;
|
|
60
82
|
else if (a === '-h' || a === '--help') out.help = true;
|
|
83
|
+
else if (a === '-v' || a === '--version') out.version = true;
|
|
84
|
+
// An unknown option must never fall through to a publish, which defaults to production.
|
|
85
|
+
else throw new Error(`unknown option "${a}", so nothing was published. Run \`npx mnfst-publish --help\` for the options.`);
|
|
61
86
|
}
|
|
87
|
+
if (out.help || out.version) return out;
|
|
62
88
|
if (out.env !== 'staging' && out.env !== 'production') throw new Error(`--env must be "staging" or "production" (got "${out.env}")`);
|
|
63
|
-
if (out.
|
|
89
|
+
if (out.list) {
|
|
90
|
+
for (const [given, flag] of [[out.promote, '--promote'], [out.live === false, '--no-live'], [out.label !== undefined, '--label'], [out.deployment !== undefined, '--deployment'], [out.expectLive !== undefined, '--expect-live'], [out.source !== undefined, '--source'], [out.outputDir !== undefined, '--output-dir'], [out.render !== undefined, '--render/--no-render']]) {
|
|
91
|
+
if (given) throw new Error(`${flag} does not apply to --list`);
|
|
92
|
+
}
|
|
93
|
+
} else if (out.promote) {
|
|
64
94
|
if (out.live === false) throw new Error('--no-live applies to a publish, not to --promote');
|
|
65
95
|
if (out.label !== undefined) throw new Error('--label is set when publishing; --promote carries the label of the deployment it promotes');
|
|
66
96
|
} else {
|
|
@@ -230,7 +260,10 @@ async function callTool(url, key, name, args) {
|
|
|
230
260
|
if (!result) throw new Error(`unexpected response from ${name} (HTTP ${res.status})`);
|
|
231
261
|
const textPart = (result.content || []).find((c) => c.type === 'text');
|
|
232
262
|
const payloadText = textPart ? textPart.text : '';
|
|
233
|
-
if (result.isError)
|
|
263
|
+
if (result.isError) {
|
|
264
|
+
const sc = result.structuredContent;
|
|
265
|
+
throw codedError(sc && typeof sc.error === 'string' ? sc.error : 'refused', payloadText || `${name} failed`);
|
|
266
|
+
}
|
|
234
267
|
try {
|
|
235
268
|
return JSON.parse(payloadText);
|
|
236
269
|
} catch {
|
|
@@ -848,7 +881,7 @@ export function isJsonMode() {
|
|
|
848
881
|
/** The --json failure object for an error. */
|
|
849
882
|
export function jsonFailure(err) {
|
|
850
883
|
const message = err && err.message ? err.message : String(err);
|
|
851
|
-
return { ok: false, error: (err && err.code)
|
|
884
|
+
return { ok: false, error: publicCode(err && err.code), message };
|
|
852
885
|
}
|
|
853
886
|
|
|
854
887
|
/** manifest_promote arguments for these options. */
|
|
@@ -882,12 +915,12 @@ export async function runPromote(opts, { url, key, callToolImpl = callTool, tool
|
|
|
882
915
|
if (Object.keys(args).length) {
|
|
883
916
|
const missing = unsupportedPromoteArgs(args, await toolParamsImpl(url, key, 'manifest_promote'));
|
|
884
917
|
if (missing.length) {
|
|
885
|
-
throw
|
|
918
|
+
throw codedError('unsupported_server', `this Manifest server does not support ${missing.map((k) => (k === 'deployment_id' ? '--deployment' : '--expect-live')).join(' or ')} yet, so nothing was promoted.`);
|
|
886
919
|
}
|
|
887
920
|
}
|
|
888
921
|
const res = await callToolImpl(url, key, 'manifest_promote', args);
|
|
889
922
|
if (opts.deployment && res.from_deployment_id && res.from_deployment_id !== opts.deployment) {
|
|
890
|
-
throw
|
|
923
|
+
throw codedError('promoted_other', `the server promoted ${res.from_deployment_id}, not ${opts.deployment}. Check production now.`);
|
|
891
924
|
}
|
|
892
925
|
return res;
|
|
893
926
|
}
|
|
@@ -895,10 +928,10 @@ export async function runPromote(opts, { url, key, callToolImpl = callTool, tool
|
|
|
895
928
|
/** The handshake must confirm a held publish and the label before anything is uploaded; an older server drops both. */
|
|
896
929
|
export function checkHeldHandshake(opts, handshake) {
|
|
897
930
|
if (opts.live === false && handshake.live !== false) {
|
|
898
|
-
throw
|
|
931
|
+
throw codedError('unsupported_server', 'this Manifest server does not support --no-live yet, so nothing was uploaded.');
|
|
899
932
|
}
|
|
900
933
|
if (opts.label && handshake.label !== opts.label) {
|
|
901
|
-
throw
|
|
934
|
+
throw codedError('unsupported_server', 'this Manifest server does not support --label yet, so nothing was uploaded.');
|
|
902
935
|
}
|
|
903
936
|
}
|
|
904
937
|
|
|
@@ -915,7 +948,7 @@ export async function checkHeldLink(uploadUrl, { fetchImpl = fetch } = {}) {
|
|
|
915
948
|
/* unreadable: treated as unconfirmed */
|
|
916
949
|
}
|
|
917
950
|
if (!json || json.live !== false) {
|
|
918
|
-
throw
|
|
951
|
+
throw codedError('link_not_held', '--no-live was given, but this upload link was not minted as a held publish, so nothing was uploaded. Call manifest_publish with live=false for a new link.');
|
|
919
952
|
}
|
|
920
953
|
}
|
|
921
954
|
|
|
@@ -945,17 +978,47 @@ export function publishSummary(opts, up) {
|
|
|
945
978
|
return { lines, json };
|
|
946
979
|
}
|
|
947
980
|
|
|
981
|
+
/** The --json object and human lines for a deployment listing. */
|
|
982
|
+
export function listSummary(res) {
|
|
983
|
+
const deployments = (res.deployments || []).map((d) => ({
|
|
984
|
+
deployment_id: d.deployment_id,
|
|
985
|
+
status: d.status,
|
|
986
|
+
is_live: !!d.is_live,
|
|
987
|
+
held: !!d.held,
|
|
988
|
+
label: d.label ?? null,
|
|
989
|
+
preview_url: d.preview_url ?? null,
|
|
990
|
+
published_at: d.published_at ?? null,
|
|
991
|
+
source: d.source ?? null,
|
|
992
|
+
}));
|
|
993
|
+
const json = { ok: true, env: res.env, live_deployment_id: res.live_deployment_id ?? null, deployments };
|
|
994
|
+
const lines = [`${res.env}: ${json.live_deployment_id ? `live ${json.live_deployment_id}` : 'nothing live'}`];
|
|
995
|
+
for (const d of deployments) {
|
|
996
|
+
const tags = [d.is_live ? 'live' : null, d.held ? 'held' : null, d.status].filter(Boolean).join(', ');
|
|
997
|
+
lines.push(` ${d.deployment_id} ${d.published_at || ''} [${tags}]${d.label ? ` ${d.label}` : ''}`);
|
|
998
|
+
}
|
|
999
|
+
return { lines, json };
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
/** This package's version. */
|
|
1003
|
+
export function packageVersion() {
|
|
1004
|
+
return JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
948
1007
|
const USAGE = [
|
|
949
1008
|
'Usage: npx mnfst-publish [--staging|--production] [--source spa|render] [--output-dir <dir>] [--no-render]',
|
|
950
1009
|
' [--no-live] [--label <text>] [--json]',
|
|
951
1010
|
' npx mnfst-publish --promote [--deployment <id>] [--expect-live <id>] [--json]',
|
|
1011
|
+
' npx mnfst-publish --list [--staging|--production] [--json]',
|
|
952
1012
|
'Publishes the current Manifest project to managed hosting and prints the live URL.',
|
|
953
1013
|
' --no-live staging only: store the build without changing what staging serves; prints its preview URL',
|
|
954
1014
|
' --label <text> name the deployment (up to 200 characters)',
|
|
955
1015
|
' --promote promote what staging serves to production',
|
|
956
1016
|
' --deployment <id> with --promote: promote exactly this staging deployment',
|
|
957
1017
|
' --expect-live <id> with --promote: refuse unless production is serving this deployment now',
|
|
1018
|
+
' --list list recent deployments and which is live (production unless --staging); publishes nothing',
|
|
958
1019
|
' --json print the result as one JSON object on stdout (progress goes to stderr)',
|
|
1020
|
+
' --version print the version; publishes nothing',
|
|
1021
|
+
'Unknown options are refused, so nothing is published.',
|
|
959
1022
|
];
|
|
960
1023
|
|
|
961
1024
|
export async function main() {
|
|
@@ -966,10 +1029,16 @@ export async function main() {
|
|
|
966
1029
|
try {
|
|
967
1030
|
opts = parseArgs(argv);
|
|
968
1031
|
} catch (e) {
|
|
969
|
-
fail(e.message);
|
|
1032
|
+
fail(e.message, e.code);
|
|
970
1033
|
}
|
|
971
1034
|
if (opts.help) {
|
|
972
|
-
for (const line of USAGE) log(line);
|
|
1035
|
+
for (const line of USAGE) console.log(line);
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
if (opts.version) {
|
|
1039
|
+
const version = packageVersion();
|
|
1040
|
+
if (jsonMode) process.stdout.write(JSON.stringify({ ok: true, version }) + '\n');
|
|
1041
|
+
else console.log(version);
|
|
973
1042
|
return;
|
|
974
1043
|
}
|
|
975
1044
|
|
|
@@ -984,17 +1053,31 @@ export async function main() {
|
|
|
984
1053
|
const injectedUpload = process.env.MNFST_PUBLISH_UPLOAD_URL || null;
|
|
985
1054
|
const key = readApiKey(root, opts.key);
|
|
986
1055
|
|
|
1056
|
+
if (opts.list) {
|
|
1057
|
+
if (!key) fail('no API key found for --list. Set MANIFEST_API_KEY in .env for headless use, or list deployments from Claude with the Manifest connector (no key needed).', 'no_api_key');
|
|
1058
|
+
let res;
|
|
1059
|
+
try {
|
|
1060
|
+
res = await callTool(url, key, 'manifest_deployments', { env: opts.env });
|
|
1061
|
+
} catch (e) {
|
|
1062
|
+
fail(e.message, e.code);
|
|
1063
|
+
}
|
|
1064
|
+
const { lines, json } = listSummary(res);
|
|
1065
|
+
if (jsonMode) process.stdout.write(JSON.stringify(json) + '\n');
|
|
1066
|
+
for (const line of lines) log(line);
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
987
1070
|
// Promote a previously-staged build straight to production (no upload). Headless
|
|
988
1071
|
// convenience; interactive users promote via the connector's manifest_promote
|
|
989
1072
|
// tool (no key). Needs a key.
|
|
990
1073
|
if (opts.promote) {
|
|
991
|
-
if (!key) fail('no API key found for --promote. Set MANIFEST_API_KEY in .env for headless use, or promote from Claude with the Manifest connector (no key needed).');
|
|
1074
|
+
if (!key) fail('no API key found for --promote. Set MANIFEST_API_KEY in .env for headless use, or promote from Claude with the Manifest connector (no key needed).', 'no_api_key');
|
|
992
1075
|
log(opts.deployment ? `Promoting ${opts.deployment} to production…` : 'Promoting the staged version to production…');
|
|
993
1076
|
let res;
|
|
994
1077
|
try {
|
|
995
1078
|
res = await runPromote(opts, { url, key });
|
|
996
1079
|
} catch (e) {
|
|
997
|
-
fail(e.message);
|
|
1080
|
+
fail(e.message, e.code);
|
|
998
1081
|
}
|
|
999
1082
|
if (jsonMode) {
|
|
1000
1083
|
process.stdout.write(
|
|
@@ -1016,7 +1099,7 @@ export async function main() {
|
|
|
1016
1099
|
// A normal publish needs either the injected one-time URL (connector) or a
|
|
1017
1100
|
// stored key (headless/CI). Without either, there's nothing to authorise with.
|
|
1018
1101
|
if (!injectedUpload && !key) {
|
|
1019
|
-
fail('no API key found. Publish from Claude with the Manifest connector (no key needed), or set MANIFEST_API_KEY in .env for headless/CI use.');
|
|
1102
|
+
fail('no API key found. Publish from Claude with the Manifest connector (no key needed), or set MANIFEST_API_KEY in .env for headless/CI use.', 'no_api_key');
|
|
1020
1103
|
}
|
|
1021
1104
|
|
|
1022
1105
|
// Checked before rendering, since the link is renewed while the render runs.
|
|
@@ -1026,7 +1109,7 @@ export async function main() {
|
|
|
1026
1109
|
try {
|
|
1027
1110
|
await checkHeldLink(injectedUpload);
|
|
1028
1111
|
} catch (e) {
|
|
1029
|
-
fail(e.message);
|
|
1112
|
+
fail(e.message, e.code);
|
|
1030
1113
|
}
|
|
1031
1114
|
}
|
|
1032
1115
|
if (injectedUpload && opts.label) log(' note: --label is ignored here; the connector set the label when it minted this upload link.');
|
|
@@ -1071,7 +1154,7 @@ export async function main() {
|
|
|
1071
1154
|
try {
|
|
1072
1155
|
checkHeldHandshake(opts, handshake);
|
|
1073
1156
|
} catch (e) {
|
|
1074
|
-
fail(e.message);
|
|
1157
|
+
fail(e.message, e.code);
|
|
1075
1158
|
}
|
|
1076
1159
|
checkUploadUrl(uploadUrl, url);
|
|
1077
1160
|
}
|
|
@@ -1092,9 +1175,9 @@ export async function main() {
|
|
|
1092
1175
|
upJson = await uploadBundle(uploadUrl, zip);
|
|
1093
1176
|
} catch (e) {
|
|
1094
1177
|
if (e.code === 'link_expired') {
|
|
1095
|
-
fail(/--no-render/.test(e.message) || !recovery.rendered ? e.message : `${e.message} ${noRenderHint(recovery.outputDir)}
|
|
1178
|
+
fail(/--no-render/.test(e.message) || !recovery.rendered ? e.message : `${e.message} ${noRenderHint(recovery.outputDir)}`, e.code);
|
|
1096
1179
|
}
|
|
1097
|
-
fail(e.message);
|
|
1180
|
+
fail(e.message, e.code);
|
|
1098
1181
|
}
|
|
1099
1182
|
|
|
1100
1183
|
const summary = publishSummary(opts, upJson);
|