From b9e7f89589626f1443216a584c539491cec19a4d Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Wed, 4 Aug 2021 12:22:48 -0400 Subject: [PATCH] fix(@angular-devkit/schematics-cli): log when in debug and/or dry run modes When using the schematics-cli with a local collection, the debug mode is enabled by default. Debug mode also enables dry run mode by default. This can result in a confusing situation when developing a schematic locally as files will not be written to disk but no messages are present explaining why. To improve the developer experience, messages will now be shown both when debug mode is enabled and when dry run is enabled. If either is enabled by default the reason will also be shown. --- .../schematics_cli/bin/schematics.ts | 19 +++++++++++++++++-- .../schematics_cli/bin/schematics_spec.ts | 3 +++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/angular_devkit/schematics_cli/bin/schematics.ts b/packages/angular_devkit/schematics_cli/bin/schematics.ts index 806afff2d2b4..31619a0f6ddc 100644 --- a/packages/angular_devkit/schematics_cli/bin/schematics.ts +++ b/packages/angular_devkit/schematics_cli/bin/schematics.ts @@ -107,6 +107,7 @@ function _createPromptProvider(): schema.PromptProvider { }; } +// eslint-disable-next-line max-lines-per-function export async function main({ args, stdout = process.stdout, @@ -141,8 +142,10 @@ export async function main({ const isLocalCollection = collectionName.startsWith('.') || collectionName.startsWith('/'); /** Gather the arguments for later use. */ - const debug: boolean = argv.debug === null ? isLocalCollection : argv.debug; - const dryRun: boolean = argv['dry-run'] === null ? debug : argv['dry-run']; + const debugPresent = argv['debug'] !== null; + const debug = debugPresent ? !!argv['debug'] : isLocalCollection; + const dryRunPresent = argv['dry-run'] !== null; + const dryRun = dryRunPresent ? !!argv['dry-run'] : debug; const force = argv['force']; const allowPrivate = argv['allow-private']; @@ -165,6 +168,12 @@ export async function main({ return 1; } + if (debug) { + logger.info( + `Debug mode enabled${isLocalCollection ? ' by default for local collections' : ''}.`, + ); + } + // Indicate to the user when nothing has been done. This is automatically set to off when there's // a new DryRunEvent. let nothingDone = true; @@ -285,6 +294,12 @@ export async function main({ if (nothingDone) { logger.info('Nothing to be done.'); + } else if (dryRun) { + logger.info( + `Dry run enabled${ + dryRunPresent ? '' : ' by default in debug mode' + }. No files written to disk.`, + ); } return 0; diff --git a/packages/angular_devkit/schematics_cli/bin/schematics_spec.ts b/packages/angular_devkit/schematics_cli/bin/schematics_spec.ts index 3c71096915c6..2055d474333e 100644 --- a/packages/angular_devkit/schematics_cli/bin/schematics_spec.ts +++ b/packages/angular_devkit/schematics_cli/bin/schematics_spec.ts @@ -50,16 +50,19 @@ describe('schematics-cli binary', () => { expect(stdout.lines).toMatch(/CREATE foo\/.gitignore/); expect(stdout.lines).toMatch(/CREATE foo\/src\/foo\/index.ts/); expect(stdout.lines).toMatch(/CREATE foo\/src\/foo\/index_spec.ts/); + expect(stdout.lines).toMatch(/Dry run enabled./); expect(res).toEqual(0); }); it('dry-run is default when debug mode', async () => { const args = ['blank', 'foo', '--debug']; const res = await main({ args, stdout, stderr }); + expect(stdout.lines).toMatch(/Debug mode enabled./); expect(stdout.lines).toMatch(/CREATE foo\/README.md/); expect(stdout.lines).toMatch(/CREATE foo\/.gitignore/); expect(stdout.lines).toMatch(/CREATE foo\/src\/foo\/index.ts/); expect(stdout.lines).toMatch(/CREATE foo\/src\/foo\/index_spec.ts/); + expect(stdout.lines).toMatch(/Dry run enabled by default in debug mode./); expect(res).toEqual(0); });