Skip to content

Commit c498f59

Browse files
authored
fix(angular): always provide the project name fallback (#4349)
1 parent d53cee3 commit c498f59

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { CommandLineOptions } from '../../../../definitions';
2+
import { AngularGenerateRunner } from '../generate';
3+
4+
describe('@ionic/cli', () => {
5+
6+
describe('lib/project/angular/generate', () => {
7+
8+
describe('AngularGenerateRunner', () => {
9+
10+
describe('createOptionsFromCommandLine', () => {
11+
12+
const defaults = {
13+
name: undefined,
14+
project: 'app',
15+
type: undefined,
16+
};
17+
18+
it('should provide defaults with no inputs or options', () => {
19+
const runner = new AngularGenerateRunner({} as any);
20+
const result = runner.createOptionsFromCommandLine([], {} as CommandLineOptions);
21+
expect(result).toEqual(defaults);
22+
});
23+
24+
it('should provide options from inputs', () => {
25+
const runner = new AngularGenerateRunner({} as any);
26+
const result = runner.createOptionsFromCommandLine(['service', 'FancyBar'], { _: [] });
27+
expect(result).toEqual({ ...defaults, name: 'FancyBar', type: 'service' });
28+
});
29+
30+
it('should respect --project', () => {
31+
const runner = new AngularGenerateRunner({} as any);
32+
const result = runner.createOptionsFromCommandLine([], { _: [], project: 'otherProject' });
33+
expect(result).toEqual({ ...defaults, project: 'otherProject' });
34+
});
35+
36+
});
37+
38+
});
39+
40+
});
41+
42+
});

packages/@ionic/cli/src/lib/project/angular/__tests__/serve.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('@ionic/cli', () => {
2424
open: false,
2525
port: 8100,
2626
proxy: true,
27-
project: undefined,
27+
project: 'app',
2828
prod: undefined,
2929
platform: undefined,
3030
verbose: false,
@@ -62,8 +62,8 @@ describe('@ionic/cli', () => {
6262

6363
it('should respect --project and --configuration flags', () => {
6464
const runner = new AngularServeRunner({} as any);
65-
const result = runner.createOptionsFromCommandLine([], { _: [], project: 'app', configuration: 'production' });
66-
expect(result).toEqual({ ...defaults, project: 'app', configuration: 'production' });
65+
const result = runner.createOptionsFromCommandLine([], { _: [], project: 'otherProject', configuration: 'production' });
66+
expect(result).toEqual({ ...defaults, project: 'otherProject', configuration: 'production' });
6767
});
6868

6969
it('should pass on separated args', () => {

packages/@ionic/cli/src/lib/project/angular/build.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,15 @@ ${input('ionic build')} uses the Angular CLI. Use ${input('ng build --help')} to
8080
const baseOptions = super.createBaseOptionsFromCommandLine(inputs, options);
8181
const prod = options['prod'] ? Boolean(options['prod']) : undefined;
8282
const configuration = options['configuration'] ? String(options['configuration']) : (prod ? 'production' : undefined);
83+
const project = options['project'] ? String(options['project']) : 'app';
8384
const sourcemaps = typeof options['source-map'] === 'boolean' ? Boolean(options['source-map']) : undefined;
8485
const cordovaAssets = typeof options['cordova-assets'] === 'boolean' ? Boolean(options['cordova-assets']) : undefined;
8586
const watch = typeof options['watch'] === 'boolean' ? Boolean(options['watch']) : undefined;
8687

8788
return {
8889
...baseOptions,
8990
configuration,
91+
project,
9092
sourcemaps,
9193
cordovaAssets,
9294
watch,
@@ -161,8 +163,7 @@ export class AngularBuildCLI extends BuildCLI<AngularBuildOptions> {
161163

162164
protected buildArchitectCommand(options: AngularBuildOptions): string[] {
163165
const cmd = options.engine === 'cordova' ? 'ionic-cordova-build' : 'build';
164-
const project = options.project ? options.project : 'app';
165166

166-
return ['run', `${project}:${cmd}${options.configuration ? `:${options.configuration}` : ''}`];
167+
return ['run', `${options.project}:${cmd}${options.configuration ? `:${options.configuration}` : ''}`];
167168
}
168169
}

packages/@ionic/cli/src/lib/project/angular/generate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,13 @@ To test a generator before file modifications are made, use the ${input('--dry-r
100100

101101
createOptionsFromCommandLine(inputs: CommandLineInputs, options: CommandLineOptions): AngularGenerateOptions {
102102
const baseOptions = super.createOptionsFromCommandLine(inputs, options);
103+
const project = options['project'] ? String(options['project']) : 'app';
103104

104105
// TODO: this is a little gross, is there a better way to pass in all the
105106
// options that the command got?
106107
return {
107108
...lodash.omit(options, '_', '--', ...GLOBAL_OPTIONS.map(opt => opt.name)),
108-
project: options['project'],
109+
project,
109110
...baseOptions,
110111
};
111112
}

packages/@ionic/cli/src/lib/project/angular/serve.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ The dev server can use HTTPS via the ${input('--ssl')} option ${chalk.bold.red('
9494
const prod = options['prod'] ? Boolean(options['prod']) : undefined;
9595
const ssl = options['ssl'] ? Boolean(options['ssl']) : undefined;
9696
const configuration = options['configuration'] ? String(options['configuration']) : (prod ? 'production' : undefined);
97+
const project = options['project'] ? String(options['project']) : 'app';
9798
const sourcemaps = typeof options['source-map'] === 'boolean' ? Boolean(options['source-map']) : undefined;
9899
const consolelogs = typeof options['consolelogs'] === 'boolean' ? Boolean(options['consolelogs']) : undefined;
99100
const consolelogsPort = consolelogs ? str2num(options['consolelogs-port'], DEFAULT_CONSOLE_LOGS_PORT) : undefined;
@@ -104,6 +105,7 @@ The dev server can use HTTPS via the ${input('--ssl')} option ${chalk.bold.red('
104105
consolelogsPort,
105106
ssl,
106107
configuration,
108+
project,
107109
sourcemaps,
108110
};
109111
}
@@ -250,8 +252,7 @@ export class AngularServeCLI extends ServeCLI<AngularServeOptions> {
250252

251253
protected buildArchitectCommand(options: AngularServeOptions): string[] {
252254
const cmd = options.engine === 'cordova' ? 'ionic-cordova-serve' : 'serve';
253-
const project = options.project ? options.project : 'app';
254255

255-
return ['run', `${project}:${cmd}${options.configuration ? `:${options.configuration}` : ''}`];
256+
return ['run', `${options.project}:${cmd}${options.configuration ? `:${options.configuration}` : ''}`];
256257
}
257258
}

0 commit comments

Comments
 (0)