@coderook/cli 0.25.3 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/dist/cli/src/api.js +156 -6
- package/dist/cli/src/cli.js +170 -1
- package/dist/cli/src/git_history.js +10 -4
- package/dist/cli/src/git_remote.js +136 -12
- package/dist/cli/src/git_remote_bin.js +33 -3
- package/dist/cli/src/project_commands.js +23 -1
- package/dist/cli/src/publish.js +9 -0
- package/dist/cli/src/service_commands.js +2 -1
- package/dist/cli/src/version_commands.js +493 -0
- package/dist/desktop-app/src/main/secret_patterns.js +75 -0
- package/dist/desktop-app/src/main/tracks.js +58 -0
- package/dist/desktop-app/src/main/upload.js +2 -0
- package/dist/desktop-app/src/main/worktree.js +79 -47
- package/package.json +1 -1
- package/skills/coderook/SKILL.md +24 -0
|
@@ -14,9 +14,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
*/
|
|
15
15
|
const node_process_1 = __importDefault(require("node:process"));
|
|
16
16
|
const git_remote_js_1 = require("./git_remote.js");
|
|
17
|
+
/**
|
|
18
|
+
* Finish, without cutting the pipe to git mid-sentence.
|
|
19
|
+
*
|
|
20
|
+
* `process.exit()` ends the process immediately, while stdout may still hold
|
|
21
|
+
* writes queued for git. On Windows that surfaced as
|
|
22
|
+
*
|
|
23
|
+
* Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), src\win\async.c
|
|
24
|
+
*
|
|
25
|
+
* on the way out of a clone — libuv tearing down a handle that was still
|
|
26
|
+
* being written to. Setting the code instead lets the loop drain what is
|
|
27
|
+
* owed and end on its own, which is also the only way git reliably sees the
|
|
28
|
+
* last of the protocol.
|
|
29
|
+
*
|
|
30
|
+
* The timer is the belt: it only fires if something else is still holding
|
|
31
|
+
* the loop open, and being unreferenced it cannot be the thing holding it.
|
|
32
|
+
*/
|
|
33
|
+
function finish(code) {
|
|
34
|
+
node_process_1.default.exitCode = code;
|
|
35
|
+
/* stdin is already at EOF by the time main returns; this releases it. */
|
|
36
|
+
node_process_1.default.stdin.pause();
|
|
37
|
+
setTimeout(() => node_process_1.default.exit(code), 5000).unref();
|
|
38
|
+
}
|
|
17
39
|
(0, git_remote_js_1.main)(node_process_1.default.argv.slice(2))
|
|
18
|
-
.then(
|
|
40
|
+
.then(finish)
|
|
19
41
|
.catch((error) => {
|
|
20
|
-
|
|
21
|
-
|
|
42
|
+
/*
|
|
43
|
+
Said once. A refusal that has already set itself out in full does not
|
|
44
|
+
want the same paragraph printed again with a program name in front of
|
|
45
|
+
it — which is what a reader got when a push was turned down for
|
|
46
|
+
carrying a credential.
|
|
47
|
+
*/
|
|
48
|
+
if (!(error instanceof git_remote_js_1.AlreadyReported)) {
|
|
49
|
+
node_process_1.default.stderr.write(`git-remote-coderook: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
50
|
+
}
|
|
51
|
+
finish(1);
|
|
22
52
|
});
|
|
@@ -138,8 +138,30 @@ async function commandVersions(parsed) {
|
|
|
138
138
|
const when = version.createdAt
|
|
139
139
|
? new Date(version.createdAt).toLocaleString()
|
|
140
140
|
: "";
|
|
141
|
+
/*
|
|
142
|
+
What the project has made of this version, said before the numbers.
|
|
143
|
+
|
|
144
|
+
A name, a pin and a set of labels are how somebody finds the version
|
|
145
|
+
they meant among forty; the file count is how they check it once they
|
|
146
|
+
have. Putting the arrangement first is the difference between a log and
|
|
147
|
+
a list they organised.
|
|
148
|
+
*/
|
|
149
|
+
const marks = [
|
|
150
|
+
/* Which one the project is standing on, which is not the same as which
|
|
151
|
+
one is at the top once somebody has pinned something. */
|
|
152
|
+
version.head ? green("current") : "",
|
|
153
|
+
version.pinned ? accent("pinned") : "",
|
|
154
|
+
version.name ? bold(version.name) : "",
|
|
155
|
+
version.state === "held" ? red("held") : "",
|
|
156
|
+
version.state === "declined" ? dim("declined") : "",
|
|
157
|
+
version.removedAt ? dim("taken down") : "",
|
|
158
|
+
version.visibility === "private" ? dim("private") : "",
|
|
159
|
+
version.visibility === "unlisted" ? dim("link only") : "",
|
|
160
|
+
...version.labels.map((label) => accent(label.name)),
|
|
161
|
+
].filter(Boolean);
|
|
141
162
|
console.log(` ${accent(`v${version.sequence}`).padEnd(16)} ${when.padEnd(22)}` +
|
|
142
|
-
`${String(version.fileCount).padStart(5)} files ${bytes(version.storedSize)}`
|
|
163
|
+
`${String(version.fileCount).padStart(5)} files ${bytes(version.storedSize)}` +
|
|
164
|
+
(marks.length ? ` ${marks.join(" ")}` : ""));
|
|
143
165
|
if (version.message)
|
|
144
166
|
console.log(` ${dim(version.message)}`);
|
|
145
167
|
}
|
package/dist/cli/src/publish.js
CHANGED
|
@@ -15,6 +15,7 @@ function uploadRequestFor(input) {
|
|
|
15
15
|
baseVersionId: input.baseVersionId,
|
|
16
16
|
...(input.track ? { track: input.track } : {}),
|
|
17
17
|
...(input.allowIgnored ? { allowIgnored: true } : {}),
|
|
18
|
+
...(input.allowSecrets ? { allowSecrets: true } : {}),
|
|
18
19
|
...(input.acknowledged ? { acknowledged: true } : {}),
|
|
19
20
|
...(input.acknowledgedNoLicence ? { acknowledgedNoLicence: true } : {}),
|
|
20
21
|
...(input.baseVersionId
|
|
@@ -29,6 +30,14 @@ function classifyPublishFailure(error) {
|
|
|
29
30
|
if (code === "merge_required" || code === "track_moved") {
|
|
30
31
|
return { kind: "conflict", message };
|
|
31
32
|
}
|
|
33
|
+
/*
|
|
34
|
+
A credential the service refused. Named separately because the answer is
|
|
35
|
+
not "try again" — it is "take the key out", and for a push there is no
|
|
36
|
+
flag to pass instead, because git has nowhere to ask the question.
|
|
37
|
+
*/
|
|
38
|
+
if (code === "version_credentials") {
|
|
39
|
+
return { kind: "credentials", message };
|
|
40
|
+
}
|
|
32
41
|
if (!code &&
|
|
33
42
|
/fetch failed|ECONNRESET|socket hang up|network|ETIMEDOUT/i.test(message)) {
|
|
34
43
|
return { kind: "interrupted", message };
|
|
@@ -105,7 +105,8 @@ async function commandRelease(parsed) {
|
|
|
105
105
|
const wanted = parsed.flags.get("version");
|
|
106
106
|
const target = typeof wanted === "string"
|
|
107
107
|
? all.find((version) => String(version.sequence) === wanted.replace(/^v/i, ""))
|
|
108
|
-
|
|
108
|
+
/* The newest by number rather than by position in the list. */
|
|
109
|
+
: all.reduce((newest, one) => (one.sequence > newest.sequence ? one : newest));
|
|
109
110
|
if (!target) {
|
|
110
111
|
console.error(red(`This project has no version ${String(wanted)}.`));
|
|
111
112
|
return 1;
|
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Arranging a project's versions from the terminal.
|
|
4
|
+
*
|
|
5
|
+
* Every one of these things could already be done — from the website, and only
|
|
6
|
+
* from the website. That is the gap this closes: naming worked here, hiding
|
|
7
|
+
* did not, and colouring and pinning existed nowhere. A person who works in a
|
|
8
|
+
* terminal should not have to open a browser to say which version matters.
|
|
9
|
+
*
|
|
10
|
+
* One command does the changing, because the service takes one patch: `cbx
|
|
11
|
+
* version 12 --name v2.1 --hide --pin` is a single request that either happened
|
|
12
|
+
* or did not, rather than three that can half-happen.
|
|
13
|
+
*/
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.split = split;
|
|
19
|
+
exports.commandVersion = commandVersion;
|
|
20
|
+
exports.commandLabels = commandLabels;
|
|
21
|
+
exports.commandHeld = commandHeld;
|
|
22
|
+
exports.commandReview = commandReview;
|
|
23
|
+
exports.commandTakeDown = commandTakeDown;
|
|
24
|
+
exports.commandPromote = commandPromote;
|
|
25
|
+
exports.commandUndo = commandUndo;
|
|
26
|
+
const api_js_1 = require("./api.js");
|
|
27
|
+
const project_commands_js_1 = require("./project_commands.js");
|
|
28
|
+
const promises_1 = require("node:readline/promises");
|
|
29
|
+
const node_process_1 = __importDefault(require("node:process"));
|
|
30
|
+
/* Written out rather than imported: the same four escapes every other command
|
|
31
|
+
file in here declares for itself, and a shared module for four one-line
|
|
32
|
+
functions would be the only thing they all depend on. */
|
|
33
|
+
const dim = (value) => `[2m${value}[0m`;
|
|
34
|
+
const bold = (value) => `[1m${value}[0m`;
|
|
35
|
+
const red = (value) => `[31m${value}[0m`;
|
|
36
|
+
const accent = (value) => `[33m${value}[0m`;
|
|
37
|
+
/**
|
|
38
|
+
* Which of `[n] [project]` the arguments actually were.
|
|
39
|
+
*
|
|
40
|
+
* Both are optional and both are positional, so `cbx undo blog` has to be read
|
|
41
|
+
* as a project and `cbx undo 41` as a save — the shape of the word is the only
|
|
42
|
+
* thing that separates them. A save is digits, optionally with a leading v;
|
|
43
|
+
* anything else is a project name.
|
|
44
|
+
*
|
|
45
|
+
* That leaves a project whose whole name is digits unreachable this way. It
|
|
46
|
+
* still works as `--project 41`, and reading a bare number as a save is the
|
|
47
|
+
* one that comes up.
|
|
48
|
+
*/
|
|
49
|
+
function split(parsed) {
|
|
50
|
+
const named = parsed.flags.get("project") ?? parsed.flags.get("p");
|
|
51
|
+
const flagged = typeof named === "string" && named ? named : undefined;
|
|
52
|
+
const [first, second] = parsed.positional;
|
|
53
|
+
if (second !== undefined)
|
|
54
|
+
return { n: first, project: flagged ?? second };
|
|
55
|
+
if (first === undefined)
|
|
56
|
+
return { project: flagged };
|
|
57
|
+
if (flagged)
|
|
58
|
+
return { n: first, project: flagged };
|
|
59
|
+
return /^v?\d+$/i.test(first) ? { n: first } : { project: first };
|
|
60
|
+
}
|
|
61
|
+
/** The version somebody meant, which is usually the newest one. */
|
|
62
|
+
async function pick(repositoryId, wanted) {
|
|
63
|
+
const all = await (0, api_js_1.versions)(repositoryId);
|
|
64
|
+
if (!all.length) {
|
|
65
|
+
console.error(red("This project has no versions yet."));
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
/*
|
|
69
|
+
The newest by number, not by position.
|
|
70
|
+
|
|
71
|
+
The list arrives newest first today, and relying on that is how three
|
|
72
|
+
callers started reporting a pinned old save as the current one when the
|
|
73
|
+
order changed for a while. Asking for the largest number cannot be broken
|
|
74
|
+
by how the list happens to be sorted.
|
|
75
|
+
*/
|
|
76
|
+
if (!wanted) {
|
|
77
|
+
return all.reduce((newest, one) => (one.sequence > newest.sequence ? one : newest));
|
|
78
|
+
}
|
|
79
|
+
const sequence = wanted.replace(/^v/i, "");
|
|
80
|
+
const found = all.find((one) => String(one.sequence) === sequence);
|
|
81
|
+
if (!found) {
|
|
82
|
+
console.error(red(`This project has no version ${wanted}.`));
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return found;
|
|
86
|
+
}
|
|
87
|
+
const SWATCH = {
|
|
88
|
+
red: "#e0574a",
|
|
89
|
+
amber: "#e8a13f",
|
|
90
|
+
yellow: "#e8d13f",
|
|
91
|
+
green: "#5fcf8d",
|
|
92
|
+
blue: "#5aa9e6",
|
|
93
|
+
purple: "#a98ae0",
|
|
94
|
+
pink: "#e68ab8",
|
|
95
|
+
grey: "#8c968f",
|
|
96
|
+
gray: "#8c968f",
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* A colour, given either as a name or as hex.
|
|
100
|
+
*
|
|
101
|
+
* Names because nobody remembers hex, hex because somebody will want their own
|
|
102
|
+
* exact one and being told "pick from these eight" is the kind of small refusal
|
|
103
|
+
* that makes a tool feel like it is arguing.
|
|
104
|
+
*/
|
|
105
|
+
function colourOf(given) {
|
|
106
|
+
const value = given.trim().toLowerCase();
|
|
107
|
+
if (SWATCH[value])
|
|
108
|
+
return SWATCH[value];
|
|
109
|
+
const hex = value.startsWith("#") ? value : `#${value}`;
|
|
110
|
+
return /^#[0-9a-f]{6}$/.test(hex) ? hex : null;
|
|
111
|
+
}
|
|
112
|
+
function paint(label) {
|
|
113
|
+
return accent(label.name);
|
|
114
|
+
}
|
|
115
|
+
async function commandVersion(parsed) {
|
|
116
|
+
const which = split(parsed);
|
|
117
|
+
const project = await (0, project_commands_js_1.resolveProject)(which.project);
|
|
118
|
+
if (!project)
|
|
119
|
+
return 1;
|
|
120
|
+
const target = await pick(project.id, which.n);
|
|
121
|
+
if (!target)
|
|
122
|
+
return 1;
|
|
123
|
+
const patch = {};
|
|
124
|
+
const name = parsed.flags.get("name");
|
|
125
|
+
if (typeof name === "string")
|
|
126
|
+
patch.name = name;
|
|
127
|
+
if (parsed.flags.get("unname") === true)
|
|
128
|
+
patch.name = null;
|
|
129
|
+
const notes = parsed.flags.get("notes");
|
|
130
|
+
if (typeof notes === "string")
|
|
131
|
+
patch.notes = notes;
|
|
132
|
+
if (parsed.flags.get("hide") === true)
|
|
133
|
+
patch.visibility = "private";
|
|
134
|
+
if (parsed.flags.get("show") === true)
|
|
135
|
+
patch.visibility = "public";
|
|
136
|
+
const visibility = parsed.flags.get("visibility");
|
|
137
|
+
if (typeof visibility === "string") {
|
|
138
|
+
if (!["private", "unlisted", "public"].includes(visibility)) {
|
|
139
|
+
console.error(red("Visibility is private, unlisted or public."));
|
|
140
|
+
return 1;
|
|
141
|
+
}
|
|
142
|
+
patch.visibility = visibility;
|
|
143
|
+
}
|
|
144
|
+
if (parsed.flags.get("pin") === true)
|
|
145
|
+
patch.pinned = true;
|
|
146
|
+
if (parsed.flags.get("unpin") === true)
|
|
147
|
+
patch.pinned = false;
|
|
148
|
+
const labelNames = parsed.flags.get("labels");
|
|
149
|
+
if (typeof labelNames === "string") {
|
|
150
|
+
const known = await (0, api_js_1.projectLabels)(project.id);
|
|
151
|
+
const wanted = labelNames
|
|
152
|
+
.split(",")
|
|
153
|
+
.map((one) => one.trim())
|
|
154
|
+
.filter(Boolean);
|
|
155
|
+
const ids = [];
|
|
156
|
+
for (const one of wanted) {
|
|
157
|
+
const found = known.find((label) => label.name.toLowerCase() === one.toLowerCase());
|
|
158
|
+
if (!found) {
|
|
159
|
+
console.error(red(`This project has no "${one}" label.`) +
|
|
160
|
+
dim(` Make one with cbx labels add ${one} green`));
|
|
161
|
+
return 1;
|
|
162
|
+
}
|
|
163
|
+
ids.push(found.id);
|
|
164
|
+
}
|
|
165
|
+
patch.labelIds = ids;
|
|
166
|
+
}
|
|
167
|
+
if (parsed.flags.get("clear-labels") === true)
|
|
168
|
+
patch.labelIds = [];
|
|
169
|
+
if (!Object.keys(patch).length) {
|
|
170
|
+
console.error(red("Say what to change.") +
|
|
171
|
+
dim(" --name, --notes, --hide, --show, --visibility, --pin, --labels"));
|
|
172
|
+
return 1;
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
await (0, api_js_1.changeVersion)(project.id, target.id, patch);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
console.error(red(error instanceof Error ? error.message : String(error)));
|
|
179
|
+
return 1;
|
|
180
|
+
}
|
|
181
|
+
const said = [];
|
|
182
|
+
if (patch.name !== undefined) {
|
|
183
|
+
said.push(patch.name ? `named ${accent(patch.name)}` : "name removed");
|
|
184
|
+
}
|
|
185
|
+
if (patch.visibility)
|
|
186
|
+
said.push(patch.visibility);
|
|
187
|
+
if (patch.pinned !== undefined)
|
|
188
|
+
said.push(patch.pinned ? "pinned" : "unpinned");
|
|
189
|
+
if (patch.labelIds) {
|
|
190
|
+
said.push(patch.labelIds.length ? "labelled" : "labels cleared");
|
|
191
|
+
}
|
|
192
|
+
console.log(`${bold(`v${target.sequence}`)} ${said.join(", ")}.`);
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
async function commandLabels(parsed) {
|
|
196
|
+
const action = parsed.positional[0] ?? "list";
|
|
197
|
+
if (action === "list") {
|
|
198
|
+
const project = await (0, project_commands_js_1.resolveProject)(parsed.positional[1]);
|
|
199
|
+
if (!project)
|
|
200
|
+
return 1;
|
|
201
|
+
const labels = await (0, api_js_1.projectLabels)(project.id);
|
|
202
|
+
if (!labels.length) {
|
|
203
|
+
console.log(dim("No labels yet. Make one with cbx labels add shipped green"));
|
|
204
|
+
return 0;
|
|
205
|
+
}
|
|
206
|
+
console.log(bold(project.name));
|
|
207
|
+
for (const label of labels) {
|
|
208
|
+
console.log(` ${paint(label).padEnd(28)} ${dim(label.colour)}` +
|
|
209
|
+
(label.description ? ` ${dim(label.description)}` : ""));
|
|
210
|
+
}
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
if (action === "add") {
|
|
214
|
+
const name = parsed.positional[1];
|
|
215
|
+
const colour = parsed.positional[2] ?? "grey";
|
|
216
|
+
if (!name) {
|
|
217
|
+
console.error(red("Name the label: cbx labels add shipped green"));
|
|
218
|
+
return 1;
|
|
219
|
+
}
|
|
220
|
+
const project = await (0, project_commands_js_1.resolveProject)(parsed.positional[3]);
|
|
221
|
+
if (!project)
|
|
222
|
+
return 1;
|
|
223
|
+
const hex = colourOf(colour);
|
|
224
|
+
if (!hex) {
|
|
225
|
+
console.error(red(`"${colour}" is not a colour.`) +
|
|
226
|
+
dim(` Try one of ${Object.keys(SWATCH).slice(0, 8).join(", ")}, or #rrggbb`));
|
|
227
|
+
return 1;
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
const made = await (0, api_js_1.createProjectLabel)(project.id, name, hex);
|
|
231
|
+
console.log(`Added ${paint(made)} ${dim(made.colour)}.`);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
console.error(red(error instanceof Error ? error.message : String(error)));
|
|
235
|
+
return 1;
|
|
236
|
+
}
|
|
237
|
+
return 0;
|
|
238
|
+
}
|
|
239
|
+
if (action === "remove" || action === "rm") {
|
|
240
|
+
const name = parsed.positional[1];
|
|
241
|
+
if (!name) {
|
|
242
|
+
console.error(red("Name the label to remove: cbx labels remove shipped"));
|
|
243
|
+
return 1;
|
|
244
|
+
}
|
|
245
|
+
const project = await (0, project_commands_js_1.resolveProject)(parsed.positional[2]);
|
|
246
|
+
if (!project)
|
|
247
|
+
return 1;
|
|
248
|
+
const labels = await (0, api_js_1.projectLabels)(project.id);
|
|
249
|
+
const found = labels.find((one) => one.name.toLowerCase() === name.toLowerCase());
|
|
250
|
+
if (!found) {
|
|
251
|
+
console.error(red(`This project has no "${name}" label.`));
|
|
252
|
+
return 1;
|
|
253
|
+
}
|
|
254
|
+
await (0, api_js_1.deleteProjectLabel)(project.id, found.id);
|
|
255
|
+
console.log(`Removed ${found.name}. ` +
|
|
256
|
+
dim("Versions that wore it keep everything else about them."));
|
|
257
|
+
return 0;
|
|
258
|
+
}
|
|
259
|
+
console.error(red(`Unknown: cbx labels ${action}`) + dim(" Try list, add or remove"));
|
|
260
|
+
return 1;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* The versions a project is holding until somebody says yes.
|
|
264
|
+
*
|
|
265
|
+
* Listed first rather than requiring a version number, because the person
|
|
266
|
+
* running this is usually asking "is there anything waiting for me" rather
|
|
267
|
+
* than acting on one they already know about.
|
|
268
|
+
*/
|
|
269
|
+
async function commandHeld(parsed) {
|
|
270
|
+
const project = await (0, project_commands_js_1.resolveProject)(parsed.positional[0]);
|
|
271
|
+
if (!project)
|
|
272
|
+
return 1;
|
|
273
|
+
const waiting = (await (0, api_js_1.versions)(project.id)).filter((one) => one.state === "held");
|
|
274
|
+
if (!waiting.length) {
|
|
275
|
+
console.log(dim("Nothing is waiting for a decision."));
|
|
276
|
+
return 0;
|
|
277
|
+
}
|
|
278
|
+
console.log(bold(`${waiting.length} waiting on ${project.name}`));
|
|
279
|
+
for (const one of waiting) {
|
|
280
|
+
console.log(` ${accent(`v${one.sequence}`).padEnd(16)} ${one.authorName.padEnd(20)} ` +
|
|
281
|
+
dim(one.message));
|
|
282
|
+
}
|
|
283
|
+
console.log(dim(`\n cbx review v${waiting[0].sequence} --approve`));
|
|
284
|
+
return 0;
|
|
285
|
+
}
|
|
286
|
+
async function commandReview(parsed) {
|
|
287
|
+
const which = split(parsed);
|
|
288
|
+
const approve = parsed.flags.get("approve") === true;
|
|
289
|
+
const decline = parsed.flags.get("decline") === true;
|
|
290
|
+
if (approve === decline) {
|
|
291
|
+
console.error(red("Say which: --approve or --decline."));
|
|
292
|
+
return 1;
|
|
293
|
+
}
|
|
294
|
+
const project = await (0, project_commands_js_1.resolveProject)(which.project);
|
|
295
|
+
if (!project)
|
|
296
|
+
return 1;
|
|
297
|
+
const target = await pick(project.id, which.n);
|
|
298
|
+
if (!target)
|
|
299
|
+
return 1;
|
|
300
|
+
if (target.state !== "held") {
|
|
301
|
+
console.error(red(`v${target.sequence} is not waiting for a decision.`));
|
|
302
|
+
return 1;
|
|
303
|
+
}
|
|
304
|
+
const note = parsed.flags.get("note");
|
|
305
|
+
try {
|
|
306
|
+
await (0, api_js_1.reviewVersion)(project.id, target.id, approve ? "approve" : "decline", typeof note === "string" ? note : null);
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
console.error(red(error instanceof Error ? error.message : String(error)));
|
|
310
|
+
return 1;
|
|
311
|
+
}
|
|
312
|
+
console.log(approve
|
|
313
|
+
? `${bold(`v${target.sequence}`)} approved. It is now the current version.`
|
|
314
|
+
: `${bold(`v${target.sequence}`)} declined. It stays in the history as a version that was not accepted.`);
|
|
315
|
+
return 0;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Take a version's content down.
|
|
319
|
+
*
|
|
320
|
+
* Asks first, and says exactly what will survive, because this is the one
|
|
321
|
+
* command here that destroys something. The version itself stays — the list
|
|
322
|
+
* keeps a gap saying what went and who removed it — and that distinction is
|
|
323
|
+
* the difference between this and rewriting history.
|
|
324
|
+
*/
|
|
325
|
+
async function commandTakeDown(parsed) {
|
|
326
|
+
const which = split(parsed);
|
|
327
|
+
const project = await (0, project_commands_js_1.resolveProject)(which.project);
|
|
328
|
+
if (!project)
|
|
329
|
+
return 1;
|
|
330
|
+
const target = await pick(project.id, which.n);
|
|
331
|
+
if (!target)
|
|
332
|
+
return 1;
|
|
333
|
+
const reason = parsed.flags.get("reason");
|
|
334
|
+
if (parsed.flags.get("yes") !== true) {
|
|
335
|
+
console.log(red(`This removes the files in v${target.sequence}. They do not come back.`));
|
|
336
|
+
console.log(dim(` The version stays in the history as a gap saying it was removed.\n` +
|
|
337
|
+
` Add --yes when you are sure.`));
|
|
338
|
+
return 1;
|
|
339
|
+
}
|
|
340
|
+
try {
|
|
341
|
+
await (0, api_js_1.removeVersionContent)(project.id, target.id, typeof reason === "string" ? reason : null);
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
console.error(red(error instanceof Error ? error.message : String(error)));
|
|
345
|
+
return 1;
|
|
346
|
+
}
|
|
347
|
+
console.log(`${bold(`v${target.sequence}`)} taken down.`);
|
|
348
|
+
return 0;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Turning a commit into a version.
|
|
352
|
+
*
|
|
353
|
+
* A project's history is its working history — most of it says "fix that
|
|
354
|
+
* file", and none of that is anybody else's business. A version is a commit
|
|
355
|
+
* somebody decided was worth showing, and this is where that decision gets
|
|
356
|
+
* made: the last ten, pick one, name it.
|
|
357
|
+
*
|
|
358
|
+
* Named rather than numbered on purpose. A version people fetch is "v2.1" or
|
|
359
|
+
* "the one for the client", and inventing a second counter beside the commit
|
|
360
|
+
* numbers would give everybody two numbers to hold and tell them nothing.
|
|
361
|
+
*/
|
|
362
|
+
async function commandPromote(parsed) {
|
|
363
|
+
const which = split(parsed);
|
|
364
|
+
const project = await (0, project_commands_js_1.resolveProject)(which.project);
|
|
365
|
+
if (!project)
|
|
366
|
+
return 1;
|
|
367
|
+
const all = await (0, api_js_1.versions)(project.id);
|
|
368
|
+
if (!all.length) {
|
|
369
|
+
console.error(red("This project has nothing saved yet."));
|
|
370
|
+
return 1;
|
|
371
|
+
}
|
|
372
|
+
const named = parsed.flags.get("name");
|
|
373
|
+
const notes = parsed.flags.get("notes");
|
|
374
|
+
/* A number given outright skips the list, for anybody scripting this. */
|
|
375
|
+
const asked = which.n;
|
|
376
|
+
let target = asked
|
|
377
|
+
? all.find((one) => String(one.sequence) === asked.replace(/^v/i, ""))
|
|
378
|
+
: null;
|
|
379
|
+
if (asked && !target) {
|
|
380
|
+
console.error(red(`This project has no ${asked}.`));
|
|
381
|
+
return 1;
|
|
382
|
+
}
|
|
383
|
+
if (!target) {
|
|
384
|
+
const recent = all.filter((one) => one.state === "verified").slice(0, 10);
|
|
385
|
+
if (!recent.length) {
|
|
386
|
+
console.error(red("Nothing here can be promoted yet."));
|
|
387
|
+
return 1;
|
|
388
|
+
}
|
|
389
|
+
console.log(bold(`Recent commits on ${project.name}`));
|
|
390
|
+
recent.forEach((one, at) => {
|
|
391
|
+
const when = one.createdAt
|
|
392
|
+
? new Date(one.createdAt).toLocaleString()
|
|
393
|
+
: "";
|
|
394
|
+
const already = one.name ? accent(` → ${one.name}`) : "";
|
|
395
|
+
console.log(` ${String(at + 1).padStart(2)}. ${accent(`v${one.sequence}`).padEnd(16)}` +
|
|
396
|
+
`${when.padEnd(22)}${dim(one.message)}${already}`);
|
|
397
|
+
});
|
|
398
|
+
const prompt = (0, promises_1.createInterface)({
|
|
399
|
+
input: node_process_1.default.stdin,
|
|
400
|
+
output: node_process_1.default.stdout,
|
|
401
|
+
});
|
|
402
|
+
const typed = await prompt.question("\nWhich one? (1-" + recent.length + ", or blank to stop) ");
|
|
403
|
+
prompt.close();
|
|
404
|
+
const choice = Number(typed.trim());
|
|
405
|
+
if (!typed.trim()) {
|
|
406
|
+
console.log(dim("Nothing promoted."));
|
|
407
|
+
return 0;
|
|
408
|
+
}
|
|
409
|
+
if (!Number.isInteger(choice) || choice < 1 || choice > recent.length) {
|
|
410
|
+
console.error(red("That was not one of the numbers listed."));
|
|
411
|
+
return 1;
|
|
412
|
+
}
|
|
413
|
+
target = recent[choice - 1];
|
|
414
|
+
}
|
|
415
|
+
let versionName = typeof named === "string" ? named.trim() : "";
|
|
416
|
+
if (!versionName) {
|
|
417
|
+
const prompt = (0, promises_1.createInterface)({
|
|
418
|
+
input: node_process_1.default.stdin,
|
|
419
|
+
output: node_process_1.default.stdout,
|
|
420
|
+
});
|
|
421
|
+
const typed = await prompt.question(`Call it what? (blank for v${target.sequence}.0) `);
|
|
422
|
+
prompt.close();
|
|
423
|
+
versionName = typed.trim() || `v${target.sequence}.0`;
|
|
424
|
+
}
|
|
425
|
+
try {
|
|
426
|
+
await (0, api_js_1.changeVersion)(project.id, target.id, {
|
|
427
|
+
name: versionName,
|
|
428
|
+
...(typeof notes === "string" ? { notes } : {}),
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
catch (error) {
|
|
432
|
+
console.error(red(error instanceof Error ? error.message : String(error)));
|
|
433
|
+
return 1;
|
|
434
|
+
}
|
|
435
|
+
console.log(`${bold(versionName)} is now a version. ` +
|
|
436
|
+
dim("It is what the public side of this project offers."));
|
|
437
|
+
return 0;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Putting the project back where it was.
|
|
441
|
+
*
|
|
442
|
+
* Hiding a bad push stops strangers reading it and leaves everybody on the
|
|
443
|
+
* team standing on it. This moves the project itself, which is the half that
|
|
444
|
+
* was missing — and it destroys nothing: the commits that get passed over stay
|
|
445
|
+
* in the history with their numbers, and a later save carries on from here.
|
|
446
|
+
*/
|
|
447
|
+
async function commandUndo(parsed) {
|
|
448
|
+
const which = split(parsed);
|
|
449
|
+
const project = await (0, project_commands_js_1.resolveProject)(which.project);
|
|
450
|
+
if (!project)
|
|
451
|
+
return 1;
|
|
452
|
+
const all = await (0, api_js_1.versions)(project.id);
|
|
453
|
+
if (all.length < 2) {
|
|
454
|
+
console.error(red("There is nothing before this to go back to."));
|
|
455
|
+
return 1;
|
|
456
|
+
}
|
|
457
|
+
let to = null;
|
|
458
|
+
const asked = which.n;
|
|
459
|
+
if (asked) {
|
|
460
|
+
const wanted = all.find((one) => String(one.sequence) === asked.replace(/^v/i, ""));
|
|
461
|
+
if (!wanted) {
|
|
462
|
+
console.error(red(`This project has no ${asked}.`));
|
|
463
|
+
return 1;
|
|
464
|
+
}
|
|
465
|
+
to = wanted.id;
|
|
466
|
+
}
|
|
467
|
+
try {
|
|
468
|
+
const undone = await (0, api_js_1.undoTo)(project.id, to);
|
|
469
|
+
console.log(`${bold(project.name)} is back on ${accent(`v${undone.to.sequence}`)}.`);
|
|
470
|
+
if (undone.skipped.length) {
|
|
471
|
+
/*
|
|
472
|
+
Named rather than counted. "3 commits passed over" tells somebody
|
|
473
|
+
nothing they can act on; the numbers let them look at one, or promote
|
|
474
|
+
one, or put the head back where it was.
|
|
475
|
+
*/
|
|
476
|
+
console.log(dim(` Passed over: ${undone.skipped
|
|
477
|
+
.map((one) => `v${one.sequence}${one.name ? ` (${one.name})` : ""}`)
|
|
478
|
+
.join(", ")}`));
|
|
479
|
+
console.log(dim(" They are still here. Nothing was deleted and nothing renumbered."));
|
|
480
|
+
const stillPublic = undone.skipped.filter((one) => one.name);
|
|
481
|
+
if (stillPublic.length) {
|
|
482
|
+
console.log(dim(` ${stillPublic.map((one) => one.name).join(", ")} ` +
|
|
483
|
+
`${stillPublic.length === 1 ? "is" : "are"} still a published version — ` +
|
|
484
|
+
`use cbx mark to take ${stillPublic.length === 1 ? "it" : "them"} down.`));
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
catch (error) {
|
|
489
|
+
console.error(red(error instanceof Error ? error.message : String(error)));
|
|
490
|
+
return 1;
|
|
491
|
+
}
|
|
492
|
+
return 0;
|
|
493
|
+
}
|