Skip to content

Commit

Permalink
feat: ngmodules and insert components based on the AST
Browse files Browse the repository at this point in the history
  • Loading branch information
hansl committed Aug 10, 2016
1 parent 4fd8e9c commit 2b67514
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 111 deletions.
27 changes: 11 additions & 16 deletions addon/ng2/blueprints/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,23 @@ module.exports = {
return;
}

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

if (!options.flat) {
returns.push(function() {
return addBarrelRegistration(this, this.generatePath)
});
returns.push(addBarrelRegistration(this, componentDir));
} else {
returns.push(function() {
return addBarrelRegistration(
this,
this.generatePath,
options.entity.name + '.component')
});
returns.push(addBarrelRegistration(this, componentDir, fileName));
}

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

return Promise.all(returns);
Expand Down
30 changes: 15 additions & 15 deletions addon/ng2/blueprints/directive/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ module.exports = {
},

afterInstall: function(options) {
var returns = [];
var modulePath = path.resolve(process.env.PWD, this.dynamicPath.appRoot, 'app.module.ts');
var classifiedName =
stringUtils.classify(options.entity.name);
var importPath = '\'./' + stringUtils.dasherize(`${options.entity.name}.directive';`);
if (options.dryRun) {
return;
}

const returns = [];
const modulePath = path.join(this.project.root, this.dynamicPath.appRoot, 'app.module.ts');
const className = stringUtils.classify(`${options.entity.name}`);
const fileName = stringUtils.dasherize(`${options.entity.name}.directive`);
const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath);
const importPath = `./${componentDir}/${fileName}`;

if (!options.flat) {
returns.push(function() {
return addBarrelRegistration(this, this.generatePath)
});
returns.push(addBarrelRegistration(this, componentDir));
} else {
returns.push(function() {
return addBarrelRegistration(
this,
this.generatePath,
options.entity.name + '.directive')
});
returns.push(addBarrelRegistration(this, componentDir, fileName));
}

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

return Promise.all(returns);
Expand Down
8 changes: 3 additions & 5 deletions addon/ng2/blueprints/ng2/files/__path__/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { BrowserModule } from '@angular/platform-browser';
import { NgModule, ApplicationRef } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';<% if (isMobile) { %>
import { AppShellModule } from '../app-shell-module';<% } %>
import { AppComponent } from './app.component';

@NgModule({
declarations: [
Expand All @@ -12,12 +11,11 @@ import { AppShellModule } from '../app-shell-module';<% } %>
imports: [
BrowserModule,
CommonModule,
FormsModule<% if (isMobile) { %>,
AppShellModule<% } %>
FormsModule
],
entryComponents: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {

}
}
16 changes: 8 additions & 8 deletions addon/ng2/blueprints/ng2/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
},
"private": true,
"dependencies": {
"@angular/common": "github:angular/common-builds",
"@angular/compiler": "github:angular/compiler-builds",
"@angular/core": "github:angular/core-builds",
"@angular/forms": "github:angular/forms-builds",
"@angular/http": "github:angular/http-builds",
"@angular/platform-browser": "github:angular/platform-browser-builds",
"@angular/platform-browser-dynamic": "github:angular/platform-browser-dynamic-builds",
"@angular/router": "github:angular/router-builds",
"@angular/common": "2.0.0-rc.5",
"@angular/compiler": "2.0.0-rc.5",
"@angular/core": "2.0.0-rc.5",
"@angular/forms": "0.3.0",
"@angular/http": "2.0.0-rc.5",
"@angular/platform-browser": "2.0.0-rc.5",
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
"@angular/router": "3.0.0-rc.1",
"core-js": "^2.4.0",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
Expand Down
30 changes: 15 additions & 15 deletions addon/ng2/blueprints/pipe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,27 @@ module.exports = {
},

afterInstall: function(options) {
var returns = [];
var modulePath = path.resolve(process.env.PWD, this.dynamicPath.appRoot, 'app.module.ts');
var classifiedName =
stringUtils.classify(`${options.entity.name}-${options.originBlueprintName}`);
var importPath = '\'./' + stringUtils.dasherize(`${options.entity.name}.pipe';`);
if (options.dryRun) {
return;
}

const returns = [];
const modulePath = path.join(this.project.root, this.dynamicPath.appRoot, 'app.module.ts');
const className = stringUtils.classify(`${options.entity.name}Pipe`);
const fileName = stringUtils.dasherize(`${options.entity.name}.pipe`);
const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath);
const importPath = `./${componentDir}/${fileName}`;

if (!options.flat) {
returns.push(function() {
return addBarrelRegistration(this, this.generatePath)
});
returns.push(addBarrelRegistration(this, componentDir));
} else {
returns.push(function() {
return addBarrelRegistration(
this,
this.generatePath,
options.entity.name + '.pipe')
});
returns.push(addBarrelRegistration(this, componentDir, fileName));
}

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

return Promise.all(returns);
Expand Down
1 change: 1 addition & 0 deletions addon/ng2/commands/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const VersionCommand = Command.extend({
}],

run: function (options) {
console.log(123);
var versions = process.versions;
var pkg = require(path.resolve(__dirname, '..', '..', '..', 'package.json'));

Expand Down
Loading

0 comments on commit 2b67514

Please sign in to comment.