Skip to content

Commit 2422388

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

File tree

25 files changed

+188
-65
lines changed

25 files changed

+188
-65
lines changed

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

Lines changed: 10 additions & 1 deletion
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

Lines changed: 16 additions & 10 deletions
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

Lines changed: 14 additions & 9 deletions
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

Lines changed: 13 additions & 1 deletion
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/interface/index.ts

Lines changed: 13 additions & 1 deletion
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

Lines changed: 10 additions & 1 deletion
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

Lines changed: 13 additions & 3 deletions
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

Lines changed: 11 additions & 2 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 {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

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
@@ -24,6 +24,7 @@ const E2eCommand = Command.extend({
2424
baseServeCommandOptions.concat([
2525
{ name: 'config', type: String, aliases: ['c'] },
2626
{ name: 'specs', type: Array, default: [], aliases: ['sp'] },
27+
{ name: 'app', type: String, aliases: ['a'] },
2728
{ name: 'element-explorer', type: Boolean, default: false, aliases: ['ee'] },
2829
{ name: 'webdriver-update', type: Boolean, default: true, aliases: ['wu'] },
2930
{ name: 'serve', type: Boolean, default: true, aliases: ['s'] }

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ 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+
{
12+
name: 'app',
13+
type: String,
14+
aliases: ['a'],
15+
description: 'Specifies app name to use.'
16+
}
1117
];
1218

1319
export interface EjectTaskOptions extends BuildOptions {
1420
force?: boolean;
21+
app?: string;
1522
}
1623

1724

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface ServeTaskOptions extends BuildOptions {
2828
sslCert?: string;
2929
open?: boolean;
3030
hmr?: boolean;
31+
app?: string;
3132
}
3233

3334
// Expose options unrelated to live-reload to other commands that need to run serve
@@ -66,6 +67,12 @@ export const baseServeCommandOptions: any = overrideOptions(
6667
}
6768
]), [
6869
{ name: 'watch', default: true },
70+
{
71+
name: 'app',
72+
type: String,
73+
aliases: ['a'],
74+
description: 'Specifies app name to use.'
75+
}
6976
]
7077
);
7178

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

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

2425

0 commit comments

Comments
 (0)