From 44edffa81875f0dbd6c7ffc85821181cb0814129 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Fri, 4 Mar 2022 02:51:53 -0500 Subject: [PATCH] add new style of --help output --- package-lock.json | 16 ++++------ package.json | 1 + src/bin.ts | 75 +++++++++++++++++++++++++++++++++++------------ 3 files changed, 62 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3ad590ffe..6044a43fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1658,10 +1658,9 @@ } }, "chalk": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz", - "integrity": "sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==", - "dev": true, + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", "requires": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -1671,7 +1670,6 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, "requires": { "color-convert": "^2.0.1" } @@ -1680,7 +1678,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, "requires": { "color-name": "~1.1.4" } @@ -1688,8 +1685,7 @@ "color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" } } }, @@ -2519,8 +2515,7 @@ "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" }, "has-symbols": { "version": "1.0.1", @@ -4555,7 +4550,6 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, "requires": { "has-flag": "^4.0.0" } diff --git a/package.json b/package.json index 9ae86a3b9..d28546808 100644 --- a/package.json +++ b/package.json @@ -161,6 +161,7 @@ "acorn": "^8.4.1", "acorn-walk": "^8.1.1", "arg": "^4.1.0", + "chalk": "^4.1.2", "create-require": "^1.1.0", "diff": "^4.0.1", "make-error": "^1.1.1", diff --git a/src/bin.ts b/src/bin.ts index 13907f39e..07d5f66f5 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -159,43 +159,80 @@ export function main( } = args; if (help) { + const chalk = require('chalk') as typeof import('chalk'); console.log(` -Usage: ts-node [options] [ -e script | script.ts ] [arguments] +${chalk.bold(`Usage:`)} + ts-node [options] [ -e script | script.ts ] [arguments] -Options: +${chalk.bold(`Documentation:`)} + ${chalk.underline(`https://typestrong.org/ts-node/docs/`)} + +${chalk.bold(`Common Options:`)} -e, --eval [code] Evaluate code -p, --print Print result of \`--eval\` -r, --require [path] Require a node module before execution -i, --interactive Opens the REPL even if stdin does not appear to be a terminal + --esm Bootstrap with the ESM loader, enabling full ESM support + --swc Use the faster swc transpiler. Implies \`--transpileOnly\` + +${chalk.bold(`Informational Options:`)} + -h, --help Print CLI usage - -v, --version Print module version information - --cwdMode Use current directory instead of for config resolution + -v, --version Print module version information. \`-vvv\` to print additional information --showConfig Print resolved configuration and exit - -T, --transpileOnly Use TypeScript's faster \`transpileModule\` or a third-party transpiler - --swc Use the swc transpiler - -H, --compilerHost Use TypeScript's compiler host API - -I, --ignore [pattern] Override the path patterns to skip compilation - -P, --project [path] Path to TypeScript JSON project file - -C, --compiler [name] Specify a custom TypeScript compiler - --transpiler [name] Specify a third-party, non-typechecking transpiler - -D, --ignoreDiagnostics [code] Ignore TypeScript warnings by diagnostic code +${chalk.bold(`TSConfig Options:`)} + + -P, --project [path] Path to \`tsconfig.json\` + --skipProject Skip reading \`tsconfig.json\` + --cwdMode Use current directory instead of to search for \`tsconfig.json\` -O, --compilerOptions [opts] JSON object to merge with compiler options - --cwd Behave as if invoked within this working directory. +${chalk.bold(`Typechecking Options:`)} + + -D, --ignoreDiagnostics [code] Ignore TypeScript warnings by diagnostic code + --logError Logs TypeScript errors to stderr instead of throwing exceptions --files Load \`files\`, \`include\` and \`exclude\` from \`tsconfig.json\` on startup + May avoid typechecking failures due to missing types --pretty Use pretty diagnostic formatter (usually enabled by default) - --skipProject Skip reading \`tsconfig.json\` - --skipIgnore Skip \`--ignore\` checks - --emit Emit output files into \`.ts-node\` directory + +${chalk.bold(`Transpilation Options:`)} + + --swc Use the faster swc transpiler. Implies \`--transpileOnly\` + -T, --transpileOnly Skip typechecking to compile faster + --transpiler [name] Specify a third-party, non-typechecking transpiler + +${chalk.bold(`Scope Options:`)} + + -I, --ignore [pattern] Skip compiling files matching these regexp patterns. Default: skips \`node_modules\` + --skipIgnore Skip \`--ignore\` checks, compile files in \`node_modules\` --scope Scope compiler to files within \`scopeDir\`. Anything outside this directory is ignored. --scopeDir Directory for \`--scope\` + +${chalk.bold(`Advanced Options:`)} + + -C, --compiler [name] Specify a custom TypeScript compiler + --cwd Behave as if invoked within this working directory. + --emit Emit output files into \`.ts-node\` directory --preferTsExts Prefer importing TypeScript files over JavaScript files - --logError Logs TypeScript errors to stderr instead of throwing exceptions - --noExperimentalReplAwait Disable top-level await in REPL. Equivalent to node's --no-experimental-repl-await -`); + -H, --compilerHost Use TypeScript's compiler host API + --noExperimentalReplAwait Disable top-level await in REPL. Equivalent to node's \`--no-experimental-repl-await\` +`.replace(/.*\n/g, (v) => { + console.dir(v); + const maxWidth = Math.min(120, process.stdout.getWindowSize()?.[0] ?? 120); + const indent = 34; + let offset = 0; + let ret = ''; + while(v.length - offset > maxWidth) { + let i; + for(i = offset + maxWidth; v[i] !== ' ' && i > offset; i--) {} + ret += v.slice(offset, offset + i) + '\n' + ' '.repeat(indent); + offset += i + 1; + } + return ret + v.slice(offset); +}).replace(/\`.*?\`/g, (v) => chalk.cyan(v))); process.exit(0); }