10000 feat: ngmodules and insert components based on the AST (#1616) · mikebellcoder/angular-cli@5bcb7be · GitHub
[go: up one dir, main page]

Skip to content

Commit 5bcb7be

Browse files
authored
feat: ngmodules and insert components based on the AST (angular#1616)
1 parent 4fd8e9c commit 5bcb7be

File tree

15 files changed

+558
-213
lines changed

15 files changed

+558
-213
lines changed

addon/ng2/blueprints/component/index.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,23 @@ module.exports = {
120120
return;
121121
}
122122

123-
var returns = [];
124-
var modulePath = path.resolve(process.env.PWD, this.dynamicPath.appRoot, 'app.module.ts');
125-
var classifiedName =
126-
stringUtils.classify(`${options.entity.name}-${options.originBlueprintName}`);
127-
var importPath = `'./${options.entity.name}/` +
128-
stringUtils.dasherize(`${options.entity.name}.component';`);
123+
const returns = [];
124+
const modulePath = path.join(this.project.root, this.dynamicPath.appRoot, 'app.module.ts');
125+
const className = stringUtils.classify(`${options.entity.name}Component`);
126+
const fileName = stringUtils.dasherize(`${options.entity.name}.component`);
127+
const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath);
128+
const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`;
129129

130130
if (!options.flat) {
131-
returns.push(function() {
132-
return addBarrelRegistration(this, this.generatePath)
133-
});
131+
returns.push(addBarrelRegistration(this, componentDir));
134132
} else {
135-
returns.push(function() {
136-
return addBarrelRegistration(
137-
this,
138-
this.generatePath,
139-
options.entity.name + '.component')
140-
});
133+
returns.push(addBarrelRegistration(this, componentDir, fileName));
141134
}
142135

143136
if (!options['skip-import']) {
144-
returns.push(astUtils.importComponent(modulePath, classifiedName, importPath));
137+
returns.push(
138+
astUtils.addComponentToModule(modulePath, className, importPath)
139+
.then(change => change.apply()));
145140
}
146141

147142
return Promise.all(returns);

addon/ng2/blueprints/directive/index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,27 @@ module.exports = {
5454
},
5555

5656
afterInstall: function(options) {
57-
var returns = [];
58-
var modulePath = path.resolve(process.env.PWD, this.dynamicPath.appRoot, 'app.module.ts');
59-
var classifiedName =
60-
stringUtils.classify(options.entity.name);
61-
var importPath = '\'./' + stringUtils.dasherize(`${options.entity.name}.directive';`);
57+
if (options.dryRun) {
58+
return;
59+
}
60+
61+
const returns = [];
62+
const modulePath = path.join(this.project.root, this.dynamicPath.appRoot, 'app.module.ts');
63+
const className = stringUtils.classify(`${options.entity.name}`);
64+
const fileName = stringUtils.dasherize(`${options.entity.name}.directive`);
65+
const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath);
66+
const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`;
6267

6368
if (!options.flat) {
64-
returns.push(function() {
65-
return addBarrelRegistration(this, this.generatePath)
66-
});
69+
returns.push(addBarrelRegistration(this, componentDir));
6770
} else {
68-
returns.push(function() {
69-
return addBarrelRegistration(
70-
this,
71-
this.generatePath,
72-
options.entity.name + '.directive')
73-
});
71+
returns.push(addBarrelRegistration(this, componentDir, fileName));
7472
}
7573

7674
if (!options['skip-import']) {
77-
returns.push(astUtils.importComponent(modulePath, classifiedName, importPath));
75+
returns.push(
76+
astUtils.addComponentToModule(modulePath, className, importPath)
77+
.then(change => change.ap 10000 ply()));
7878
}
7979

8080
return Promise.all(returns);

addon/ng2/blueprints/ng2/files/__path__/app/app.module.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule, ApplicationRef } from '@angular/core';
33
import { CommonModule } from '@angular/common';
44
import { FormsModule } from '@angular/forms';
5-
import { AppComponent } from './app.component';<% if (isMobile) { %>
6-
import { AppShellModule } from '../app-shell-module';<% } %>
5+
import { AppComponent } from './app.component';
76

87
@NgModule({
98
declarations: [
@@ -12,12 +11,12 @@ import { AppShellModule } from '../app-shell-module';<% } %>
1211
imports: [
1312
BrowserModule,
1413
CommonModule,
15-
FormsModule<% if (isMobile) { %>,
16-
AppShellModule<% } %>
14+
FormsModule
1715
],
16+
providers: [],
1817
entryComponents: [AppComponent],
1918
bootstrap: [AppComponent]
2019
})
2120
export class AppModule {
2221

23-
}
22+
}

addon/ng2/blueprints/ng2/files/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
},
1313
"private": true,
1414
"dependencies": {
15-
"@angular/common": "github:angular/common-builds",
16-
"@angular/compiler": "github:angular/compiler-builds",
17-
"@angular/core": "github:angular/core-builds",
18-
"@angular/forms": "github:angular/forms-builds",
19-
"@angular/http": "github:angular/http-builds",
20-
"@angular/platform-browser": "github:angular/platform-browser-builds",
21-
"@angular/platform-browser-dynamic": "github:angular/platform-browser-dynamic-builds",
22-
"@angular/router": "github:angular/router-builds",
15+
"@angular/common": "2.0.0-rc.5",
16+
"@angular/compiler": "2.0.0-rc.5",
17+
"@angular/core": "2.0.0-rc.5",
18+
"@angular/forms": "0.3.0",
19+
"@angular/http": "2.0.0-rc.5",
20+
"@angular/platform-browser": "2.0.0-rc.5",
21+
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
22+
"@angular/router": "3.0.0-rc.1",
2323
"core-js": "^2.4.0",
2424
"reflect-metadata": "0.1.3",
2525
"rxjs": "5.0.0-beta.6",

addon/ng2/blueprints/pipe/index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,27 @@ module.exports = {
5252
},
5353

5454
afterInstall: function(options) {
55-
var returns = [];
56-
var modulePath = path.resolve(process.env.PWD, this.dynamicPath.appRoot, 'app.module.ts');
57-
var classifiedName =
58-
stringUtils.classify(`${options.entity.name}-${options.originBlueprintName}`);
59-
var importPath = '\'./' + stringUtils.dasherize(`${options.entity.name}.pipe';`);
55+
if (options.dryRun) {
56+ return;
57+
}
58+
59+
const returns = [];
60+
const modulePath = path.join(this.project.root, this.dynamicPath.appRoot, 'app.module.ts');
61+
const className = stringUtils.classify(`${options.entity.name}Pipe`);
62+
const fileName = stringUtils.dasherize(`${options.entity.name}.pipe`);
63+
const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath);
64+
const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`;
6065

6166
if (!options.flat) {
62-
returns.push(function() {
63-
return addBarrelRegistration(this, this.generatePath)
64-
});
67+
returns.push(addBarrelRegistration(this, componentDir));
6568
} else {
66-
returns.push(function() {
67-
return addBarrelRegistration(
68-
this,
69-
this.generatePath,
70-
options.entity.name + '.pipe')
71-
});
69+
returns.push(addBarrelRegistration(this, componentDir, fileName));
7270
}
7371

7472
if (!options['skip-import']) {
75-
returns.push(astUtils.importComponent(modulePath, classifiedName, importPath));
73+
returns.push(
74+
astUtils.addComponentToModule(modulePath, className, importPath)
75+
.then(change => change.apply()));
7676
}
7777

7878
return Promise.all(returns);

addon/ng2/blueprints/service/index.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ var Blueprint = require('ember-cli/lib/models/blueprint');
33
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
44
var addBarrelRegistration = require('../../utilities/barrel-management');
55
var getFiles = Blueprint.prototype.files;
6+
const stringUtils = require('ember-cli-string-utils');
67

78
module.exports = {
89
description: '',
9-
10+
1011
availableOptions: [
1112
{ name: 'flat', type: Boolean, default: true }
1213
],
@@ -24,10 +25,10 @@ module.exports = {
2425
flat: options.flat
2526
};
2627
},
27-
28+
2829
files: function() {
2930
var fileList = getFiles.call(this);
30-
31+
3132
if (this.options && this.options.flat) {
3233
fileList = fileList.filter(p => p.indexOf('index.ts') <= 0);
3334
}
@@ -48,17 +49,17 @@ module.exports = {
4849
}
4950
};
5051
},
51-
52+
5253
afterInstall: function(options) {
54+
const returns = [];
55+
const fileName = stringUtils.dasherize(`${options.entity.name}.service`);
56+
5357
if (!options.flat) {
54-
return addBarrelRegistration(
55-
this,
56-
this.generatePath);
58+
returns.push(addBarrelRegistration(this, this.generatePath));
5759
} else {
58-
return addBarrelRegistration(
59-
this,
60-
this.generatePath,
61-
options.entity.name + '.service');
60+
returns.push(addBarrelRegistration(this, this.generatePath, fileName));
6261
}
62+
63+
return Promise.all(returns);
6364
}
6465
};

0 commit comments

Comments
 (0)
0