Skip to content

Commit b246573

Browse files
committed
feat(command): adding the --app command option
1 parent bac6e75 commit b246573

File tree

24 files changed

+141
-68
lines changed

24 files changed

+141
-68
lines changed

packages/@angular/cli/blueprints/class/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as appUtils from '../../utilities/app-utils';
2+
13
const stringUtils = require('ember-cli-string-utils');
24
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
35
const Blueprint = require('../../ember-cli/lib/models/blueprint');
@@ -11,11 +13,13 @@ export default Blueprint.extend({
1113
name: 'spec',
1214
type: Boolean,
1315
description: 'Specifies if a spec file is generated.'
14-
}
16+
},
17+
{ name: 'app', type: String, aliases: ['a'] }
1518
],
1619

1720
normalizeEntityName: function (entityName: string) {
18-
const parsedPath = dynamicPathParser(this.project, entityName.split('.')[0]);
21+
const appConfig = appUtils.getAppFromConfig(this.project.ngConfig.apps, this.options.app);
22+
const parsedPath = dynamicPathParser(this.project, entityName.split('.')[0], appConfig);
1923

2024
this.dynamicPath = parsedPath;
2125
return parsedPath.name;

packages/@angular/cli/blueprints/component/index.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { NodeHost } from '../../lib/ast-tools';
2+
import * as appUtils from '../../utilities/app-utils';
23

34
import * as fs from 'fs';
45
import * as path from 'path';
@@ -71,22 +72,25 @@ export default Blueprint.extend({
7172
type: Boolean,
7273
default: false,
7374
description: 'Specifies if declaring module exports the component.'
74-
}
75+
},
76+
{ name: 'app', type: String, aliases: ['a'] }
7577
],
7678

