citty 0.0.2 → 0.1.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/dist/index.cjs CHANGED
@@ -1,20 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const scule = require('scule');
4
- const tty = require('tty');
5
-
6
- function _interopNamespaceDefault(e) {
7
- const n = Object.create(null);
8
- if (e) {
9
- for (const k in e) {
10
- n[k] = e[k];
11
- }
12
- }
13
- n.default = e;
14
- return n;
15
- }
16
-
17
- const tty__namespace = /*#__PURE__*/_interopNamespaceDefault(tty);
4
+ const colorette = require('colorette');
18
5
 
19
6
  function toArray(val) {
20
7
  if (Array.isArray(val)) {
@@ -361,155 +348,6 @@ async function renderUsage(cmd, parent) {
361
348
  return usageLines.filter((l) => typeof l === "string").join("\n");
362
349
  }
363
350
 
364
- const {
365
- env = {},
366
- argv = [],
367
- platform = "",
368
- } = typeof process === "undefined" ? {} : process;
369
-
370
- const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
371
- const isForced = "FORCE_COLOR" in env || argv.includes("--color");
372
- const isWindows = platform === "win32";
373
- const isDumbTerminal = env.TERM === "dumb";
374
-
375
- const isCompatibleTerminal =
376
- tty__namespace && tty__namespace.isatty && tty__namespace.isatty(1) && env.TERM && !isDumbTerminal;
377
-
378
- const isCI =
379
- "CI" in env &&
380
- ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
381
-
382
- const isColorSupported =
383
- !isDisabled &&
384
- (isForced || (isWindows && !isDumbTerminal) || isCompatibleTerminal || isCI);
385
-
386
- const replaceClose = (
387
- index,
388
- string,
389
- close,
390
- replace,
391
- head = string.substring(0, index) + replace,
392
- tail = string.substring(index + close.length),
393
- next = tail.indexOf(close)
394
- ) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
395
-
396
- const clearBleed = (index, string, open, close, replace) =>
397
- index < 0
398
- ? open + string + close
399
- : open + replaceClose(index, string, close, replace) + close;
400
-
401
- const filterEmpty =
402
- (open, close, replace = open, at = open.length + 1) =>
403
- (string) =>
404
- string || !(string === "" || string === undefined)
405
- ? clearBleed(
406
- ("" + string).indexOf(close, at),
407
- string,
408
- open,
409
- close,
410
- replace
411
- )
412
- : "";
413
-
414
- const init = (open, close, replace) =>
415
- filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
416
-
417
- const colors = {
418
- reset: init(0, 0),
419
- bold: init(1, 22, "\x1b[22m\x1b[1m"),
420
- dim: init(2, 22, "\x1b[22m\x1b[2m"),
421
- italic: init(3, 23),
422
- underline: init(4, 24),
423
- inverse: init(7, 27),
424
- hidden: init(8, 28),
425
- strikethrough: init(9, 29),
426
- black: init(30, 39),
427
- red: init(31, 39),
428
- green: init(32, 39),
429
- yellow: init(33, 39),
430
- blue: init(34, 39),
431
- magenta: init(35, 39),
432
- cyan: init(36, 39),
433
- white: init(37, 39),
434
- gray: init(90, 39),
435
- bgBlack: init(40, 49),
436
- bgRed: init(41, 49),
437
- bgGreen: init(42, 49),
438
- bgYellow: init(43, 49),
439
- bgBlue: init(44, 49),
440
- bgMagenta: init(45, 49),
441
- bgCyan: init(46, 49),
442
- bgWhite: init(47, 49),
443
- blackBright: init(90, 39),
444
- redBright: init(91, 39),
445
- greenBright: init(92, 39),
446
- yellowBright: init(93, 39),
447
- blueBright: init(94, 39),
448
- magentaBright: init(95, 39),
449
- cyanBright: init(96, 39),
450
- whiteBright: init(97, 39),
451
- bgBlackBright: init(100, 49),
452
- bgRedBright: init(101, 49),
453
- bgGreenBright: init(102, 49),
454
- bgYellowBright: init(103, 49),
455
- bgBlueBright: init(104, 49),
456
- bgMagentaBright: init(105, 49),
457
- bgCyanBright: init(106, 49),
458
- bgWhiteBright: init(107, 49),
459
- };
460
-
461
- const createColors = ({ useColor = isColorSupported } = {}) =>
462
- useColor
463
- ? colors
464
- : Object.keys(colors).reduce(
465
- (colors, key) => ({ ...colors, [key]: String }),
466
- {}
467
- );
468
-
469
- const {
470
- reset,
471
- bold,
472
- dim,
473
- italic,
474
- underline,
475
- inverse,
476
- hidden,
477
- strikethrough,
478
- black,
479
- red,
480
- green,
481
- yellow,
482
- blue,
483
- magenta,
484
- cyan,
485
- white,
486
- gray,
487
- bgBlack,
488
- bgRed,
489
- bgGreen,
490
- bgYellow,
491
- bgBlue,
492
- bgMagenta,
493
- bgCyan,
494
- bgWhite,
495
- blackBright,
496
- redBright,
497
- greenBright,
498
- yellowBright,
499
- blueBright,
500
- magentaBright,
501
- cyanBright,
502
- whiteBright,
503
- bgBlackBright,
504
- bgRedBright,
505
- bgGreenBright,
506
- bgYellowBright,
507
- bgBlueBright,
508
- bgMagentaBright,
509
- bgCyanBright,
510
- bgWhiteBright,
511
- } = createColors();
512
-
513
351
  async function runMain(cmd, opts = {}) {
514
352
  const rawArgs = opts.rawArgs || process.argv.slice(2);
515
353
  try {
@@ -526,7 +364,7 @@ async function runMain(cmd, opts = {}) {
526
364
  }
527
365
  console.error(
528
366
  `
529
- ${bgRed(` ${error.code || error.name} `)} ${error.message}
367
+ ${colorette.bgRed(` ${error.code || error.name} `)} ${error.message}
530
368
  `
531
369
  );
532
370
  if (isCLIError) {
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { camelCase, kebabCase } from 'scule';
2
- import * as tty from 'tty';
2
+ import { bgRed } from 'colorette';
3
3
 
4
4
  function toArray(val) {
5
5
  if (Array.isArray(val)) {
@@ -346,155 +346,6 @@ async function renderUsage(cmd, parent) {
346
346
  return usageLines.filter((l) => typeof l === "string").join("\n");
347
347
  }
348
348
 
349
- const {
350
- env = {},
351
- argv = [],
352
- platform = "",
353
- } = typeof process === "undefined" ? {} : process;
354
-
355
- const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
356
- const isForced = "FORCE_COLOR" in env || argv.includes("--color");
357
- const isWindows = platform === "win32";
358
- const isDumbTerminal = env.TERM === "dumb";
359
-
360
- const isCompatibleTerminal =
361
- tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
362
-
363
- const isCI =
364
- "CI" in env &&
365
- ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
366
-
367
- const isColorSupported =
368
- !isDisabled &&
369
- (isForced || (isWindows && !isDumbTerminal) || isCompatibleTerminal || isCI);
370
-
371
- const replaceClose = (
372
- index,
373
- string,
374
- close,
375
- replace,
376
- head = string.substring(0, index) + replace,
377
- tail = string.substring(index + close.length),
378
- next = tail.indexOf(close)
379
- ) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
380
-
381
- const clearBleed = (index, string, open, close, replace) =>
382
- index < 0
383
- ? open + string + close
384
- : open + replaceClose(index, string, close, replace) + close;
385
-
386
- const filterEmpty =
387
- (open, close, replace = open, at = open.length + 1) =>
388
- (string) =>
389
- string || !(string === "" || string === undefined)
390
- ? clearBleed(
391
- ("" + string).indexOf(close, at),
392
- string,
393
- open,
394
- close,
395
- replace
396
- )
397
- : "";
398
-
399
- const init = (open, close, replace) =>
400
- filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
401
-
402
- const colors = {
403
- reset: init(0, 0),
404
- bold: init(1, 22, "\x1b[22m\x1b[1m"),
405
- dim: init(2, 22, "\x1b[22m\x1b[2m"),
406
- italic: init(3, 23),
407
- underline: init(4, 24),
408
- inverse: init(7, 27),
409
- hidden: init(8, 28),
410
- strikethrough: init(9, 29),
411
- black: init(30, 39),
412
- red: init(31, 39),
413
- green: init(32, 39),
414
- yellow: init(33, 39),
415
- blue: init(34, 39),
416
- magenta: init(35, 39),
417
- cyan: init(36, 39),
418
- white: init(37, 39),
419
- gray: init(90, 39),
420
- bgBlack: init(40, 49),
421
- bgRed: init(41, 49),
422
- bgGreen: init(42, 49),
423
- bgYellow: init(43, 49),
424
- bgBlue: init(44, 49),
425
- bgMagenta: init(45, 49),
426
- bgCyan: init(46, 49),
427
- bgWhite: init(47, 49),
428
- blackBright: init(90, 39),
429
- redBright: init(91, 39),
430
- greenBright: init(92, 39),
431
- yellowBright: init(93, 39),
432
- blueBright: init(94, 39),
433
- magentaBright: init(95, 39),
434
- cyanBright: init(96, 39),
435
- whiteBright: init(97, 39),
436
- bgBlackBright: init(100, 49),
437
- bgRedBright: init(101, 49),
438
- bgGreenBright: init(102, 49),
439
- bgYellowBright: init(103, 49),
440
- bgBlueBright: init(104, 49),
441
- bgMagentaBright: init(105, 49),
442
- bgCyanBright: init(106, 49),
443
- bgWhiteBright: init(107, 49),
444
- };
445
-
446
- const createColors = ({ useColor = isColorSupported } = {}) =>
447
- useColor
448
- ? colors
449
- : Object.keys(colors).reduce(
450
- (colors, key) => ({ ...colors, [key]: String }),
451
- {}
452
- );
453
-
454
- const {
455
- reset,
456
- bold,
457
- dim,
458
- italic,
459
- underline,
460
- inverse,
461
- hidden,
462
- strikethrough,
463
- black,
464
- red,
465
- green,
466
- yellow,
467
- blue,
468
- magenta,
469
- cyan,
470
- white,
471
- gray,
472
- bgBlack,
473
- bgRed,
474
- bgGreen,
475
- bgYellow,
476
- bgBlue,
477
- bgMagenta,
478
- bgCyan,
479
- bgWhite,
480
- blackBright,
481
- redBright,
482
- greenBright,
483
- yellowBright,
484
- blueBright,
485
- magentaBright,
486
- cyanBright,
487
- whiteBright,
488
- bgBlackBright,
489
- bgRedBright,
490
- bgGreenBright,
491
- bgYellowBright,
492
- bgBlueBright,
493
- bgMagentaBright,
494
- bgCyanBright,
495
- bgWhiteBright,
496
- } = createColors();
497
-
498
349
  async function runMain(cmd, opts = {}) {
499
350
  const rawArgs = opts.rawArgs || process.argv.slice(2);
500
351
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "citty",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "Elegant CLI Builder",
5
5
  "repository": "unjs/citty",
6
6
  "license": "MIT",
@@ -30,20 +30,18 @@
30
30
  "test": "pnpm lint && vitest run --coverage"
31
31
  },
32
32
  "dependencies": {
33
- "scule": "^1.0.0"
34
- },
35
- "devDependencies": {
36
- "@types/node": "^18.15.10",
33
+ "@types/node": "^18.15.11",
37
34
  "@vitest/coverage-c8": "^0.29.8",
38
35
  "changelogen": "^0.5.2",
39
36
  "colorette": "^2.0.19",
40
- "eslint": "^8.36.0",
37
+ "eslint": "^8.37.0",
41
38
  "eslint-config-unjs": "^0.1.0",
42
39
  "jiti": "^1.18.2",
43
40
  "prettier": "^2.8.7",
44
- "typescript": "^5.0.2",
41
+ "scule": "^1.0.0",
42
+ "typescript": "^5.0.3",
45
43
  "unbuild": "^1.1.2",
46
44
  "vitest": "^0.29.8"
47
45
  },
48
- "packageManager": "pnpm@8.0.0"
46
+ "packageManager": "pnpm@8.1.0"
49
47
  }