@coderook/cli 0.34.2 → 0.34.4

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.
@@ -27,11 +27,7 @@ const node_process_1 = __importDefault(require("node:process"));
27
27
  const tracks_js_1 = require("../../cbx/src/core/tracks.js");
28
28
  const config_js_1 = require("./config.js");
29
29
  const project_commands_js_1 = require("./project_commands.js");
30
- const dim = (value) => `${value}`;
31
- const bold = (value) => `${value}`;
32
- const red = (value) => `${value}`;
33
- const green = (value) => `${value}`;
34
- const accent = (value) => `${value}`;
30
+ const colour_js_1 = require("./colour.js");
35
31
  /** The line a folder saves to when nobody has said otherwise. */
36
32
  exports.DEFAULT_TRACK = "main";
37
33
  function client() {
@@ -50,8 +46,8 @@ async function trackFor(localPath) {
50
46
  }
51
47
  function describe(track, current) {
52
48
  const here = track.name === current;
53
- const mark = here ? accent("*") : " ";
54
- const name = here ? bold(track.name) : track.name;
49
+ const mark = here ? (0, colour_js_1.accent)("*") : " ";
50
+ const name = here ? (0, colour_js_1.bold)(track.name) : track.name;
55
51
  const notes = [];
56
52
  if (track.kind === "merge")
57
53
  notes.push("waiting on a decision");
@@ -59,7 +55,7 @@ function describe(track, current) {
59
55
  notes.push("protected");
60
56
  if (!track.headVersionId)
61
57
  notes.push("nothing saved yet");
62
- return `${mark} ${name}${notes.length ? dim(` ${notes.join(" · ")}`) : ""}`;
58
+ return `${mark} ${name}${notes.length ? (0, colour_js_1.dim)(` ${notes.join(" · ")}`) : ""}`;
63
59
  }
64
60
  /**
65
61
  * Every line and unfinished merge on the project.
@@ -74,24 +70,24 @@ async function commandTracks(parsed) {
74
70
  return 1;
75
71
  const tracks = await client().list(project.id);
76
72
  if (!tracks.length) {
77
- console.log(dim("No lines recorded yet. The first save creates ") + bold(exports.DEFAULT_TRACK) + dim("."));
73
+ console.log((0, colour_js_1.dim)("No lines recorded yet. The first save creates ") + (0, colour_js_1.bold)(exports.DEFAULT_TRACK) + (0, colour_js_1.dim)("."));
78
74
  return 0;
79
75
  }
80
76
  const current = await trackFor(node_process_1.default.cwd());
81
77
  const lines = tracks.filter((track) => track.kind === "line");
82
78
  const merges = tracks.filter((track) => track.kind === "merge");
83
- console.log(bold(`Lines on ${project.slug}`));
79
+ console.log((0, colour_js_1.bold)(`Lines on ${project.slug}`));
84
80
  for (const track of lines)
85
81
  console.log(` ${describe(track, current)}`);
86
82
  if (merges.length) {
87
83
  console.log("");
88
- console.log(bold("Waiting on a decision"));
84
+ console.log((0, colour_js_1.bold)("Waiting on a decision"));
89
85
  for (const track of merges)
90
86
  console.log(` ${describe(track, current)}`);
91
- console.log(dim(" Finish one with ") + "cbx merge");
87
+ console.log((0, colour_js_1.dim)(" Finish one with ") + "cbx merge");
92
88
  }
93
89
  console.log("");
94
- console.log(dim("This folder saves to ") + accent(current));
90
+ console.log((0, colour_js_1.dim)("This folder saves to ") + (0, colour_js_1.accent)(current));
95
91
  return 0;
96
92
  }
97
93
  /**
@@ -106,21 +102,21 @@ async function commandTrack(parsed) {
106
102
  const folder = node_process_1.default.cwd();
107
103
  const link = await (0, config_js_1.readLink)(folder);
108
104
  if (!link) {
109
- console.error(red("This folder is not linked to a project. Run ") + "cbx get" + red(" first."));
105
+ console.error((0, colour_js_1.red)("This folder is not linked to a project. Run ") + "cbx get" + (0, colour_js_1.red)(" first."));
110
106
  return 1;
111
107
  }
112
108
  const wanted = parsed.positional[0];
113
109
  const current = link.track?.trim() || exports.DEFAULT_TRACK;
114
110
  if (!wanted) {
115
- console.log(accent(current));
116
- console.log(dim("Switch with ") + "cbx track <name>");
111
+ console.log((0, colour_js_1.accent)(current));
112
+ console.log((0, colour_js_1.dim)("Switch with ") + "cbx track <name>");
117
113
  return 0;
118
114
  }
119
115
  const starting = parsed.flags.has("new") || parsed.flags.has("n");
120
116
  const tracks = await client().list(link.repositoryId);
121
117
  const existing = tracks.find((track) => track.name === wanted);
122
118
  if (existing && starting) {
123
- console.error(red(`There is already a line called "${wanted}".`));
119
+ console.error((0, colour_js_1.red)(`There is already a line called "${wanted}".`));
124
120
  return 1;
125
121
  }
126
122
  if (!existing && !starting) {
@@ -129,13 +125,13 @@ async function commandTrack(parsed) {
129
125
  normal thing to do, and silently starting a line called `mian` puts
130
126
  work somewhere nobody will look for it.
131
127
  */
132
- console.error(red(`No line called "${wanted}" on this project.`));
133
- console.error(dim("Start one with ") + `cbx track ${wanted} --new`);
128
+ console.error((0, colour_js_1.red)(`No line called "${wanted}" on this project.`));
129
+ console.error((0, colour_js_1.dim)("Start one with ") + `cbx track ${wanted} --new`);
134
130
  return 1;
135
131
  }
136
132
  if (existing?.kind === "merge") {
137
- console.error(red(`"${wanted}" is a merge waiting on a decision, not a line to save onto.`));
138
- console.error(dim("Finish it with ") + "cbx merge");
133
+ console.error((0, colour_js_1.red)(`"${wanted}" is a merge waiting on a decision, not a line to save onto.`));
134
+ console.error((0, colour_js_1.dim)("Finish it with ") + "cbx merge");
139
135
  return 1;
140
136
  }
141
137
  if (starting) {
@@ -143,15 +139,15 @@ async function commandTrack(parsed) {
143
139
  await client().create(link.repositoryId, wanted);
144
140
  }
145
141
  catch (error) {
146
- console.error(red(error instanceof Error ? error.message : String(error)));
142
+ console.error((0, colour_js_1.red)(error instanceof Error ? error.message : String(error)));
147
143
  return 1;
148
144
  }
149
- console.log(green(`Started ${bold(wanted)} from where the project is now.`));
145
+ console.log((0, colour_js_1.green)(`Started ${(0, colour_js_1.bold)(wanted)} from where the project is now.`));
150
146
  }
151
147
  await (0, config_js_1.writeLink)(folder, { ...link, track: wanted });
152
- console.log(dim("This folder now saves to ") + accent(wanted));
148
+ console.log((0, colour_js_1.dim)("This folder now saves to ") + (0, colour_js_1.accent)(wanted));
153
149
  if (existing) {
154
- console.log(dim("Its files are not here yet — fetch them with ") + `cbx get`);
150
+ console.log((0, colour_js_1.dim)("Its files are not here yet — fetch them with ") + `cbx get`);
155
151
  }
156
152
  return 0;
157
153
  }
