@homepages/concrete 13.0.1 → 14.1.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/CHANGELOG.md +46 -0
- package/README.md +4 -5
- package/codemods/manifest.json +11 -0
- package/dist/artifact/playground/client/assets/index-DZbV6Ucf.js +1338 -0
- package/dist/artifact/playground/client/index.html +1 -1
- package/dist/artifact/playground/host.mjs +22 -22
- package/dist/cli/build/esbuild.js +42 -3
- package/dist/cli/build/manifest.js +1 -1
- package/dist/cli/build/record.js +5 -4
- package/dist/cli/build/sections.js +13 -6
- package/dist/cli/build/template-build.js +19 -9
- package/dist/cli/check/load-workspace.js +3 -6
- package/dist/cli/commands.js +63 -15
- package/dist/cli/media/deriver-plugin.js +36 -5
- package/dist/cli/publish/artifact.js +18 -40
- package/dist/cli/publish/fixtures.js +1 -1
- package/dist/cli/publish/index.js +90 -115
- package/dist/cli/publish/report.js +36 -56
- package/dist/cli/publish/send.js +142 -0
- package/dist/cli/publish/target.js +33 -31
- package/dist/cli/publish/verdict.js +65 -0
- package/dist/cli/release/client.js +69 -0
- package/dist/cli/release/index.js +143 -0
- package/dist/cli/release/report.js +73 -0
- package/dist/cli/upgrade/fixture-modules.js +3 -5
- package/dist/cli.js +1 -0
- package/dist/css/graph.js +29 -40
- package/dist/css/inline.js +2 -3
- package/dist/fixtures/media-plugin.js +7 -25
- package/dist/fixtures/package-stylesheets.js +12 -48
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/packages/internal/download-files/dist/capture-origin.js +5 -5
- package/dist/packages/internal/media-resolution/dist/image.js +43 -4
- package/dist/packages/internal/media-resolution/dist/list.js +4 -4
- package/dist/packages/internal/media-resolution/dist/media.js +2 -2
- package/dist/packages/internal/media-resolution/dist/slot.js +2 -2
- package/dist/packages/internal/playground/dist/fixture-formats.js +5 -1
- package/dist/packages/internal/playground/dist/host/built.js +4 -12
- package/dist/packages/internal/playground/dist/host/catalog-fixture.js +0 -1
- package/dist/packages/internal/playground/dist/host/download.js +1 -8
- package/dist/packages/internal/playground/dist/host/fixture-addresses.js +3 -4
- package/dist/packages/internal/playground/dist/host/program.js +1 -2
- package/dist/packages/internal/playground/dist/host/serve.js +4 -30
- package/dist/packages/internal/playground/dist/host/stored-fixtures.js +2 -9
- package/dist/packages/internal/playground/dist/layout.js +5 -5
- package/dist/packages/internal/playground/dist/send-wire.js +9 -0
- package/dist/packages/internal/playground/dist/server/changes.js +0 -1
- package/dist/packages/internal/playground/dist/server/listen.js +2 -19
- package/dist/packages/internal/playground/dist/server/playground-server.js +2 -3
- package/dist/packages/internal/property-facts/dist/registry-facts.js +0 -7
- package/dist/packages/internal/site-files/dist/site.js +4 -6
- package/dist/packages/internal/static-assets-binding/dist/index.js +2 -1
- package/dist/packages/internal/static-assets-binding/dist/section-asset-url.js +16 -4
- package/dist/packages/internal/template-artifact/dist/framework-floor.js +33 -0
- package/dist/packages/internal/template-artifact/dist/index.js +3 -3
- package/dist/packages/internal/template-artifact/dist/layout.js +7 -39
- package/dist/packages/internal/template-artifact/dist/manifest.js +1 -1
- package/dist/packages/internal/template-artifact/dist/verify.js +14 -57
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +8 -1
- package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/video-value.d.ts +1 -1
- package/dist/template/logic-build.js +38 -19
- package/guide/reference/cli/INDEX.md +5 -4
- package/guide/reference/cli/build.md +1 -1
- package/guide/reference/cli/check.md +1 -1
- package/guide/reference/cli/dev.md +1 -1
- package/guide/reference/cli/install.md +1 -1
- package/guide/reference/cli/property-add.md +1 -1
- package/guide/reference/cli/property-list.md +1 -1
- package/guide/reference/cli/publish.md +17 -16
- package/guide/reference/cli/release.md +57 -0
- package/guide/reference/cli/upgrade.md +1 -1
- package/guide/reference/rules/INDEX.md +1 -1
- package/package.json +6 -4
- package/dist/artifact/playground/client/assets/index-Bmvcss4B.js +0 -1338
- package/dist/cli/publish/captures.js +0 -61
- package/dist/cli/publish/client.js +0 -118
- package/dist/cli/publish/pack.js +0 -77
- package/dist/cli/publish/playground.js +0 -27
- package/dist/cli/publish/wire.js +0 -23
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { DEFAULT_BUILD_DIR, booleanFlag, parseSpec, stringFlag } from "../commands.js";
|
|
2
|
-
import { removeTree } from "../../platform/fs.js";
|
|
3
2
|
import { findWorkspaceRoot } from "../workspace.js";
|
|
4
3
|
import { formatHuman } from "../check/report.js";
|
|
5
|
-
import { TERMINAL_STATES } from "./wire.js";
|
|
6
|
-
import { publicationClient } from "./client.js";
|
|
7
4
|
import { readSourceFacts } from "./git.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { mkdtemp, stat } from "node:fs/promises";
|
|
13
|
-
import { tmpdir } from "node:os";
|
|
5
|
+
import { CONSOLE_KEY_VARIABLE, CONSOLE_URL_VARIABLE, TargetError, maskToken, resolveConsoleTarget } from "./target.js";
|
|
6
|
+
import { behindText, builtText, consoleText, notReleasedText, refusedText, sendLines, stageLine, verdictText } from "./report.js";
|
|
7
|
+
import { askVerdict } from "./verdict.js";
|
|
8
|
+
import { resolve } from "node:path";
|
|
14
9
|
import { parseArgs } from "node:util";
|
|
15
10
|
|
|
16
11
|
//#region src/cli/publish/index.ts
|
|
17
12
|
const EXIT_OK = 0;
|
|
18
13
|
const EXIT_REFUSED = 1;
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const POLL_FAILURES_TOLERATED = 30;
|
|
14
|
+
const EXIT_FAILED = 2;
|
|
15
|
+
const VERDICT_ASKS_TOLERATED = 10;
|
|
22
16
|
const DEFAULT_DEPS = {
|
|
23
17
|
artifact: async (options) => (await import("./artifact.js")).assembleArtifact(options),
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
send: async (target, input) => (await import("./send.js")).sendTemplate({
|
|
19
|
+
console: target.console,
|
|
20
|
+
key: target.key
|
|
21
|
+
}, input),
|
|
22
|
+
verdict: (target, template, version) => askVerdict(target.console, target.key, {
|
|
23
|
+
template,
|
|
24
|
+
version,
|
|
25
|
+
wait: 60
|
|
26
|
+
}),
|
|
27
|
+
sourceFacts: readSourceFacts
|
|
28
28
|
};
|
|
29
29
|
var Ending = class extends Error {
|
|
30
30
|
code;
|
|
@@ -36,115 +36,90 @@ var Ending = class extends Error {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
const say = (sentence) => `concrete publish: ${sentence}\n`;
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
39
|
+
function failureEnding(answer, target, doing, after) {
|
|
40
|
+
const where = target.console;
|
|
41
|
+
if (answer.kind === "unreachable") return new Ending(EXIT_FAILED, say(`could not reach ${where} while ${doing} (${answer.reason}); check the connection${target.overridden ? ` and ${CONSOLE_URL_VARIABLE}` : ""}, then run again.${after}`));
|
|
42
|
+
return new Ending(EXIT_FAILED, say(`${where} did not answer as the console while ${doing} (${answer.reason}); ${target.overridden ? `check that ${CONSOLE_URL_VARIABLE} names the development console` : "run again, and report it if it repeats"}.${after}`));
|
|
43
|
+
}
|
|
44
|
+
function sendEnding(answer, target) {
|
|
45
|
+
if (answer.kind !== "refused") return failureEnding(answer, target, "sending", "");
|
|
46
|
+
const detail = answer.refusal?.detail ?? `${target.console} refused the send (HTTP ${String(answer.status)}).`;
|
|
47
|
+
if (answer.status === 401) return new Ending(EXIT_FAILED, say(`${target.console} did not accept ${CONSOLE_KEY_VARIABLE} (${maskToken(target.key)}): ${detail}`));
|
|
48
|
+
return new Ending(EXIT_REFUSED, say(detail));
|
|
50
49
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
function verdictEnding(answer, target, version) {
|
|
51
|
+
const after = ` Version ${version} is on the console; \`concrete release --version ${version}\` asks for its verdict again before it releases.`;
|
|
52
|
+
if (answer.kind !== "refused") return failureEnding(answer, target, "asking for the verdict", after);
|
|
53
|
+
const detail = answer.refusal?.detail ?? `${target.console} gave no verdict (HTTP ${String(answer.status)}).`;
|
|
54
|
+
return new Ending(EXIT_FAILED, say(`${detail}${after}`));
|
|
54
55
|
}
|
|
55
|
-
async function produceArtifact(run, root
|
|
56
|
+
async function produceArtifact(run, root) {
|
|
56
57
|
const { io, deps } = run;
|
|
57
58
|
let outcome;
|
|
58
59
|
try {
|
|
59
60
|
outcome = await deps.artifact({
|
|
60
61
|
root,
|
|
61
|
-
buildDir: resolve(root, DEFAULT_BUILD_DIR)
|
|
62
|
-
out
|
|
62
|
+
buildDir: resolve(root, DEFAULT_BUILD_DIR)
|
|
63
63
|
});
|
|
64
64
|
} catch (cause) {
|
|
65
65
|
throw new Ending(EXIT_REFUSED, say(`the build failed: ${cause instanceof Error ? cause.message : String(cause)}`));
|
|
66
66
|
}
|
|
67
67
|
if (!outcome.ok) {
|
|
68
68
|
io.stderr.write(formatHuman(outcome.report));
|
|
69
|
-
throw new Ending(EXIT_REFUSED, say("check is not green, so nothing was built or
|
|
69
|
+
throw new Ending(EXIT_REFUSED, say("check is not green, so nothing was built or sent; fix the findings above and run again."));
|
|
70
70
|
}
|
|
71
71
|
io.stderr.write(stageLine("build", builtText(outcome.manifest)));
|
|
72
|
-
return outcome
|
|
72
|
+
return outcome;
|
|
73
73
|
}
|
|
74
|
-
async function
|
|
75
|
-
const { io, deps } = run;
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (answer.kind === "unreachable" && failures < POLL_FAILURES_TOLERATED) {
|
|
100
|
-
failures += 1;
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
if (answer.kind !== "ok") {
|
|
104
|
-
const ending = endingFor(answer, target, `following publication ${record.id}`);
|
|
105
|
-
throw new Ending(ending.code, `${ending.sentence.trimEnd()} The publication may still finish; a later run reports it already current if it did.\n`);
|
|
106
|
-
}
|
|
107
|
-
failures = 0;
|
|
108
|
-
record = answer.value;
|
|
74
|
+
async function sendToConsole(run, root, built) {
|
|
75
|
+
const { io, deps, target } = run;
|
|
76
|
+
const { manifest } = built;
|
|
77
|
+
const answer = await deps.send(target, {
|
|
78
|
+
template: manifest.key,
|
|
79
|
+
frameworkVersion: manifest.framework_version,
|
|
80
|
+
files: built.sendable,
|
|
81
|
+
source: await deps.sourceFacts(root)
|
|
82
|
+
});
|
|
83
|
+
if (answer.kind !== "merged") throw sendEnding(answer, target);
|
|
84
|
+
const [first, ...rest] = sendLines(answer);
|
|
85
|
+
io.stderr.write(stageLine("send", first ?? ""));
|
|
86
|
+
for (const line of rest) io.stderr.write(stageLine(null, line));
|
|
87
|
+
const behind = behindText(manifest.framework_version, answer.merged.concrete_version);
|
|
88
|
+
if (behind !== null) io.stderr.write(behind);
|
|
89
|
+
return answer;
|
|
90
|
+
}
|
|
91
|
+
async function awaitVerdict(run, template, version) {
|
|
92
|
+
const { io, deps, target } = run;
|
|
93
|
+
for (let asks = 1;; asks++) {
|
|
94
|
+
const answer = await deps.verdict(target, template, version);
|
|
95
|
+
if (answer.kind === "given") return answer.verdict;
|
|
96
|
+
if (answer.kind !== "pending") throw verdictEnding(answer, target, version);
|
|
97
|
+
if (asks === 1) io.stderr.write(stageLine("verify", `the console is verifying version ${version}…`));
|
|
98
|
+
if (asks >= 10) throw new Ending(EXIT_FAILED, say(`the console has not verified version ${version} after ${String(asks)} asks. It is on the console; \`concrete release --version ${version}\` asks for its verdict again before it releases.`));
|
|
109
99
|
}
|
|
110
100
|
}
|
|
111
|
-
async function publishWorkspace(run, root
|
|
112
|
-
const { io
|
|
113
|
-
io.stderr.write(stageLine("
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
source_digest: manifest.source_digest,
|
|
131
|
-
source_commit: facts.commit,
|
|
132
|
-
source_remote: facts.remote
|
|
133
|
-
}), target, "creating the publication");
|
|
134
|
-
unwrap(await client.upload(created.upload, tarball), target, "uploading the artifact");
|
|
135
|
-
io.stderr.write(stageLine("upload", uploadText(manifest, size, created.publication.publisher.name)));
|
|
136
|
-
const settled = await follow(run, client, target, unwrap(await client.submit(created.publication.id, run.dryRun ? { dry_run: true } : null), target, "submitting the publication").publication);
|
|
137
|
-
if (run.json) io.stdout.write(`${JSON.stringify(settled, null, 2)}\n`);
|
|
138
|
-
if (settled.state === "refused" || settled.state === "failed") {
|
|
139
|
-
io.stderr.write(refusalText(settled));
|
|
140
|
-
return EXIT_REFUSED;
|
|
141
|
-
}
|
|
142
|
-
if (settled.review_url !== null) io.stderr.write(stageLine("review", settled.review_url));
|
|
143
|
-
io.stderr.write(`${summaryText(settled)}\n`);
|
|
144
|
-
return EXIT_OK;
|
|
145
|
-
} finally {
|
|
146
|
-
await removeTree(scratch);
|
|
101
|
+
async function publishWorkspace(run, root) {
|
|
102
|
+
const { io } = run;
|
|
103
|
+
io.stderr.write(stageLine("console", consoleText(run.target)));
|
|
104
|
+
const sent = await sendToConsole(run, root, await produceArtifact(run, root));
|
|
105
|
+
const verdict = await awaitVerdict(run, sent.merged.template, sent.merged.version);
|
|
106
|
+
io.stderr.write(stageLine("verify", verdictText(verdict)));
|
|
107
|
+
if (run.json) {
|
|
108
|
+
const outcome = {
|
|
109
|
+
template: sent.merged.template,
|
|
110
|
+
version: sent.merged.version,
|
|
111
|
+
link: sent.link,
|
|
112
|
+
merge: sent.merged.merge,
|
|
113
|
+
verdict
|
|
114
|
+
};
|
|
115
|
+
io.stdout.write(`${JSON.stringify(outcome, null, 2)}\n`);
|
|
116
|
+
}
|
|
117
|
+
if (!verdict.passed) {
|
|
118
|
+
io.stderr.write(refusedText(verdict));
|
|
119
|
+
return EXIT_REFUSED;
|
|
147
120
|
}
|
|
121
|
+
io.stderr.write(notReleasedText(verdict));
|
|
122
|
+
return EXIT_OK;
|
|
148
123
|
}
|
|
149
124
|
async function publish(argv, io, deps) {
|
|
150
125
|
let values;
|
|
@@ -155,29 +130,29 @@ async function publish(argv, io, deps) {
|
|
|
155
130
|
}));
|
|
156
131
|
} catch (cause) {
|
|
157
132
|
io.stderr.write(say(`${cause instanceof Error ? cause.message : String(cause)}; run \`concrete --help\` for the flags publish takes.`));
|
|
158
|
-
return
|
|
133
|
+
return EXIT_FAILED;
|
|
159
134
|
}
|
|
160
135
|
try {
|
|
161
136
|
let root;
|
|
162
137
|
try {
|
|
163
138
|
root = await findWorkspaceRoot(io.cwd);
|
|
164
139
|
} catch (cause) {
|
|
165
|
-
throw new Ending(
|
|
140
|
+
throw new Ending(EXIT_FAILED, say(cause instanceof Error ? cause.message : String(cause)));
|
|
166
141
|
}
|
|
167
142
|
let target;
|
|
168
143
|
try {
|
|
169
|
-
const
|
|
170
|
-
target = await
|
|
144
|
+
const flag = stringFlag(values, "env-file");
|
|
145
|
+
target = await resolveConsoleTarget(root, io.env, flag === null ? void 0 : resolve(io.cwd, flag));
|
|
171
146
|
} catch (cause) {
|
|
172
|
-
if (cause instanceof TargetError) throw new Ending(
|
|
147
|
+
if (cause instanceof TargetError) throw new Ending(EXIT_FAILED, say(cause.message));
|
|
173
148
|
throw cause;
|
|
174
149
|
}
|
|
175
150
|
return await publishWorkspace({
|
|
176
151
|
io,
|
|
177
152
|
deps,
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}, root
|
|
153
|
+
target,
|
|
154
|
+
json: booleanFlag(values, "json")
|
|
155
|
+
}, root);
|
|
181
156
|
} catch (cause) {
|
|
182
157
|
if (cause instanceof Ending) {
|
|
183
158
|
io.stderr.write(cause.sentence);
|
|
@@ -189,4 +164,4 @@ async function publish(argv, io, deps) {
|
|
|
189
164
|
const runPublish = (argv, io) => publish(argv, io, DEFAULT_DEPS);
|
|
190
165
|
|
|
191
166
|
//#endregion
|
|
192
|
-
export { DEFAULT_DEPS,
|
|
167
|
+
export { DEFAULT_DEPS, publish, runPublish };
|
|
@@ -1,74 +1,54 @@
|
|
|
1
|
+
import { compareVersions } from "../../packages/internal/template-artifact/dist/framework-floor.js";
|
|
1
2
|
import { maskToken } from "./target.js";
|
|
2
3
|
|
|
3
4
|
//#region src/cli/publish/report.ts
|
|
4
5
|
const LABEL_WIDTH = 9;
|
|
5
6
|
function stageLine(stage, text) {
|
|
6
|
-
return `${stage.padEnd(LABEL_WIDTH)}${text}\n`;
|
|
7
|
+
return `${(stage ?? "").padEnd(LABEL_WIDTH)}${text}\n`;
|
|
7
8
|
}
|
|
8
9
|
const shortHash = (hash) => hash.slice(0, 12);
|
|
9
|
-
function formatBytes(bytes) {
|
|
10
|
-
if (bytes < 1024) return `${String(bytes)} B`;
|
|
11
|
-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
12
|
-
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
13
|
-
}
|
|
14
10
|
const plural = (count, one, many) => `${String(count)} ${count === 1 ? one : many}`;
|
|
15
|
-
function
|
|
16
|
-
return `${target.environmentName} · key ${maskToken(target.
|
|
11
|
+
function consoleText(target) {
|
|
12
|
+
return `${target.environmentName} · team key ${maskToken(target.key)} · ${target.console}${target.overridden ? " (CONCRETE_CONSOLE_URL)" : ""}`;
|
|
13
|
+
}
|
|
14
|
+
function sendLines(answer) {
|
|
15
|
+
const { merge } = answer.merged;
|
|
16
|
+
const lines = [`version ${answer.merged.version} · ${answer.link}`];
|
|
17
|
+
for (const unit of merge.replaced) lines.push(`replaced on the console (it stays in the version before this one): ${unit.unit}`);
|
|
18
|
+
for (const unit of merge.kept) lines.push(`kept from the console (${unit.change} there): ${unit.unit}`);
|
|
19
|
+
for (const held of merge.held) lines.push(`kept ${held.unit}: ${held.fixtures.join(", ")} ${held.fixtures.length === 1 ? "is" : "are"} on it`);
|
|
20
|
+
return lines;
|
|
21
|
+
}
|
|
22
|
+
function behindText(frameworkVersion, consoleVersion) {
|
|
23
|
+
if (consoleVersion === null) return null;
|
|
24
|
+
const order = compareVersions(frameworkVersion, consoleVersion);
|
|
25
|
+
if (order === null || order >= 0) return null;
|
|
26
|
+
return `concrete publish: warning: this build's @homepages/concrete ${frameworkVersion} is older than the console's ${consoleVersion}; run \`concrete upgrade\` so the playground runs the build as the console would build it.\n`;
|
|
17
27
|
}
|
|
18
28
|
function builtText(manifest) {
|
|
19
29
|
return `built ${shortHash(manifest.template.content_hash)} · ${plural(manifest.sections.length, "section", "sections")} · check passed`;
|
|
20
30
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
template: entries[record.template_key],
|
|
28
|
-
sections: Object.entries(entries).filter(([key]) => key !== record.template_key).map(([, entry]) => entry)
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function isAlreadyCurrent(record) {
|
|
32
|
-
const { template, sections } = buildsOf(record);
|
|
33
|
-
return template !== void 0 && template.status === "unchanged" && sections.every((entry) => entry.status === "unchanged");
|
|
34
|
-
}
|
|
35
|
-
function sectionCounts(sections) {
|
|
36
|
-
const count = (status) => String(sections.filter((entry) => entry.status === status).length);
|
|
37
|
-
return `sections: ${count("new")} new, ${count("changed")} changed, ${count("unchanged")} unchanged`;
|
|
38
|
-
}
|
|
39
|
-
function writeText(record) {
|
|
40
|
-
const hash = shortHash(record.artifact_hash);
|
|
41
|
-
const { template, sections } = buildsOf(record);
|
|
42
|
-
if (record.state === "dry_run") {
|
|
43
|
-
if (template?.status === "new") return `would write template ${hash} as new · ${sectionCounts(sections)}`;
|
|
44
|
-
if (template?.status === "changed") return `would replace the template's build with ${hash} · ${sectionCounts(sections)}`;
|
|
45
|
-
return `would write nothing new · template build ${hash} is already current`;
|
|
46
|
-
}
|
|
47
|
-
if (isAlreadyCurrent(record)) return `already current · template build ${hash}`;
|
|
48
|
-
return `${template?.status === "new" ? `template ${hash} is new` : `template build ${hash} replaces the previous one`} · ${sectionCounts(sections)}`;
|
|
31
|
+
const PROBLEMS_SHOWN = 20;
|
|
32
|
+
function problemLines(problems) {
|
|
33
|
+
const lines = problems.slice(0, PROBLEMS_SHOWN).map((problem) => ` ${problem.path}: ${problem.message}`);
|
|
34
|
+
if (problems.length > PROBLEMS_SHOWN) lines.push(` …and ${String(problems.length - PROBLEMS_SHOWN)} more`);
|
|
35
|
+
return lines;
|
|
49
36
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const checked = plural(summary.scanned, "deliverable checked", "deliverables checked");
|
|
54
|
-
if (summary.enqueued === 0) return `no deliverable to move · ${checked}`;
|
|
55
|
-
return `${plural(summary.enqueued, "deliverable", "deliverables")} adopting this build · ${checked}`;
|
|
37
|
+
function verdictText(verdict) {
|
|
38
|
+
if (verdict.passed) return `passed · platform ${verdict.platform} loads and renders every section`;
|
|
39
|
+
return `failed · platform ${verdict.platform} did not load the build (${plural(verdict.problems.length, "problem", "problems")})`;
|
|
56
40
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
if (isAlreadyCurrent(record)) return `${record.template_key} is already current.`;
|
|
60
|
-
return `Published ${record.template_key}.`;
|
|
41
|
+
function notReleasedText(verdict) {
|
|
42
|
+
return `Not released. \`concrete release --version ${verdict.version}\` hands this build to the app.\n`;
|
|
61
43
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (problems.length > PROBLEMS_SHOWN) lines.push(` …and ${String(problems.length - PROBLEMS_SHOWN)} more`);
|
|
70
|
-
return `${lines.join("\n")}\n`;
|
|
44
|
+
function refusedText(verdict) {
|
|
45
|
+
return [
|
|
46
|
+
`concrete publish: refused: platform ${verdict.platform} did not load the build of version ${verdict.version}:`,
|
|
47
|
+
...problemLines(verdict.problems),
|
|
48
|
+
"concrete publish: the version stays on the console and its playground shows the build; fix the problems and run `concrete publish` again.",
|
|
49
|
+
""
|
|
50
|
+
].join("\n");
|
|
71
51
|
}
|
|
72
52
|
|
|
73
53
|
//#endregion
|
|
74
|
-
export {
|
|
54
|
+
export { behindText, builtText, consoleText, notReleasedText, problemLines, refusedText, sendLines, shortHash, stageLine, verdictText };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { fixtureFormat } from "../../packages/internal/playground/dist/fixture-formats.js";
|
|
2
|
+
import { CONSOLE_KEY_HEADER, CONTENT_ROUTE, SEND_ROUTE } from "../../packages/internal/playground/dist/send-wire.js";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
|
|
5
|
+
//#region src/cli/publish/send.ts
|
|
6
|
+
const UPLOAD_CONCURRENCY = 6;
|
|
7
|
+
const UPLOAD_ROUNDS = 3;
|
|
8
|
+
const fingerprintOf = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
9
|
+
const isObject = (value) => typeof value === "object" && value !== null;
|
|
10
|
+
function reasonOf(cause) {
|
|
11
|
+
if (cause instanceof Error) {
|
|
12
|
+
const code = cause.cause?.code;
|
|
13
|
+
return typeof code === "string" ? `${code}: ${cause.message}` : cause.message;
|
|
14
|
+
}
|
|
15
|
+
return String(cause);
|
|
16
|
+
}
|
|
17
|
+
async function sendTemplate(target, input, options = {}) {
|
|
18
|
+
const fetchFn = options.fetch ?? fetch;
|
|
19
|
+
const origin = target.console.replace(/\/+$/, "");
|
|
20
|
+
const sent = [...input.files].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
21
|
+
const byFingerprint = /* @__PURE__ */ new Map();
|
|
22
|
+
const files = sent.map(([path, bytes]) => {
|
|
23
|
+
const fingerprint = fingerprintOf(bytes);
|
|
24
|
+
byFingerprint.set(fingerprint, bytes);
|
|
25
|
+
return {
|
|
26
|
+
path,
|
|
27
|
+
fingerprint,
|
|
28
|
+
size: bytes.byteLength
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
const body = {
|
|
32
|
+
template: input.template,
|
|
33
|
+
framework_version: input.frameworkVersion,
|
|
34
|
+
files,
|
|
35
|
+
fixture_format: fixtureFormat(),
|
|
36
|
+
...input.source === void 0 ? {} : {
|
|
37
|
+
source_commit: input.source.commit,
|
|
38
|
+
source_remote: input.source.remote
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const headers = {
|
|
42
|
+
[CONSOLE_KEY_HEADER]: target.key,
|
|
43
|
+
accept: "application/json"
|
|
44
|
+
};
|
|
45
|
+
async function exchange(path, init) {
|
|
46
|
+
let response;
|
|
47
|
+
try {
|
|
48
|
+
response = await fetchFn(`${origin}${path}`, init);
|
|
49
|
+
} catch (cause) {
|
|
50
|
+
return {
|
|
51
|
+
kind: "unreachable",
|
|
52
|
+
reason: reasonOf(cause)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const text = await response.text();
|
|
56
|
+
let value = null;
|
|
57
|
+
if (text !== "") try {
|
|
58
|
+
value = JSON.parse(text);
|
|
59
|
+
} catch {
|
|
60
|
+
return {
|
|
61
|
+
kind: "unexpected",
|
|
62
|
+
status: response.status,
|
|
63
|
+
reason: "the answer is not JSON"
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (response.status >= 400) {
|
|
67
|
+
const refusal = isObject(value) && typeof value["detail"] === "string" && typeof value["code"] === "string" ? value : null;
|
|
68
|
+
return {
|
|
69
|
+
kind: "refused",
|
|
70
|
+
status: response.status,
|
|
71
|
+
refusal
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
status: response.status,
|
|
76
|
+
value
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const isAnswer = (value) => "kind" in value;
|
|
80
|
+
async function upload(fingerprint) {
|
|
81
|
+
const bytes = byFingerprint.get(fingerprint);
|
|
82
|
+
if (bytes === void 0) return {
|
|
83
|
+
kind: "unexpected",
|
|
84
|
+
status: 200,
|
|
85
|
+
reason: `the console asked for ${fingerprint}, which the send does not carry`
|
|
86
|
+
};
|
|
87
|
+
const answer = await exchange(`${CONTENT_ROUTE}${fingerprint}`, {
|
|
88
|
+
method: "PUT",
|
|
89
|
+
headers: {
|
|
90
|
+
...headers,
|
|
91
|
+
"content-type": "application/octet-stream"
|
|
92
|
+
},
|
|
93
|
+
body: bytes
|
|
94
|
+
});
|
|
95
|
+
return isAnswer(answer) ? answer : null;
|
|
96
|
+
}
|
|
97
|
+
for (let round = 0; round <= UPLOAD_ROUNDS; round++) {
|
|
98
|
+
const answer = await exchange(SEND_ROUTE, {
|
|
99
|
+
method: "POST",
|
|
100
|
+
headers: {
|
|
101
|
+
...headers,
|
|
102
|
+
"content-type": "application/json"
|
|
103
|
+
},
|
|
104
|
+
body: JSON.stringify(body)
|
|
105
|
+
});
|
|
106
|
+
if (isAnswer(answer)) return answer;
|
|
107
|
+
if (answer.status === 201 && isObject(answer.value) && typeof answer.value["link"] === "string") {
|
|
108
|
+
const merged = answer.value;
|
|
109
|
+
return {
|
|
110
|
+
kind: "merged",
|
|
111
|
+
merged,
|
|
112
|
+
link: new URL(merged.link, `${origin}/`).href
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
if (answer.status !== 200 || !isObject(answer.value) || !Array.isArray(answer.value["missing"])) return {
|
|
116
|
+
kind: "unexpected",
|
|
117
|
+
status: answer.status,
|
|
118
|
+
reason: "the answer is not the send's"
|
|
119
|
+
};
|
|
120
|
+
if (round === UPLOAD_ROUNDS) break;
|
|
121
|
+
const missing = answer.value.missing;
|
|
122
|
+
let done = 0;
|
|
123
|
+
const queue = [...missing];
|
|
124
|
+
const failures = [];
|
|
125
|
+
await Promise.all(Array.from({ length: Math.min(UPLOAD_CONCURRENCY, queue.length) }, async () => {
|
|
126
|
+
for (let next = queue.shift(); next !== void 0 && failures.length === 0; next = queue.shift()) {
|
|
127
|
+
const failed = await upload(next);
|
|
128
|
+
if (failed !== null) failures.push(failed);
|
|
129
|
+
else options.uploaded?.(++done, missing.length);
|
|
130
|
+
}
|
|
131
|
+
}));
|
|
132
|
+
if (failures.length > 0) return failures[0];
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
kind: "unexpected",
|
|
136
|
+
status: 200,
|
|
137
|
+
reason: `the console still lacked contents after ${String(UPLOAD_ROUNDS)} rounds of uploads`
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
export { sendTemplate };
|
|
@@ -2,19 +2,11 @@ import { join } from "node:path";
|
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
|
|
4
4
|
//#region src/cli/publish/target.ts
|
|
5
|
-
const TOKEN_VARIABLE = "CONCRETE_TOKEN";
|
|
6
|
-
const API_URL_VARIABLE = "CONCRETE_API_URL";
|
|
7
|
-
const ENDPOINTS = {
|
|
8
|
-
prod: "https://api.homepages.io",
|
|
9
|
-
staging: "https://api.homepages.christmas",
|
|
10
|
-
dev: "http://localhost:8000"
|
|
11
|
-
};
|
|
12
5
|
const ENVIRONMENT_NAMES = {
|
|
13
6
|
prod: "production",
|
|
14
7
|
staging: "staging",
|
|
15
8
|
dev: "dev"
|
|
16
9
|
};
|
|
17
|
-
const TOKEN = /^cpt_(prod|staging|dev)_[0-9A-Za-z]{43}$/;
|
|
18
10
|
var TargetError = class extends Error {};
|
|
19
11
|
function parseDotenv(text) {
|
|
20
12
|
const values = /* @__PURE__ */ new Map();
|
|
@@ -40,7 +32,7 @@ async function readWorkspaceDotenv(root) {
|
|
|
40
32
|
}
|
|
41
33
|
}
|
|
42
34
|
function maskToken(token) {
|
|
43
|
-
return `${/^
|
|
35
|
+
return `${/^cck_[a-z]+_/.exec(token)?.[0] ?? ""}…${token.slice(-4)}`;
|
|
44
36
|
}
|
|
45
37
|
async function readNamedDotenv(file) {
|
|
46
38
|
try {
|
|
@@ -50,41 +42,51 @@ async function readNamedDotenv(file) {
|
|
|
50
42
|
throw cause;
|
|
51
43
|
}
|
|
52
44
|
}
|
|
53
|
-
async function
|
|
45
|
+
async function variableReader(root, env, envFile) {
|
|
54
46
|
const named = envFile === void 0 ? /* @__PURE__ */ new Map() : await readNamedDotenv(envFile);
|
|
55
47
|
const dotenv = envFile === void 0 ? await readWorkspaceDotenv(root) : /* @__PURE__ */ new Map();
|
|
56
|
-
|
|
48
|
+
return (name) => {
|
|
57
49
|
const value = named.get(name) ?? env[name] ?? dotenv.get(name);
|
|
58
50
|
return value === void 0 || value.trim() === "" ? void 0 : value.trim();
|
|
59
51
|
};
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
}
|
|
53
|
+
function overrideOrigin(variable, value, example) {
|
|
54
|
+
let url;
|
|
55
|
+
try {
|
|
56
|
+
url = new URL(value);
|
|
57
|
+
} catch {
|
|
58
|
+
throw new TargetError(`${variable} is not a URL ("${value}"); set it to an origin such as ${example}, or unset it.`);
|
|
59
|
+
}
|
|
60
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") throw new TargetError(`${variable} must be an http or https URL ("${value}"); set it to an origin such as ${example}, or unset it.`);
|
|
61
|
+
return value.replace(/\/+$/, "");
|
|
62
|
+
}
|
|
63
|
+
const CONSOLE_KEY_VARIABLE = "CONCRETE_CONSOLE_KEY";
|
|
64
|
+
const CONSOLE_URL_VARIABLE = "CONCRETE_CONSOLE_URL";
|
|
65
|
+
const CONSOLES = {
|
|
66
|
+
prod: "https://console.homepages.io",
|
|
67
|
+
staging: "https://console.homepages.christmas",
|
|
68
|
+
dev: "http://console.localhost:8010"
|
|
69
|
+
};
|
|
70
|
+
const CONSOLE_KEY = /^cck_(prod|staging|dev)_[0-9A-Za-z]{43}$/;
|
|
71
|
+
async function resolveConsoleTarget(root, env, envFile) {
|
|
72
|
+
const read = await variableReader(root, env, envFile);
|
|
73
|
+
const key = read(CONSOLE_KEY_VARIABLE);
|
|
74
|
+
if (key === void 0) {
|
|
62
75
|
const where = envFile === void 0 ? "in the environment or in this workspace's .env" : `in ${envFile}`;
|
|
63
|
-
throw new TargetError(`${
|
|
76
|
+
throw new TargetError(`${CONSOLE_KEY_VARIABLE} is not set; set it ${where} to your team's console key.`);
|
|
64
77
|
}
|
|
65
|
-
const match =
|
|
66
|
-
if (match === null) throw new TargetError(`${
|
|
78
|
+
const match = CONSOLE_KEY.exec(key);
|
|
79
|
+
if (match === null) throw new TargetError(`${CONSOLE_KEY_VARIABLE} is not a console key (a key reads cck_prod_…, cck_staging_… or cck_dev_… followed by 43 letters and digits); set it to your team's console key.`);
|
|
67
80
|
const environment = match[1];
|
|
68
|
-
const override = read(
|
|
69
|
-
let endpoint = ENDPOINTS[environment];
|
|
70
|
-
if (override !== void 0) {
|
|
71
|
-
let url;
|
|
72
|
-
try {
|
|
73
|
-
url = new URL(override);
|
|
74
|
-
} catch {
|
|
75
|
-
throw new TargetError(`${API_URL_VARIABLE} is not a URL ("${override}"); set it to an API origin such as http://localhost:8000, or unset it.`);
|
|
76
|
-
}
|
|
77
|
-
if (url.protocol !== "http:" && url.protocol !== "https:") throw new TargetError(`${API_URL_VARIABLE} must be an http or https URL ("${override}"); set it to an API origin, or unset it.`);
|
|
78
|
-
endpoint = override;
|
|
79
|
-
}
|
|
81
|
+
const override = read(CONSOLE_URL_VARIABLE);
|
|
80
82
|
return {
|
|
81
83
|
environment,
|
|
82
84
|
environmentName: ENVIRONMENT_NAMES[environment],
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
key,
|
|
86
|
+
console: override === void 0 ? CONSOLES[environment] : overrideOrigin(CONSOLE_URL_VARIABLE, override, "http://console.localhost:8010"),
|
|
85
87
|
overridden: override !== void 0
|
|
86
88
|
};
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
//#endregion
|
|
90
|
-
export {
|
|
92
|
+
export { CONSOLES, CONSOLE_KEY_VARIABLE, CONSOLE_URL_VARIABLE, TargetError, maskToken, parseDotenv, resolveConsoleTarget };
|