diff --git a/README.md b/README.md index eaf761573..5c6eb5b0e 100644 --- a/README.md +++ b/README.md @@ -338,6 +338,8 @@ export interface TsdxOptions { tsconfig?: string; // Is error extraction running? extractErrors?: boolean; + // Are output progress animations disabled? + noProgress?: boolean; // Is minifying? minify?: boolean; // Is this the very first rollup config (and thus should one-off metadata be extracted)? @@ -430,6 +432,7 @@ Options --onFailure Run a command on a failed build --noClean Don't clean the dist folder --transpileOnly Skip type checking + --noProgress Don't show progress animations -h, --help Displays this message Examples @@ -443,6 +446,7 @@ Examples $ tsdx watch --onSuccess "echo Successful build!" $ tsdx watch --onFailure "echo The build failed!" $ tsdx watch --transpileOnly + $ tsdx watch --noProgress ``` ### `tsdx build` @@ -462,6 +466,7 @@ Options --extractErrors Opt-in to extracting invariant error codes --tsconfig Specify your custom tsconfig path (default /tsconfig.json) --transpileOnly Skip type checking + --noProgress Don't show progress animations -h, --help Displays this message Examples @@ -472,6 +477,7 @@ Examples $ tsdx build --extractErrors $ tsdx build --tsconfig ./tsconfig.foo.json $ tsdx build --transpileOnly + $ tsdx build --noProgress ``` ### `tsdx test` diff --git a/src/createProgressEstimator.ts b/src/createProgressEstimator.ts index e3eba5ce3..adfd2e9f4 100644 --- a/src/createProgressEstimator.ts +++ b/src/createProgressEstimator.ts @@ -4,7 +4,12 @@ import { paths } from './constants'; const progressEstimator = require('progress-estimator'); -export async function createProgressEstimator() { +export async function createProgressEstimator(showProgress = true) { + if (!showProgress) { + return (_promise: Promise, message: string) => { + console.log(message); + }; + } await fs.ensureDir(paths.progressEstimatorCache); return progressEstimator({ // All configuration keys are optional, but it's recommended to specify a storage location. diff --git a/src/index.ts b/src/index.ts index c9b0399eb..04feb989a 100755 --- a/src/index.ts +++ b/src/index.ts @@ -281,6 +281,8 @@ prog .example('watch --transpileOnly') .option('--extractErrors', 'Extract invariant errors to ./errors/codes.json.') .example('watch --extractErrors') + .option('--noProgress', "Don't show progress animations") + .example('watch --noProgress') .action(async (dirtyOpts: WatchOpts) => { const opts = await normalizeOpts(dirtyOpts); const buildConfigs = await createBuildConfigs(opts); @@ -315,7 +317,8 @@ prog ]); } - const spinner = ora().start(); + // Leave isEnabled as undefined to preserve default behavior if noProgress is not set + const spinner = ora({ isEnabled: opts.noProgress && false }).start(); watch( (buildConfigs as RollupWatchOptions[]).map(inputOptions => ({ watch: { @@ -382,11 +385,13 @@ prog .example( 'build --extractErrors=https://reactjs.org/docs/error-decoder.html?invariant=' ) + .option('--noProgress', "Don't show progress animations") + .example('build --noProgress') .action(async (dirtyOpts: BuildOpts) => { const opts = await normalizeOpts(dirtyOpts); const buildConfigs = await createBuildConfigs(opts); await cleanDistFolder(); - const logger = await createProgressEstimator(); + const logger = await createProgressEstimator(!opts.noProgress); if (opts.format.includes('cjs')) { const promise = writeCjsEntryFile(opts.name).catch(logError); logger(promise, 'Creating entry file'); diff --git a/src/types.ts b/src/types.ts index e6878897e..6d44d647a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -5,6 +5,8 @@ interface SharedOpts { tsconfig?: string; // Is error extraction running? extractErrors?: boolean; + // Are output progress animations disabled? + noProgress?: boolean; } export type ModuleFormat = 'cjs' | 'umd' | 'esm' | 'system'; diff --git a/website/pages/customization.md b/website/pages/customization.md index 9912eb16e..11977f2f3 100644 --- a/website/pages/customization.md +++ b/website/pages/customization.md @@ -35,6 +35,8 @@ export interface TsdxOptions { tsconfig?: string; // Is error extraction running? extractErrors?: boolean; + // Are output progress animations disabled? + noProgress?: boolean; // Is minifying? minify?: boolean; // Is this the very first rollup config (and thus should one-off metadata be extracted)?