@coderook/cli 0.34.2 → 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.
@@ -32,14 +32,10 @@ const node_fs_1 = require("node:fs");
32
32
  const node_os_1 = require("node:os");
33
33
  const node_path_1 = __importDefault(require("node:path"));
34
34
  const node_process_1 = __importDefault(require("node:process"));
35
+ const colour_js_1 = require("./colour.js");
35
36
  /* Written out rather than imported: the same four escapes every other command
36
37
  file in here declares for itself, and a shared module for four one-line
37
38
  functions would be the only thing they all depend on. */
38
- const dim = (value) => `${value}`;
39
- const bold = (value) => `${value}`;
40
- const red = (value) => `${value}`;
41
- const accent = (value) => `${value}`;
42
- const green = (value) => `${value}`;
43
39
  /**
44
40
  * Which of `[n] [project]` the arguments actually were.
45
41
  *
@@ -68,7 +64,7 @@ function split(parsed) {
68
64
  async function pick(repositoryId, wanted) {
69
65
  const all = await (0, api_js_1.versions)(repositoryId);
70
66
  if (!all.length) {
71
- console.error(red("This project has no versions yet."));
67
+ console.error((0, colour_js_1.red)("This project has no versions yet."));
72
68
  return null;
73
69
  }
74
70
  /*
@@ -85,7 +81,7 @@ async function pick(repositoryId, wanted) {
85
81
  const sequence = wanted.replace(/^v/i, "");
86
82
  const found = all.find((one) => String(one.sequence) === sequence);
87
83
  if (!found) {
88
- console.error(red(`This project has no version ${wanted}.`));
84
+ console.error((0, colour_js_1.red)(`This project has no version ${wanted}.`));
89
85
  return null;
90
86
  }
91
87
  return found;
@@ -116,7 +112,7 @@ function colourOf(given) {
116
112
  return /^#[0-9a-f]{6}$/.test(hex) ? hex : null;
117
113
  }
118
114
  function paint(label) {
119
- return accent(label.name);
115
+ return (0, colour_js_1.accent)(label.name);
120
116
  }
121
117
  /**
122
118
  * Release info, from wherever the writer keeps it.
@@ -222,7 +218,7 @@ async function commandNotes(parsed) {
222
218
  return 1;
223
219
  if (parsed.flags.get("clear") === true) {
224
220
  await (0, api_js_1.changeVersion)(project.id, target.id, { notes: null });
225
- console.log(green(`Cleared the notes on v${target.sequence}.`));
221
+ console.log((0, colour_js_1.green)(`Cleared the notes on v${target.sequence}.`));
226
222
  return 0;
227
223
  }
228
224
  let next;
@@ -230,13 +226,13 @@ async function commandNotes(parsed) {
230
226
  next = notesFrom(parsed);
231
227
  }
232
228
  catch (error) {
233
- console.error(red(error instanceof Error ? error.message : String(error)));
229
+ console.error((0, colour_js_1.red)(error instanceof Error ? error.message : String(error)));
234
230
  return 1;
235
231
  }
236
232
  if (parsed.flags.get("edit") === true) {
237
233
  const written = writeInEditor(target.notes ?? "");
238
234
  if (written === null) {
239
- console.log(dim("Left as it was."));
235
+ console.log((0, colour_js_1.dim)("Left as it was."));
240
236
  return 0;
241
237
  }
242
238
  next = written;
@@ -245,17 +241,17 @@ async function commandNotes(parsed) {
245
241
  /* Nothing to write, so this is a read. */
246
242
  const text = (target.notes ?? "").trim();
247
243
  if (!text) {
248
- console.log(dim(`v${target.sequence} has no notes.`) +
249
- dim(" Write some with --edit, --notes-file or --notes"));
244
+ console.log((0, colour_js_1.dim)(`v${target.sequence} has no notes.`) +
245
+ (0, colour_js_1.dim)(" Write some with --edit, --notes-file or --notes"));
250
246
  return 0;
251
247
  }