@@ -48,11 +48,7 @@ const node_path_1 = __importDefault(require("node:path"));
48
48
  const node_process_1 = __importDefault(require("node:process"));
49
49
  const api_js_1 = require("./api.js");
50
50
  const forge_url_js_1 = require("./forge_url.js");
51
- const dim = (value) => `${value}`;
52
- const bold = (value) => `${value}`;
53
- const red = (value) => `${value}`;
54
- const green = (value) => `${value}`;
55
- const accent = (value) => `${value}`;
51
+ const colour_js_1 = require("./colour.js");
56
52
  /** A read token from the environment, or nothing. Never a flag. */
57
53
  function forgeToken(forge) {
58
54
  for (const name of forge.tokenNames) {
@@ -141,7 +137,7 @@ function run(command, args, cwd) {
141
137
  async function commandTransfer(parsed) {
142
138
  const address = parsed.positional[0];
143
139
  if (!address) {
144
- console.error(red("Which repository? Try: cbx transfer https://github.com/owner/project"));
140
+ console.error((0, colour_js_1.red)("Which repository? Try: cbx transfer https://github.com/owner/project"));
145
141
  return 1;
146
142
  }
147
143
  let forge;
@@ -149,11 +145,11 @@ async function commandTransfer(parsed) {
149
145
  forge = (0, forge_url_js_1.readForgeUrl)(address);
150
146
  }
151
147
  catch (error) {
152
- console.error(red(error instanceof Error ? error.message : String(error)));
148
+ console.error((0, colour_js_1.red)(error instanceof Error ? error.message : String(error)));
153
149
  return 1;
154
150
  }
155
151
  if (!run("git", ["--version"]).ok) {
156
- console.error(red("Transferring needs git on this machine."));
152
+ console.error((0, colour_js_1.red)("Transferring needs git on this machine."));
157
153
  return 1;
158
154
  }
159
155
  /*
@@ -164,10 +160,10 @@ async function commandTransfer(parsed) {
164
160
  if (!run("git", ["remote-coderook", "--probe"]).ok) {
165
161
  const help = run("git", ["help", "-a"]);
166
162
  if (!/remote-coderook/.test(help.out)) {
167
- console.error(red("git cannot find `git-remote-coderook` on this machine."));
163
+ console.error((0, colour_js_1.red)("git cannot find `git-remote-coderook` on this machine."));
168
164
  console.error("It ships with this tool, so this usually means cbx was run from a\n" +
169
165
  "checkout rather than installed. Install it globally and try again:\n" +
170
- ` ${accent("npm install --global @coderook/cli")}`);
166
+ ` ${(0, colour_js_1.accent)("npm install --global @coderook/cli")}`);
171
167
  return 1;
172
168
  }
173
169
  }
@@ -176,14 +172,14 @@ async function commandTransfer(parsed) {
176
172
  : forge.repo).toLowerCase();
177
173
  const existing = await (0, api_js_1.findProject)(wanted);
178
174
  if (existing) {
179
- console.error(red(`You already have a project called ${existing.slug}.`));
175
+ console.error((0, colour_js_1.red)(`You already have a project called ${existing.slug}.`));
180
176
  console.error(`Transfer creates a project; it does not merge into one. Choose another\n` +
181
- `name with ${accent("--name")}, or delete that project first.`);
177
+ `name with ${(0, colour_js_1.accent)("--name")}, or delete that project first.`);
182
178
  return 1;
183
179
  }
184
180
  const token = forgeToken(forge);
185
- console.log(`${bold("Transferring")} ${forge.owner}/${forge.repo} ${dim(`from ${forge.label}`)}`);
186
- console.log(dim(token
181
+ console.log(`${(0, colour_js_1.bold)("Transferring")} ${forge.owner}/${forge.repo} ${(0, colour_js_1.dim)(`from ${forge.label}`)}`);
182
+ console.log((0, colour_js_1.dim)(token
187
183
  ? ` Using the read token in ${forge.tokenNames.find((name) => node_process_1.default.env[name]?.trim())}.`
188
184
  : ` No token set. Public repositories work; set ${forge.tokenNames[0]} for a private one or for issues.`));
189
185
  const scratch = await (0, promises_1.mkdtemp)(node_path_1.default.join(node_os_1.default.tmpdir(), "cbx-transfer-"));
@@ -195,13 +191,13 @@ async function commandTransfer(parsed) {
195
191
  the history, and `--depth 1` would silently deliver a single commit under
196
192
  a command whose name promises everything.
197
193
  */
198
- console.log(`\n${dim("Fetching the repository with its full history…")}`);
194
+ console.log(`\n${(0, colour_js_1.dim)("Fetching the repository with its full history…")}`);
199
195
  const cloned = run("git", ["clone", "--no-single-branch", forge.clone, checkout]);
200
196
  if (!cloned.ok) {
201
- console.error(red(`\nCould not clone ${forge.clone}`));
197
+ console.error((0, colour_js_1.red)(`\nCould not clone ${forge.clone}`));
202
198
  console.error(cloned.out.trim().split("\n").slice(-4).join("\n"));
203
199
  if (!token) {
204
- console.error(dim(`\nIf it is private, set ${forge.tokenNames[0]} and try again.`));
200
+ console.error((0, colour_js_1.dim)(`\nIf it is private, set ${forge.tokenNames[0]} and try again.`));
205
201
  }
206
202
  return 1;
207
203
  }
@@ -231,15 +227,15 @@ async function commandTransfer(parsed) {
231
227
  `${remoteBranches.length} branch${remoteBranches.length === 1 ? "" : "es"} · ` +
232
228
  `${tags.length} tag${tags.length === 1 ? "" : "s"}`);
233
229
  if (commits > 200) {
234
- console.log(dim(` Each commit becomes a version, so this will take a while —\n` +
230
+ console.log((0, colour_js_1.dim)(` Each commit becomes a version, so this will take a while —\n` +
235
231
  ` roughly ${Math.round((commits * 11) / 60)} minutes. It resumes if interrupted.`));
236
232
  }
237
233
  run("git", ["remote", "add", "coderook", `coderook://${wanted}`], checkout);
238
- console.log(`\n${dim("Publishing the history…")}`);
234
+ console.log(`\n${(0, colour_js_1.dim)("Publishing the history…")}`);
239
235
  const pushed = run("git", ["push", "coderook", "--all"], checkout);
240
236
  node_process_1.default.stderr.write(pushed.out);
241
237
  if (!pushed.ok) {
242
- console.error(red("\nThe history did not transfer completely."));
238
+ console.error((0, colour_js_1.red)("\nThe history did not transfer completely."));
243
239
  return 1;
244
240
  }
245
241
  report.push(`${commits} commits across ${remoteBranches.length} branch(es)`);
@@ -252,7 +248,7 @@ async function commandTransfer(parsed) {
252
248
  }
253
249
  const project = await (0, api_js_1.findProject)(wanted);
254
250
  if (!project) {
255
- console.error(red("\nThe project was not created. Nothing else was changed."));
251
+ console.error((0, colour_js_1.red)("\nThe project was not created. Nothing else was changed."));
256
252
  return 1;
257
253
  }
258
254
  // What the repository says about itself.
@@ -314,16 +310,16 @@ async function commandTransfer(parsed) {
314
310
  }
315
311
  }
316
312
  }
317
- console.log(`\n${green("Transferred")} ${bold(project.slug)}`);
313
+ console.log(`\n${(0, colour_js_1.green)("Transferred")} ${(0, colour_js_1.bold)(project.slug)}`);
318
314
  for (const line of report)
319
- console.log(` ${green("·")} ${line}`);
320
- console.log(`\n${dim("Not carried across:")}`);
321
- console.log(dim(" · pull requests and reviews — CodeRook has no equivalent object"));
322
- console.log(dim(" · CI configuration — runs are started deliberately, not by a push"));
323
- console.log(dim(" · collaborators — access is an invitation to accept, not a field to copy"));
324
- console.log(dim(" · stars, forks and watchers"));
315
+ console.log(` ${(0, colour_js_1.green)("·")} ${line}`);
316
+ console.log(`\n${(0, colour_js_1.dim)("Not carried across:")}`);
317
+ console.log((0, colour_js_1.dim)(" · pull requests and reviews — CodeRook has no equivalent object"));
318
+ console.log((0, colour_js_1.dim)(" · CI configuration — runs are started deliberately, not by a push"));
319
+ console.log((0, colour_js_1.dim)(" · collaborators — access is an invitation to accept, not a field to copy"));
320
+ console.log((0, colour_js_1.dim)(" · stars, forks and watchers"));
325
321
  if (!parsed.flags.has("issues")) {
326
- console.log(dim(" · issues — pass --issues to bring the open ones"));
322
+ console.log((0, colour_js_1.dim)(" · issues — pass --issues to bring the open ones"));
327
323
  }
328
324
  /*
329
325
  Said plainly rather than implied by the word "transfer".
@@ -338,7 +334,7 @@ async function commandTransfer(parsed) {
338
334
  */
339
335
  console.log([
340
336
  "",
341
- `${dim("On ownership:")} nothing was checked, and nothing could be.`,
337
+ `${(0, colour_js_1.dim)("On ownership:")} nothing was checked, and nothing could be.`,
342
338
  "A public repository is readable by anyone, which is why cloning one",
343
339
  "needs no token — so this is a clone and a publish, not a claim. The",
344
340
  "licence that came with the files is still what governs them.",
@@ -346,8 +342,8 @@ async function commandTransfer(parsed) {
346
342
  ? ["Worth reading before you make this project public."]
347
343
  : []),
348
344
  ].join("\n"));
349
- console.log(`\nFetch it anywhere with ${accent(`cbx clone ${project.slug}`)}` +
350
- `${dim(", or ")}${accent(`git clone coderook://${project.slug}`)}${dim(".")}`);
345
+ console.log(`\nFetch it anywhere with ${(0, colour_js_1.accent)(`cbx clone ${project.slug}`)}` +
346
+ `${(0, colour_js_1.dim)(", or ")}${(0, colour_js_1.accent)(`git clone coderook://${project.slug}`)}${(0, colour_js_1.dim)(".")}`);
351
347
  return 0;
352
348
  }
353
349
  finally {