Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions addon/ng2/blueprints/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var Blueprint = require('ember-cli/lib/models/blueprint');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
var addBarrelRegistration = require('../../utilities/barrel-management');
var getFiles = Blueprint.prototype.files;
const stringUtils = require('ember-cli-string-utils');
var stringUtils = require('ember-cli-string-utils');
const ngModuleUtils = require('../../utilities/ng-module-utils');

module.exports = {
description: '',
Expand Down Expand Up @@ -115,17 +116,26 @@ module.exports = {
},

afterInstall: function(options) {
const _this = this;

if (options.dryRun) {
return;
}

if (!options.flat) {
return addBarrelRegistration(this, this.generatePath);
} else {
return addBarrelRegistration(
this,
this.generatePath,
options.entity.name + '.component');
function addBarrels() {
if (!options.flat) {
return addBarrelRegistration(_this, _this.generatePath);
} else {
return addBarrelRegistration(
_this,
_this.generatePath,
options.entity.name + '.component');
}
}

return Promise.all([
addBarrels(),
ngModuleUtils.importIntoModule(options, _this.dynamicPath.appRoot, _this.project.root)
]);
}
};
26 changes: 17 additions & 9 deletions addon/ng2/blueprints/directive/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var Blueprint = require('ember-cli/lib/models/blueprint');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
var addBarrelRegistration = require('../../utilities/barrel-management');
var getFiles = Blueprint.prototype.files;
const ngModuleUtils = require('../../utilities/ng-module-utils');

module.exports = {
description: '',
Expand Down Expand Up @@ -52,15 +53,22 @@ module.exports = {
},

afterInstall: function(options) {
if (!options.flat) {
return addBarrelRegistration(
this,
this.generatePath);
} else {
return addBarrelRegistration(
this,
this.generatePath,
options.entity.name + '.directive');
const _this = this;

function addBarrels() {
if (!options.flat) {
return addBarrelRegistration(_this, _this.generatePath);
} else {
return addBarrelRegistration(
_this,
_this.generatePath,
options.entity.name + '.directive');
}
}

return Promise.all([
addBarrels(),
ngModuleUtils.importIntoModule(options, _this.dynamicPath.appRoot, _this.project.root)
]);
}
};
16 changes: 12 additions & 4 deletions addon/ng2/blueprints/interface/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const stringUtils = require('ember-cli-string-utils');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
var addBarrelRegistration = require('../../utilities/barrel-management');
const ngModuleUtils = require('../../utilities/ng-module-utils');

module.exports = {
description: '',
Expand Down Expand Up @@ -50,9 +51,16 @@ module.exports = {
},

afterInstall: function() {
return addBarrelRegistration(
this,
this.generatePath,
this.fileName);
function addBarrels() {
return addBarrelRegistration(
this,
this.generatePath,
this.fileName);
}

return Promise.all([
addBarrels(),
ngModuleUtils.importIntoModule(options, _this.dynamicPath.appRoot, _this.project.root)
]);
}
};
19 changes: 19 additions & 0 deletions addon/ng2/blueprints/mobile/files/__path__/app-shell-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NgModule, ModuleWithProviders } from '@angular/core';
import {
APP_SHELL_DIRECTIVES,
APP_SHELL_RUNTIME_PROVIDERS,
APP_SHELL_BUILD_PROVIDERS
} from '@angular/app-shell';

@NgModule({
declarations: APP_SHELL_DIRECTIVES,
exports: APP_SHELL_DIRECTIVES
})
export class AppShellModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: AppShellModule,
providers: [APP_SHELL_RUNTIME_PROVIDERS, APP_SHELL_BUILD_PROVIDERS]
};
}
}
22 changes: 11 additions & 11 deletions addon/ng2/blueprints/mobile/files/__path__/main-app-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import 'angular2-universal-polyfills';
import { provide } from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';
import { APP_SHELL_BUILD_PROVIDERS } from '@angular/app-shell';
import {
REQUEST_URL,
ORIGIN_URL,
Bootloader,
BootloaderConfig,
AppConfig
import {
REQUEST_URL,
ORIGIN_URL,
Bootloader,
BootloaderConfig,
AppConfig
} from 'angular2-universal';
import { AppComponent } from './app/';

Expand All @@ -21,7 +21,7 @@ const bootloaderConfig: BootloaderConfig = {
],
async: true,
preboot: false
}
};

const appConfig: AppConfig = {
directives: [
Expand All @@ -32,16 +32,16 @@ const appConfig: AppConfig = {
// What URL should Angular be treating the app as if navigating
provide(REQUEST_URL, { useValue: '/' })
]
}
};

