Skip to content

Commit c57ce2a

Browse files
hanslfilipesilva
authored andcommitted
fix(@angular/cli): apps fixes (angular#4942)
We dont have ngConfig on projects anymore.
1 parent dd4f177 commit c57ce2a

9 files changed

Lines changed: 89 additions & 42 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {getAppFromConfig} from '../../utilities/app-utils';
2+
import {CliConfig} from '../../models/config';
23

34
const stringUtils = require('ember-cli-string-utils');
45
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
@@ -23,7 +24,9 @@ export default Blueprint.extend({
2324
],
2425

2526
normalizeEntityName: function (entityName: string) {
26-
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
27+
const cliConfig = CliConfig.fromProject();
28+
const ngConfig = cliConfig && cliConfig.config;
29+
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
2730
const parsedPath = dynamicPathParser(this.project, entityName.split('.')[0], appConfig);
2831

2932
this.dynamicPath = parsedPath;
@@ -41,9 +44,10 @@ export default Blueprint.extend({
4144
this.fileName += '.' + classType.toLowerCase();
4245
}
4346

47+
const cliConfig = CliConfig.fromProject();
4448
options.spec = options.spec !== undefined ?
4549
options.spec :
46-
this.project.ngConfigObj.get('defaults.class.spec');
50+
cliConfig && cliConfig.get('defaults.class.spec');
4751

4852
return {
4953
dynamicPath: this.dynamicPath.dir,

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NodeHost } from '../../lib/ast-tools';
2-
import {getAppFromConfig} from '../../utilities/app-utils';
2+
import { CliConfig } from '../../models/config';
3+
import { getAppFromConfig } from '../../utilities/app-utils';
34

45
import * as fs from 'fs';
56
import * as path from 'path';
@@ -82,7 +83,9 @@ export default Blueprint.extend({
8283
],
8384

8485
beforeInstall: function (options: any) {
85-
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
86+
const cliConfig = CliConfig.fromProject();
87+
const ngConfig = cliConfig && cliConfig.config;
88+
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
8689
if (options.module) {
8790
// Resolve path to module
8891
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
@@ -105,7 +108,9 @@ export default Blueprint.extend({
105108
},
106109

107110
normalizeEntityName: function (entityName: string) {
108-
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
111+
const cliConfig = CliConfig.fromProject();
112+
const ngConfig = cliConfig && cliConfig.config;
113+
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
109114
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
110115

111116
this.dynamicPath = parsedPath;
@@ -126,36 +131,37 @@ export default Blueprint.extend({
126131
},
127132

128133
locals: function (options: any) {
134+
const cliConfig = CliConfig.fromProject();
135+
const ngConfig = cliConfig && cliConfig.config;
136+
129137
this.styleExt = 'css';
130-
if (this.project.ngConfig &&
131-
this.project.ngConfig.defaults &&
132-
this.project.ngConfig.defaults.styleExt) {
133-
this.styleExt = this.project.ngConfig.defaults.styleExt;
138+
if (ngConfig && ngConfig.defaults && ngConfig.defaults.styleExt) {
139+
this.styleExt = ngConfig.defaults.styleExt;
134140
}
135141

136142
options.inlineStyle = options.inlineStyle !== undefined ?
137143
options.inlineStyle :
138-
this.project.ngConfigObj.get('defaults.component.inlineStyle');
144+
cliConfig && cliConfig.get('defaults.component.inlineStyle');
139145

140146
options.inlineTemplate = options.inlineTemplate !== undefined ?
141147
options.inlineTemplate :
142-
this.project.ngConfigObj.get('defaults.component.inlineTemplate');
148+
cliConfig && cliConfig.get('defaults.component.inlineTemplate');
143149

144150
options.flat = options.flat !== undefined ?
145151
options.flat :
146-
this.project.ngConfigObj.get('defaults.component.flat');
152+
cliConfig && cliConfig.get('defaults.component.flat');
147153

148154
options.spec = options.spec !== undefined ?
149155
options.spec :
150-
this.project.ngConfigObj.get('defaults.component.spec');
156+
cliConfig && cliConfig.get('defaults.component.spec');
151157

152158
options.viewEncapsulation = options.viewEncapsulation !== undefined ?
153159
options.viewEncapsulation :
154-
this.project.ngConfigObj.get('defaults.component.viewEncapsulation');
160+
cliConfig && cliConfig.get('defaults.component.viewEncapsulation');
155161

156162
options.changeDetection = options.changeDetection !== undefined ?
157163
options.changeDetection :
158-
this.project.ngConfigObj.get('defaults.component.changeDetection');
164+
cliConfig && cliConfig.get('defaults.component.changeDetection');
159165

160166
return {
161167
dynamicPath: this.dynamicPath.dir.replace(this.dynamicPath.appRoot, ''),
@@ -189,14 +195,17 @@ export default Blueprint.extend({
189195
},
190196

191197
fileMapTokens: function (options: any) {
198+
const cliConfig = CliConfig.fromProject();
199+
const ngConfig = cliConfig && cliConfig.config;
200+
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
201+
192202
// Return custom template variables here.
193203
return {
194204
__path__: () => {
195205
let dir = this.dynamicPath.dir;
196206
if (!options.locals.flat) {
197207
dir += path.sep + options.dasherizedModuleName;
198208
}
199-
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
200209
const srcDir = appConfig.root;
201210
this.appDir = dir.substr(dir.indexOf(srcDir) + srcDir.length);
202211
this.generatePath = dir;

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

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

45
const path = require('path');
@@ -57,7 +58,9 @@ export default Blueprint.extend({
5758
],
5859

5960
beforeInstall: function(options: any) {
60-
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
61+
const cliConfig = CliConfig.fromProject();
62+
const ngConfig = cliConfig && cliConfig.config;
63+
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
6164
if (options.module) {
6265
// Resolve path to module
6366
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
@@ -80,7 +83,9 @@ export default Blueprint.extend({
8083
},
8184

8285
normalizeEntityName: function (entityName: string) {
83-
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
86+
const cliConfig = CliConfig.fromProject();
87+
const ngConfig = cliConfig && cliConfig.config;
88+
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
8489
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
8590

8691
this.dynamicPath = parsedPath;
@@ -97,13 +102,15 @@ export default Blueprint.extend({
97102
},
98103

99104
locals: function (options: any) {
105+
const cliConfig = CliConfig.fromProject();
106+
100107
options.spec = options.spec !== undefined ?
101108
options.spec :
102-
this.project.ngConfigObj.get('defaults.directive.spec');
109+
cliConfig && cliConfig.get('defaults.directive.spec');
103110

104111
options.flat = options.flat !== undefined ?
105112
options.flat :
106-
this.project.ngConfigObj.get('defaults.directive.flat');
113+
cliConfig && cliConfig.get('defaults.directive.flat');
107114

108115
return {
109116
dynamicPath: this.dynamicPath.dir,

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import {NodeHost} from '../../lib/ast-tools';
21
import { oneLine } from 'common-tags';
3-
import {getAppFromConfig} from '../../utilities/app-utils';
2+
import { NodeHost } from '../../lib/ast-tools';
3+
import { CliConfig } from '../../models/config';
4+
import { getAppFromConfig } from '../../utilities/app-utils';
45

56
const path = require('path');
67
const fs = require('fs');
@@ -34,7 +35,9 @@ export default Blueprint.extend({
3435
],
3536

3637
beforeInstall: function(options: any) {
37-
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
38+
const cliConfig = CliConfig.fromProject();
39+
const ngConfig = cliConfig && cliConfig.config;
40+
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
3841
if (options.module) {
3942
// Resolve path to module
4043
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
@@ -48,21 +51,22 @@ export default Blueprint.extend({
4851
},
4952

5053
normalizeEntityName: function (entityName: string) {
51-
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
54+
const cliConfig = CliConfig.fromProject();
55+
const ngConfig = cliConfig && cliConfig.config;
56+
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
5257
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
5358

5459
this.dynamicPath = parsedPath;
5560
return parsedPath.name;
5661
},
5762

5863
locals: function (options: any) {
64+
const cliConfig = CliConfig.fromProject();
5965
options.flat = options.flat !== undefined ?
60-
options.flat :
61-
this.project.ngConfigObj.get('defaults.guard.flat');
66+
options.flat : cliConfig.get('defaults.guard.flat');
6267

6368
options.spec = options.spec !== undefined ?
64-
options.spec :
65-
this.project.ngConfigObj.get('defaults.guard.spec');
69+
options.spec : cliConfig.get('defaults.guard.spec');
6670

6771
return {
6872
dynamicPath: this.dynamicPath.dir,

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {CliConfig} from '../../models/config';
12
import {getAppFromConfig} from '../../utilities/app-utils';
23

34
const stringUtils = require('ember-cli-string-utils');
@@ -21,20 +22,24 @@ export default Blueprint.extend({
2122
],
2223

2324
normalizeEntityName: function (entityName: string) {
24-
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
25+
const cliConfig = CliConfig.fromProject();
26+
const ngConfig = cliConfig && cliConfig.config;
27+
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
2528
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
2629

2730
this.dynamicPath = parsedPath;
2831
return parsedPath.name;
2932
},
3033

3134
locals: function (options: any) {
35+
const cliConfig = CliConfig.fromProject();
36+
3237
const interfaceType = options.args[2];
3338
this.fileName = stringUtils.dasherize(options.entity.name);
3439
if (interfaceType) {
3540
this.fileName += '.' + interfaceType;
3641
}
37-
const prefix = this.project.ngConfigObj.get('defaults.interface.prefix');
42+
const prefix = cliConfig && cliConfig.get('defaults.interface.prefix');
3843
return {
3944
dynamicPath: this.dynamicPath.dir,
4045
flat: options.flat,

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {CliConfig} from '../../models/config';
12
import {getAppFromConfig} from '../../utilities/app-utils';
23

34
const path = require('path');
@@ -35,21 +36,24 @@ export default Blueprint.extend({
3536

3637
normalizeEntityName: function (entityName: string) {
3738
this.entityName = entityName;
38-
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
39+
const cliConfig = CliConfig.fromProject();
40+
const ngConfig = cliConfig && cliConfig.config;
41+
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
3942
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
4043

4144
this.dynamicPath = parsedPath;
4245
return parsedPath.name;
4346
},
4447

4548
locals: function (options: any) {
49+
const cliConfig = CliConfig.fromProject();
4650
options.flat = options.flat !== undefined ?
4751
options.flat :
48-
this.project.ngConfigObj.get('defaults.module.flat');
52+
cliConfig && cliConfig.get('defaults.module.flat');
4953

5054
options.spec = options.spec !== undefined ?
5155
options.spec :
52-
this.project.ngConfigObj.get('defaults.module.spec');
56+
cliConfig && cliConfig.get('defaults.module.spec');
5357

5458
return {
5559
dynamicPath: this.dynamicPath.dir,

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

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

45
const path = require('path');
@@ -52,7 +53,9 @@ export default Blueprint.extend({
5253
],
5354

5455
beforeInstall: function(options: any) {
55-
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
56+
const cliConfig = CliConfig.fromProject();
57+
const ngConfig = cliConfig && cliConfig.config;
58+
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
5659
if (options.module) {
5760
// Resolve path to module
5861
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
@@ -75,21 +78,24 @@ export default Blueprint.extend({
7578
},
7679

7780
normalizeEntityName: function (entityName: string) {
78-
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
81+
const cliConfig = CliConfig.fromProject();
82+
const ngConfig = cliConfig && cliConfig.config;
83+
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
7984
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
8085

8186
this.dynamicPath = parsedPath;
8287
return parsedPath.name;
8388
},
8489

8590
locals: function (options: any) {
91+
const cliConfig = CliConfig.fromProject();
8692
options.flat = options.flat !== undefined ?
8793
options.flat :
88-
this.project.ngConfigObj.get('defaults.pipe.flat');
94+
cliConfig && cliConfig.get('defaults.pipe.flat');
8995

9096
options.spec = options.spec !== undefined ?
9197
options.spec :
92-
this.project.ngConfigObj.get('defaults.pipe.spec');
98+
cliConfig && cliConfig.get('defaults.pipe.spec');
9399

94100
return {
95101
dynamicPath: this.dynamicPath.dir,

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {NodeHost} from '../../lib/ast-tools';
2-
import { oneLine } from 'common-tags';
2+
import {CliConfig} from '../../models/config';
33
import {getAppFromConfig} from '../../utilities/app-utils';
4+
import { oneLine } from 'common-tags';
45

56
const path = require('path');
67
const fs = require('fs');
@@ -42,7 +43,9 @@ export default Blueprint.extend({
4243
if (options.module) {
4344
// Resolve path to module
4445
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
45-
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
46+
const cliConfig = CliConfig.fromProject();
47+
const ngConfig = cliConfig && cliConfig.config;
48+
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
4649
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
4750
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);
4851

@@ -53,21 +56,24 @@ export default Blueprint.extend({
5356
},
5457

5558
normalizeEntityName: function (entityName: string) {
56-
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
59+
const cliConfig = CliConfig.fromProject();
60+
const ngConfig = cliConfig && cliConfig.config;
61+
const appConfig = getAppFromConfig(ngConfig.apps, this.options.app);
5762
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);
5863

5964
this.dynamicPath = parsedPath;
6065
return parsedPath.name;
6166
},
6267

6368
locals: function (options: any) {
69+
const cliConfig = CliConfig.fromProject();
6470
options.flat = options.flat !== undefined ?
6571
options.flat :
66-
this.project.ngConfigObj.get('defaults.service.flat');
72+
cliConfig && cliConfig.get('defaults.service.flat');
6773

6874
options.spec = options.spec !== undefined ?
6975
options.spec :
70-
this.project.ngConfigObj.get('defaults.service.spec');
76+
cliConfig && cliConfig.get('defaults.service.spec');
7177

7278
return {
7379
dynamicPath: this.dynamicPath.dir,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
33
import * as os from 'os';
4+
import {CliConfig} from '../models/config';
45

56
const chalk = require('chalk');
67
const EmberGenerateCommand = require('../ember-cli/lib/commands/generate');
@@ -25,6 +26,7 @@ const GenerateCommand = EmberGenerateCommand.extend({
2526

2627
// map the blueprint name to allow for aliases
2728
rawArgs[0] = mapBlueprintName(rawArgs[0]);
29+
this.project.ngConfig = this.project.ngConfig || CliConfig.fromProject();
2830

2931
if (rawArgs[0] !== '--help' &&
3032
!fs.existsSync(path.join(__dirname, '..', 'blueprints', rawArgs[0]))) {

0 commit comments

Comments
 (0)