@valbuild/cli 0.132.1 → 0.134.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 +113 -0
- package/cli/dist/valbuild-cli-cli.cjs.dev.js +1428 -1
- package/cli/dist/valbuild-cli-cli.cjs.prod.js +1428 -1
- package/cli/dist/valbuild-cli-cli.esm.js +1426 -1
- package/package.json +7 -5
- package/src/cli.ts +51 -0
- package/src/debug/context.ts +1 -2
- package/src/publish/artifacts.ts +194 -0
- package/src/publish/client.ts +177 -0
- package/src/publish/contentApi.ts +210 -0
- package/src/publish/contentHost.ts +160 -0
- package/src/publish/credentials.test.ts +348 -0
- package/src/publish/credentials.ts +258 -0
- package/src/publish/fakeContent.ts +482 -0
- package/src/publish/protocol.ts +174 -0
- package/src/publish/publishWireContract.test.ts +292 -0
- package/src/publish/runPublish.test.ts +536 -0
- package/src/publish/runPublish.ts +633 -0
- package/src/publish.ts +112 -0
package/src/publish.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
import { error } from "./logger";
|
|
3
|
+
import { PublishProblem } from "./publish/protocol";
|
|
4
|
+
import { formatBytes, runPublish } from "./publish/runPublish";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `val publish` - a built project in, a live site out.
|
|
8
|
+
*
|
|
9
|
+
* A thin shell around `runPublish`: everything it decides is decided there,
|
|
10
|
+
* and everything colourful happens here. A CI job reads the exit code, a
|
|
11
|
+
* person reads the lines.
|
|
12
|
+
*/
|
|
13
|
+
export async function publish(options: {
|
|
14
|
+
root?: string;
|
|
15
|
+
artifacts?: string;
|
|
16
|
+
commit?: string;
|
|
17
|
+
branch?: string;
|
|
18
|
+
layerRev?: string;
|
|
19
|
+
buildHash?: string;
|
|
20
|
+
linksOwnCss?: boolean;
|
|
21
|
+
dryRun?: boolean;
|
|
22
|
+
}): Promise<void> {
|
|
23
|
+
const result = await runPublish({
|
|
24
|
+
...(options.root ? { root: options.root } : {}),
|
|
25
|
+
...(options.artifacts ? { artifacts: options.artifacts } : {}),
|
|
26
|
+
...(options.commit ? { commit: options.commit } : {}),
|
|
27
|
+
...(options.branch ? { branch: options.branch } : {}),
|
|
28
|
+
...(options.layerRev ? { layerRev: options.layerRev } : {}),
|
|
29
|
+
...(options.buildHash ? { buildHash: options.buildHash } : {}),
|
|
30
|
+
...(options.linksOwnCss === undefined
|
|
31
|
+
? {}
|
|
32
|
+
: { linksOwnCss: options.linksOwnCss }),
|
|
33
|
+
...(options.dryRun ? { dryRun: options.dryRun } : {}),
|
|
34
|
+
log: (line) => console.log(pc.dim(line)),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
switch (result.status) {
|
|
38
|
+
case "live":
|
|
39
|
+
case "verified": {
|
|
40
|
+
const uploaded =
|
|
41
|
+
result.uploaded === 0
|
|
42
|
+
? "nothing new to upload"
|
|
43
|
+
: `${result.uploaded} uploaded, ${formatBytes(result.uploadedBytes)}`;
|
|
44
|
+
console.log(
|
|
45
|
+
pc.green(
|
|
46
|
+
result.status === "live"
|
|
47
|
+
? "✅ Published"
|
|
48
|
+
: "✅ Verified (not published: --dry-run)",
|
|
49
|
+
) +
|
|
50
|
+
pc.dim(
|
|
51
|
+
` — ${result.artifacts} artifact${result.artifacts === 1 ? "" : "s"}, ${uploaded}`,
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
if (result.status === "live" && result.url) {
|
|
55
|
+
console.log(pc.cyan(result.url));
|
|
56
|
+
}
|
|
57
|
+
if (result.previewUrl) {
|
|
58
|
+
console.log(pc.dim("Canary: ") + pc.cyan(result.previewUrl));
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
case "failed": {
|
|
63
|
+
error(result.message);
|
|
64
|
+
for (const problem of result.problems) {
|
|
65
|
+
printProblem(problem);
|
|
66
|
+
}
|
|
67
|
+
if (result.previewUrl) {
|
|
68
|
+
console.error(pc.dim("Canary: ") + pc.cyan(result.previewUrl));
|
|
69
|
+
}
|
|
70
|
+
if (result.publishId) {
|
|
71
|
+
console.error(
|
|
72
|
+
pc.dim(
|
|
73
|
+
`Publish ${result.publishId}${result.state ? ` is "${result.state}"` : ""}.`,
|
|
74
|
+
),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
process.exitCode = 1;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
case "error": {
|
|
81
|
+
error(result.message);
|
|
82
|
+
process.exitCode = 1;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* A problem, as content wrote it.
|
|
90
|
+
*
|
|
91
|
+
* Verbatim, including the codes the build platform passed through: content
|
|
92
|
+
* knows what went wrong with the canary and this does not, so rewording can
|
|
93
|
+
* only lose the sentence that says what to change. The hint is printed for the
|
|
94
|
+
* same reason - a gate that merely fails is useless.
|
|
95
|
+
*/
|
|
96
|
+
function printProblem(problem: PublishProblem) {
|
|
97
|
+
console.error(
|
|
98
|
+
pc.red(problem.code ? ` ${problem.code}: ` : " ") + problem.message,
|
|
99
|
+
);
|
|
100
|
+
const keys = problem.keys ?? [];
|
|
101
|
+
if (keys.length > 0) {
|
|
102
|
+
const shown = keys.slice(0, 10).join(", ");
|
|
103
|
+
console.error(
|
|
104
|
+
pc.dim(
|
|
105
|
+
` ${shown}${keys.length > 10 ? `, and ${keys.length - 10} more` : ""}`,
|
|
106
|
+
),
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (problem.hint) {
|
|
110
|
+
console.error(pc.dim(` ${problem.hint}`));
|
|
111
|
+
}
|
|
112
|
+
}
|