252
- console.log(bold(`v${target.sequence}${target.name ? ` ${target.name}` : ""}`));
248
+ console.log((0, colour_js_1.bold)(`v${target.sequence}${target.name ? ` ${target.name}` : ""}`));
253
249
  console.log(text);
254
250
  return 0;
255
251
  }
256
252
  const text = (next ?? "").trim();
257
253
  await (0, api_js_1.changeVersion)(project.id, target.id, { notes: text ? next : null });
258
- console.log(green(text
254
+ console.log((0, colour_js_1.green)(text
259
255
  ? `Wrote the notes on v${target.sequence}.`
260
256
  : `Cleared the notes on v${target.sequence}.`));
261
257
  return 0;
@@ -280,7 +276,7 @@ async function commandVersion(parsed) {
280
276
  patch.notes = notes;
281
277
  }
282
278
  catch (error) {
283
- console.error(red(error instanceof Error ? error.message : String(error)));
279
+ console.error((0, colour_js_1.red)(error instanceof Error ? error.message : String(error)));
284
280
  return 1;
285
281
  }
286
282
  if (parsed.flags.get("edit") === true) {
@@ -295,7 +291,7 @@ async function commandVersion(parsed) {
295
291
  const visibility = parsed.flags.get("visibility");
296
292
  if (typeof visibility === "string") {
297
293
  if (!["private", "public"].includes(visibility)) {
298
- console.error(red("Visibility is private, unlisted or public."));
294
+ console.error((0, colour_js_1.red)("Visibility is private, unlisted or public."));
299
295
  return 1;
300
296
  }
301
297
  patch.visibility = visibility;
@@ -315,8 +311,8 @@ async function commandVersion(parsed) {
315
311
  for (const one of wanted) {
316
312
  const found = known.find((label) => label.name.toLowerCase() === one.toLowerCase());
317
313
  if (!found) {
318
- console.error(red(`This project has no "${one}" label.`) +
319
- dim(` Make one with cbx labels add ${one} green`));
314
+ console.error((0, colour_js_1.red)(`This project has no "${one}" label.`) +
315
+ (0, colour_js_1.dim)(` Make one with cbx labels add ${one} green`));
320
316
  return 1;
321
317
  }
322
318
  ids.push(found.id);
@@ -326,20 +322,20 @@ async function commandVersion(parsed) {
326
322
  if (parsed.flags.get("clear-labels") === true)
327
323
  patch.labelIds = [];
328
324
  if (!Object.keys(patch).length) {
329
- console.error(red("Say what to change.") +
330
- dim(" --name, --notes, --hide, --show, --visibility, --pin, --labels"));
325
+ console.error((0, colour_js_1.red)("Say what to change.") +
326
+ (0, colour_js_1.dim)(" --name, --notes, --hide, --show, --visibility, --pin, --labels"));
331
327
  return 1;
332
328
  }
333
329
  try {
334
330
  await (0, api_js_1.changeVersion)(project.id, target.id, patch);
335
331
  }
336
332
  catch (error) {
337
- console.error(red(error instanceof Error ? error.message : String(error)));
333
+ console.error((0, colour_js_1.red)(error instanceof Error ? error.message : String(error)));
338
334
  return 1;
339
335
  }
340
336
  const said = [];
341
337
  if (patch.name !== undefined) {
342
- said.push(patch.name ? `named ${accent(patch.name)}` : "name removed");
338
+ said.push(patch.name ? `named ${(0, colour_js_1.accent)(patch.name)}` : "name removed");
343
339
  }
344
340
  if (patch.visibility)
345
341
  said.push(patch.visibility);
@@ -348,7 +344,7 @@ async function commandVersion(parsed) {
348
344
  if (patch.labelIds) {
349
345
  said.push(patch.labelIds.length ? "labelled" : "labels cleared");
350
346
  }
351
- console.log(`${bold(`v${target.sequence}`)} ${said.join(", ")}.`);
347
+ console.log(`${(0, colour_js_1.bold)(`v${target.sequence}`)} ${said.join(", ")}.`);
352
348
  return 0;
353
349
  }
354
350
  async function commandLabels(parsed) {
@@ -359,13 +355,13 @@ async function commandLabels(parsed) {
359
355
  return 1;
360
356
  const labels = await (0, api_js_1.projectLabels)(project.id);
361
357
  if (!labels.length) {
362
- console.log(dim("No labels yet. Make one with cbx labels add shipped green"));
358
+ console.log((0, colour_js_1.dim)("No labels yet. Make one with cbx labels add shipped green"));
363
359
  return 0;
364
360
  }
365
- console.log(bold(project.name));
361
+ console.log((0, colour_js_1.bold)(project.name));
366
362
  for (const label of labels) {
367
- console.log(` ${paint(label).padEnd(28)} ${dim(label.colour)}` +
368
- (label.description ? ` ${dim(label.description)}` : ""));
363
+ console.log(` ${paint(label).padEnd(28)} ${(0, colour_js_1.dim)(label.colour)}` +
364
+ (label.description ? ` ${(0, colour_js_1.dim)(label.description)}` : ""));
369
365
  }
370
366
  return 0;
371
367
  }
@@ -373,7 +369,7 @@ async function commandLabels(parsed) {
373
369
  const name = parsed.positional[1];
374
370
  const colour = parsed.positional[2] ?? "grey";
375
371
  if (!name) {
376
- console.error(red("Name the label: cbx labels add shipped green"));
372
+ console.error((0, colour_js_1.red)("Name the label: cbx labels add shipped green"));
377
373
  return 1;
378
374
  }
379
375
  const project = await (0, project_commands_js_1.resolveProject)(parsed.positional[3]);
@@ -381,16 +377,16 @@ async function commandLabels(parsed) {
381
377
  return 1;
382
378
  const hex = colourOf(colour);
383
379
  if (!hex) {
384
- console.error(red(`"${colour}" is not a colour.`) +
385
- dim(` Try one of ${Object.keys(SWATCH).slice(0, 8).join(", ")}, or #rrggbb`));
380
+ console.error((0, colour_js_1.red)(`"${colour}" is not a colour.`) +
381
+ (0, colour_js_1.dim)(` Try one of ${Object.keys(SWATCH).slice(0, 8).join(", ")}, or #rrggbb`));
386
382
  return 1;
387
383
  }
388
384
  try {
389
385
  const made = await (0, api_js_1.createProjectLabel)(project.id, name, hex);
390
- console.log(`Added ${paint(made)} ${dim(made.colour)}.`);
386
+ console.log(`Added ${paint(made)} ${(0, colour_js_1.dim)(made.colour)}.`);
391
387
  }
392
388
  catch (error) {
393
- console.error(red(error instanceof Error ? error.message : String(error)));
389
+ console.error((0, colour_js_1.red)(error instanceof Error ? error.message : String(error)));
394
390
  return 1;
395
391
  }
396
392
  return 0;
@@ -398,7 +394,7 @@ async function commandLabels(parsed) {
398
394
  if (action === "remove" || action === "rm") {
399
395
  const name = parsed.positional[1];
400
396
  if (!name) {
401
- console.error(red("Name the label to remove: cbx labels remove shipped"));
397
+ console.error((0, colour_js_1.red)("Name the label to remove: cbx labels remove shipped"));
402
398
  return 1;
403
399
  }
404
400
  const project = await (0, project_commands_js_1.resolveProject)(parsed.positional[2]);
@@ -407,15 +403,15 @@ async function commandLabels(parsed) {
407
403
  const labels = await (0, api_js_1.projectLabels)(project.id);
408
404
  const found = labels.find((one) => one.name.toLowerCase() === name.toLowerCase());
409
405
  if (!found) {
410
- console.error(red(`This project has no "${name}" label.`));
406
+ console.error((0, colour_js_1.red)(`This project has no "${name}" label.`));
411
407
  return 1;
412
408
  }
413
409
  await (0, api_js_1.deleteProjectLabel)(project.id, found.id);
414
410
  console.log(`Removed ${found.name}. ` +
415
- dim("Versions that wore it keep everything else about them."));
411
+ (0, colour_js_1.dim)("Versions that wore it keep everything else about them."));
416
412
  return 0;
417
413
  }
418
- console.error(red(`Unknown: cbx labels ${action}`) + dim(" Try list, add or remove"));
414
+ console.error((0, colour_js_1.red)(`Unknown: cbx labels ${action}`) + (0, colour_js_1.dim)(" Try list, add or remove"));
419
415
  return 1;
420
416
  }
421
417
  /**
@@ -431,15 +427,15 @@ async function commandHeld(parsed) {
431
427
  return 1;
432
428
  const waiting = (await (0, api_js_1.versions)(project.id)).filter((one) => one.state === "held");
433
429
  if (!waiting.length) {
434
- console.log(dim("Nothing is waiting for a decision."));
430
+ console.log((0, colour_js_1.dim)("Nothing is waiting for a decision."));
435
431
  return 0;
436
432
  }
437
- console.log(bold(`${waiting.length} waiting on ${project.name}`));
433
+ console.log((0, colour_js_1.bold)(`${waiting.length} waiting on ${project.name}`));
438
434
  for (const one of waiting) {
439
- console.log(` ${accent(`v${one.sequence}`).padEnd(16)} ${one.authorName.padEnd(20)} ` +
440
- dim(one.message));
435
+ console.log(` ${(0, colour_js_1.accent)(`v${one.sequence}`).padEnd(16)} ${one.authorName.padEnd(20)} ` +
436
+ (0, colour_js_1.dim)(one.message));
441
437
  }
442
- console.log(dim(`\n cbx review v${waiting[0].sequence} --approve`));
438
+ console.log((0, colour_js_1.dim)(`\n cbx review v${waiting[0].sequence} --approve`));
443
439
  return 0;
444
440
  }
445
441
  async function commandReview(parsed) {
@@ -447,7 +443,7 @@ async function commandReview(parsed) {
447
443
  const approve = parsed.flags.get("approve") === true;
448
444
  const decline = parsed.flags.get("decline") === true;
449
445
  if (approve === decline) {
450
- console.error(red("Say which: --approve or --decline."));
446
+ console.error((0, colour_js_1.red)("Say which: --approve or --decline."));
451
447
  return 1;
452
448
  }
453
449
  const project = await (0, project_commands_js_1.resolveProject)(which.project);
@@ -457,7 +453,7 @@ async function commandReview(parsed) {
457
453
  if (!target)
458
454
  return 1;
459
455
  if (target.state !== "held") {
460
- console.error(red(`v${target.sequence} is not waiting for a decision.`));
456
+ console.error((0, colour_js_1.red)(`v${target.sequence} is not waiting for a decision.`));
461
457
  return 1;
462
458
  }
463
459
  const note = parsed.flags.get("note");
@@ -465,12 +461,12 @@ async function commandReview(parsed) {
465
461
  await (0, api_js_1.reviewVersion)(project.id, target.id, approve ? "approve" : "decline", typeof note === "string" ? note : null);
466
462
  }
467
463
  catch (error) {
468
- console.error(red(error instanceof Error ? error.message : String(error)));
464
+ console.error((0, colour_js_1.red)(error instanceof Error ? error.message : String(error)));
469
465
  return 1;
470
466
  }
471
467
  console.log(approve
472
- ? `${bold(`v${target.sequence}`)} approved. It is now the current version.`
473
- : `${bold(`v${target.sequence}`)} declined. It stays in the history as a version that was not accepted.`);
468
+ ? `${(0, colour_js_1.bold)(`v${target.sequence}`)} approved. It is now the current version.`
469
+ : `${(0, colour_js_1.bold)(`v${target.sequence}`)} declined. It stays in the history as a version that was not accepted.`);
474
470
  return 0;
475
471
  }
476
472
  /**
@@ -491,8 +487,8 @@ async function commandTakeDown(parsed) {
491
487
  return 1;
492
488
  const reason = parsed.flags.get("reason");
493
489
  if (parsed.flags.get("yes") !== true) {
494
- console.log(red(`This removes the files in v${target.sequence}. They do not come back.`));
495
- console.log(dim(` The version stays in the history as a gap saying it was removed.\n` +
490
+ console.log((0, colour_js_1.red)(`This removes the files in v${target.sequence}. They do not come back.`));
491
+ console.log((0, colour_js_1.dim)(` The version stays in the history as a gap saying it was removed.\n` +
496
492
  ` Add --yes when you are sure.`));
497
493
  return 1;
498
494
  }
@@ -500,10 +496,10 @@ async function commandTakeDown(parsed) {
500
496
  await (0, api_js_1.removeVersionContent)(project.id, target.id, typeof reason === "string" ? reason : null);
501
497
  }
502
498
  catch (error) {
503
- console.error(red(error instanceof Error ? error.message : String(error)));
499
+ console.error((0, colour_js_1.red)(error instanceof Error ? error.message : String(error)));
504
500
  return 1;
505
501
  }
506
- console.log(`${bold(`v${target.sequence}`)} taken down.`);
502
+ console.log(`${(0, colour_js_1.bold)(`v${target.sequence}`)} taken down.`);
507
503
  return 0;
508
504
  }
509
505
  /**
@@ -525,7 +521,7 @@ async function commandPromote(parsed) {
525
521
  return 1;
526
522
  const all = await (0, api_js_1.versions)(project.id);
527
523
  if (!all.length) {
528
- console.error(red("This project has nothing saved yet."));
524
+ console.error((0, colour_js_1.red)("This project has nothing saved yet."));
529
525
  return 1;
530
526
  }
531
527
  const named = parsed.flags.get("name");
@@ -536,23 +532,23 @@ async function commandPromote(parsed) {
536
532
  ? all.find((one) => String(one.sequence) === asked.replace(/^v/i, ""))
537
533
  : null;
538
534
  if (asked && !target) {
539
- console.error(red(`This project has no ${asked}.`));
535
+ console.error((0, colour_js_1.red)(`This project has no ${asked}.`));
540
536
  return 1;
541
537
  }
542
538
  if (!target) {
543
539
  const recent = all.filter((one) => one.state === "verified").slice(0, 10);
544
540
  if (!recent.length) {
545
- console.error(red("Nothing here can be promoted yet."));
541
+ console.error((0, colour_js_1.red)("Nothing here can be promoted yet."));
546
542
  return 1;
547
543
  }
548
- console.log(bold(`Recent commits on ${project.name}`));
544
+ console.log((0, colour_js_1.bold)(`Recent commits on ${project.name}`));
549
545
  recent.forEach((one, at) => {
550
546
  const when = one.createdAt
551
547
  ? new Date(one.createdAt).toLocaleString()
552
548
  : "";
553
- const already = one.name ? accent(` → ${one.name}`) : "";
554
- console.log(` ${String(at + 1).padStart(2)}. ${accent(`v${one.sequence}`).padEnd(16)}` +
555
- `${when.padEnd(22)}${dim(one.message)}${already}`);
549
+ const already = one.name ? (0, colour_js_1.accent)(` → ${one.name}`) : "";
550
+ console.log(` ${String(at + 1).padStart(2)}. ${(0, colour_js_1.accent)(`v${one.sequence}`).padEnd(16)}` +
551
+ `${when.padEnd(22)}${(0, colour_js_1.dim)(one.message)}${already}`);
556
552
  });
557
553
  const prompt = (0, promises_1.createInterface)({
558
554
  input: node_process_1.default.stdin,
@@ -562,11 +558,11 @@ async function commandPromote(parsed) {
562
558
  prompt.close();
563
559
  const choice = Number(typed.trim());
564
560
  if (!typed.trim()) {
565
- console.log(dim("Nothing promoted."));
561
+ console.log((0, colour_js_1.dim)("Nothing promoted."));
566
562
  return 0;
567
563
  }
568
564
  if (!Number.isInteger(choice) || choice < 1 || choice > recent.length) {
569
- console.error(red("That was not one of the numbers listed."));
565
+ console.error((0, colour_js_1.red)("That was not one of the numbers listed."));
570
566
  return 1;
571
567
  }
572
568
  target = recent[choice - 1];
@@ -588,11 +584,11 @@ async function commandPromote(parsed) {
588
584
  });
589
585
  }
590
586
  catch (error) {
591
- console.error(red(error instanceof Error ? error.message : String(error)));
587
+ console.error((0, colour_js_1.red)(error instanceof Error ? error.message : String(error)));
592
588
  return 1;
593
589
  }
594
- console.log(`${bold(versionName)} is now a version. ` +
595
- dim("It is what the public side of this project offers."));
590
+ console.log(`${(0, colour_js_1.bold)(versionName)} is now a version. ` +
591
+ (0, colour_js_1.dim)("It is what the public side of this project offers."));
596
592
  return 0;
597
593
  }
598
594
  /**
@@ -610,7 +606,7 @@ async function commandUndo(parsed) {
610
606
  return 1;
611
607
  const all = await (0, api_js_1.versions)(project.id);
612
608
  if (all.length < 2) {
613
- console.error(red("There is nothing before this to go back to."));
609
+ console.error((0, colour_js_1.red)("There is nothing before this to go back to."));
614
610
  return 1;
615
611
  }
616
612
  let to = null;
@@ -618,34 +614,34 @@ async function commandUndo(parsed) {
618
614
  if (asked) {
619
615
  const wanted = all.find((one) => String(one.sequence) === asked.replace(/^v/i, ""));
620
616
  if (!wanted) {
621
- console.error(red(`This project has no ${asked}.`));
617
+ console.error((0, colour_js_1.red)(`This project has no ${asked}.`));
622
618
  return 1;
623
619
  }
624
620
  to = wanted.id;
625
621
  }
626
622
  try {
627
623
  const undone = await (0, api_js_1.undoTo)(project.id, to);
628
- console.log(`${bold(project.name)} is back on ${accent(`v${undone.to.sequence}`)}.`);
624
+ console.log(`${(0, colour_js_1.bold)(project.name)} is back on ${(0, colour_js_1.accent)(`v${undone.to.sequence}`)}.`);
629
625
  if (undone.skipped.length) {
630
626
  /*
631
627
  Named rather than counted. "3 commits passed over" tells somebody
632
628
  nothing they can act on; the numbers let them look at one, or promote
633
629
  one, or put the head back where it was.
634
630
  */
635
- console.log(dim(` Passed over: ${undone.skipped
631
+ console.log((0, colour_js_1.dim)(` Passed over: ${undone.skipped
636
632
  .map((one) => `v${one.sequence}${one.name ? ` (${one.name})` : ""}`)
637
633
  .join(", ")}`));
638
- console.log(dim(" They are still here. Nothing was deleted and nothing renumbered."));
634
+ console.log((0, colour_js_1.dim)(" They are still here. Nothing was deleted and nothing renumbered."));
639
635
  const stillPublic = undone.skipped.filter((one) => one.name);
640
636
  if (stillPublic.length) {
641
- console.log(dim(` ${stillPublic.map((one) => one.name).join(", ")} ` +
637
+ console.log((0, colour_js_1.dim)(` ${stillPublic.map((one) => one.name).join(", ")} ` +
642
638
  `${stillPublic.length === 1 ? "is" : "are"} still a published version — ` +
643
639
  `use cbx mark to take ${stillPublic.length === 1 ? "it" : "them"} down.`));
644
640
  }
645
641
  }
646
642
  }
647
643
  catch (error) {
648
- console.error(red(error instanceof Error ? error.message : String(error)));
644
+ console.error((0, colour_js_1.red)(error instanceof Error ? error.message : String(error)));
649
645
  return 1;
650
646
  }
651
647
  return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coderook/cli",
3
- "version": "0.34.2",
3
+ "version": "0.34.3",
4
4
  "description": "The command line for CodeRook (coderook.com): version control and project hosting for projects of any size. Every save is a compressed snapshot, private or public, never used to train AI.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://coderook.com",