shiplane 0.6.0-rc.0 → 0.6.0-rc.2

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.
Files changed (45) hide show
  1. package/README.md +10 -9
  2. package/dist/cli.js +7 -510
  3. package/dist/cli.js.map +1 -1
  4. package/dist/compose-D3Rozb5H.js +135 -0
  5. package/dist/compose-D3Rozb5H.js.map +1 -0
  6. package/dist/display-dKB0pRgZ.js +5 -0
  7. package/dist/display-dKB0pRgZ.js.map +1 -0
  8. package/dist/{index-BKW_wMrq.d.ts → index-CxUS_sOO.d.ts} +13 -3
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +1 -4
  11. package/dist/issues-B-wb80Zl.js +2 -0
  12. package/dist/{issues-DCRpXUBW.js.map → issues-B-wb80Zl.js.map} +1 -1
  13. package/dist/memory.d.ts +1 -1
  14. package/dist/memory.js +1 -2
  15. package/dist/package-registry.fake-BJGbjIUG.js +3 -0
  16. package/dist/{package-registry.fake-C8Xocl62.js.map → package-registry.fake-BJGbjIUG.js.map} +1 -1
  17. package/dist/{package-registry.fake-CCJ6bqG4.d.ts → package-registry.fake-C11alV4O.d.ts} +2 -2
  18. package/dist/perEnv-qqNFhdIA.js +2 -0
  19. package/dist/{perEnv-n2qFRplP.js.map → perEnv-qqNFhdIA.js.map} +1 -1
  20. package/dist/plugin-Bi5bQ1z9.d.ts +194 -0
  21. package/dist/plugin.d.ts +3 -3
  22. package/dist/plugin.js +3 -84
  23. package/dist/plugin.js.map +1 -1
  24. package/dist/shell-server-hosting.adapter-DlW8Sr2k.js +4 -0
  25. package/dist/shell-server-hosting.adapter-DlW8Sr2k.js.map +1 -0
  26. package/dist/src-BOglFy_j.js +2 -0
  27. package/dist/src-BOglFy_j.js.map +1 -0
  28. package/dist/testing.d.ts +8 -7
  29. package/dist/testing.js +20 -951
  30. package/dist/testing.js.map +1 -1
  31. package/package.json +5 -3
  32. package/shiplane.schema.json +1092 -0
  33. package/dist/compose-Jfnl-x4-.js +0 -5660
  34. package/dist/compose-Jfnl-x4-.js.map +0 -1
  35. package/dist/display-CfV4G1TR.js +0 -455
  36. package/dist/display-CfV4G1TR.js.map +0 -1
  37. package/dist/issues-DCRpXUBW.js +0 -6
  38. package/dist/package-registry.fake-C8Xocl62.js +0 -703
  39. package/dist/perEnv-n2qFRplP.js +0 -11
  40. package/dist/plugin-BHiDpa2j.d.ts +0 -118
  41. package/dist/shell-server-hosting.adapter-Q42-G2wE.js +0 -384
  42. package/dist/shell-server-hosting.adapter-Q42-G2wE.js.map +0 -1
  43. package/dist/src-DuehLcrZ.js +0 -114
  44. package/dist/src-DuehLcrZ.js.map +0 -1
  45. package/dist/tsconfig.tsbuildinfo +0 -1
