shiplane 0.5.2 → 0.6.0-main.329aafb
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 +150 -312
- package/dist/cli.js.map +1 -1
- package/dist/{readStatus-DypM0faL.js → compose-B8QDCrMv.js} +2686 -1453
- package/dist/compose-B8QDCrMv.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-Cfx1yqKP.d.ts} +394 -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-CN6M1-Gi.js → package-registry.fake-CMoOUEk7.js} +49 -6
- package/dist/package-registry.fake-CMoOUEk7.js.map +1 -0
- package/dist/{package-registry.fake-BLBdd7IQ.d.ts → package-registry.fake-Dbhan5nM.d.ts} +47 -6
- package/dist/plugin-Cwo6_I09.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-D3rJwB1K.js +265 -0
- package/dist/shell-server-hosting.adapter-D3rJwB1K.js.map +1 -0
- package/dist/{src-DO7WyrfV.js → src-DuhUlBoT.js} +2 -2
- package/dist/src-DuhUlBoT.js.map +1 -0
- package/dist/testing.d.ts +97 -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-B8QDCrMv.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,64 @@ 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 publish a temporary npm version for testers, from any branch
|
|
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 publish a temporary npm version for testers, from any branch
|
|
418
215
|
shiplane promote production, from what preview runs (--channel production too)
|
|
419
216
|
shiplane status [--json] where every unit stands, and what to run next
|
|
420
217
|
shiplane version open the release PR for what is pending
|
|
421
218
|
shiplane tag tag merged versions and publish their release notes
|
|
422
219
|
shiplane ship [unit...] trigger each tagged unit's deploy, then return
|
|
423
|
-
shiplane plan every command a ship would run, run nothing
|
|
424
220
|
shiplane plugins [--json] the flow, the modules in release order and who uses each, the features
|
|
425
221
|
|
|
426
|
-
shiplane setup [--yes] set up or
|
|
427
|
-
|
|
428
|
-
shiplane add <folder> init's questions for one folder
|
|
222
|
+
shiplane setup [--yes] set up, check, or add an app: asks only what it can't tell, rehearses, then writes
|
|
223
|
+
(shiplane init and shiplane add are now setup; both still run for now)
|
|
429
224
|
shiplane remove <unit> stop shipping a unit; it stays versioned
|
|
430
225
|
shiplane doctor check the config, tools and sign-ins, offer each fix
|
|
226
|
+
shiplane doctor --ci [unit...] on a runner: units, --channel, tools (installed when missing), secrets
|
|
431
227
|
shiplane adapter new <name> scaffold a server hosting adapter, its contract test and its module
|
|
432
228
|
shiplane docs <name> every key a module's or an adapter's unit files take
|
|
433
|
-
shiplane help
|
|
229
|
+
shiplane help [all] the main commands; all: this, every command and flag
|
|
434
230
|
|
|
435
231
|
--channel preview|production where status reads (preview by default)
|
|
436
|
-
--via
|
|
232
|
+
--via ci|local ship through the CI pipeline (such as GitHub Actions) or this machine, without asking
|
|
437
233
|
--yes answer yes to every question (never on production)
|
|
234
|
+
--dry-run with shiplane, ship or promote: every command it would run, run nothing
|
|
235
|
+
(shiplane plan before)
|
|
438
236
|
--verbose / --no-verbose say each thing it reads and runs, with a progress bar (on by default)
|
|
439
237
|
--mascot / --no-mascot the mascot beside it, still in CI or under NO_MOTION=1 (on by default)
|
|
440
238
|
Both defaults live in shiplane.config.ts: display: { verbose, mascot }
|
|
441
239
|
`;
|
|
240
|
+
/** The commands `--dry-run` previews instead of running. */
|
|
241
|
+
const DRY_RUNS = new Set([
|
|
242
|
+
"next",
|
|
243
|
+
"ship",
|
|
244
|
+
"promote"
|
|
245
|
+
]);
|
|
246
|
+
/** --via ci|local; the older --via github still means the CI pipeline, said once. */
|
|
247
|
+
const viaFlag = (value) => {
|
|
248
|
+
if (value === void 0) return void 0;
|
|
249
|
+
if (value === "github") {
|
|
250
|
+
out(paint("dim", "--via github is now --via ci: the flow's CI pipeline"));
|
|
251
|
+
return "ci";
|
|
252
|
+
}
|
|
253
|
+
return z.enum(["ci", "local"]).parse(value);
|
|
254
|
+
};
|
|
442
255
|
/** The CLI as a person runs it, from its arguments and folder; resolves to its exit code. */
|
|
443
256
|
const runCli = async (argv, cwd, io = {}) => {
|
|
444
257
|
const { values, positionals } = parseArgs({
|
|
@@ -448,6 +261,10 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
448
261
|
options: {
|
|
449
262
|
verbose: { type: "boolean" },
|
|
450
263
|
mascot: { type: "boolean" },
|
|
264
|
+
"dry-run": {
|
|
265
|
+
type: "boolean",
|
|
266
|
+
default: false
|
|
267
|
+
},
|
|
451
268
|
json: {
|
|
452
269
|
type: "boolean",
|
|
453
270
|
default: false
|
|
@@ -465,14 +282,20 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
465
282
|
blank: {
|
|
466
283
|
type: "boolean",
|
|
467
284
|
default: false
|
|
285
|
+
},
|
|
286
|
+
ci: {
|
|
287
|
+
type: "boolean",
|
|
288
|
+
default: false
|
|
468
289
|
}
|
|
469
290
|
}
|
|
470
291
|
});
|
|
471
292
|
const [command = "next", ...units] = positionals;
|
|
472
|
-
const environment = z.enum(ENVIRONMENTS).parse(values.channel);
|
|
473
|
-
const via =
|
|
293
|
+
const environment = command === "doctor" ? "preview" : z.enum(ENVIRONMENTS).parse(values.channel);
|
|
294
|
+
const via = viaFlag(values.via);
|
|
474
295
|
const commands = {
|
|
475
|
-
next: (context) => environment === "preview" ?
|
|
296
|
+
next: (context) => environment === "preview" ? branchRelease(context, { onDefault: "release" }) : promote(context, via),
|
|
297
|
+
"test-release": (context) => branchRelease(context, { onDefault: "publish" }),
|
|
298
|
+
branch: (context) => branchRelease(context, { onDefault: "publish" }),
|
|
476
299
|
promote: (context) => promote(context, via),
|
|
477
300
|
status: (context) => statusCommand(context, {
|
|
478
301
|
environment,
|
|
@@ -488,7 +311,10 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
488
311
|
via,
|
|
489
312
|
...units.length > 0 ? { scope: new Set(units) } : {}
|
|
490
313
|
}),
|
|
491
|
-
plan: (context) =>
|
|
314
|
+
plan: (context) => {
|
|
315
|
+
out(paint("dim", "plan is now --dry-run: shiplane ship --dry-run, shiplane promote --dry-run"));
|
|
316
|
+
return planShips(context, environment);
|
|
317
|
+
},
|
|
492
318
|
plugins: (context) => Promise.resolve(pluginsCommand(context.release, { json: values.json }))
|
|
493
319
|
};
|
|
494
320
|
const [first = ""] = units;
|
|
@@ -502,9 +328,15 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
502
328
|
out(paint("dim", "init is now shiplane setup"));
|
|
503
329
|
return setup(context, { yes: values.yes });
|
|
504
330
|
},
|
|
505
|
-
add: (context) =>
|
|
331
|
+
add: (context) => {
|
|
332
|
+
out(paint("dim", "add is now shiplane setup: run it again to add an app"));
|
|
333
|
+
return addUnit(context, first);
|
|
334
|
+
},
|
|
506
335
|
remove: (context) => removeUnit(context, first),
|
|
507
|
-
doctor: (context) =>
|
|
336
|
+
doctor: (context) => values.ci ? doctorCi(context, {
|
|
337
|
+
units,
|
|
338
|
+
channel: values.channel
|
|
339
|
+
}) : doctor(context, { yes: values.yes }),
|
|
508
340
|
adapter: (context) => {
|
|
509
341
|
if (first === "new" && units[1]) return newAdapter(context, units[1]);
|
|
510
342
|
out(`${paint("red", "✗")} shiplane adapter new <name>`);
|
|
@@ -515,11 +347,17 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
515
347
|
const root = findRoot(cwd);
|
|
516
348
|
const files = io.setup?.files ?? nodeFiles(root);
|
|
517
349
|
const firstRun = command === "next" && !files.exists("shiplane.config.ts");
|
|
518
|
-
const run = commands[command];
|
|
350
|
+
const run = values["dry-run"] && DRY_RUNS.has(command) ? (context) => planShips(context, command === "promote" ? "production" : environment) : commands[command];
|
|
519
351
|
const setUp = setupCommands[firstRun ? "setup" : command];
|
|
520
|
-
if (setUp)
|
|
352
|
+
if (setUp) {
|
|
353
|
+
const load = () => loadReleaseOnDisk(root, { aliases: io.aliases });
|
|
354
|
+
return await setUp(await composeSetup(root, {
|
|
355
|
+
load,
|
|
356
|
+
...io.setup
|
|
357
|
+
})) ? 0 : 1;
|
|
358
|
+
}
|
|
521
359
|
if (command === "help") {
|
|
522
|
-
out(HELP);
|
|
360
|
+
out(first === "all" ? HELP : SHORT_HELP);
|
|
523
361
|
return 0;
|
|
524
362
|
}
|
|
525
363
|
if (!run) {
|
|
@@ -527,7 +365,7 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
527
365
|
out(HELP);
|
|
528
366
|
return 1;
|
|
529
367
|
}
|
|
530
|
-
const release = await
|
|
368
|
+
const release = await loadReleaseOnDisk(root, { aliases: io.aliases });
|
|
531
369
|
if (release.problems.length > 0) {
|
|
532
370
|
printProblems(release.problems);
|
|
533
371
|
return 2;
|