Skip to content

Commit

Permalink
fix(@angular-devkit/schematics-cli): log when in debug and/or dry run…
Browse files Browse the repository at this point in the history
… 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.

(cherry picked from commit b9e7f89)
  • Loading branch information
clydin authored and alan-agius4 committed Aug 5, 2021
1 parent 4bc10ab commit eded012
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/angular_devkit/schematics_cli/bin/schematics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function _createPromptProvider(): schema.PromptProvider {
};
}

// eslint-disable-next-line max-lines-per-function
export async function main({
args,
stdout = process.stdout,
Expand Down Expand Up @@ -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'];

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions packages/angular_devkit/schematics_cli/bin/schematics_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit eded012

Please sign in to comment.