7779
beforeInstall: function (options: any) {
80+
const appConfig = appUtils.getAppFromConfig(this.project.ngConfig.apps, this.options.app);
7881
if (options.module) {
7982
// Resolve path to module
8083
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
81-
const parsedPath = dynamicPathParser(this.project, modulePath);
84+
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
8285
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);
8386

8487
if (!fs.existsSync(this.pathToModule)) {
8588
throw 'Module specified does not exist';
8689
}
8790
} else {
8891
try {
89-
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
92+
this.pathToModule = findParentModule
93+
(this.project.root, appConfig.root, this.dynamicPath.dir);
9094
} catch (e) {
9195
if (!options.skipImport) {
9296
throw `Error locating module for declaration\n\t${e}`;
@@ -96,16 +100,12 @@ export default Blueprint.extend({
96100
},
97101

98102
normalizeEntityName: function (entityName: string) {
99-
const parsedPath = dynamicPathParser(this.project, entityName);
103+
const appConfig = appUtils.getAppFromConfig(this.project.ngConfig.apps, this.options.app);
104+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
100105

101106
this.dynamicPath = parsedPath;
102107

103-
let defaultPrefix = '';
104-
if (this.project.ngConfig &&
105-
this.project.ngConfig.apps[0] &&
106-
this.project.ngConfig.apps[0].prefix) {
107-
defaultPrefix = this.project.ngConfig.apps[0].prefix;
108-
}
108+
const defaultPrefix = (appConfig && appConfig.prefix) || '';
109109

110110
let prefix = (this.options.prefix === 'false' || this.options.prefix === '')
111111
? '' : (this.options.prefix || defaultPrefix);
@@ -191,7 +191,8 @@ export default Blueprint.extend({
191191
if (!options.locals.flat) {
192192
dir += path.sep + options.dasherizedModuleName;
193193
}
194-
const srcDir = this.project.ngConfig.apps[0].root;
194+
const appConfig = appUtils.getAppFromConfig(this.project.ngConfig.apps, this.options.app);
195+
const srcDir = appConfig.root;
195196
this.appDir = dir.substr(dir.indexOf(srcDir) + srcDir.length);
196197
this.generatePath = dir;
197198
return dir;

packages/@angular/cli/blueprints/directive/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {NodeHost} from '../../lib/ast-tools';
2+
import * as appUtils from '../../utilities/app-utils';
23

34
const path = require('path');
45
const fs = require('fs');
@@ -46,22 +47,25 @@ export default Blueprint.extend({
4647
type: Boolean,
4748
default: false,
4849
description: 'Specifies if declaring module exports the component.'
49-
}
50+
},
51+
{ name: 'app', type: String, aliases: ['a'] }
5052
],
5153

5254
beforeInstall: function(options: any) {
55+
const appConfig = appUtils.getAppFromConfig(this.project.ngConfig.apps, this.options.app);
5356
if (options.module) {
5457
// Resolve path to module
5558
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
56-
const parsedPath = dynamicPathParser(this.project, modulePath);
59+
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
5760
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);
5861

5962
if (!fs.existsSync(this.pathToModule)) {
6063
throw ' ';
6164
}
6265
} else {
6366
try {
64-
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
67+
this.pathToModule = findParentModule
68+
(this.project.root, appConfig.root, this.dynamicPath.dir);
6569
} catch (e) {
6670
if (!options.skipImport) {
6771
throw `Error locating module for declaration\n\t${e}`;
@@ -71,16 +75,12 @@ export default Blueprint.extend({
7175
},
7276

7377
normalizeEntityName: function (entityName: string) {
74-
const parsedPath = dynamicPathParser(this.project, entityName);
78+
const appConfig = appUtils.getAppFromConfig(this.project.ngConfig.apps, this.options.app);
79+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
7580

7681
this.dynamicPath = parsedPath;
7782

78-
let defaultPrefix = '';
79-
if (this.project.ngConfig &&
80-
this.project.ngConfig.apps[0] &&
81-
this.project.ngConfig.apps[0].prefix) {
82-
defaultPrefix = this.project.ngConfig.apps[0].prefix;
83-
}
83+
const defaultPrefix = (appConfig && appConfig.prefix) || '';
8484

8585
let prefix = (this.options.prefix === 'false' || this.options.prefix === '')
8686
? '' : (this.options.prefix || defaultPrefix);

packages/@angular/cli/blueprints/enum/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
import * as appUtils from '../../utilities/app-utils';
2+
13
const stringUtils = require('ember-cli-string-utils');
24
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
35
const Blueprint = require('../../ember-cli/lib/models/blueprint');
46

57
export default Blueprint.extend({
68
description: '',
79

10+
availableOptions: [
11+
{ name: 'app', type: String, aliases: ['a'] }
12+
],
13+
814
normalizeEntityName: function (entityName: string) {
9-
const parsedPath = dynamicPathParser(this.project, entityName);
15+
const appConfig = appUtils.getAppFromConfig(this.project.ngConfig.apps, this.options.app);
16+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
1017

1118
this.dynamicPath = parsedPath;
1219
return parsedPath.name;

packages/@angular/cli/blueprints/interface/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as appUtils from '../../utilities/app-utils';
2+
13
const stringUtils = require('ember-cli-string-utils');
24
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
35
const Blueprint = require('../../ember-cli/lib/models/blueprint');
@@ -9,8 +11,13 @@ export default Blueprint.extend({
911
'<interface-type>'
1012
],
1113

14+
availableOptions: [
15+
{ name: 'app', type: String, aliases: ['a'] }
16+
],
17+
1218
normalizeEntityName: function (entityName: string) {
13-
const parsedPath = dynamicPathParser(this.project, entityName);
19+
const appConfig = appUtils.getAppFromConfig(this.project.ngConfig.apps, this.options.app);
20+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
1421

1522
this.dynamicPath = parsedPath;
1623
return parsedPath.name;

packages/@angular/cli/blueprints/module/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as appUtils from '../../utilities/app-utils';
2+
13
const path = require('path');
24
const Blueprint = require('../../ember-cli/lib/models/blueprint');
35
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
@@ -22,12 +24,14 @@ export default Blueprint.extend({
2224
type: Boolean,
2325
default: false,
2426
description: 'Specifies if a routing module file should be generated.'
25-
}
27+
},
28+
{ name: 'app', type: String, aliases: ['a'] }
2629
],
2730

2831
normalizeEntityName: function (entityName: string) {
2932
this.entityName = entityName;
30-
const parsedPath = dynamicPathParser(this.project, entityName);
33+
const appConfig = appUtils.getAppFromConfig(this.project.ngConfig.apps, this.options.app);
34+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
3135

3236
this.dynamicPath = parsedPath;
3337
return parsedPath.name;

packages/@angular/cli/blueprints/pipe/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {NodeHost} from '../../lib/ast-tools';
2+
import * as appUtils from '../../utilities/app-utils';
23

34
const path = require('path');
45
const fs = require('fs');
@@ -41,22 +42,25 @@ export default Blueprint.extend({
4142
type: Boolean,
4243
default: false,
4344
description: 'Specifies if declaring module exports the pipe.'
44-
}
45+
},
46+
{ name: 'app', type: String, aliases: ['a'] }
4547
],
4648

4749
beforeInstall: function(options: any) {
50+
const appConfig = appUtils.getAppFromConfig(this.project.ngConfig.apps, this.options.app);
4851
if (options.module) {
4952
// Resolve path to module
5053
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
51-
const parsedPath = dynamicPathParser(this.project, modulePath);
54+
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
5255
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);
5356

5457
if (!fs.existsSync(this.pathToModule)) {
5558
throw 'Module specified does not exist';
5659
}
5760
} else {
5861
try {
59-
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
62+
this.pathToModule = findParentModule
63+
(this.project.root, appConfig.root, this.dynamicPath.dir);
6064
} catch (e) {
6165
if (!options.skipImport) {
6266
throw `Error locating module for declaration\n\t${e}`;
@@ -66,7 +70,8 @@ export default Blueprint.extend({
6670
},
6771

6872
normalizeEntityName: function (entityName: string) {
69-
const parsedPath = dynamicPathParser(this.project, entityName);
73+
const appConfig = appUtils.getAppFromConfig(this.project.ngConfig.apps, this.options.app);
74+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
7075

7176
this.dynamicPath = parsedPath;
7277
return parsedPath.name;

packages/@angular/cli/blueprints/service/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {NodeHost} from '../../lib/ast-tools';
22
import { oneLine } from 'common-tags';
3+
import * as appUtils from '../../utilities/app-utils';
34

45
const path = require('path');
56
const fs = require('fs');
@@ -28,14 +29,16 @@ export default Blueprint.extend({
2829
name: 'module',
2930
type: String, aliases: ['m'],
3031
description: 'Allows specification of the declaring module.'
31-
}
32+
},
33+
{ name: 'app', type: String, aliases: ['a'] }
3234
],
3335

3436
beforeInstall: function(options: any) {
3537
if (options.module) {
3638
// Resolve path to module
3739
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
38-
const parsedPath = dynamicPathParser(this.project, modulePath);
40+
const appConfig = appUtils.getAppFromConfig(this.project.ngConfig.apps, this.options.app);
41+
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
3942
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);
4043

4144
if (!fs.existsSync(this.pathToModule)) {
@@ -45,7 +48,8 @@ export default Blueprint.extend({
4548
},
4649

4750
normalizeEntityName: function (entityName: string) {
48-
const parsedPath = dynamicPathParser(this.project, entityName);
51+
const appConfig = appUtils.getAppFromConfig(this.project.ngConfig.apps, this.options.app);
52+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
4953

5054
this.dynamicPath = parsedPath;
5155
return parsedPath.name;

packages/@angular/cli/commands/build.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export const baseBuildCommandOptions: any = [
4545
];
4646

4747
export interface BuildTaskOptions extends BuildOptions {
48+
watch?: boolean;
49+
app?: String;
4850
statsJson?: boolean;
4951
}
5052

@@ -54,7 +56,9 @@ const BuildCommand = Command.extend({
5456
aliases: ['b'],
5557

5658
availableOptions: baseBuildCommandOptions.concat([
57-
{ name: 'stats-json', type: Boolean, default: false }
59+
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] },
60+
{ name: 'stats-json', type: Boolean, default: false },
61+
{ name: 'app', type: String, aliases: ['a'] }
5862
]),
5963

6064
run: function (commandOptions: BuildTaskOptions) {

packages/@angular/cli/commands/e2e.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface E2eTaskOptions extends ServeTaskOptions {
1515

1616
export const e2eCommandOptions = baseServeCommandOptions.concat([
1717
{ name: 'config', type: String, aliases: ['c'] },
18+
{ name: 'app', type: String, aliases: ['a'] },
1819
{ name: 'specs', type: Array, default: [], aliases: ['sp'] },
1920
{ name: 'element-explorer', type: Boolean, default: false, aliases: ['ee'] },
2021
{ name: 'webdriver-update', type: Boolean, default: true, aliases: ['wu'] },

packages/@angular/cli/commands/eject.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ const Command = require('../ember-cli/lib/models/command');
77
// defaults for BuildOptions
88
export const baseEjectCommandOptions: any = [
99
...baseBuildCommandOptions,
10-
{ name: 'force', 'type': Boolean }
10+
{ name: 'force', 'type': Boolean },
11+
{ name: 'app', type: String, aliases: ['a'] }
1112
];
1213

1314
export interface EjectTaskOptions extends BuildOptions {
1415
force?: boolean;
16+
app?: string;
1517
}
1618

1719

packages/@angular/cli/commands/serve.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface ServeTaskOptions extends BuildOptions {
3030
sslCert?: string;
3131
open?: boolean;
3232
hmr?: boolean;
33+
app?: string;
3334
}
3435

3536
// Expose options unrelated to live-reload to other commands that need to run serve
@@ -62,6 +63,7 @@ const ServeCommand = Command.extend({
6263

6364
availableOptions: baseServeCommandOptions.concat([
6465
{ name: 'live-reload', type: Boolean, default: true, aliases: ['lr'] },
66+
{ name: 'app', type: String, aliases: ['a'] },
6567
{
6668
name: 'live-reload-host',
6769
type: String,

packages/@angular/cli/commands/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ export interface TestOptions {
1919
progress?: boolean;
2020
config: string;
2121
poll?: number;
22+
app?: string;
2223
}
2324

2425

2526
const TestCommand = EmberTestCommand.extend({
2627
availableOptions: [
2728
{ name: 'watch', type: Boolean, default: true, aliases: ['w'] },
29+
{ name: 'app', type: String, aliases: ['a'] },
2830
{ name: 'code-coverage', type: Boolean, default: false, aliases: ['cc'] },
2931
{ name: 'config', type: String, aliases: ['c'] },
3032
{ name: 'single-run', type: Boolean, default: false, aliases: ['sr'] },

packages/@angular/cli/commands/xi18n.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const Xi18nCommand = Command.extend({
1919
},
2020
{ name: 'output-path', type: 'Path', default: null, aliases: ['op']},
2121
{ name: 'verbose', type: Boolean, default: false},
22-
{ name: 'progress', type: Boolean, default: true }
22+
{ name: 'progress', type: Boolean, default: true },
23+
{ name: 'app', type: String, aliases: ['a'] }
2324

2425
],
2526
run: function (commandOptions: any) {

packages/@angular/cli/models/webpack-config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ export interface WebpackConfigOptions {
2020

2121
export class NgCliWebpackConfig {
2222
public config: any;
23-
constructor(buildOptions: BuildOptions) {
23+
constructor(buildOptions: BuildOptions, appConfig: any) {
2424

2525
this.validateBuildOptions(buildOptions);
2626

2727
const configPath = CliConfig.configFilePath();
2828
const projectRoot = path.dirname(configPath);
29-
let appConfig = CliConfig.fromProject().config.apps[0];
3029

3130
appConfig = this.addAppConfigDefaults(appConfig);
3231
buildOptions = this.addTargetDefaults(buildOptions);

0 commit comments

Comments
 (0)