@coderook/cli 0.34.1 → 0.34.3

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.
@@ -24,11 +24,7 @@ const node_process_1 = __importDefault(require("node:process"));
24
24
  const promises_1 = require("node:readline/promises");
25
25
  const api_js_1 = require("./api.js");
26
26
  const config_js_1 = require("./config.js");
27
- const dim = (value) => `${value}`;
28
- const bold = (value) => `${value}`;
29
- const red = (value) => `${value}`;
30
- const green = (value) => `${value}`;
31
- const accent = (value) => `${value}`;
27
+ const colour_js_1 = require("./colour.js");
32
28
  function bytes(value) {
33
29
  if (value >= 1024 ** 3)
34
30
  return `${(value / 1024 ** 3).toFixed(2)} GB`;
@@ -48,12 +44,12 @@ function bytes(value) {
48
44
  async function resolveProject(reference) {
49
45
  const wanted = reference ?? (await (0, config_js_1.readLink)(node_process_1.default.cwd()))?.slug;
50
46
  if (!wanted) {
51
- console.error(red("Which project? Name one, or run this inside a linked folder."));
47
+ console.error((0, colour_js_1.red)("Which project? Name one, or run this inside a linked folder."));
52
48
  return null;
53
49
  }
54
50
  const project = await (0, api_js_1.findProject)(wanted);
55
51
  if (!project) {
56
- console.error(red(`No project matching "${wanted}" on your account.`));
52
+ console.error((0, colour_js_1.red)(`No project matching "${wanted}" on your account.`));
57
53
  return null;
58
54
  }
59
55
  return project;
@@ -112,19 +108,19 @@ async function commandAi(parsed) {
112
108
  }
113
109
  if (Object.keys(change).length) {
114
110
  await (0, api_js_1.setAiAccess)(project.id, change);
115
- console.log(green(`Updated ${project.name}.`));
111
+ console.log((0, colour_js_1.green)(`Updated ${project.name}.`));
116
112
  }
117
113
  const access = await (0, api_js_1.aiAccess)(project.id);
118
114
  console.log("");
119
- console.log(bold(project.name));
115
+ console.log((0, colour_js_1.bold)(project.name));
120
116
  for (const [name, field, question, meaning] of AI_SWITCHES) {
121
- const mark = access[field] ? green("allowed") : red("refused");
122
- console.log(` ${question.padEnd(30)} ${mark} ${dim("--" + name)}`);
123
- console.log(` ${dim(meaning)}`);
117
+ const mark = access[field] ? (0, colour_js_1.green)("allowed") : (0, colour_js_1.red)("refused");
118
+ console.log(` ${question.padEnd(30)} ${mark} ${(0, colour_js_1.dim)("--" + name)}`);
119
+ console.log(` ${(0, colour_js_1.dim)(meaning)}`);
124
120
  }
125
121
  console.log("");
126
- console.log(dim("Everything is allowed until you say otherwise. Turning reading off is the"));
127
- console.log(dim("one that refuses model training."));
122
+ console.log((0, colour_js_1.dim)("Everything is allowed until you say otherwise. Turning reading off is the"));
123
+ console.log((0, colour_js_1.dim)("one that refuses model training."));
128
124
  return 0;
129
125
  }
130
126
  /**
@@ -230,7 +226,7 @@ async function agreed(question) {
230
226
  async function commandVisibility(parsed) {
231
227
  const asked = splitVisibility(parsed.positional);
232
228
  if (asked.error) {
233
- console.error(red(asked.error));
229
+ console.error((0, colour_js_1.red)(asked.error));
234
230
  return 1;
235
231
  }
236
232
  const project = await resolveProject(asked.project);
@@ -238,10 +234,10 @@ async function commandVisibility(parsed) {
238
234
  return 1;
239
235
  const current = readLevel(project.visibility) ?? "private";
240
236
  if (!asked.level) {
241
- console.log(`${bold(project.name)} is ${accent(wordFor(current))}.`);
237
+ console.log(`${(0, colour_js_1.bold)(project.name)} is ${(0, colour_js_1.accent)(wordFor(current))}.`);
242
238
  for (const [level, , meaning] of LEVELS) {
243
- const mark = level === current ? accent("›") : " ";
244
- console.log(` ${mark} ${level.padEnd(9)} ${dim(meaning)}`);
239
+ const mark = level === current ? (0, colour_js_1.accent)("›") : " ";
240
+ console.log(` ${mark} ${level.padEnd(9)} ${(0, colour_js_1.dim)(meaning)}`);
245
241
  }
246
242
  if (current === "public") {
247
243
  const address = await publicAddress(project);
@@ -249,7 +245,7 @@ async function commandVisibility(parsed) {
249
245
  console.log(`\n ${address}`);
250
246
  }
251
247
  console.log("");
252
- console.log(dim(`Change it with: cbx visibility <level>` +
248
+ console.log((0, colour_js_1.dim)(`Change it with: cbx visibility <level>` +
253
249
  (asked.project ? ` ${asked.project}` : "")));
254
250
  return 0;
255
251
  }
@@ -268,14 +264,14 @@ async function commandVisibility(parsed) {
268
264
  tells whoever wrote the script what to do about it.
269
265
  */
270
266
  if (asking && !node_process_1.default.stdin.isTTY) {
271
- console.error(red(`Making ${project.name} ${wordFor(target)} needs a yes, and nobody is here to give one.`));
272
- console.error(dim(" Run it in a terminal to be asked, or add --yes."));
267
+ console.error((0, colour_js_1.red)(`Making ${project.name} ${wordFor(target)} needs a yes, and nobody is here to give one.`));
268
+ console.error((0, colour_js_1.dim)(" Run it in a terminal to be asked, or add --yes."));
273
269
  return 1;
274
270
  }
275
271
  const offered = target === "public" ? offeredPublicly(await (0, api_js_1.versions)(project.id)) : [];
276
272
  if (asking) {
277
273
  if (target === "public") {
278
- console.log(`Making ${bold(project.name)} public lists it on your profile and in search.`);
274
+ console.log(`Making ${(0, colour_js_1.bold)(project.name)} public lists it on your profile and in search.`);
279
275
  if (offered.length) {
280
276
  const names = offered.slice(0, 5).map((one) => one.name).join(", ");
281
277
  const more = offered.length > 5 ? ` and ${offered.length - 5} more` : "";
@@ -284,13 +280,13 @@ async function commandVisibility(parsed) {
284
280
  else {
285
281
  console.log(" Its page will be empty until a save is named — cbx promote does that.");
286
282
  }
287
- console.log(dim(" Saves nobody named, and versions you hid, are not on the page."));
283
+ console.log((0, colour_js_1.dim)(" Saves nobody named, and versions you hid, are not on the page."));
288
284
  }
289
285
  else {
290
- console.log(`Making ${bold(project.name)} link only keeps it off your profile and out of search.`);
286
+ console.log(`Making ${(0, colour_js_1.bold)(project.name)} link only keeps it off your profile and out of search.`);
291
287
  }
292
288
  if (!(await agreed(`Make ${project.name} ${wordFor(target)}? [y/N] `))) {
293
- console.log(dim(`Nothing changed. ${project.name} is still ${wordFor(current)}.`));
289
+ console.log((0, colour_js_1.dim)(`Nothing changed. ${project.name} is still ${wordFor(current)}.`));
294
290
  return 1;
295
291
  }
296
292
  }
@@ -298,23 +294,23 @@ async function commandVisibility(parsed) {
298
294
  await (0, api_js_1.updateProject)(project.id, { visibility: target });
299
295
  }
300
296
  catch (error) {
301
- console.error(red(error instanceof Error ? error.message : String(error)));
297
+ console.error((0, colour_js_1.red)(error instanceof Error ? error.message : String(error)));
302
298
  return 1;
303
299
  }
304
300
  if (target === "public") {
305
301
  const address = await publicAddress(project);
306
- console.log(green(`${project.name} is now public`) + (address ? `: ${address}` : "."));
307
- console.log(dim(offered.length
302
+ console.log((0, colour_js_1.green)(`${project.name} is now public`) + (address ? `: ${address}` : "."));
303
+ console.log((0, colour_js_1.dim)(offered.length
308
304
  ? ` Its page offers ${offered.length} named version${offered.length === 1 ? "" : "s"}.`
309
305
  : " Its page is empty until a save is named — cbx promote does that."));
310
306
  }
311
307
  else if (target === "unlisted") {
312
- console.log(green(`${project.name} is now link only.`));
313
- console.log(dim(" It is not listed anywhere; any account signed in with its link can read it."));
308
+ console.log((0, colour_js_1.green)(`${project.name} is now link only.`));
309
+ console.log((0, colour_js_1.dim)(" It is not listed anywhere; any account signed in with its link can read it."));
314
310
  }
315
311
  else {
316
- console.log(green(`${project.name} is now private.`));
317
- console.log(dim(" Only you and the people you invite can reach it."));
312
+ console.log((0, colour_js_1.green)(`${project.name} is now private.`));
313
+ console.log((0, colour_js_1.dim)(" Only you and the people you invite can reach it."));
318
314
  }
319
315
  return 0;
320
316
  }
@@ -325,7 +321,7 @@ async function commandVersions(parsed) {
325
321
  return 1;
326
322
  const saved = await (0, api_js_1.versions)(project.id);
327
323
  if (!saved.length) {
328
- console.log(dim("Nothing has been saved to this project yet."));
324
+ console.log((0, colour_js_1.dim)("Nothing has been saved to this project yet."));
329
325
  return 0;
330
326
  }
331
327
  /*
@@ -340,7 +336,7 @@ async function commandVersions(parsed) {
340
336
  const onlyVersions = parsed.flags.get("versions") === true;
341
337
  const onlyCommits = parsed.flags.get("commits") === true;
342
338
  if (onlyVersions && onlyCommits) {
343
- console.error(red("Pick one: --versions or --commits, or neither for both."));
339
+ console.error((0, colour_js_1.red)("Pick one: --versions or --commits, or neither for both."));
344
340
  return 1;
345
341
  }
346
342
  const lane = saved.filter((version) => {
@@ -351,7 +347,7 @@ async function commandVersions(parsed) {
351
347
  return true;
352
348
  });
353
349
  if (!lane.length) {
354
- console.log(dim(onlyVersions
350
+ console.log((0, colour_js_1.dim)(onlyVersions
355
351
  ? "Nothing has been made a version yet."
356
352
  : "Every save here has been made a version."));
357
353
  return 0;
@@ -359,7 +355,7 @@ async function commandVersions(parsed) {
359
355
  const withNotes = parsed.flags.get("notes") === true;
360
356
  const asked = Number(parsed.flags.get("limit") ?? 20);
361
357
  const limit = Number.isFinite(asked) && asked > 0 ? asked : 20;
362
- console.log(bold(project.name));
358
+ console.log((0, colour_js_1.bold)(project.name));
363
359
  for (const version of lane.slice(0, limit)) {
364
360
  const when = version.createdAt
365
361
  ? new Date(version.createdAt).toLocaleString()
@@ -375,24 +371,24 @@ async function commandVersions(parsed) {
375
371
  const marks = [
376
372
  /* Which one the project is standing on, which is not the same as which
377
373
  one is at the top once somebody has pinned something. */
378
- version.head ? green("current") : "",
379
- version.pinned ? accent("pinned") : "",
380
- version.name ? bold(version.name) : "",
381
- version.state === "held" ? red("held") : "",
382
- version.state === "declined" ? dim("declined") : "",
383
- version.removedAt ? dim("taken down") : "",
374
+ version.head ? (0, colour_js_1.green)("current") : "",
375
+ version.pinned ? (0, colour_js_1.accent)("pinned") : "",
376
+ version.name ? (0, colour_js_1.bold)(version.name) : "",
377
+ version.state === "held" ? (0, colour_js_1.red)("held") : "",
378
+ version.state === "declined" ? (0, colour_js_1.dim)("declined") : "",
379
+ version.removedAt ? (0, colour_js_1.dim)("taken down") : "",
384
380
  /*
385
381
  Said only of a version, because only a version is offered to anybody.
386
382
  A commit nobody has promoted is not hidden — it was never on offer.
387
383
  */
388
- version.name && version.visibility === "private" ? dim("hidden") : "",
389
- ...version.labels.map((label) => accent(label.name)),
384
+ version.name && version.visibility === "private" ? (0, colour_js_1.dim)("hidden") : "",
385
+ ...version.labels.map((label) => (0, colour_js_1.accent)(label.name)),
390
386
  ].filter(Boolean);
391
- console.log(` ${accent(`v${version.sequence}`).padEnd(16)} ${when.padEnd(22)}` +
387
+ console.log(` ${(0, colour_js_1.accent)(`v${version.sequence}`).padEnd(16)} ${when.padEnd(22)}` +
392
388
  `${String(version.fileCount).padStart(5)} files ${bytes(version.storedSize)}` +
393
389
  (marks.length ? ` ${marks.join(" ")}` : ""));
394
390
  if (version.message)
395
- console.log(` ${dim(version.message)}`);
391
+ console.log(` ${(0, colour_js_1.dim)(version.message)}`);
396
392
  /*
397
393
  Indented under the save it belongs to rather than printed flat, so a
398
394
  note of several paragraphs still reads as part of one row.
@@ -404,7 +400,7 @@ async function commandVersions(parsed) {
404
400
  }
405
401
  }
406
402
  if (lane.length > limit) {
407
- console.log(dim(` … ${lane.length - limit} older. Use --limit to see more.`));
403
+ console.log((0, colour_js_1.dim)(` … ${lane.length - limit} older. Use --limit to see more.`));
408
404
  }
409
405
  return 0;
410
406
  }