Skip to content

Commit eded012

Browse files
clydinalan-agius4
authored andcommitted
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. (cherry picked from commit b9e7f89)
1 parent 4bc10ab commit eded012

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/angular_devkit/schematics_cli/bin/schematics.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ function _createPromptProvider(): schema.PromptProvider {
107107
};
108108
}
109109

110+
// eslint-disable-next-line max-lines-per-function
110111
export async function main({
111112
args,
112113
stdout = process.stdout,
@@ -141,8 +142,10 @@ export async function main({
141142
const isLocalCollection = collectionName.startsWith('.') || collectionName.startsWith('/');
142143

143144
/** Gather the arguments for later use. */
144-
const debug: boolean = argv.debug === null ? isLocalCollection : argv.debug;
145-
const dryRun: boolean = argv['dry-run'] === null ? debug : argv['dry-run'];
145+
const debugPresent = argv['debug'] !== null;
146+
const debug = debugPresent ? !!argv['debug'] : isLocalCollection;
147+
const dryRunPresent = argv['dry-run'] !== null;
148+
const dryRun = dryRunPresent ? !!argv['dry-run'] : debug;
146149
const force = argv['force'];
147150
const allowPrivate = argv['allow-private'];
148151

@@ -165,6 +168,12 @@ export async function main({
165168
return 1;
166169
}
167170

171+
if (debug) {
172+
logger.info(
173+
`Debug mode enabled${isLocalCollection ? ' by default for local collections' : ''}.`,
174+
);
175+
}
176+
168177
// Indicate to the user when nothing has been done. This is automatically set to off when there's
169178
// a new DryRunEvent.
170179
let nothingDone = true;
@@ -285,6 +294,12 @@ export async function main({
285294

286295
if (nothingDone) {
287296
logger.info('Nothing to be done.');
297+
} else if (dryRun) {
298+
logger.info(
299+
`Dry run enabled${
300+
dryRunPresent ? '' : ' by default in debug mode'
301+
}. No files written to disk.`,
302+
);
288303
}
289304

290305
return 0;

packages/angular_devkit/schematics_cli/bin/schematics_spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,19 @@ describe('schematics-cli binary', () => {
5050
expect(stdout.lines).toMatch(/CREATE foo\/.gitignore/);
5151
expect(stdout.lines).toMatch(/CREATE foo\/src\/foo\/index.ts/);
5252
expect(stdout.lines).toMatch(/CREATE foo\/src\/foo\/index_spec.ts/);
53+
expect(stdout.lines).toMatch(/Dry run enabled./);
5354
expect(res).toEqual(0);
5455
});
5556

5657
it('dry-run is default when debug mode', async () => {
5758
const args = ['blank', 'foo', '--debug'];
5859
const res = await main({ args, stdout, stderr });
60+
expect(stdout.lines).toMatch(/Debug mode enabled./);
5961
expect(stdout.lines).toMatch(/CREATE foo\/README.md/);
6062
expect(stdout.lines).toMatch(/CREATE foo\/.gitignore/);
6163
expect(stdout.lines).toMatch(/CREATE foo\/src\/foo\/index.ts/);
6264
expect(stdout.lines).toMatch(/CREATE foo\/src\/foo\/index_spec.ts/);
65+
expect(stdout.lines).toMatch(/Dry run enabled by default in debug mode./);
6366
expect(res).toEqual(0);
6467
});
6568

0 commit comments

Comments
 (0)