mnfst-publish 0.1.17 → 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 +36 -1
- package/bin/mnfst-publish.js +2 -1
- package/manifest.publish.mjs +324 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,42 @@ 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.
|
|
19
|
+
|
|
20
|
+
## Release scripts
|
|
21
|
+
|
|
22
|
+
Review a build at its own address before it reaches production, then ship
|
|
23
|
+
exactly that build:
|
|
24
|
+
|
|
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"},…]}
|
|
28
|
+
npx mnfst-publish --no-live --label "v2.4.0" --json
|
|
29
|
+
# {"ok":true,"env":"staging","deployment_id":"dep_…","live":false,"preview_url":"https://preview--….manifestx.ai",…}
|
|
30
|
+
npx mnfst-publish --promote --deployment dep_… --expect-live dep_… --json
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
- `--no-live`: staging only. Stores the deployment without changing what
|
|
34
|
+
staging serves and prints its preview URL (unlisted, noindex).
|
|
35
|
+
- `--label <text>`: names the deployment (up to 200 characters).
|
|
36
|
+
- `--promote --deployment <id>`: promotes exactly that staging deployment;
|
|
37
|
+
staging is unchanged. Without `--deployment`, promotes what staging serves.
|
|
38
|
+
- `--expect-live <id>`: with `--promote`, refuses unless production is serving
|
|
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.
|
|
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`.
|
|
49
|
+
|
|
50
|
+
Against a server that doesn't support these yet, mnfst-publish stops before
|
|
51
|
+
uploading or promoting anything.
|
|
17
52
|
|
|
18
53
|
Publishing from Claude with the Manifest connector needs no key: the command it
|
|
19
54
|
gives you carries a one-time upload link. While the site renders, mnfst-publish
|
package/bin/mnfst-publish.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { main } from '../manifest.publish.mjs';
|
|
2
|
+
import { main, isJsonMode, jsonFailure } from '../manifest.publish.mjs';
|
|
3
3
|
|
|
4
4
|
main().catch((err) => {
|
|
5
|
+
if (isJsonMode()) process.stdout.write(JSON.stringify(jsonFailure(err)) + '\n');
|
|
5
6
|
console.error('mnfst-publish:', err && err.message ? err.message : err);
|
|
6
7
|
process.exit(1);
|
|
7
8
|
});
|
package/manifest.publish.mjs
CHANGED
|
@@ -14,32 +14,100 @@ import { join, dirname, relative, sep } from 'node:path';
|
|
|
14
14
|
|
|
15
15
|
const DEFAULT_MCP = 'https://mcp.manifestx.dev/mcp';
|
|
16
16
|
|
|
17
|
+
// --json: progress goes to stderr, the final result is one JSON object on stdout.
|
|
18
|
+
let jsonMode = false;
|
|
19
|
+
|
|
17
20
|
function log(msg) {
|
|
18
|
-
process.stdout.write(msg + '\n');
|
|
21
|
+
(jsonMode ? process.stderr : process.stdout).write(msg + '\n');
|
|
22
|
+
}
|
|
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';
|
|
19
26
|
}
|
|
20
|
-
|
|
27
|
+
|
|
28
|
+
function fail(msg, code) {
|
|
29
|
+
if (jsonMode) process.stdout.write(JSON.stringify({ ok: false, error: publicCode(code), message: msg }) + '\n');
|
|
21
30
|
console.error('mnfst-publish: ' + msg);
|
|
22
31
|
process.exit(1);
|
|
23
32
|
}
|
|
24
33
|
|
|
25
|
-
|
|
34
|
+
export const LABEL_MAX_LENGTH = 200;
|
|
35
|
+
// C0/C1 controls, DEL, line/paragraph separators, zero-width and bidi override/isolate characters.
|
|
36
|
+
const NON_PRINTABLE = new RegExp('[\\u0000-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2066-\\u2069\\ufeff]');
|
|
37
|
+
|
|
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. */
|
|
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) {
|
|
26
56
|
const out = { env: 'production', render: undefined, promote: false };
|
|
57
|
+
let envGiven = false;
|
|
58
|
+
const value = (flag, i) => {
|
|
59
|
+
const v = argv[i];
|
|
60
|
+
if (v === undefined || v.startsWith('--')) throw new Error(`${flag} needs a value`);
|
|
61
|
+
return v;
|
|
62
|
+
};
|
|
27
63
|
for (let i = 0; i < argv.length; i++) {
|
|
28
64
|
const a = argv[i];
|
|
29
|
-
if (a === '--staging') out.env = 'staging';
|
|
30
|
-
else if (a === '--production' || a === '--prod') out.env = 'production';
|
|
31
|
-
else if (a === '--env') out.env =
|
|
32
|
-
else if (a === '--source') out.source =
|
|
33
|
-
else if (a === '--output-dir') out.outputDir =
|
|
65
|
+
if (a === '--staging') { out.env = 'staging'; envGiven = true; }
|
|
66
|
+
else if (a === '--production' || a === '--prod') { out.env = 'production'; envGiven = true; }
|
|
67
|
+
else if (a === '--env') { out.env = value(a, ++i); envGiven = true; }
|
|
68
|
+
else if (a === '--source') out.source = value(a, ++i);
|
|
69
|
+
else if (a === '--output-dir') out.outputDir = value(a, ++i);
|
|
34
70
|
else if (a === '--no-render') out.render = false;
|
|
35
71
|
else if (a === '--render') out.render = true;
|
|
36
72
|
else if (a === '--promote') out.promote = true;
|
|
37
|
-
else if (a === '--
|
|
38
|
-
else if (a === '--
|
|
39
|
-
else if (a === '--
|
|
73
|
+
else if (a === '--no-live') out.live = false;
|
|
74
|
+
else if (a === '--label') out.label = value(a, ++i);
|
|
75
|
+
else if (a === '--deployment') out.deployment = value(a, ++i);
|
|
76
|
+
else if (a === '--expect-live') out.expectLive = value(a, ++i);
|
|
77
|
+
else if (a === '--json') out.json = true;
|
|
78
|
+
else if (a === '--key') out.key = value(a, ++i);
|
|
79
|
+
else if (a === '--mcp') out.mcp = value(a, ++i);
|
|
80
|
+
else if (a === '--root') out.root = value(a, ++i);
|
|
81
|
+
else if (a === '--list') out.list = true;
|
|
40
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.`);
|
|
86
|
+
}
|
|
87
|
+
if (out.help || out.version) return out;
|
|
88
|
+
if (out.env !== 'staging' && out.env !== 'production') throw new Error(`--env must be "staging" or "production" (got "${out.env}")`);
|
|
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) {
|
|
94
|
+
if (out.live === false) throw new Error('--no-live applies to a publish, not to --promote');
|
|
95
|
+
if (out.label !== undefined) throw new Error('--label is set when publishing; --promote carries the label of the deployment it promotes');
|
|
96
|
+
} else {
|
|
97
|
+
if (out.deployment !== undefined) throw new Error('--deployment only applies with --promote');
|
|
98
|
+
if (out.expectLive !== undefined) throw new Error('--expect-live only applies with --promote');
|
|
99
|
+
}
|
|
100
|
+
if (out.live === false) {
|
|
101
|
+
// A held publish is a staging publish; production has no held form.
|
|
102
|
+
if (envGiven && out.env !== 'staging') throw new Error('--no-live only applies to staging (drop --production, or use --staging)');
|
|
103
|
+
out.env = 'staging';
|
|
104
|
+
}
|
|
105
|
+
if (out.label !== undefined) {
|
|
106
|
+
out.label = out.label.trim();
|
|
107
|
+
if (!out.label) throw new Error('--label must not be empty');
|
|
108
|
+
if (out.label.length > LABEL_MAX_LENGTH) throw new Error(`--label must be at most ${LABEL_MAX_LENGTH} characters`);
|
|
109
|
+
if (NON_PRINTABLE.test(out.label)) throw new Error('--label must be printable (no control, zero-width or bidi characters, no line breaks)');
|
|
41
110
|
}
|
|
42
|
-
if (out.env !== 'staging' && out.env !== 'production') fail(`--env must be "staging" or "production" (got "${out.env}")`);
|
|
43
111
|
return out;
|
|
44
112
|
}
|
|
45
113
|
|
|
@@ -165,7 +233,7 @@ async function mcp(url, key, method, params, sessionId) {
|
|
|
165
233
|
return { json, sessionId: sid, status: res.status, raw: text };
|
|
166
234
|
}
|
|
167
235
|
|
|
168
|
-
async function
|
|
236
|
+
async function openSession(url, key) {
|
|
169
237
|
const init = await mcp(url, key, 'initialize', {
|
|
170
238
|
protocolVersion: '2024-11-05',
|
|
171
239
|
capabilities: {},
|
|
@@ -174,12 +242,28 @@ async function callTool(url, key, name, args) {
|
|
|
174
242
|
const sid = init.sessionId;
|
|
175
243
|
if (!sid) throw new Error('no MCP session — check your API key and network connection');
|
|
176
244
|
await mcp(url, key, 'notifications/initialized', {}, sid);
|
|
245
|
+
return sid;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** The input-schema property names of `name`, or null when the server does not list it. */
|
|
249
|
+
async function toolParams(url, key, name) {
|
|
250
|
+
const sid = await openSession(url, key);
|
|
251
|
+
const res = await mcp(url, key, 'tools/list', {}, sid);
|
|
252
|
+
const tool = ((res.json && res.json.result && res.json.result.tools) || []).find((t) => t.name === name);
|
|
253
|
+
return tool ? Object.keys((tool.inputSchema && tool.inputSchema.properties) || {}) : null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async function callTool(url, key, name, args) {
|
|
257
|
+
const sid = await openSession(url, key);
|
|
177
258
|
const res = await mcp(url, key, 'tools/call', { name, arguments: args }, sid);
|
|
178
259
|
const result = res.json && res.json.result;
|
|
179
260
|
if (!result) throw new Error(`unexpected response from ${name} (HTTP ${res.status})`);
|
|
180
261
|
const textPart = (result.content || []).find((c) => c.type === 'text');
|
|
181
262
|
const payloadText = textPart ? textPart.text : '';
|
|
182
|
-
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
|
+
}
|
|
183
267
|
try {
|
|
184
268
|
return JSON.parse(payloadText);
|
|
185
269
|
} catch {
|
|
@@ -784,11 +868,177 @@ function checkUploadUrl(uploadUrl, mcpUrl) {
|
|
|
784
868
|
}
|
|
785
869
|
}
|
|
786
870
|
|
|
871
|
+
/** Child process stdio: with --json, the child's stdout joins stderr so stdout stays one JSON object. */
|
|
872
|
+
export function childStdio(json) {
|
|
873
|
+
return json ? ['inherit', 2, 'inherit'] : 'inherit';
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/** Whether --json is on (the bin reports uncaught errors as JSON then). */
|
|
877
|
+
export function isJsonMode() {
|
|
878
|
+
return jsonMode;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/** The --json failure object for an error. */
|
|
882
|
+
export function jsonFailure(err) {
|
|
883
|
+
const message = err && err.message ? err.message : String(err);
|
|
884
|
+
return { ok: false, error: publicCode(err && err.code), message };
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/** manifest_promote arguments for these options. */
|
|
888
|
+
export function promoteToolArgs(opts) {
|
|
889
|
+
const args = {};
|
|
890
|
+
if (opts.deployment) args.deployment_id = opts.deployment;
|
|
891
|
+
if (opts.expectLive) args.expect_live = opts.expectLive;
|
|
892
|
+
return args;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/** manifest_publish handshake arguments for these options (headless/CI path). */
|
|
896
|
+
export function publishToolArgs(opts, source) {
|
|
897
|
+
const args = { env: opts.env, source, via_cli: true };
|
|
898
|
+
if (opts.live === false) args.live = false;
|
|
899
|
+
if (opts.label) args.label = opts.label;
|
|
900
|
+
return args;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* An older server drops arguments it does not know, so a promote by id would
|
|
905
|
+
* promote whatever staging serves instead. Refuse before calling it.
|
|
906
|
+
*/
|
|
907
|
+
export function unsupportedPromoteArgs(args, params) {
|
|
908
|
+
if (!params) return Object.keys(args);
|
|
909
|
+
return Object.keys(args).filter((k) => !params.includes(k));
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/** Promote, by id when asked. Resolves the tool result; throws on refusal or an unsupported server. */
|
|
913
|
+
export async function runPromote(opts, { url, key, callToolImpl = callTool, toolParamsImpl = toolParams }) {
|
|
914
|
+
const args = promoteToolArgs(opts);
|
|
915
|
+
if (Object.keys(args).length) {
|
|
916
|
+
const missing = unsupportedPromoteArgs(args, await toolParamsImpl(url, key, 'manifest_promote'));
|
|
917
|
+
if (missing.length) {
|
|
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.`);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
const res = await callToolImpl(url, key, 'manifest_promote', args);
|
|
922
|
+
if (opts.deployment && res.from_deployment_id && res.from_deployment_id !== opts.deployment) {
|
|
923
|
+
throw codedError('promoted_other', `the server promoted ${res.from_deployment_id}, not ${opts.deployment}. Check production now.`);
|
|
924
|
+
}
|
|
925
|
+
return res;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
/** The handshake must confirm a held publish and the label before anything is uploaded; an older server drops both. */
|
|
929
|
+
export function checkHeldHandshake(opts, handshake) {
|
|
930
|
+
if (opts.live === false && handshake.live !== false) {
|
|
931
|
+
throw codedError('unsupported_server', 'this Manifest server does not support --no-live yet, so nothing was uploaded.');
|
|
932
|
+
}
|
|
933
|
+
if (opts.label && handshake.label !== opts.label) {
|
|
934
|
+
throw codedError('unsupported_server', 'this Manifest server does not support --label yet, so nothing was uploaded.');
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* A connector link carries no flags of its own: with --no-live, confirm from its
|
|
940
|
+
* status that the server minted it held before uploading anything.
|
|
941
|
+
*/
|
|
942
|
+
export async function checkHeldLink(uploadUrl, { fetchImpl = fetch } = {}) {
|
|
943
|
+
let json = null;
|
|
944
|
+
try {
|
|
945
|
+
const res = await fetchImpl(statusUrlFor(uploadUrl), { method: 'GET', headers: { accept: 'application/json' } });
|
|
946
|
+
json = JSON.parse(await res.text());
|
|
947
|
+
} catch {
|
|
948
|
+
/* unreadable: treated as unconfirmed */
|
|
949
|
+
}
|
|
950
|
+
if (!json || json.live !== false) {
|
|
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.');
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/** Human lines and the --json object for a finished publish. */
|
|
956
|
+
export function publishSummary(opts, up) {
|
|
957
|
+
const held = up.live === false;
|
|
958
|
+
const json = {
|
|
959
|
+
ok: true,
|
|
960
|
+
env: up.env || opts.env,
|
|
961
|
+
deployment_id: up.deployment_id || null,
|
|
962
|
+
live: !held,
|
|
963
|
+
url: up.url || null,
|
|
964
|
+
...(held ? { preview_url: up.preview_url || up.url || null } : {}),
|
|
965
|
+
label: up.label ?? opts.label ?? null,
|
|
966
|
+
};
|
|
967
|
+
const lines = [''];
|
|
968
|
+
if (held) {
|
|
969
|
+
lines.push(`✓ Stored on staging without going live: ${json.deployment_id}`);
|
|
970
|
+
if (json.preview_url) lines.push(` Preview: ${json.preview_url}`);
|
|
971
|
+
if (json.label) lines.push(` Label: ${json.label}`);
|
|
972
|
+
lines.push(` Ship it with \`npx mnfst-publish --promote --deployment ${json.deployment_id}\`.`);
|
|
973
|
+
} else {
|
|
974
|
+
lines.push(`✓ Published to ${json.env}: ${json.url}`);
|
|
975
|
+
if (json.deployment_id) lines.push(` Deployment: ${json.deployment_id}`);
|
|
976
|
+
if (json.env === 'staging') lines.push(' Review it, then run `npx mnfst-publish --promote` to take it live.');
|
|
977
|
+
}
|
|
978
|
+
return { lines, json };
|
|
979
|
+
}
|
|
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
|
+
|
|
1007
|
+
const USAGE = [
|
|
1008
|
+
'Usage: npx mnfst-publish [--staging|--production] [--source spa|render] [--output-dir <dir>] [--no-render]',
|
|
1009
|
+
' [--no-live] [--label <text>] [--json]',
|
|
1010
|
+
' npx mnfst-publish --promote [--deployment <id>] [--expect-live <id>] [--json]',
|
|
1011
|
+
' npx mnfst-publish --list [--staging|--production] [--json]',
|
|
1012
|
+
'Publishes the current Manifest project to managed hosting and prints the live URL.',
|
|
1013
|
+
' --no-live staging only: store the build without changing what staging serves; prints its preview URL',
|
|
1014
|
+
' --label <text> name the deployment (up to 200 characters)',
|
|
1015
|
+
' --promote promote what staging serves to production',
|
|
1016
|
+
' --deployment <id> with --promote: promote exactly this staging deployment',
|
|
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',
|
|
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.',
|
|
1022
|
+
];
|
|
1023
|
+
|
|
787
1024
|
export async function main() {
|
|
788
|
-
const
|
|
1025
|
+
const argv = process.argv.slice(2);
|
|
1026
|
+
// Set before parsing, so a bad flag is reported as JSON too.
|
|
1027
|
+
jsonMode = argv.includes('--json');
|
|
1028
|
+
let opts;
|
|
1029
|
+
try {
|
|
1030
|
+
opts = parseArgs(argv);
|
|
1031
|
+
} catch (e) {
|
|
1032
|
+
fail(e.message, e.code);
|
|
1033
|
+
}
|
|
789
1034
|
if (opts.help) {
|
|
790
|
-
|
|
791
|
-
|
|
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);
|
|
792
1042
|
return;
|
|
793
1043
|
}
|
|
794
1044
|
|
|
@@ -803,32 +1053,73 @@ export async function main() {
|
|
|
803
1053
|
const injectedUpload = process.env.MNFST_PUBLISH_UPLOAD_URL || null;
|
|
804
1054
|
const key = readApiKey(root, opts.key);
|
|
805
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
|
+
|
|
806
1070
|
// Promote a previously-staged build straight to production (no upload). Headless
|
|
807
1071
|
// convenience; interactive users promote via the connector's manifest_promote
|
|
808
1072
|
// tool (no key). Needs a key.
|
|
809
1073
|
if (opts.promote) {
|
|
810
|
-
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).');
|
|
811
|
-
log('Promoting the staged version to production…');
|
|
812
|
-
|
|
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');
|
|
1075
|
+
log(opts.deployment ? `Promoting ${opts.deployment} to production…` : 'Promoting the staged version to production…');
|
|
1076
|
+
let res;
|
|
1077
|
+
try {
|
|
1078
|
+
res = await runPromote(opts, { url, key });
|
|
1079
|
+
} catch (e) {
|
|
1080
|
+
fail(e.message, e.code);
|
|
1081
|
+
}
|
|
1082
|
+
if (jsonMode) {
|
|
1083
|
+
process.stdout.write(
|
|
1084
|
+
JSON.stringify({
|
|
1085
|
+
ok: true,
|
|
1086
|
+
env: 'production',
|
|
1087
|
+
deployment_id: res.live_deployment_id ?? null,
|
|
1088
|
+
from_deployment_id: res.from_deployment_id ?? null,
|
|
1089
|
+
label: res.label ?? null,
|
|
1090
|
+
url: res.url ?? null,
|
|
1091
|
+
}) + '\n',
|
|
1092
|
+
);
|
|
1093
|
+
}
|
|
813
1094
|
log('✓ Live: ' + (res.url || res._text || 'production updated'));
|
|
1095
|
+
if (res.live_deployment_id) log(` Deployment: ${res.live_deployment_id}${res.from_deployment_id ? ` (from ${res.from_deployment_id})` : ''}`);
|
|
814
1096
|
return;
|
|
815
1097
|
}
|
|
816
1098
|
|
|
817
1099
|
// A normal publish needs either the injected one-time URL (connector) or a
|
|
818
1100
|
// stored key (headless/CI). Without either, there's nothing to authorise with.
|
|
819
1101
|
if (!injectedUpload && !key) {
|
|
820
|
-
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');
|
|
821
1103
|
}
|
|
822
1104
|
|
|
823
1105
|
// Checked before rendering, since the link is renewed while the render runs.
|
|
824
1106
|
if (injectedUpload) checkUploadUrl(injectedUpload, url);
|
|
1107
|
+
// Before any render, so a wrong link costs nothing.
|
|
1108
|
+
if (injectedUpload && opts.live === false) {
|
|
1109
|
+
try {
|
|
1110
|
+
await checkHeldLink(injectedUpload);
|
|
1111
|
+
} catch (e) {
|
|
1112
|
+
fail(e.message, e.code);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
if (injectedUpload && opts.label) log(' note: --label is ignored here; the connector set the label when it minted this upload link.');
|
|
825
1116
|
const keepAlive = injectedUpload ? keepUploadLinkAlive(injectedUpload) : null;
|
|
826
1117
|
|
|
827
1118
|
const rendering = source === 'render' && opts.render !== false;
|
|
828
1119
|
if (rendering) {
|
|
829
1120
|
log('Rendering the site…');
|
|
830
1121
|
// Async, so the renewal timer runs during the render.
|
|
831
|
-
const code = await runCommand('npx', ['mnfst-render'], { cwd: root, stdio:
|
|
1122
|
+
const code = await runCommand('npx', ['mnfst-render'], { cwd: root, stdio: childStdio(jsonMode), shell: process.platform === 'win32' });
|
|
832
1123
|
if (code !== 0) fail('render failed — fix the errors above and try again.');
|
|
833
1124
|
}
|
|
834
1125
|
|
|
@@ -857,9 +1148,14 @@ export async function main() {
|
|
|
857
1148
|
} else {
|
|
858
1149
|
// Headless/CI: authenticate the handshake with the key to get an upload URL.
|
|
859
1150
|
log(`Preparing ${opts.env} deploy…`);
|
|
860
|
-
const handshake = await callTool(url, key, 'manifest_publish',
|
|
1151
|
+
const handshake = await callTool(url, key, 'manifest_publish', publishToolArgs(opts, source));
|
|
861
1152
|
uploadUrl = handshake.upload_url;
|
|
862
1153
|
if (!uploadUrl) fail(handshake._text || 'could not start the publish (no upload URL returned).');
|
|
1154
|
+
try {
|
|
1155
|
+
checkHeldHandshake(opts, handshake);
|
|
1156
|
+
} catch (e) {
|
|
1157
|
+
fail(e.message, e.code);
|
|
1158
|
+
}
|
|
863
1159
|
checkUploadUrl(uploadUrl, url);
|
|
864
1160
|
}
|
|
865
1161
|
|
|
@@ -879,12 +1175,12 @@ export async function main() {
|
|
|
879
1175
|
upJson = await uploadBundle(uploadUrl, zip);
|
|
880
1176
|
} catch (e) {
|
|
881
1177
|
if (e.code === 'link_expired') {
|
|
882
|
-
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);
|
|
883
1179
|
}
|
|
884
|
-
fail(e.message);
|
|
1180
|
+
fail(e.message, e.code);
|
|
885
1181
|
}
|
|
886
1182
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
1183
|
+
const summary = publishSummary(opts, upJson);
|
|
1184
|
+
if (jsonMode) process.stdout.write(JSON.stringify(summary.json) + '\n');
|
|
1185
|
+
for (const line of summary.lines) log(line);
|
|
890
1186
|
}
|