// The build system will call this function to get a bootloader
export function getBootloader() : Bootloader {
export function getBootloader(): Bootloader {
return new Bootloader(bootloaderConfig);
}

// The build system will call this function with the bootloader from
// getBootloader and the contents of the index page
export function serialize(bootloader: Bootloader, template: string) : string {
export function serialize(bootloader: Bootloader, template: string): string {
appConfig.template = template;
return bootloader.serializeApplication(appConfig);
}
}
29 changes: 14 additions & 15 deletions addon/ng2/blueprints/ng2/files/__path__/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
/* tslint:disable:no-unused-variable */

import { addProviders, async, inject } from '@angular/core/testing';
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';

describe('App: <%= jsComponentName %>', () => {
beforeEach(() => {
addProviders([AppComponent]);
});
describe('App: TestProject', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({ declarations: [AppComponent] });
TestBed.compileComponents();
}));

it('should create the app',
inject([AppComponent], (app: AppComponent) => {
expect(app).toBeTruthy();
}));
it('should create the app', () => {
const compFixture = TestBed.createComponent(AppComponent);
expect(compFixture).toBeTruthy();
});

it('should have as title \'app works!\'',
inject([AppComponent], (app: AppComponent) => {
expect(app.title).toEqual('app works!');
}));
it('should have a title `app works!`', () => {
const compFixture = TestBed.createComponent(AppComponent);
expect(compFixture.componentInstance.title).toBe('app works!');
});
});
24 changes: 24 additions & 0 deletions addon/ng2/blueprints/ng2/files/__path__/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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) { %>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this on the previous line.

import { AppShellModule } from '../app-shell-module';
<% } %>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same. So there's no space if isMobile is true.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay.


@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
CommonModule,
FormsModule<% if (isMobile) { %>,
AppShellModule<% } %>
],
entryComponents: [AppComponent]
})
export class AppModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(AppComponent);
}
}
1 change: 1 addition & 0 deletions addon/ng2/blueprints/ng2/files/__path__/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './environments/environment';
export * from './app.component';
export * from './app.module';
7 changes: 3 additions & 4 deletions addon/ng2/blueprints/ng2/files/__path__/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { bootstrap } from '@angular/platform-browser-dynamic';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppComponent, environment } from './app/';<% if(isMobile) { %>
import { APP_SHELL_RUNTIME_PROVIDERS } from '@angular/app-shell';<% } %>
import { AppModule, environment } from './app/';

if (environment.production) {
enableProdMode();
}

bootstrap(AppComponent<% if(isMobile) { %>, [ APP_SHELL_RUNTIME_PROVIDERS ]<% } %>);
platformBrowserDynamic().bootstrapModule(AppModule);
1 change: 1 addition & 0 deletions addon/ng2/blueprints/ng2/files/angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"apps": [
{
"main": "<%= sourceDir %>/main.ts",
"appmodule": "app.module.ts",
"tsconfig": "<%= sourceDir %>/tsconfig.json",
"mobile": <%= isMobile %>
}
Expand Down
32 changes: 16 additions & 16 deletions addon/ng2/blueprints/ng2/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "2.0.0-rc.4",
"@angular/compiler": "2.0.0-rc.4",
"@angular/core": "2.0.0-rc.4",
"@angular/forms": "0.2.0",
"@angular/http": "2.0.0-rc.4",
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/router": "3.0.0-beta.2",
"core-js": "^2.4.0",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"ts-helpers": "^1.1.1",
"zone.js": "0.6.12"
},
"devDependencies": {<% if(isMobile) { %>
"dependencies": {<% if(isMobile) { %>
"@angular/platform-server": "2.0.0-rc.4",
"@angular/service-worker": "0.2.0",
"@angular/app-shell": "0.0.0",
"angular2-universal":"0.104.5",
"angular2-universal-polyfills": "0.4.1",
"preboot": "2.1.2",
"parse5": "1.5.1",<% } %>
"@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",
"core-js": "^2.4.0",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"ts-helpers": "^1.1.1",
"zone.js": "0.6.12"
},
"devDependencies": {
"@types/jasmine": "^2.2.30",
"@types/protractor": "^1.5.16",
"angular-cli": "<%= version %>",
Expand Down
28 changes: 19 additions & 9 deletions addon/ng2/blueprints/pipe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var Blueprint = require('ember-cli/lib/models/blueprint');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
var addBarrelRegistration = require('../../utilities/barrel-management');
var getFiles = Blueprint.prototype.files;
const ngModuleUtils = require('../../utilities/ng-module-utils');

module.exports = {
description: '',
Expand Down Expand Up @@ -50,15 +51,24 @@ module.exports = {
},

afterInstall: function(options) {
if (!options.flat) {
return addBarrelRegistration(
this,
this.generatePath);
} else {
return addBarrelRegistration(
this,
this.generatePath,
options.entity.name + '.pipe');
const _this = this;

function addBarrels() {
if (!options.flat) {
return addBarrelRegistration(
_this,
_this.generatePath);
} else {
return addBarrelRegistration(
_this,
_this.generatePath,
options.entity.name + '.pipe');
}
}

return Promise.all([
addBarrels(),
ngModuleUtils.importIntoModule(options, _this.dynamicPath.appRoot, _this.project.root)
]);
}
};
20 changes: 20 additions & 0 deletions addon/ng2/utilities/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ export function findNodes(node: ts.Node, kind: ts.SyntaxKind): ts.Node[] {
foundNodes.concat(findNodes(child, kind)), arr);
}

/**
* Find all nodes from the AST in the subtree of node based on text.
* @param node
* @param name
* @return all nodes of that match given name, or [] if none is found
*/
export function findNodesByText(node: ts.Node, name: string): ts.Node[] {
if (!node) {
return [];
}
let nodes: ts.Node[] = [];
if (node.getText() === name) {
nodes.push(node);
}

return node.getChildren().reduce((foundNodes, child) => {
return foundNodes.concat(findNodesByText(child, name));
}, nodes);
}

/**
* Helper for sorting nodes.
* @return function to sort nodes in increasing order of position in sourceFile
Expand Down
Loading