Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to not show progress animations in logs #942

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down Expand Up @@ -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
Expand All @@ -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`
Expand All @@ -462,6 +466,7 @@ Options
--extractErrors Opt-in to extracting invariant error codes
--tsconfig Specify your custom tsconfig path (default <root-folder>/tsconfig.json)
--transpileOnly Skip type checking
--noProgress Don't show progress animations
-h, --help Displays this message

Examples
Expand All @@ -472,6 +477,7 @@ Examples
$ tsdx build --extractErrors
$ tsdx build --tsconfig ./tsconfig.foo.json
$ tsdx build --transpileOnly
$ tsdx build --noProgress
```

### `tsdx test`
Expand Down
7 changes: 6 additions & 1 deletion src/createProgressEstimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>, 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.
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions website/pages/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down