Skip to content

Commit fb37dbe

Browse files
sumitaroraZhicheng Wang
authored and
Zhicheng Wang
committed
feat(@angular/cli): adding the --app command option (angular#4754)
1 parent e9e9efc commit fb37dbe

29 files changed

+213
-72
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {getAppFromConfig} 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,18 @@ export default Blueprint.extend({
1113
name: 'spec',
1214
type: Boolean,
1315
description: 'Specifies if a spec file is generated.'
16+
},
17+
{
18+
name: 'app',
19+
type: String,
20+
aliases: ['a'],
21+
description: 'Specifies app name to use.'
1422
}
1523
],
1624

1725
normalizeEntityName: function (entityName: string) {
18-
const parsedPath = dynamicPathParser(this.project, entityName.split('.')[0]);
26+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
27+
const parsedPath = dynamicPathParser(this.project, entityName.split('.')[0], appConfig);
1928

2029
this.dynamicPath = parsedPath;
2130
return parsedPath.name;

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

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { NodeHost } from '../../lib/ast-tools';
2+
import {getAppFromConfig} from '../../utilities/app-utils';
23

34
import * as fs from 'fs';
45
import * as path from 'path';
@@ -71,22 +72,30 @@ export default Blueprint.extend({
7172
type: Boolean,
7273
default: false,
7374
description: 'Specifies if declaring module exports the component.'
75+
},
76+
{
77+
name: 'app',
78+
type: String,
79+
aliases: ['a'],
80+
description: 'Specifies app name to use.'
7481
}
7582
],
7683

7784
beforeInstall: function (options: any) {
85+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
7886
if (options.module) {
7987
// Resolve path to module
8088
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
81-
const parsedPath = dynamicPathParser(this.project, modulePath);
89+
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
8290
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);
8391

8492
if (!fs.existsSync(this.pathToModule)) {
8593
throw 'Module specified does not exist';
8694
}
8795
} else {
8896
try {
89-
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
97+
this.pathToModule = findParentModule(
98+
this.project.root, appConfig.root, this.dynamicPath.dir);
9099
} catch (e) {
91100
if (!options.skipImport) {
92101
throw `Error locating module for declaration\n\t${e}`;
@@ -96,16 +105,12 @@ export default Blueprint.extend({
96105
},
97106

98107
normalizeEntityName: function (entityName: string) {
99-
const parsedPath = dynamicPathParser(this.project, entityName);
108+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
109+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
100110

101111
this.dynamicPath = parsedPath;
102112

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-
}
113+
const defaultPrefix = (appConfig && appConfig.prefix) || '';
109114

110115
let prefix = (this.options.prefix === 'false' || this.options.prefix === '')
111116
? '' : (this.options.prefix || defaultPrefix);
@@ -191,7 +196,8 @@ export default Blueprint.extend({
191196
if (!options.locals.flat) {
192197
dir += path.sep + options.dasherizedModuleName;
193198
}
194-
const srcDir = this.project.ngConfig.apps[0].root;
199+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
200+
const srcDir = appConfig.root;
195201
this.appDir = dir.substr(dir.indexOf(srcDir) + srcDir.length);
196202
this.generatePath = dir;
197203
return dir;

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

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {NodeHost} from '../../lib/ast-tools';
2+
import {getAppFromConfig} from '../../utilities/app-utils';
23

34
const path = require('path');
45
const fs = require('fs');
@@ -46,22 +47,30 @@ export default Blueprint.extend({
4647
type: Boolean,
4748
default: false,
4849
description: 'Specifies if declaring module exports the component.'
50+
},
51+
{
52+
name: 'app',
53+
type: String,
54+
aliases: ['a'],
55+
description: 'Specifies app name to use.'
4956
}
5057
],
5158

5259
beforeInstall: function(options: any) {
60+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
5361
if (options.module) {
5462
// Resolve path to module
5563
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
56-
const parsedPath = dynamicPathParser(this.project, modulePath);
64+
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
5765
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);
5866

5967
if (!fs.existsSync(this.pathToModule)) {
6068
throw ' ';
6169
}
6270
} else {
6371
try {
64-
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
72+
this.pathToModule = findParentModule
73+
(this.project.root, appConfig.root, this.dynamicPath.dir);
6574
} catch (e) {
6675
if (!options.skipImport) {
6776
throw `Error locating module for declaration\n\t${e}`;
@@ -71,16 +80,12 @@ export default Blueprint.extend({
7180
},
7281

7382
normalizeEntityName: function (entityName: string) {
74-
const parsedPath = dynamicPathParser(this.project, entityName);
83+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
84+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
7585

7686
this.dynamicPath = parsedPath;
7787

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-
}
88+
const defaultPrefix = (appConfig && appConfig.prefix) || '';
8489

8590
let prefix = (this.options.prefix === 'false' || this.options.prefix === '')
8691
? '' : (this.options.prefix || defaultPrefix);

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1+
import {getAppFromConfig} 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+
{
12+
name: 'app',
13+
type: String,
14+
aliases: ['a'],
15+
description: 'Specifies app name to use.'
16+
}
17+
],
18+
819
normalizeEntityName: function (entityName: string) {
9-
const parsedPath = dynamicPathParser(this.project, entityName);
20+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
21+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
1022

1123
this.dynamicPath = parsedPath;
1224
return parsedPath.name;

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

+5-2
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 {getAppFromConfig} from '../../utilities/app-utils';
34

45
const path = require('path');
56
const fs = require('fs');
@@ -20,10 +21,11 @@ export default Blueprint.extend({
2021
],
2122

2223
beforeInstall: function(options: any) {
24+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
2325
if (options.module) {
2426
// Resolve path to module
2527
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
26-
const parsedPath = dynamicPathParser(this.project, modulePath);
28+
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
2729
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);
2830

2931
if (!fs.existsSync(this.pathToModule)) {
@@ -33,7 +35,8 @@ export default Blueprint.extend({
3335
},
3436

3537
normalizeEntityName: function (entityName: string) {
36-
const parsedPath = dynamicPathParser(this.project, entityName);
38+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
39+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
3740

3841
this.dynamicPath = parsedPath;
3942
return parsedPath.name;

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {getAppFromConfig} 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,18 @@ export default Blueprint.extend({
911
'<interface-type>'
1012
],
1113

14+
availableOptions: [
15+
{
16+
name: 'app',
17+
type: String,
18+
aliases: ['a'],
19+
description: 'Specifies app name to use.'
20+
}
21+
],
22+
1223
normalizeEntityName: function (entityName: string) {
13-
const parsedPath = dynamicPathParser(this.project, entityName);
24+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
25+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
1426

1527
this.dynamicPath = parsedPath;
1628
return parsedPath.name;

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {getAppFromConfig} 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,19 @@ export default Blueprint.extend({
2224
type: Boolean,
2325
default: false,
2426
description: 'Specifies if a routing module file should be generated.'
27+
},
28+
{
29+
name: 'app',
30+
type: String,
31+
aliases: ['a'],
32+
description: 'Specifies app name to use.'
2533
}
2634
],
2735

2836
normalizeEntityName: function (entityName: string) {
2937
this.entityName = entityName;
30-
const parsedPath = dynamicPathParser(this.project, entityName);
38+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
39+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
3140

3241
this.dynamicPath = parsedPath;
3342
return parsedPath.name;

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {NodeHost} from '../../lib/ast-tools';
2+
import {getAppFromConfig} from '../../utilities/app-utils';
23

34
const path = require('path');
45
const fs = require('fs');
@@ -41,22 +42,30 @@ export default Blueprint.extend({
4142
type: Boolean,
4243
default: false,
4344
description: 'Specifies if declaring module exports the pipe.'
45+
},
46+
{
47+
name: 'app',
48+
type: String,
49+
aliases: ['a'],
50+
description: 'Specifies app name to use.'
4451
}
4552
],
4653

4754
beforeInstall: function(options: any) {
55+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
4856
if (options.module) {
4957
// Resolve path to module
5058
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
51-
const parsedPath = dynamicPathParser(this.project, modulePath);
59+
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
5260
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);
5361

5462
if (!fs.existsSync(this.pathToModule)) {
5563
throw 'Module specified does not exist';
5664
}
5765
} else {
5866
try {
59-
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
67+
this.pathToModule = findParentModule
68+
(this.project.root, appConfig.root, this.dynamicPath.dir);
6069
} catch (e) {
6170
if (!options.skipImport) {
6271
throw `Error locating module for declaration\n\t${e}`;
@@ -66,7 +75,8 @@ export default Blueprint.extend({
6675
},
6776

6877
normalizeEntityName: function (entityName: string) {
69-
const parsedPath = dynamicPathParser(this.project, entityName);
78+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
79+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
7080

7181
this.dynamicPath = parsedPath;
7282
return parsedPath.name;

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

+11-2
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 {getAppFromConfig} from '../../utilities/app-utils';
34

45
const path = require('path');
56
const fs = require('fs');
@@ -28,14 +29,21 @@ export default Blueprint.extend({
2829
name: 'module',
2930
type: String, aliases: ['m'],
3031
description: 'Allows specification of the declaring module.'
32+
},
33+
{
34+
name: 'app',
35+
type: String,
36+
aliases: ['a'],
37+
description: 'Specifies app name to use.'
3138
}
3239
],
3340

3441
beforeInstall: function(options: any) {
3542
if (options.module) {
3643
// Resolve path to module
3744
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
38-
const parsedPath = dynamicPathParser(this.project, modulePath);
45+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
46+
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
3947
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);
4048

4149
if (!fs.existsSync(this.pathToModule)) {
@@ -45,7 +53,8 @@ export default Blueprint.extend({
4553
},
4654

4755
normalizeEntityName: function (entityName: string) {
48-
const parsedPath = dynamicPathParser(this.project, entityName);
56+
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
57+
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
4958

5059
this.dynamicPath = parsedPath;
5160
return parsedPath.name;

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

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ export const baseBuildCommandOptions: any = [
4141
type: Number,
4242
default: pollDefault,
4343
description: 'enable and define the file watching poll time period (milliseconds)'
44+
},
45+
{
46+
name: 'app',
47+
type: String,
48+
aliases: ['a'],
49+
description: 'Specifies app name to use.'
4450
}
4551
];
4652

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ const Command = require('../ember-cli/lib/models/command');
66
// defaults for BuildOptions
77
export const baseEjectCommandOptions: any = [
88
...baseBuildCommandOptions,
9-
{ name: 'force', 'type': Boolean }
9+
{ name: 'force', 'type': Boolean },
10+
{
11+
name: 'app',
12+
type: String,
13+
aliases: ['a'],
14+
description: 'Specifies app name to use.'
15+
}
1016
];
1117

1218
export interface EjectTaskOptions extends BuildOptions {
1319
force?: boolean;
20+
app?: string;
1421
}
1522

1623

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const baseServeCommandOptions: any = overrideOptions(
6363
description: 'Enable hot module replacement',
6464
}
6565
]), [
66-
{ name: 'watch', default: true },
66+
{ name: 'watch', default: true }
6767
]
6868
);
6969

0 commit comments

Comments
 (0)