package/README.md CHANGED
@@ -95,15 +95,16 @@ export default defineRelease({
95
95
 
96
96
  Swap any piece:
97
97
 
98
- | Want | Use |
99
- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
100
- | To write the changelog yourself | [`changesetsVersioning()`](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/how-to.md#choose-how-versions-are-bumped) |
101
- | Any host with a deploy command | [`shellServerHosting()`](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/plugins.md#built-in-shellserverhosting) |
102
- | To release Claude Code, Codex, Cursor or Gemini plugins | [`agentPlugin()`](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/how-to.md#release-claude-code-plugins) |
103
- | To comment on each PR when it ships | [`releaseComments()`](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/how-to.md#comment-on-what-shipped) |
104
- | Your own host | [Write a plugin](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/how-to.md#write-a-plugin) |
105
- | To ship from this machine, not Actions | [`--via local`](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/how-to.md#choose-github-actions-or-this-machine) |
106
- | A quieter terminal | [`display: { mascot: false }`](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/how-to.md#turn-the-mascot-off) |
98
+ | Want | Use |
99
+ | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
100
+ | To write the changelog yourself | [`changesetsVersioning()`](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/how-to-versions.md#choose-how-versions-are-bumped) |
101
+ | Any host with a deploy command | [`shellServerHosting()`](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/plugins.md#built-in-shellserverhosting) |
102
+ | To release Claude Code, Codex, Cursor or Gemini plugins | [`agentPlugin()`](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/how-to-versions.md#release-claude-code-plugins) |
103
+ | To comment on each PR when it ships | [`releaseComments()`](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/how-to-hosts.md#comment-on-what-shipped) |
104
+ | Your own host | [Write a plugin](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/how-to-hosts.md#write-a-plugin) |
105
+ | To ship from this machine, not Actions | [`--via local`](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/how-to-ci.md#choose-github-actions-or-this-machine) |
106
+ | A config in YAML, no TypeScript | [`shiplane.yml`](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/how-to-yaml.md) |
107
+ | A quieter terminal | [`display: { mascot: false }`](https://github.com/arnaud-zg/packages/blob/main/docs/shiplane/how-to-terminal.md#turn-the-mascot-off) |
107
108
 
108
109
  `pnpm shiplane plugins` in that repository shows what got injected where:
109
110
 
package/dist/cli.js CHANGED
@@ -1,350 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { A as checkStatus, B as fail, C as addUnit, E as doctor, F as decideContext, G as nodeFiles, H as reasonOf, I as environmentLabel, L as runHere, M as signInsOf, N as checkout, O as refreshEditorSchema, P as commandLine, R as unitTarget, S as plural, T as initRelease, U as ENVIRONMENTS, V as paint, W as keysAt, _ 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 requirementsOf, 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 removeUnit, x as padded, y as openReleasePr } from "./compose-Jfnl-x4-.js";
3
- import { z } from "zod";
4
- import fs from "node:fs";
5
- import path from "node:path";
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) ?? "");
23
- /**
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.
26
- */
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`);
42
- }
43
- return await checkStatus(shell, root, requirement) === 127 ? `${label} still missing after ${commandLine(command)}` : null;
44
- };
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]))];
56
- /**
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.
59
- */
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;
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;
90
- };
91
- const DAY_MS = 1440 * 60 * 1e3;
92
- const SNAPSHOT = /^\d+\.\d+\.\d+-([a-z0-9-]+)\.(g?[0-9a-f]{7})$/;
93
- /**
94
- * Whether a tag is one a shiplane snapshot left: its version has a snapshot's shape and the tag is
95
- * that version's branch slug (as branch snapshots were tagged), `branch-<slug>`, or `snapshot`.
96
- */
97
- const isSnapshotTag = ({ tag, version }) => {
98
- const slug = SNAPSHOT.exec(version)?.[1];
99
- if (slug === void 0 || tag === "latest") return false;
100
- return tag === slug || tag === `branch-${slug}` || tag === "snapshot";
101
- };
102
- /** Why an age cannot be one, or null when it can. */
103
- const ageProblem = (days) => Number.isInteger(days) && days >= 7 ? null : `--older-than takes a whole number of days, 7 or more`;
104
- /** Whole days between a publish time and now; null when the time is missing or unreadable. */
105
- const ageInDays = (publishedAt, now) => {
106
- const at = publishedAt === null ? NaN : Date.parse(publishedAt);
107
- return Number.isNaN(at) ? null : Math.floor((now.getTime() - at) / DAY_MS);
108
- };
109
- /**
110
- * The snapshot tags old enough to remove: a shiplane snapshot's tag, on a version published at
111
- * least `olderThanDays` ago, never the one `latest` points at. A version with no publish time is
112
- * kept: old is never guessed.
113
- */
114
- const staleSnapshotTags = ({ tags, now, olderThanDays = 30 }) => {
115
- const latest = tags.find(({ tag }) => tag === "latest")?.version;
116
- return tags.flatMap((tagged) => {
117
- const days = ageInDays(tagged.publishedAt, now);
118
- if (!isSnapshotTag(tagged) || tagged.version === latest) return [];
119
- return days !== null && days >= olderThanDays ? [{
120
- ...tagged,
121
- days
122
- }] : [];
123
- });
124
- };
125
- //#endregion
126
- //#region src/application/pruneSnapshots.ts
127
- /** Every package's snapshot tags at least `olderThanDays` old, as each registry lists them. */
128
- const staleTags = async (context, olderThanDays) => {
129
- const at = await checkout(context);
130
- const decide = decideContext(context);
131
- const now = context.clock.now();
132
- return (await Promise.all(context.release.units.map(async (unit) => {
133
- const target = unitTarget(context, {
134
- unit,
135
- environment: "preview",
136
- ...at
137
- });
138
- const read = target?.module.tags;
139
- if (!target || !read) return [];
140
- const name = target.module.publishedName?.(decide, target.input) ?? unit.packageName;
141
- return staleSnapshotTags({
142
- tags: await read(decide, target.input),
143
- now,
144
- olderThanDays
145
- }).map((stale) => ({
146
- ...stale,
147
- name,
148
- target
149
- }));
150
- }))).flat();
151
- };
152
- const printTable = ({ output }, stale) => {
153
- const [header = "", ...rows] = padded([[
154
- "Package",
155
- "Tag",
156
- "Version",
157
- "Published"
158
- ], ...stale.map(({ name, tag, version, days }) => [
159
- name,
160
- tag,
161
- version,
162
- `${days} days ago`
163
- ])]);
164
- output.line(paint("dim", ` ${header}`));
165
- rows.forEach((row) => output.line(` ${row}`));
166
- };
167
- /** Yes from the person in a terminal, or --yes anywhere: removing tags is never done unasked. */
168
- const agreed = async (context, count) => {
169
- if (context.options.yes) return true;
170
- if (!context.prompter.interactive) {
171
- fail(context, "Not removed", "add --yes to remove them without a terminal to ask in.");
172
- return false;
173
- }
174
- return context.prompter.confirm(`Remove ${plural(count, "tag")}? Each version stays installable by its number.`);
175
- };
176
- /** The code passed with --otp, or one asked for in a terminal; none when the account needs none. */
177
- const firstCode = async ({ prompter }, otp) => {
178
- if (otp !== void 0 || !prompter.interactive) return otp;
179
- return (await prompter.text("npm one-time code, if your account asks for one (Enter: none)"))?.trim() || void 0;
180
- };
181
- /**
182
- * Removes each tag in turn, with one code for all. A failure in a terminal asks for a fresh code
183
- * and retries, since a code lasts about 30 seconds; anywhere else it stops, and a rerun picks up
184
- * the tags still there. False when it stopped.
185
- */
186
- const removeAll = async (context, stale, otp) => {
187
- const decide = decideContext(context);
188
- let code = otp;
189
- for (const [index, entry] of stale.entries()) for (;;) {
190
- const job = entry.target.module.untagJob?.(decide, entry.target.input, entry.tag, code);
191
- if (!job) break;
192
- try {
193
- await context.progress.during(job.label, "working", () => runHere(context, job, {
194
- tag: entry.target.tag,
195
- environment: "preview"
196
- }), {
197
- index,
198
- total: stale.length
199
- });
200
- break;
201
- } catch (error) {
202
- const fresh = context.prompter.interactive ? await context.prompter.text(`${job.label} failed: a fresh npm one-time code to retry (Enter: stop)`) : null;
203
- if (!fresh?.trim()) {
204
- fail(context, `${job.label} failed`, `${reasonOf(error)}; ${plural(index, "tag")} of ${stale.length} removed. A one-time code lasts about 30 seconds: run it again with a fresh --otp, it picks up the tags still there.`);
205
- return false;
206
- }
207
- code = fresh.trim();
208
- }
209
- }
210
- return true;
211
- };
212
- /**
213
- * `shiplane prune-snapshots`: removes the npm tags old snapshots left, those of a version published
214
- * `olderThanDays` ago or more (30 by default, never under 7). Only tags a shiplane snapshot gives
215
- * are touched, never `latest` nor a numbered channel's; the versions stay installable by their
216
- * number. False when refused or stopped.
217
- */
218
- const pruneSnapshots = async (context, { olderThanDays = 30, otp, dryRun = false }) => {
219
- const problem = ageProblem(olderThanDays);
220
- if (problem) {
221
- fail(context, "Not an age", problem);
222
- return false;
223
- }
224
- const stale = await staleTags(context, olderThanDays);
225
- if (stale.length === 0) {
226
- context.progress.say("resting", `No snapshot tag older than ${olderThanDays} days.`);
227
- return true;
228
- }
229
- context.progress.say("resting", `${plural(stale.length, "snapshot tag")} older than ${olderThanDays} days${dryRun ? " (dry run)" : ""}`);
230
- printTable(context, stale);
231
- if (dryRun) {
232
- context.output.line(paint("dim", " Nothing removed."));
233
- return true;
234
- }
235
- if (!await agreed(context, stale.length)) return false;
236
- if (!await removeAll(context, stale, await firstCode(context, otp))) return false;
237
- context.progress.say("happy", `${paint("green", "✓")} Removed ${plural(stale.length, "tag")}`);
238
- return true;
239
- };
240
- //#endregion
241
- //#region src/cli/findRoot.ts
242
- /** The nearest folder up from here with a release config, else the git root, else here. */
243
- const findRoot = (from) => {
244
- const ancestors = (dir) => {
245
- const parent = path.dirname(dir);
246
- return parent === dir ? [dir] : [dir, ...ancestors(parent)];
247
- };
248
- const chain = ancestors(path.resolve(from));
249
- return chain.find((dir) => findConfig(dir)) ?? chain.find((dir) => fs.existsSync(path.join(dir, ".git"))) ?? path.resolve(from);
250
- };
251
- //#endregion
252
- //#region src/cli/output.ts
253
- const out = (line = "") => process.stdout.write(`${line}\n`);
254
- /** Problems as `file:line message`, each hint on the line below. */
255
- const printProblems = (problems) => {
256
- problems.forEach(({ file, line, message, hint }) => {
257
- const where = line === void 0 ? file : `${file}:${line}`;
258
- out(`${paint("red", "✗")} ${paint("bold", where)} ${message}`);
259
- if (hint) out(` ${paint("dim", hint)}`);
260
- });
261
- };
262
- //#endregion
263
- //#region src/cli/pluginsCommand.ts
264
- /** `shiplane plugins`: the flow's adapters, the modules in release order with their apps, the features. */
265
- const pluginsCommand = (release, { json }) => {
266
- const { flow } = release;
267
- const ports = {
268
- sourceControl: flow.sourceControl.name,
269
- codeHost: flow.codeHost.name,
270
- ciPipeline: flow.ciPipeline.name,
271
- versioning: flow.versioning.name
272
- };
273
- const modules = release.modules.map(({ name, kind, provider, settings }) => ({
274
- name,
275
- kind,
276
- provider,
277
- keys: keysAt(settings, []),
278
- apps: release.units.filter(({ module }) => module === name).map(({ name: app }) => app)
279
- }));
280
- const features = release.features.map(({ name, adapters }) => ({
281
- name,
282
- uses: adapters.map((adapter) => adapter.name)
283
- }));
284
- if (json) {
285
- out(JSON.stringify({
286
- flow: ports,
287
- modules,
288
- features
289
- }, null, 2));
290
- return;
291
- }
292
- const width = Math.max(14, ...modules.map(({ name }) => name.length), ...features.map(({ name }) => name.length)) + 2;
293
- const section = (title) => {
294
- out();
295
- out(paint("bold", title));
296
- out();
297
- };
298
- section("Flow in shiplane.config.ts");
299
- Object.entries(ports).forEach(([port, name]) => out(` ${port.padEnd(width)}${name}`));
300
- section("Modules, in release order");
301
- modules.forEach(({ name, provider, keys, apps }) => {
302
- const used = apps.length > 0 ? `used by ${apps.join(", ")}` : paint("dim", "no app names it");
303
- out(` ${name.padEnd(width)}${provider} ${paint("dim", keys.join(", ") || "no options")}`);
304
- out(` ${" ".repeat(width)}${used}`);
305
- });
306
- section("Features, after the ship");
307
- if (features.length === 0) out(` ${paint("dim", "none")}`);
308
- features.forEach(({ name, uses }) => out(` ${name.padEnd(width)}${paint("dim", `uses ${uses.join(", ")}`)}`));
309
- out();
310
- };
311
- //#endregion
312
- //#region src/cli/statusCommand.ts
313
- const NEXT = {
314
- "release-pr": "open the release PR: shiplane",
315
- "wait-merge": "merge the release PR, then: shiplane",
316
- ship: "tag what was versioned and ship it: shiplane"
317
- };
318
- /** The next step as a person reads it; a ship with nothing pending anywhere is nothing to do. */
319
- const nextLabel = ({ next, units, untagged }, nextChange) => next.step === "ship" && untagged.length === 0 && !units.some(({ pending }) => pending) ? `nothing to release: queue a change with ${nextChange}` : NEXT[next.step] ?? "";
320
- /** `shiplane status`: where every unit stands on an environment, and what to run next. Reads only. */
321
- const statusCommand = async (context, { environment, json }) => {
322
- const status = await readStatus(context, environment);
323
- if (json) {
324
- out(JSON.stringify(status, null, 2));
325
- return;
326
- }
327
- const dot = paint("dim", "·");
328
- out();
329
- const label = environmentLabel(context, [], environment);
330
- out(` ${paint("bold", "Release status")} ${dot} ${label}`);
331
- out();
332
- const width = Math.max(8, ...status.units.map(({ unit }) => unit.length)) + 2;
333
- out(paint("dim", ` ${"Unit".padEnd(width)}${"Version".padEnd(12)}${"Target".padEnd(18)}Where it stands`));
334
- status.units.forEach(({ unit, version, target, pending, hint }) => {
335
- const mark = pending ? paint("yellow", "↑") : paint("dim", "·");
336
- out(` ${unit.padEnd(width)}${version.padEnd(12)}${target.padEnd(18)}${mark} ${hint}`);
337
- });
338
- status.releasePrs.forEach(({ url }) => out(`\n ${paint("cyan", "Release PR")} ${url}`));
339
- if (status.untagged.length > 0) out(` ${paint("yellow", "Untagged")} ${status.untagged.map(({ tag }) => tag).join(", ")}`);
340
- out();
341
- out(`${paint(["bold", "green"], "→ Next:")} ${nextLabel(status, context.services.versioning.nextChange)}`);
342
- out();
343
- };
344
- //#endregion
345
- //#region src/cli/main.ts
346
- /** What `shiplane help` shows: the commands a person runs day to day, and where the rest are. */
347
- const SHORT_HELP = `${paint("bold", "shiplane")}: detect what changed, version it, trigger each app's deploy.
2
+ import{E as e,y as t}from"./shell-server-hosting.adapter-DlW8Sr2k.js";import{$ as n,A as r,B as i,C as a,D as o,E as s,F as c,G as l,H as u,I as d,J as f,K as p,L as m,N as h,O as g,Q as _,R as v,S as y,T as b,U as x,V as S,X as C,Y as w,Z as T,_ as E,a as D,b as O,c as k,d as ee,et as A,f as j,g as M,h as N,i as P,j as F,k as I,l as L,m as R,n as z,nt as B,p as te,q as ne,r as V,rt as H,t as U,tt as W,u as G,w as K,x as q,y as J,z as Y}from"./compose-D3Rozb5H.js";import{z as X}from"zod";import Z from"node:fs";import Q from"node:path";import{parseArgs as re}from"node:util";const writeConfigSchema=({files:e,output:t},n)=>{e.write(R,M(n));let count=e=>n.filter(t=>t.kind===e).length;t.line(`${p(`green`,`◇`)} Wrote ${R}: ${count(`adapter`)} adapters, ${count(`module`)} modules, ${count(`feature`)} features`);let r=_.find(t=>e.exists(t)),i=r?e.read(r):null;return r&&i!==null&&!i.includes(`yaml-language-server: $schema=`)&&(e.write(r,`${N}\n${i}`),t.line(`${p(`green`,`◇`)} ${r} points your editor at it`)),!0},unitsSchema=e=>X.array(X.string()).superRefine((t,n)=>{let r=t.filter(t=>!e.includes(t));r.length>0&&n.addIssue({code:`custom`,message:`unknown units [${r.join(`, `)}]: known [${e.join(`, `)}]`})}),ie=X.enum(B,{error:({input:e})=>`unknown environment "${String(e)}": ${B.join(`, `)}`}),problemOf=e=>e.issues[0]?.message??`invalid`,expand=(e,t)=>t.replace(/\$\{?(\w+)\}?/g,(t,n)=>e.shell.env(n)??``),install=async(e,t)=>{let{shell:n,files:r,root:i}=e,{label:a,install:o}=t;if(!o)return`${a} missing and no install for linux`;let{command:s}=o,l=await n.attach(s.command,s.args,{cwd:Q.join(i,s.cwd??``),env:s.env});if(l!==0)return`${a} install failed: ${Y(s)} exited with ${l}`;if(o.path!==void 0){let t=expand(e,o.path);n.prependPath?.(t);let i=n.env(`GITHUB_PATH`);i&&r.append(i,`${t}\n`)}return await c(n,i,t)===127?`${a} still missing after ${Y(s)}`:null},missing=(e,t,n)=>n.flatMap(({label:n,secrets:r=[]})=>r.filter(t=>!e.shell.env(t)).map(e=>({who:t,label:n,name:e}))),missingSecrets=(e,t,n)=>[...t.units.filter(({name:e})=>n.has(e)).flatMap(n=>{let r=t.modules.find(({name:e})=>e===n.module)?.provider;return missing(e,`${n.name} ships with ${r??n.module}`,m(t,new Set([n.name])))}),...d(t,new Set).flatMap(t=>missing(e,`shiplane needs ${t.label}`,[t]))],doctorCi=async(e,{units:t,channel:n})=>{let{output:r,shell:i,root:a}=e,passed=(e,t)=>r.line(`${p(`green`,`✓`)} ${e} ${p(`dim`,t)}`),stop=e=>(r.line(`${p(`red`,`✗`)} ${e}`),r.line(` ${p(`dim`,`https://github.com/arnaud-zg/js-packages/blob/main/docs/shiplane/reference.md#github-actions-workflow`)}`),!1),o=await e.load(),[s]=o.problems;if(s)return stop(`${s.line===void 0?s.file:`${s.file}:${s.line}`}: ${s.message}`);let l=o.units.map(({name:e})=>e),u=unitsSchema(l).safeParse(t.length>0?t:l);if(!u.success)return stop(problemOf(u.error));passed(`units`,u.data.join(`, `));let f=ie.safeParse(n);if(!f.success)return stop(problemOf(f.error));passed(`environment`,f.data);let m=new Set(u.data);for(let t of d(o,m)){let n=await c(i,a,t)!==127,r=n?null:await install(e,t);if(r)return stop(r);passed(t.label,n?`installed`:`installed now`)}let[h]=missingSecrets(e,o,m);if(h)return stop(`${h.who}: ${h.name} missing in "${f.data}"`);let g=d(o,m).flatMap(({secrets:e=[]})=>e);return passed(`secrets`,g.length>0?[...new Set(g)].join(`, `):`none needed`),!0},madeName=e=>{try{let t=e.make({},{});return W(t)&&typeof t.name==`string`?t.name:null}catch{return null}},isFunctionIn=e=>typeof e==`function`||(Array.isArray(e)?e.some(isFunctionIn):W(e)&&Object.values(e).some(isFunctionIn)),sameJson=(e,t)=>JSON.stringify(e)===JSON.stringify(t),presetName=(e,t)=>Object.entries(e).find(([,e])=>sameJson(e,t))?.[0],yamlFromDeclaration=(r,i)=>{let a=[],o=[],cannot=(e,t,n)=>(a.push({at:e,message:t,hint:n}),null),named=(e,t,n,r)=>{if(t!==void 0&&!W(t))return cannot(r,`its options are not a map`,``);t===void 0&&Object.keys(e.options.shape).length>0&&o.push(`${r}: ${e.name} does not say which options it was given; add any to its with:`);let i=t??{},a=Object.keys(i).find(e=>isFunctionIn(i[e]));if(a!==void 0)return cannot(`${r}.with.${a}`,`is a function: YAML holds values only`,`give it a value, or keep shiplane.config.ts`);if(!e.options.safeParse(i).success)return cannot(r,`${e.name} was given options its catalog does not take`,`check them against shiplane docs or the schema`);let s={...i,...n};return Object.keys(s).length===0?e.name:{use:e.name,with:s}},slotOf=(e,t,n)=>{if(!W(e)||typeof e.name!=`string`)return cannot(n,`is not an adapter`,``);let r=i.find(n=>n.kind===`adapter`&&n.port===t&&(n.name===e.name||A(n.name)&&madeName(n)===e.name));return r?named(r,e.options,{},n):cannot(n,`the ${t} adapter "${e.name}" is in no catalog`,`export a catalog from its file (adapterEntry from shiplane/plugin), then name it by its path in shiplane.yml`)};if(!W(r))return{text:``,unconverted:[{at:`shiplane.config.ts`,message:`its default export is not defineRelease({ ... })`,hint:``}],check:o};let s=W(r.flow)?r.flow:{},c=Object.fromEntries(C.map(e=>[e,slotOf(s[e],e,`flow.${e}`)]));s.approval===`required`&&(c.approval=`required`);let listOf=e=>(Array.isArray(r[e])?r[e]:[]).map((t,r)=>{let a=`${e}[${r}]`;if(!W(t))return cannot(a,`is not a module or a feature`,``);let o=e===`modules`?`module`:`feature`,c=typeof t.kind==`string`?t.kind:t.name,l=i.find(e=>e.kind===o&&e.name===c);if(!l)return cannot(a,`the ${o} "${String(c)}" is in no catalog`,`export a catalog from its file, then name it by its path in shiplane.yml`);let u=Array.isArray(t.adapters)?t.adapters:[],d={};Object.entries(l.slots).forEach(([e,{port:t}],r)=>{let i=u[r];n(t)&&(i===void 0||i===s[t])||(d[e]=slotOf(i,t,`${a}.with.${e}`))});let f=o===`module`&&t.name!==t.kind?{name:t.name}:void 0;return named(l,o===`module`?f:t.options,d,a)}),l=W(r.display)?r.display:void 0;l&&typeof l.mascot==`function`&&cannot(`display.mascot`,`is a function: YAML holds values only`,`use true, false, frames per mood, or keep shiplane.config.ts`);let u={flow:c,...r.units===void 0?{}:{units:r.units},modules:listOf(`modules`),...r.features===void 0?{}:{features:listOf(`features`)},...r.tag===void 0?{}:{tag:r.tag},...r.via===void 0?{}:{via:r.via},...l===void 0?{}:{display:l},...r.testComment===void 0?{}:{testComment:presetName(e,r.testComment)??r.testComment},...r.testRelease===void 0?{}:{testRelease:presetName(t,r.testRelease)??r.testRelease},...r.prepare===void 0?{}:{prepare:r.prepare}};return a.length>0?{text:``,unconverted:a,check:o}:{text:[N,`# How this repository releases, written by shiplane migrate from shiplane.config.ts.`,j(u)].join(`
3
+ `),unconverted:a,check:o}},composed=e=>JSON.stringify({flow:[e.flow.sourceControl.name,e.flow.codeHost.name,e.flow.ciPipeline.name,e.flow.versioning.name,e.flow.approval],modules:e.modules.map(({name:e,kind:t,provider:n})=>[e,t,n]),features:e.features.map(({name:e})=>e),units:e.units.map(({name:e,module:t})=>[e,t]),settings:[e.tagFormat,e.via,e.testComment,e.testRelease,e.prepare,e.display]}),migrate=async({files:e,output:t},n)=>{let fail=(e,n)=>(t.line(`${p(`red`,`✗`)} ${e}`),n&&t.line(` ${p(`dim`,n)}`),!1);if(e.exists(`shiplane.yml`))return fail(`${T} already exists`,`shiplane migrate writes it from shiplane.config.ts; remove one of them`);if(!n.tsFile)return fail(`no shiplane.config.ts to migrate`,`shiplane setup --format yaml writes a shiplane.yml`);let r=Q.basename(n.tsFile),i=await n.load(`ts`);if(i.problems.length>0)return i.problems.forEach(({file:e,line:n,message:r})=>t.line(`${p(`red`,`✗`)} ${n===void 0?e:`${e}:${n}`} ${r}`)),fail(`${r} has problems: fix them, then migrate`);let{text:a,unconverted:o,check:s}=yamlFromDeclaration(await n.declared(),n.catalog);if(o.length>0)return o.forEach(({at:e,message:n,hint:r})=>{t.line(`${p(`red`,`✗`)} ${p(`bold`,e)} ${n}`),r&&t.line(` ${p(`dim`,r)}`)}),fail(`Nothing written: YAML cannot hold ${o.length===1?`this`:`these`}. Change ${o.length===1?`it`:`them`} in ${r}, or keep it.`);e.write(T,a);let c=await n.load(`yaml`);return c.problems.length>0||composed(c)!==composed(i)?(e.remove(T),c.problems.forEach(({file:e,line:n,message:r})=>t.line(`${p(`red`,`✗`)} ${n===void 0?e:`${e}:${n}`} ${r}`)),fail(`${T} would not release what ${r} does: nothing changed`,`please report it, with both configs`)):(e.remove(r),t.line(`${p(`green`,`◇`)} Wrote ${T}: the same release as ${r}, which is removed`),s.forEach(e=>t.line(`${p(`yellow`,`!`)} ${e}`)),t.line(p(`dim`,` git restore ${r} brings it back`)),!0)},ae=/^\d+\.\d+\.\d+-([a-z0-9-]+)\.(g?[0-9a-f]{7})$/,isSnapshotTag=({tag:e,version:t})=>{let n=ae.exec(t)?.[1];return n===void 0||e===`latest`?!1:e===n||e===`branch-${n}`||e===`snapshot`},ageProblem=e=>Number.isInteger(e)&&e>=7?null:`--older-than takes a whole number of days, 7 or more`,ageInDays=(e,t)=>{let n=e===null?NaN:Date.parse(e);return Number.isNaN(n)?null:Math.floor((t.getTime()-n)/864e5)},staleSnapshotTags=({tags:e,now:t,olderThanDays:n=30})=>{let r=e.find(({tag:e})=>e===`latest`)?.version;return e.flatMap(e=>{let i=ageInDays(e.publishedAt,t);return!isSnapshotTag(e)||e.version===r?[]:i!==null&&i>=n?[{...e,days:i}]:[]})},staleTags=async(e,t)=>{let n=await v(e),r=i(e),a=e.clock.now();return(await Promise.all(e.release.units.map(async i=>{let o=x(e,{unit:i,environment:`preview`,...n}),s=o?.module.tags;if(!o||!s)return[];let c=o.module.publishedName?.(r,o.input)??i.packageName;return staleSnapshotTags({tags:await s(r,o.input),now:a,olderThanDays:t}).map(e=>({...e,name:c,target:o}))}))).flat()},printTable=({output:e},t)=>{let[n=``,...r]=y([[`Package`,`Tag`,`Version`,`Published`],...t.map(({name:e,tag:t,version:n,days:r})=>[e,t,n,`${r} days ago`])]);e.line(p(`dim`,` ${n}`)),r.forEach(t=>e.line(` ${t}`))},agreed=async(e,t)=>e.options.yes?!0:e.prompter.interactive?e.prompter.confirm(`Remove ${o(t,`tag`)}? Each version stays installable by its number.`):(l(e,`Not removed`,`add --yes to remove them without a terminal to ask in.`),!1),firstCode=async({prompter:e},t)=>t!==void 0||!e.interactive?t:(await e.text(`npm one-time code, if your account asks for one (Enter: none)`))?.trim()||void 0,removeAll=async(e,t,n)=>{let r=i(e),a=n;for(let[n,i]of t.entries())for(;;){let s=i.target.module.untagJob?.(r,i.target.input,i.tag,a);if(!s)break;try{await e.progress.during(s.label,`working`,()=>u(e,s,{tag:i.target.tag,environment:`preview`}),{index:n,total:t.length});break}catch(r){let i=e.prompter.interactive?await e.prompter.text(`${s.label} failed: a fresh npm one-time code to retry (Enter: stop)`):null;if(!i?.trim())return l(e,`${s.label} failed`,`${ne(r)}; ${o(n,`tag`)} of ${t.length} removed. A one-time code lasts about 30 seconds: run it again with a fresh --otp, it picks up the tags still there.`),!1;a=i.trim()}}return!0},pruneSnapshots=async(e,{olderThanDays:t=30,otp:n,dryRun:r=!1})=>{let i=ageProblem(t);if(i)return l(e,`Not an age`,i),!1;let a=await staleTags(e,t);return a.length===0?(e.progress.say(`resting`,`No snapshot tag older than ${t} days.`),!0):(e.progress.say(`resting`,`${o(a.length,`snapshot tag`)} older than ${t} days${r?` (dry run)`:``}`),printTable(e,a),r?(e.output.line(p(`dim`,` Nothing removed.`)),!0):!await agreed(e,a.length)||!await removeAll(e,a,await firstCode(e,n))?!1:(e.progress.say(`happy`,`${p(`green`,`✓`)} Removed ${o(a.length,`tag`)}`),!0))},findRoot=e=>{let ancestors=e=>{let t=Q.dirname(e);return t===e?[e]:[e,...ancestors(t)]},t=ancestors(Q.resolve(e)),n=H(),holdsConfig=e=>n.find(e)!==null||_.some(t=>Z.existsSync(Q.join(e,t)));return t.find(holdsConfig)??t.find(e=>Z.existsSync(Q.join(e,`.git`)))??Q.resolve(e)},out=(e=``)=>process.stdout.write(`${e}\n`),printProblems=e=>{e.forEach(({file:e,line:t,message:n,hint:r})=>{let i=t===void 0?e:`${e}:${t}`;out(`${p(`red`,`✗`)} ${p(`bold`,i)} ${n}`),r&&out(` ${p(`dim`,r)}`)})},pluginsCommand=(e,{json:t})=>{let{flow:n}=e,r={sourceControl:n.sourceControl.name,codeHost:n.codeHost.name,ciPipeline:n.ciPipeline.name,versioning:n.versioning.name},i=e.modules.map(({name:t,kind:n,provider:r,settings:i})=>({name:t,kind:n,provider:r,keys:f(i,[]),apps:e.units.filter(({module:e})=>e===t).map(({name:e})=>e)})),a=e.features.map(({name:e,adapters:t})=>({name:e,uses:t.map(e=>e.name)}));if(t){out(JSON.stringify({flow:r,modules:i,features:a},null,2));return}let o=Math.max(14,...i.map(({name:e})=>e.length),...a.map(({name:e})=>e.length))+2,section=e=>{out(),out(p(`bold`,e)),out()};section(`Flow in ${e.configFile??`shiplane.config.ts`}`),Object.entries(r).forEach(([e,t])=>out(` ${e.padEnd(o)}${t}`)),section(`Modules, in release order`),i.forEach(({name:e,provider:t,keys:n,apps:r})=>{let i=r.length>0?`used by ${r.join(`, `)}`:p(`dim`,`no app names it`);out(` ${e.padEnd(o)}${t} ${p(`dim`,n.join(`, `)||`no options`)}`),out(` ${` `.repeat(o)}${i}`)}),section(`Features, after the ship`),a.length===0&&out(` ${p(`dim`,`none`)}`),a.forEach(({name:e,uses:t})=>out(` ${e.padEnd(o)}${p(`dim`,`uses ${t.join(`, `)}`)}`)),out()},oe={"release-pr":`open the release PR: shiplane`,"wait-merge":`merge the release PR, then: shiplane`,ship:`tag what was versioned and ship it: shiplane`},nextLabel=({next:e,units:t,untagged:n},r)=>e.step===`ship`&&n.length===0&&!t.some(({pending:e})=>e)?`nothing to release: queue a change with ${r}`:oe[e.step]??``,statusCommand=async(e,{environment:t,json:n})=>{let r=await K(e,t);if(n){out(JSON.stringify(r,null,2));return}let i=p(`dim`,`·`);out();let a=S(e,[],t);out(` ${p(`bold`,`Release status`)} ${i} ${a}`),out();let o=Math.max(8,...r.units.map(({unit:e})=>e.length))+2;out(p(`dim`,` ${`Unit`.padEnd(o)}${`Version`.padEnd(12)}${`Target`.padEnd(18)}Where it stands`)),r.units.forEach(({unit:e,version:t,target:n,pending:r,hint:i})=>{let a=r?p(`yellow`,`↑`):p(`dim`,`·`);out(` ${e.padEnd(o)}${t.padEnd(12)}${n.padEnd(18)}${a} ${i}`)}),r.releasePrs.forEach(({url:e})=>out(`\n ${p(`cyan`,`Release PR`)} ${e}`)),r.untagged.length>0&&out(` ${p(`yellow`,`Untagged`)} ${r.untagged.map(({tag:e})=>e).join(`, `)}`),out(),out(`${p([`bold`,`green`],`→ Next:`)} ${nextLabel(r,e.services.versioning.nextChange)}`),out()},se=`${p(`bold`,`shiplane`)}: detect what changed, version it, trigger each app's deploy.
348
4
 
349
5
  shiplane the next step to preview: release PR, merge, tags, ship
350
6
  shiplane promote production, from what preview runs
@@ -355,8 +11,7 @@ const SHORT_HELP = `${paint("bold", "shiplane")}: detect what changed, version i
355
11
  shiplane docs <name> every key a module's or an adapter's unit files take
356
12
 
357
13
  shiplane help all every command and flag: version, tag, ship, remove and the rest
358
- `;
359
- const HELP = `${paint("bold", "shiplane")}: detect what changed, version it, trigger each app's deploy.
14
+ `,$=`${p(`bold`,`shiplane`)}: detect what changed, version it, trigger each app's deploy.
360
15
 
361
16
  shiplane the next step to preview: release PR, merge, tags, ship
362
17
  (on a branch: a test release, asked first)
@@ -372,12 +27,15 @@ const HELP = `${paint("bold", "shiplane")}: detect what changed, version it, tri
372
27
  shiplane plugins [--json] the flow, the modules in release order and who uses each, the features
373
28
 
374
29
  shiplane setup [--yes] set up, check, or add an app: asks only what it can't tell, rehearses, then writes
30
+ --format yaml writes shiplane.yml instead of shiplane.config.ts
375
31
  (shiplane init and shiplane add are now setup; both still run for now)
376
32
  shiplane remove <unit> stop shipping a unit; it stays versioned
377
33
  shiplane doctor check the config, tools and sign-ins, offer each fix
378
34
  shiplane doctor --ci [unit...] on a runner: units, --channel, tools (installed when missing), secrets
379
35
  shiplane adapter new <name> scaffold a server hosting adapter, its contract test and its module
380
36
  shiplane docs <name> every key a module's or an adapter's unit files take
37
+ shiplane migrate write shiplane.yml from shiplane.config.ts, the same release, and remove the TS
38
+ shiplane schema the editor schema of shiplane.yml, with the plugins installed and your own adapters
381
39
  shiplane help [all] the main commands; all: this, every command and flag
382
40
 
383
41
  --channel preview|production where status reads (preview by default)
@@ -389,166 +47,5 @@ const HELP = `${paint("bold", "shiplane")}: detect what changed, version it, tri
389
47
  --verbose / --no-verbose say each thing it reads and runs, with a progress bar (on by default)
390
48
  --mascot / --no-mascot the mascot beside it, still in CI or under NO_MOTION=1 (on by default)
391
49
  Both defaults live in shiplane.config.ts: display: { verbose, mascot }
392
- `;
393
- /** The commands `--dry-run` previews instead of running. */
394
- const DRY_RUNS = new Set([
395
- "next",
396
- "ship",
397
- "promote"
398
- ]);
399
- /** --via ci|local; the older --via github still means the CI pipeline, said once. */
400
- const viaFlag = (value) => {
401
- if (value === void 0) return void 0;
402
- if (value === "github") {
403
- out(paint("dim", "--via github is now --via ci: the flow's CI pipeline"));
404
- return "ci";
405
- }
406
- return z.enum(["ci", "local"]).parse(value);
407
- };
408
- /** The CLI as a person runs it, from its arguments and folder; resolves to its exit code. */
409
- const runCli = async (argv, cwd, io = {}) => {
410
- const { values, positionals } = parseArgs({
411
- args: argv,
412
- allowPositionals: true,
413
- allowNegative: true,
414
- options: {
415
- verbose: { type: "boolean" },
416
- mascot: { type: "boolean" },
417
- "dry-run": {
418
- type: "boolean",
419
- default: false
420
- },
421
- json: {
422
- type: "boolean",
423
- default: false
424
- },
425
- yes: {
426
- type: "boolean",
427
- short: "y",
428
- default: false
429
- },
430
- channel: {
431
- type: "string",
432
- default: "preview"
433
- },
434
- via: { type: "string" },
435
- blank: {
436
- type: "boolean",
437
- default: false
438
- },
439
- ci: {
440
- type: "boolean",
441
- default: false
442
- },
443
- "older-than": { type: "string" },
444
- otp: { type: "string" }
445
- }
446
- });
447
- const [command = "next", ...units] = positionals;
448
- const environment = command === "doctor" ? "preview" : z.enum(ENVIRONMENTS).parse(values.channel);
449
- const via = viaFlag(values.via);
450
- const testRelease = {
451
- onDefault: "publish",
452
- dryRun: values["dry-run"],
453
- ...units[0] === void 0 ? {} : { channel: units[0] }
454
- };
455
- const commands = {
456
- next: (context) => environment === "preview" ? branchRelease(context, { onDefault: "release" }) : promote(context, via),
457
- "test-release": (context) => branchRelease(context, testRelease),
458
- "prune-snapshots": (context) => pruneSnapshots(context, {
459
- dryRun: values["dry-run"],
460
- ...values["older-than"] === void 0 ? {} : { olderThanDays: Number(values["older-than"]) },
461
- ...values.otp === void 0 ? {} : { otp: values.otp }
462
- }),
463
- branch: (context) => branchRelease(context, testRelease),
464
- promote: (context) => promote(context, via),
465
- status: (context) => statusCommand(context, {
466
- environment,
467
- json: values.json
468
- }),
469
- version: async (context) => {
470
- const picked = await pickScope(context, "preview");
471
- if (!picked || picked.scope.size === 0) return true;
472
- return await openReleasePr(context, await prepareRelease(context, picked.scope)) !== null;
473
- },
474
- tag: async (context) => tagRelease(context, await missingTags(context)),
475
- ship: (context) => shipTo(context, environment, {
476
- via,
477
- ...units.length > 0 ? { scope: new Set(units) } : {}
478
- }),
479
- plan: (context) => {
480
- out(paint("dim", "plan is now --dry-run: shiplane ship --dry-run, shiplane promote --dry-run"));
481
- return planShips(context, environment);
482
- },
483
- plugins: (context) => Promise.resolve(pluginsCommand(context.release, { json: values.json }))
484
- };
485
- const [first = ""] = units;
486
- const setupCommands = {
487
- setup: (context) => setup(context, { yes: values.yes }),
488
- init: (context) => {
489
- if (values.blank) return initRelease(context, {
490
- yes: values.yes,
491
- blank: true
492
- });
493
- out(paint("dim", "init is now shiplane setup"));
494
- return setup(context, { yes: values.yes });
495
- },
496
- add: (context) => {
497
- out(paint("dim", "add is now shiplane setup: run it again to add an app"));
498
- return addUnit(context, first);
499
- },
500
- remove: (context) => removeUnit(context, first),
501
- doctor: (context) => values.ci ? doctorCi(context, {
502
- units,
503
- channel: values.channel
504
- }) : doctor(context, { yes: values.yes }),
505
- adapter: (context) => {
506
- if (first === "new" && units[1]) return newAdapter(context, units[1]);
507
- out(`${paint("red", "✗")} shiplane adapter new <name>`);
508
- return Promise.resolve(false);
509
- },
510
- docs: (context) => docsFor(context, first)
511
- };
512
- const root = findRoot(cwd);
513
- const files = io.setup?.files ?? nodeFiles(root);
514
- const firstRun = command === "next" && !files.exists("shiplane.config.ts");
515
- const run = values["dry-run"] && DRY_RUNS.has(command) ? (context) => planShips(context, command === "promote" ? "production" : environment) : commands[command];
516
- const setUp = setupCommands[firstRun ? "setup" : command];
517
- if (setUp) {
518
- const load = () => loadReleaseOnDisk(root, { aliases: io.aliases });
519
- return await setUp(await composeSetup(root, {
520
- load,
521
- ...io.setup
522
- })) ? 0 : 1;
523
- }
524
- if (command === "help") {
525
- out(first === "all" ? HELP : SHORT_HELP);
526
- return 0;
527
- }
528
- if (!run) {
529
- out(`${paint("red", "✗")} no command "${command}"`);
530
- out(HELP);
531
- return 1;
532
- }
533
- const release = await loadReleaseOnDisk(root, { aliases: io.aliases });
534
- if (release.problems.length > 0) {
535
- printProblems(release.problems);
536
- return 2;
537
- }
538
- (release.renames ?? []).forEach(({ from, to }) => out(`${paint("yellow", "!")} rename ${from} to ${to}: the old name still works for now`));
539
- refreshEditorSchema(nodeFiles(release.root), release);
540
- return await run(composeContext(release, {
541
- yes: values.yes,
542
- display: {
543
- verbose: values.verbose,
544
- mascot: values.mascot
545
- }
546
- }, io)) === false ? 1 : 0;
547
- };
548
- //#endregion
549
- //#region src/cli.ts
550
- process.exitCode = await runCli(process.argv.slice(2), process.cwd());
551
- //#endregion
552
- export {};
553
-
50
+ `,ce=new Set([`next`,`ship`,`promote`]),viaFlag=e=>{if(e!==void 0)return e===`github`?(out(p(`dim`,`--via github is now --via ci: the flow's CI pipeline`)),`ci`):X.enum([`ci`,`local`]).parse(e)},runCli=async(e,t,n={})=>{let{values:i,positionals:o}=re({args:e,allowPositionals:!0,allowNegative:!0,options:{verbose:{type:`boolean`},mascot:{type:`boolean`},"dry-run":{type:`boolean`,default:!1},json:{type:`boolean`,default:!1},yes:{type:`boolean`,short:`y`,default:!1},channel:{type:`string`,default:`preview`},via:{type:`string`},blank:{type:`boolean`,default:!1},ci:{type:`boolean`,default:!1},"older-than":{type:`string`},otp:{type:`string`},format:{type:`string`}}}),[c=`next`,...l]=o,u=c===`doctor`?`preview`:X.enum(B).parse(i.channel),d=viaFlag(i.via),f={onDefault:`publish`,dryRun:i[`dry-run`],...l[0]===void 0?{}:{channel:l[0]}},m={next:e=>u===`preview`?E(e,{onDefault:`release`}):L(e,d),"test-release":e=>E(e,f),"prune-snapshots":e=>pruneSnapshots(e,{dryRun:i[`dry-run`],...i[`older-than`]===void 0?{}:{olderThanDays:Number(i[`older-than`])},...i.otp===void 0?{}:{otp:i.otp}}),branch:e=>E(e,f),promote:e=>L(e,d),status:e=>statusCommand(e,{environment:u,json:i.json}),version:async e=>{let t=await J(e,`preview`);return!t||t.scope.size===0?!0:await O(e,await q(e,t.scope))!==null},tag:async e=>s(e,await b(e)),ship:e=>a(e,u,{via:d,...l.length>0?{scope:new Set(l)}:{}}),plan:e=>(out(p(`dim`,`plan is now --dry-run: shiplane ship --dry-run, shiplane promote --dry-run`)),G(e,u)),plugins:e=>Promise.resolve(pluginsCommand(e.release,{json:i.json}))},[v=``]=l,withSchema=async(e,t)=>t&&_.some(t=>e.files.exists(t))?writeConfigSchema(e,await D(e.root,n.aliases)):t,y={setup:e=>{if(i.format!==void 0&&i.format!==`ts`&&i.format!==`yaml`)return out(`${p(`red`,`✗`)} --format is ts (shiplane.config.ts, the default) or yaml (shiplane.yml)`),Promise.resolve(!1);let t=i.format===`yaml`?`yaml`:`ts`;return k(e,{yes:i.yes,format:t}).then(t=>withSchema(e,t))},init:e=>i.blank?r(e,{yes:i.yes,blank:!0}):(out(p(`dim`,`init is now shiplane setup`)),k(e,{yes:i.yes})),add:e=>(out(p(`dim`,`add is now shiplane setup: run it again to add an app`)),g(e,v)),remove:e=>I(e,v),doctor:e=>i.ci?doctorCi(e,{units:l,channel:i.channel}):F(e,{yes:i.yes}),adapter:e=>v===`new`&&l[1]?ee(e,l[1]):(out(`${p(`red`,`✗`)} shiplane adapter new <name>`),Promise.resolve(!1)),docs:e=>te(e,v),migrate:async e=>{let t=H({aliases:n.aliases}),r=t.find(e.root);return withSchema(e,await migrate(e,{tsFile:r,declared:()=>r?t.read(r):Promise.resolve(void 0),catalog:await D(e.root,n.aliases),load:t=>V(e.root,t,{aliases:n.aliases})}))},schema:async e=>writeConfigSchema(e,await D(e.root,n.aliases))},x=findRoot(t),S=n.setup?.files??w(x),C=c===`next`&&![`shiplane.config.ts`,..._].some(e=>S.exists(e)),T=i[`dry-run`]&&ce.has(c)?e=>G(e,c===`promote`?`production`:u):m[c],A=y[C?`setup`:c];if(A){let load=()=>P(x,{aliases:n.aliases});return+!await A(await z(x,{load,...n.setup}))}if(c===`help`)return out(v===`all`?$:se),0;if(!T)return out(`${p(`red`,`✗`)} no command "${c}"`),out($),1;let j=await P(x,{aliases:n.aliases});return j.problems.length>0?(printProblems(j.problems),2):((j.renames??[]).forEach(({from:e,to:t})=>out(`${p(`yellow`,`!`)} rename ${e} to ${t}: the old name still works for now`)),h(w(j.root),j),+(await T(U(j,{yes:i.yes,display:{verbose:i.verbose,mascot:i.mascot}},n))===!1))};process.exitCode=await runCli(process.argv.slice(2),process.cwd());export{};
554
51
  //# sourceMappingURL=cli.js.map