shiplane 0.5.2 → 0.6.0-fix-shiplane-ship-node-cache.3dccda9
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 +1 -1
- package/dist/cli.js +157 -312
- package/dist/cli.js.map +1 -1
- package/dist/{readStatus-DypM0faL.js → compose-BTQXZqHM.js} +2758 -1448
- package/dist/compose-BTQXZqHM.js.map +1 -0
- package/dist/{budget-BTnKtGF6.js → display-CfV4G1TR.js} +155 -52
- package/dist/display-CfV4G1TR.js.map +1 -0
- package/dist/{static-hosting.port-B5i6W7eD.d.ts → index-B1Rd22nM.d.ts} +482 -21
- package/dist/index.d.ts +2 -3
- package/dist/index.js +3 -4
- package/dist/{issues-TcWtMTv5.js → issues-DCRpXUBW.js} +1 -1
- package/dist/{issues-TcWtMTv5.js.map → issues-DCRpXUBW.js.map} +1 -1
- package/dist/memory.d.ts +1 -1
- package/dist/memory.js +1 -1
- package/dist/{package-registry.fake-BLBdd7IQ.d.ts → package-registry.fake-CjoePEzE.d.ts} +53 -6
- package/dist/{package-registry.fake-CN6M1-Gi.js → package-registry.fake-ykiSBd8M.js} +58 -6
- package/dist/package-registry.fake-ykiSBd8M.js.map +1 -0
- package/dist/plugin-D-JQhwVd.d.ts +118 -0
- package/dist/plugin.d.ts +3 -23
- package/dist/plugin.js +84 -7
- package/dist/plugin.js.map +1 -0
- package/dist/shell-server-hosting.adapter-CvOcC6Wh.js +369 -0
- package/dist/shell-server-hosting.adapter-CvOcC6Wh.js.map +1 -0
- package/dist/{src-DO7WyrfV.js → src-8BbKTQBb.js} +2 -2
- package/dist/src-8BbKTQBb.js.map +1 -0
- package/dist/testing.d.ts +103 -18
- package/dist/testing.js +235 -22
- package/dist/testing.js.map +1 -1
- package/package.json +2 -1
- package/dist/budget-BTnKtGF6.js.map +0 -1
- package/dist/display-IqkJ6uCw.js +0 -96
- package/dist/display-IqkJ6uCw.js.map +0 -1
- package/dist/index-C_urG4yY.d.ts +0 -252
- package/dist/package-registry.fake-CN6M1-Gi.js.map +0 -1
- package/dist/readStatus-DypM0faL.js.map +0 -1
- package/dist/shell-server-hosting.adapter-C7_5MWrl.js +0 -50
- package/dist/shell-server-hosting.adapter-C7_5MWrl.js.map +0 -1
- package/dist/src-DO7WyrfV.js.map +0 -1
- package/dist/web-app.module-BB1fY1Kd.js +0 -125
- package/dist/web-app.module-BB1fY1Kd.js.map +0 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ flowchart LR
|
|
|
16
16
|
## ⚡ Three commands
|
|
17
17
|
|
|
18
18
|
```sh
|
|
19
|
-
pnpm shiplane
|
|
19
|
+
pnpm shiplane setup # find what ships, rehearse, write the config
|
|
20
20
|
pnpm shiplane # release PR, merge, tags, ship to preview
|
|
21
21
|
pnpm shiplane promote # what preview validated, to production
|
|
22
22
|
```
|
package/dist/cli.js
CHANGED
|
@@ -1,309 +1,92 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as
|
|
3
|
-
import { C as refreshEditorSchema, D as keysAt, E as ENVIRONMENTS, O as nodeFiles, _ as loadRelease, a as releaseToPreview, b as initRelease, c as promote, d as pickScope, f as openReleasePr, g as findConfig, h as docsFor, i as setup, l as shipTo, m as newAdapter, n as systemShell, o as missingTags, p as prepareRelease, r as liveLine, s as tagRelease, t as readStatus, u as planShips, v as addUnit, w as environmentLabel, x as doctor, y as removeUnit } from "./readStatus-DypM0faL.js";
|
|
4
|
-
import { n as resolveDisplay, t as progressBar } from "./display-IqkJ6uCw.js";
|
|
5
|
-
import { createRequire } from "node:module";
|
|
2
|
+
import { A as commandLine, C as initRelease, D as checkStatus, E as refreshEditorSchema, F as keysAt, I as nodeFiles, N as paint, O as requirementsOf, P as ENVIRONMENTS, S as removeUnit, _ as tagRelease, a as findConfig, b as prepareRelease, c as promote, d as docsFor, f as branchRelease, g as missingTags, h as readStatus, j as environmentLabel, k as signInsOf, l as planShips, m as shipTo, n as composeSetup, r as loadReleaseOnDisk, s as setup, t as composeContext, u as newAdapter, v as pickScope, w as doctor, x as addUnit, y as openReleasePr } from "./compose-BTQXZqHM.js";
|
|
6
3
|
import { z } from "zod";
|
|
7
4
|
import fs from "node:fs";
|
|
8
5
|
import path from "node:path";
|
|
9
|
-
import { parseArgs
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const face = frame.slice(5, 10).join("");
|
|
27
|
-
return `${styleText("yellow", frame.slice(0, 5).join(""))}${styleText(mood === "happy" ? ["bold", "green"] : "bold", face)}${styleText("cyan", frame.slice(10).join(""))}`;
|
|
28
|
-
};
|
|
29
|
-
const elapsed = (since) => {
|
|
30
|
-
const seconds = Math.round((Date.now() - since) / 1e3);
|
|
31
|
-
return seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m ${String(seconds % 60).padStart(2, "0")}s`;
|
|
32
|
-
};
|
|
33
|
-
/** Cuts `text` to what the terminal shows on one line, so redrawing it in place stays clean. */
|
|
34
|
-
const fit = (text, taken) => {
|
|
35
|
-
const room = Math.max(20, (process.stdout.columns || 100) - taken);
|
|
36
|
-
return text.length > room ? `${text.slice(0, room - 1)}…` : text;
|
|
37
|
-
};
|
|
38
|
-
const counterOf = (step) => step && "index" in step ? `${step.index + 1}/${step.total} ` : "";
|
|
39
|
-
const batchOf = (step) => step && "done" in step ? step : null;
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
//#region src/application/doctorCi.ts
|
|
8
|
+
/** Where every check a runner makes is listed, with what it supports. */
|
|
9
|
+
const WORKFLOW_DOCS = "https://github.com/arnaud-zg/js-packages/blob/main/docs/shiplane/reference.md#github-actions-workflow";
|
|
10
|
+
/** The units a run names, each one the config's. */
|
|
11
|
+
const unitsSchema = (known) => z.array(z.string()).superRefine((names, context) => {
|
|
12
|
+
const unknown = names.filter((name) => !known.includes(name));
|
|
13
|
+
if (unknown.length > 0) context.addIssue({
|
|
14
|
+
code: "custom",
|
|
15
|
+
message: `unknown units [${unknown.join(", ")}]: known [${known.join(", ")}]`
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
const environmentSchema = z.enum(ENVIRONMENTS, { error: ({ input }) => `unknown environment "${String(input)}": ${ENVIRONMENTS.join(", ")}` });
|
|
19
|
+
/** The first problem a schema found, as said. */
|
|
20
|
+
const problemOf = (error) => error.issues[0]?.message ?? "invalid";
|
|
21
|
+
/** `$NAME` and `${NAME}` read from the environment, such as `$HOME/.fly/bin`. */
|
|
22
|
+
const expand = (context, text) => text.replace(/\$\{?(\w+)\}?/g, (_, name) => context.shell.env(name) ?? "");
|
|
40
23
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* gets plain lines, never a redraw.
|
|
24
|
+
* A missing tool installed, its folder put first on PATH for this run and, through `GITHUB_PATH`,
|
|
25
|
+
* for the steps after it. The problem, or null once it answers.
|
|
44
26
|
*/
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return work();
|
|
61
|
-
}
|
|
62
|
-
const text = fit(label, taken(step));
|
|
63
|
-
if (!inPlace || liveLine.busy) {
|
|
64
|
-
liveLine.above(` ${mascot(mood, 0, label)}${counter}${text}`);
|
|
65
|
-
return work();
|
|
66
|
-
}
|
|
67
|
-
const started = Date.now();
|
|
68
|
-
const time = () => styleText("dim", `${batch ? `${batch.done()}/${batch.total} ` : ""}${elapsed(started)}`);
|
|
69
|
-
const drawing = display.mascot;
|
|
70
|
-
liveLine.show({
|
|
71
|
-
...drawing ? { frames: Array.from({ length: display.motion ? drawing.frames(mood) : 1 }, (_, tick) => paintMascot(drawing, {
|
|
72
|
-
mood,
|
|
73
|
-
tick,
|
|
74
|
-
label
|
|
75
|
-
})) } : {},
|
|
76
|
-
text: `${counter}${text}`,
|
|
77
|
-
suffix: time
|
|
78
|
-
}, true);
|
|
79
|
-
try {
|
|
80
|
-
const result = await work();
|
|
81
|
-
liveLine.finish(` ${styleText("green", "✓")}`, `${counter}${text} ${time()}`);
|
|
82
|
-
return result;
|
|
83
|
-
} catch (error) {
|
|
84
|
-
liveLine.finish(` ${styleText("red", "✗")}`, `${counter}${text} ${time()}`);
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
return {
|
|
89
|
-
stage: (stages, index) => {
|
|
90
|
-
if (!display.verbose) return;
|
|
91
|
-
const bar = styleText("green", progressBar(index + 1, stages.length, 18));
|
|
92
|
-
liveLine.above("");
|
|
93
|
-
liveLine.above(` ${bar} ${styleText("dim", `${index + 1}/${stages.length}`)} ${styleText("bold", stages[index] ?? "")}`);
|
|
94
|
-
},
|
|
95
|
-
during,
|
|
96
|
-
say: (mood, text) => liveLine.above(display.mascot ? ` ${mascot(mood, 0, text)}${text}` : text)
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
//#endregion
|
|
100
|
-
//#region src/adapters/terminal/terminal.adapter.ts
|
|
101
|
-
const terminalOutput = { line: (line = "") => liveLine.above(line) };
|
|
102
|
-
/** Whether this process runs inside a GitHub Actions job. */
|
|
103
|
-
const onGitHubActions = () => process.env.GITHUB_ACTIONS === "true";
|
|
104
|
-
const systemClock = {
|
|
105
|
-
now: () => /* @__PURE__ */ new Date(),
|
|
106
|
-
sleep: async (ms) => {
|
|
107
|
-
await setTimeout$1(ms);
|
|
27
|
+
const install = async (context, requirement) => {
|
|
28
|
+
const { shell, files, root } = context;
|
|
29
|
+
const { label, install: how } = requirement;
|
|
30
|
+
if (!how) return `${label} missing and no install for linux`;
|
|
31
|
+
const { command } = how;
|
|
32
|
+
const status = await shell.attach(command.command, command.args, {
|
|
33
|
+
cwd: path.join(root, command.cwd ?? ""),
|
|
34
|
+
env: command.env
|
|
35
|
+
});
|
|
36
|
+
if (status !== 0) return `${label} install failed: ${commandLine(command)} exited with ${status}`;
|
|
37
|
+
if (how.path !== void 0) {
|
|
38
|
+
const dir = expand(context, how.path);
|
|
39
|
+
shell.prependPath?.(dir);
|
|
40
|
+
const githubPath = shell.env("GITHUB_PATH");
|
|
41
|
+
if (githubPath) files.append(githubPath, `${dir}\n`);
|
|
108
42
|
}
|
|
43
|
+
return await checkStatus(shell, root, requirement) === 127 ? `${label} still missing after ${commandLine(command)}` : null;
|
|
109
44
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
];
|
|
122
|
-
/** A spinner, or the mascot waiting, on one line until a listed key is pressed or `ms` pass. Ctrl-C ends the process. */
|
|
123
|
-
const waitForKey = (display, label, ms, keys) => new Promise((resolve) => {
|
|
124
|
-
const startedAt = Date.now();
|
|
125
|
-
let frame = 0;
|
|
126
|
-
const draw = () => {
|
|
127
|
-
const seconds = Math.round((Date.now() - startedAt) / 1e3);
|
|
128
|
-
const tick = frame++;
|
|
129
|
-
const glyph = display.mascot ? paintMascot(display.mascot, {
|
|
130
|
-
mood: "waiting",
|
|
131
|
-
tick: display.motion ? Math.floor(tick / 5) : 0,
|
|
132
|
-
label
|
|
133
|
-
}) : styleText("cyan", FRAMES[tick % FRAMES.length] ?? "");
|
|
134
|
-
process.stdout.write(`\r ${glyph} ${label} ${styleText("dim", `${seconds}s`)}`);
|
|
135
|
-
};
|
|
136
|
-
const timer = setInterval(draw, 80);
|
|
137
|
-
const finish = (key) => {
|
|
138
|
-
clearInterval(timer);
|
|
139
|
-
clearTimeout(timeout);
|
|
140
|
-
process.stdin.off("keypress", onKey);
|
|
141
|
-
process.stdin.setRawMode(false);
|
|
142
|
-
process.stdin.pause();
|
|
143
|
-
process.stdout.write("\r\x1B[2K");
|
|
144
|
-
resolve(key);
|
|
145
|
-
};
|
|
146
|
-
const onKey = (_text, key) => {
|
|
147
|
-
if (key?.ctrl && key.name === "c") {
|
|
148
|
-
finish(null);
|
|
149
|
-
process.stdout.write(`${styleText("dim", " Stopped waiting. release picks up right here.")}\n`);
|
|
150
|
-
process.exit(130);
|
|
151
|
-
}
|
|
152
|
-
if (key?.name && keys.includes(key.name)) finish(key.name);
|
|
153
|
-
};
|
|
154
|
-
const timeout = setTimeout(() => finish(null), ms);
|
|
155
|
-
emitKeypressEvents(process.stdin);
|
|
156
|
-
process.stdin.setRawMode(true);
|
|
157
|
-
process.stdin.resume();
|
|
158
|
-
process.stdin.on("keypress", onKey);
|
|
159
|
-
});
|
|
160
|
-
const asOptions = (choices) => choices;
|
|
161
|
-
const orNull = (answer) => isCancel(answer) ? null : answer;
|
|
162
|
-
const NO_MASCOT = {
|
|
163
|
-
verbose: false,
|
|
164
|
-
mascot: null,
|
|
165
|
-
motion: false
|
|
166
|
-
};
|
|
167
|
-
/** Questions through @clack/prompts, each owning the terminal; without one, every answer is no. */
|
|
168
|
-
const terminalPrompter = (display = NO_MASCOT) => {
|
|
169
|
-
const interactive = Boolean(process.stdin.isTTY);
|
|
170
|
-
const hold = (work) => liveLine.hold(work);
|
|
171
|
-
return {
|
|
172
|
-
interactive,
|
|
173
|
-
confirm: (question, initial = false) => hold(async () => interactive && orNull(await confirm({
|
|
174
|
-
message: question,
|
|
175
|
-
initialValue: initial
|
|
176
|
-
})) === true),
|
|
177
|
-
typed: (question, word) => hold(async () => {
|
|
178
|
-
if (!interactive) return false;
|
|
179
|
-
const prompt = createInterface({
|
|
180
|
-
input: process.stdin,
|
|
181
|
-
output: process.stdout
|
|
182
|
-
});
|
|
183
|
-
const answer = await prompt.question(`${styleText("bold", question)} `);
|
|
184
|
-
prompt.close();
|
|
185
|
-
return answer.trim() === word;
|
|
186
|
-
}),
|
|
187
|
-
select: (message, choices, initial) => hold(async () => interactive ? orNull(await select({
|
|
188
|
-
message,
|
|
189
|
-
options: asOptions(choices),
|
|
190
|
-
initialValue: initial
|
|
191
|
-
})) : null),
|
|
192
|
-
multiselect: (message, choices, initial) => hold(async () => interactive ? orNull(await multiselect({
|
|
193
|
-
message,
|
|
194
|
-
options: asOptions(choices),
|
|
195
|
-
initialValues: initial,
|
|
196
|
-
required: false
|
|
197
|
-
})) : null),
|
|
198
|
-
text: (message, initial) => hold(async () => interactive ? orNull(await text({
|
|
199
|
-
message,
|
|
200
|
-
initialValue: initial
|
|
201
|
-
})) : null),
|
|
202
|
-
waitForKey: (label, ms, keys) => hold(async () => {
|
|
203
|
-
if (interactive) return waitForKey(display, label, ms, keys);
|
|
204
|
-
await setTimeout$1(ms);
|
|
205
|
-
return null;
|
|
206
|
-
})
|
|
207
|
-
};
|
|
208
|
-
};
|
|
209
|
-
//#endregion
|
|
210
|
-
//#region src/cli/plugins.ts
|
|
211
|
-
const readJson = (file) => JSON.parse(fs.readFileSync(file, "utf8"));
|
|
212
|
-
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
45
|
+
/** Each secret a requirement names that this run does not hold, as said. */
|
|
46
|
+
const missing = (context, who, requirements) => requirements.flatMap(({ label, secrets = [] }) => secrets.filter((name) => !context.shell.env(name)).map((name) => ({
|
|
47
|
+
who,
|
|
48
|
+
label,
|
|
49
|
+
name
|
|
50
|
+
})));
|
|
51
|
+
/** Every secret the picked units and the flow need that this run does not hold, in release order. */
|
|
52
|
+
const missingSecrets = (context, release, picked) => [...release.units.filter(({ name }) => picked.has(name)).flatMap((unit) => {
|
|
53
|
+
const provider = release.modules.find(({ name }) => name === unit.module)?.provider;
|
|
54
|
+
return missing(context, `${unit.name} ships with ${provider ?? unit.module}`, signInsOf(release, new Set([unit.name])));
|
|
55
|
+
}), ...requirementsOf(release, /* @__PURE__ */ new Set()).flatMap((requirement) => missing(context, `shiplane needs ${requirement.label}`, [requirement]))];
|
|
213
56
|
/**
|
|
214
|
-
*
|
|
215
|
-
*
|
|
57
|
+
* `shiplane doctor --ci`: what a runner checks before it ships, in order, stopping at the first
|
|
58
|
+
* problem: the units, the environment, each tool (installed when missing), each secret.
|
|
216
59
|
*/
|
|
217
|
-
const
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
});
|
|
225
|
-
const require = createRequire(manifestFile);
|
|
226
|
-
return [...(await Promise.all(names.map(async (name) => {
|
|
227
|
-
try {
|
|
228
|
-
const factories = readJson(require.resolve(`${name}/package.json`)).shiplane?.adapters ?? [];
|
|
229
|
-
if (factories.length === 0) return [];
|
|
230
|
-
const loaded = await import(pathToFileURL(require.resolve(name)).href);
|
|
231
|
-
if (!isRecord(loaded)) return [];
|
|
232
|
-
return factories.flatMap((factory) => {
|
|
233
|
-
const make = loaded[factory];
|
|
234
|
-
return typeof make === "function" ? [make()] : [];
|
|
235
|
-
});
|
|
236
|
-
} catch {
|
|
237
|
-
return [];
|
|
238
|
-
}
|
|
239
|
-
}))).flat(), shellServerHosting()];
|
|
240
|
-
};
|
|
241
|
-
//#endregion
|
|
242
|
-
//#region src/cli/compose.ts
|
|
243
|
-
/** Creates each port the flow runs on, for this repository. */
|
|
244
|
-
const composeServices = (release, open) => ({
|
|
245
|
-
sourceControl: open(release.flow.sourceControl),
|
|
246
|
-
codeHost: open(release.flow.codeHost),
|
|
247
|
-
ciPipeline: open(release.flow.ciPipeline),
|
|
248
|
-
versioning: open(release.flow.versioning)
|
|
249
|
-
});
|
|
250
|
-
/** Ports created on demand, in this repository, through this shell. */
|
|
251
|
-
const opener = (root, shell) => (adapter) => adapter.create({
|
|
252
|
-
root,
|
|
253
|
-
shell
|
|
254
|
-
});
|
|
255
|
-
/** A context wired to this machine: its shell, its terminal, its clock, unless `io` says otherwise. */
|
|
256
|
-
const composeContext = (release, { yes, display: flags }, io = {}) => {
|
|
257
|
-
const ci = onGitHubActions() || systemShell.env("CI") === "true";
|
|
258
|
-
const tty = Boolean(process.stdout.isTTY);
|
|
259
|
-
const display = resolveDisplay(release.display ?? {}, flags, {
|
|
260
|
-
tty,
|
|
261
|
-
ci,
|
|
262
|
-
noMotion: Boolean(systemShell.env("NO_MOTION"))
|
|
263
|
-
});
|
|
264
|
-
const shell = io.shell ?? systemShell;
|
|
265
|
-
const output = io.output ?? terminalOutput;
|
|
266
|
-
const open = opener(release.root, shell);
|
|
267
|
-
return {
|
|
268
|
-
release,
|
|
269
|
-
load: () => loadRelease(release.root, { aliases: io.aliases }),
|
|
270
|
-
services: composeServices(release, open),
|
|
271
|
-
open,
|
|
272
|
-
prompter: io.prompter ?? terminalPrompter(display),
|
|
273
|
-
output,
|
|
274
|
-
progress: io.progress ?? terminalProgress(display, tty && !ci),
|
|
275
|
-
clock: systemClock,
|
|
276
|
-
shell,
|
|
277
|
-
options: {
|
|
278
|
-
yes,
|
|
279
|
-
ci: onGitHubActions()
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
};
|
|
283
|
-
/** What init, add, doctor and the rest need: the repository on disk and the adapters installed. */
|
|
284
|
-
const composeSetup = async (root, io = {}) => {
|
|
285
|
-
const ci = onGitHubActions() || systemShell.env("CI") === "true";
|
|
286
|
-
const tty = Boolean(process.stdout.isTTY);
|
|
287
|
-
const display = resolveDisplay({}, { mascot: false }, {
|
|
288
|
-
tty,
|
|
289
|
-
ci,
|
|
290
|
-
noMotion: Boolean(systemShell.env("NO_MOTION"))
|
|
291
|
-
});
|
|
292
|
-
return {
|
|
293
|
-
root,
|
|
294
|
-
files: nodeFiles(root),
|
|
295
|
-
shell: systemShell,
|
|
296
|
-
prompter: terminalPrompter(),
|
|
297
|
-
output: terminalOutput,
|
|
298
|
-
adapters: io.adapters ?? await installedAdapters(root),
|
|
299
|
-
load: () => loadRelease(root),
|
|
300
|
-
progress: terminalProgress(display, tty && !ci),
|
|
301
|
-
compose: (release) => composeContext(release, {
|
|
302
|
-
yes: true,
|
|
303
|
-
display: { mascot: false }
|
|
304
|
-
}),
|
|
305
|
-
...io
|
|
60
|
+
const doctorCi = async (context, { units, channel }) => {
|
|
61
|
+
const { output, shell, root } = context;
|
|
62
|
+
const passed = (check, detail) => output.line(`${paint("green", "✓")} ${check} ${paint("dim", detail)}`);
|
|
63
|
+
const stop = (problem) => {
|
|
64
|
+
output.line(`${paint("red", "✗")} ${problem}`);
|
|
65
|
+
output.line(` ${paint("dim", WORKFLOW_DOCS)}`);
|
|
66
|
+
return false;
|
|
306
67
|
};
|
|
68
|
+
const release = await context.load();
|
|
69
|
+
const [problem] = release.problems;
|
|
70
|
+
if (problem) return stop(`${problem.line === void 0 ? problem.file : `${problem.file}:${problem.line}`}: ${problem.message}`);
|
|
71
|
+
const known = release.units.map(({ name }) => name);
|
|
72
|
+
const named = unitsSchema(known).safeParse(units.length > 0 ? units : known);
|
|
73
|
+
if (!named.success) return stop(problemOf(named.error));
|
|
74
|
+
passed("units", named.data.join(", "));
|
|
75
|
+
const environment = environmentSchema.safeParse(channel);
|
|
76
|
+
if (!environment.success) return stop(problemOf(environment.error));
|
|
77
|
+
passed("environment", environment.data);
|
|
78
|
+
const picked = new Set(named.data);
|
|
79
|
+
for (const requirement of requirementsOf(release, picked)) {
|
|
80
|
+
const found = await checkStatus(shell, root, requirement) !== 127;
|
|
81
|
+
const problem = found ? null : await install(context, requirement);
|
|
82
|
+
if (problem) return stop(problem);
|
|
83
|
+
passed(requirement.label, found ? "installed" : "installed now");
|
|
84
|
+
}
|
|
85
|
+
const [absent] = missingSecrets(context, release, picked);
|
|
86
|
+
if (absent) return stop(`${absent.who}: ${absent.name} missing in "${environment.data}"`);
|
|
87
|
+
const secrets = requirementsOf(release, picked).flatMap(({ secrets = [] }) => secrets);
|
|
88
|
+
passed("secrets", secrets.length > 0 ? [...new Set(secrets)].join(", ") : "none needed");
|
|
89
|
+
return true;
|
|
307
90
|
};
|
|
308
91
|
//#endregion
|
|
309
92
|
//#region src/cli/findRoot.ts
|
|
@@ -318,7 +101,6 @@ const findRoot = (from) => {
|
|
|
318
101
|
};
|
|
319
102
|
//#endregion
|
|
320
103
|
//#region src/cli/output.ts
|
|
321
|
-
const paint = (style, text) => styleText(style, text);
|
|
322
104
|
const out = (line = "") => process.stdout.write(`${line}\n`);
|
|
323
105
|
/** Problems as `file:line message`, each hint on the line below. */
|
|
324
106
|
const printProblems = (problems) => {
|
|
@@ -412,33 +194,66 @@ const statusCommand = async (context, { environment, json }) => {
|
|
|
412
194
|
};
|
|
413
195
|
//#endregion
|
|
414
196
|
//#region src/cli/main.ts
|
|
197
|
+
/** What `shiplane help` shows: the commands a person runs day to day, and where the rest are. */
|
|
198
|
+
const SHORT_HELP = `${paint("bold", "shiplane")}: detect what changed, version it, trigger each app's deploy.
|
|
199
|
+
|
|
200
|
+
shiplane the next step to preview: release PR, merge, tags, ship
|
|
201
|
+
shiplane promote production, from what preview runs
|
|
202
|
+
shiplane test-release [channel] publish what the changesets release for testers: a snapshot, or beta, nightly…
|
|
203
|
+
shiplane status where every unit stands, and what to run next
|
|
204
|
+
shiplane setup set up releases, or add an app
|
|
205
|
+
shiplane doctor check the config, tools and sign-ins, offer each fix
|
|
206
|
+
shiplane docs <name> every key a module's or an adapter's unit files take
|
|
207
|
+
|
|
208
|
+
shiplane help all every command and flag: version, tag, ship, remove and the rest
|
|
209
|
+
`;
|
|
415
210
|
const HELP = `${paint("bold", "shiplane")}: detect what changed, version it, trigger each app's deploy.
|
|
416
211
|
|
|
417
212
|
shiplane the next step to preview: release PR, merge, tags, ship
|
|
213
|
+
(on a branch: a test release, asked first)
|
|
214
|
+
shiplane test-release [channel] publish what the changesets release for testers, npm packages only:
|
|
215
|
+
a snapshot (0.6.0-main.329aafb) or a numbered channel (0.6.0-beta.2)
|
|
418
216
|
shiplane promote production, from what preview runs (--channel production too)
|
|
419
217
|
shiplane status [--json] where every unit stands, and what to run next
|
|
420
218
|
shiplane version open the release PR for what is pending
|
|
421
219
|
shiplane tag tag merged versions and publish their release notes
|
|
422
220
|
shiplane ship [unit...] trigger each tagged unit's deploy, then return
|
|
423
|
-
shiplane plan every command a ship would run, run nothing
|
|
424
221
|
shiplane plugins [--json] the flow, the modules in release order and who uses each, the features
|
|
425
222
|
|
|
426
|
-
shiplane setup [--yes] set up or
|
|
427
|
-
|
|
428
|
-
shiplane add <folder> init's questions for one folder
|
|
223
|
+
shiplane setup [--yes] set up, check, or add an app: asks only what it can't tell, rehearses, then writes
|
|
224
|
+
(shiplane init and shiplane add are now setup; both still run for now)
|
|
429
225
|
shiplane remove <unit> stop shipping a unit; it stays versioned
|
|
430
226
|
shiplane doctor check the config, tools and sign-ins, offer each fix
|
|
227
|
+
shiplane doctor --ci [unit...] on a runner: units, --channel, tools (installed when missing), secrets
|
|
431
228
|
shiplane adapter new <name> scaffold a server hosting adapter, its contract test and its module
|
|
432
229
|
shiplane docs <name> every key a module's or an adapter's unit files take
|
|
433
|
-
shiplane help
|
|
230
|
+
shiplane help [all] the main commands; all: this, every command and flag
|
|
434
231
|
|
|
435
232
|
--channel preview|production where status reads (preview by default)
|
|
436
|
-
--via
|
|
233
|
+
--via ci|local ship through the CI pipeline (such as GitHub Actions) or this machine, without asking
|
|
437
234
|
--yes answer yes to every question (never on production)
|
|
235
|
+
--dry-run with shiplane, ship or promote: every command it would run, run nothing;
|
|
236
|
+
with test-release: each package's version and npm tag, publish nothing
|
|
237
|
+
(shiplane plan before)
|
|
438
238
|
--verbose / --no-verbose say each thing it reads and runs, with a progress bar (on by default)
|
|
439
239
|
--mascot / --no-mascot the mascot beside it, still in CI or under NO_MOTION=1 (on by default)
|
|
440
240
|
Both defaults live in shiplane.config.ts: display: { verbose, mascot }
|
|
441
241
|
`;
|
|
242
|
+
/** The commands `--dry-run` previews instead of running. */
|
|
243
|
+
const DRY_RUNS = new Set([
|
|
244
|
+
"next",
|
|
245
|
+
"ship",
|
|
246
|
+
"promote"
|
|
247
|
+
]);
|
|
248
|
+
/** --via ci|local; the older --via github still means the CI pipeline, said once. */
|
|
249
|
+
const viaFlag = (value) => {
|
|
250
|
+
if (value === void 0) return void 0;
|
|
251
|
+
if (value === "github") {
|
|
252
|
+
out(paint("dim", "--via github is now --via ci: the flow's CI pipeline"));
|
|
253
|
+
return "ci";
|
|
254
|
+
}
|
|
255
|
+
return z.enum(["ci", "local"]).parse(value);
|
|
256
|
+
};
|
|
442
257
|
/** The CLI as a person runs it, from its arguments and folder; resolves to its exit code. */
|
|
443
258
|
const runCli = async (argv, cwd, io = {}) => {
|
|
444
259
|
const { values, positionals } = parseArgs({
|
|
@@ -448,6 +263,10 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
448
263
|
options: {
|
|
449
264
|
verbose: { type: "boolean" },
|
|
450
265
|
mascot: { type: "boolean" },
|
|
266
|
+
"dry-run": {
|
|
267
|
+
type: "boolean",
|
|
268
|
+
default: false
|
|
269
|
+
},
|
|
451
270
|
json: {
|
|
452
271
|
type: "boolean",
|
|
453
272
|
default: false
|
|
@@ -465,14 +284,25 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
465
284
|
blank: {
|
|
466
285
|
type: "boolean",
|
|
467
286
|
default: false
|
|
287
|
+
},
|
|
288
|
+
ci: {
|
|
289
|
+
type: "boolean",
|
|
290
|
+
default: false
|
|
468
291
|
}
|
|
469
292
|
}
|
|
470
293
|
});
|
|
471
294
|
const [command = "next", ...units] = positionals;
|
|
472
|
-
const environment = z.enum(ENVIRONMENTS).parse(values.channel);
|
|
473
|
-
const via =
|
|
295
|
+
const environment = command === "doctor" ? "preview" : z.enum(ENVIRONMENTS).parse(values.channel);
|
|
296
|
+
const via = viaFlag(values.via);
|
|
297
|
+
const testRelease = {
|
|
298
|
+
onDefault: "publish",
|
|
299
|
+
dryRun: values["dry-run"],
|
|
300
|
+
...units[0] === void 0 ? {} : { channel: units[0] }
|
|
301
|
+
};
|
|
474
302
|
const commands = {
|
|
475
|
-
next: (context) => environment === "preview" ?
|
|
303
|
+
next: (context) => environment === "preview" ? branchRelease(context, { onDefault: "release" }) : promote(context, via),
|
|
304
|
+
"test-release": (context) => branchRelease(context, testRelease),
|
|
305
|
+
branch: (context) => branchRelease(context, testRelease),
|
|
476
306
|
promote: (context) => promote(context, via),
|
|
477
307
|
status: (context) => statusCommand(context, {
|
|
478
308
|
environment,
|
|
@@ -488,7 +318,10 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
488
318
|
via,
|
|
489
319
|
...units.length > 0 ? { scope: new Set(units) } : {}
|
|
490
320
|
}),
|
|
491
|
-
plan: (context) =>
|
|
321
|
+
plan: (context) => {
|
|
322
|
+
out(paint("dim", "plan is now --dry-run: shiplane ship --dry-run, shiplane promote --dry-run"));
|
|
323
|
+
return planShips(context, environment);
|
|
324
|
+
},
|
|
492
325
|
plugins: (context) => Promise.resolve(pluginsCommand(context.release, { json: values.json }))
|
|
493
326
|
};
|
|
494
327
|
const [first = ""] = units;
|
|
@@ -502,9 +335,15 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
502
335
|
out(paint("dim", "init is now shiplane setup"));
|
|
503
336
|
return setup(context, { yes: values.yes });
|
|
504
337
|
},
|
|
505
|
-
add: (context) =>
|
|
338
|
+
add: (context) => {
|
|
339
|
+
out(paint("dim", "add is now shiplane setup: run it again to add an app"));
|
|
340
|
+
return addUnit(context, first);
|
|
341
|
+
},
|
|
506
342
|
remove: (context) => removeUnit(context, first),
|
|
507
|
-
doctor: (context) =>
|
|
343
|
+
doctor: (context) => values.ci ? doctorCi(context, {
|
|
344
|
+
units,
|
|
345
|
+
channel: values.channel
|
|
346
|
+
}) : doctor(context, { yes: values.yes }),
|
|
508
347
|
adapter: (context) => {
|
|
509
348
|
if (first === "new" && units[1]) return newAdapter(context, units[1]);
|
|
510
349
|
out(`${paint("red", "✗")} shiplane adapter new <name>`);
|
|
@@ -515,11 +354,17 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
515
354
|
const root = findRoot(cwd);
|
|
516
355
|
const files = io.setup?.files ?? nodeFiles(root);
|
|
517
356
|
const firstRun = command === "next" && !files.exists("shiplane.config.ts");
|
|
518
|
-
const run = commands[command];
|
|
357
|
+
const run = values["dry-run"] && DRY_RUNS.has(command) ? (context) => planShips(context, command === "promote" ? "production" : environment) : commands[command];
|
|
519
358
|
const setUp = setupCommands[firstRun ? "setup" : command];
|
|
520
|
-
if (setUp)
|
|
359
|
+
if (setUp) {
|
|
360
|
+
const load = () => loadReleaseOnDisk(root, { aliases: io.aliases });
|
|
361
|
+
return await setUp(await composeSetup(root, {
|
|
362
|
+
load,
|
|
363
|
+
...io.setup
|
|
364
|
+
})) ? 0 : 1;
|
|
365
|
+
}
|
|
521
366
|
if (command === "help") {
|
|
522
|
-
out(HELP);
|
|
367
|
+
out(first === "all" ? HELP : SHORT_HELP);
|
|
523
368
|
return 0;
|
|
524
369
|
}
|
|
525
370
|
if (!run) {
|
|
@@ -527,7 +372,7 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
527
372
|
out(HELP);
|
|
528
373
|
return 1;
|
|
529
374
|
}
|
|
530
|
-
const release = await
|
|
375
|
+
const release = await loadReleaseOnDisk(root, { aliases: io.aliases });
|
|
531
376
|
if (release.problems.length > 0) {
|
|
532
377
|
printProblems(release.problems);
|
|
533
378
|
return 2;
|