diff --git a/addon/ng2/blueprints/component/files/__path__/__name__.css b/addon/ng2/blueprints/component/files/__path__/__name__.component.__styleext__
similarity index 100%
rename from addon/ng2/blueprints/component/files/__path__/__name__.css
rename to addon/ng2/blueprints/component/files/__path__/__name__.component.__styleext__
diff --git a/addon/ng2/blueprints/component/files/__path__/__name__.html b/addon/ng2/blueprints/component/files/__path__/__name__.component.html
similarity index 100%
rename from addon/ng2/blueprints/component/files/__path__/__name__.html
rename to addon/ng2/blueprints/component/files/__path__/__name__.component.html
diff --git a/addon/ng2/blueprints/component/files/__path__/__name__.spec.ts b/addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts
similarity index 59%
rename from addon/ng2/blueprints/component/files/__path__/__name__.spec.ts
rename to addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts
index 82961b117413..634ab9bb2567 100644
--- a/addon/ng2/blueprints/component/files/__path__/__name__.spec.ts
+++ b/addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts
@@ -1,16 +1,17 @@
import {
- it,
- iit,
+ beforeEachProviders,
describe,
ddescribe,
expect,
+ iit,
+ it,
inject,
injectAsync,
- TestComponentBuilder,
- beforeEachProviders
+ ComponentFixture,
+ TestComponentBuilder
} from 'angular2/testing';
import {provide} from 'angular2/core';
-import {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>';
+import {<%= classifiedModuleName %>Component} from './<%= dasherizedModuleName %>.component';
describe('<%= classifiedModuleName %> Component', () => {
@@ -18,7 +19,7 @@ describe('<%= classifiedModuleName %> Component', () => {
it('should ...', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
- return tcb.createAsync(<%= classifiedModuleName %>).then((fixture) => {
+ return tcb.createAsync(<%= classifiedModuleName %>Component).then((fixture: ComponentFixture) => {
fixture.detectChanges();
});
}));
diff --git a/addon/ng2/blueprints/component/files/__path__/__name__.component.ts b/addon/ng2/blueprints/component/files/__path__/__name__.component.ts
new file mode 100644
index 000000000000..56c1cffc7399
--- /dev/null
+++ b/addon/ng2/blueprints/component/files/__path__/__name__.component.ts
@@ -0,0 +1,16 @@
+import {Component, OnInit} from 'angular2/core';
+
+@Component({
+ moduleId: __moduleName,
+ selector: '<%= dasherizedModuleName %>',
+ templateUrl: '<%= dasherizedModuleName %>.component.html',
+ styleUrls: ['<%= dasherizedModuleName %>.component.<%= styleExt %>']
+})
+export class <%= classifiedModuleName %>Component implements OnInit {
+
+ constructor() {}
+
+ ngOnInit() {
+ }
+
+}
diff --git a/addon/ng2/blueprints/component/files/__path__/__name__.ts b/addon/ng2/blueprints/component/files/__path__/__name__.ts
deleted file mode 100644
index d20bdb6ba757..000000000000
--- a/addon/ng2/blueprints/component/files/__path__/__name__.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import {Component} from 'angular2/core';
-
-
-@Component({
- selector: '<%= dasherizedModuleName %>',
- templateUrl: 'app<%= dynamicPath %>/<%= dasherizedModuleName %>/<%= dasherizedModuleName %>.html',
- styleUrls: ['app<%= dynamicPath %>/<%= dasherizedModuleName %>/<%= dasherizedModuleName %>.css'],
- providers: [],
- directives: [],
- pipes: []
-})
-export class <%= classifiedModuleName %> {
-
- constructor() {}
-
-}
diff --git a/addon/ng2/blueprints/component/files/__path__/index.ts b/addon/ng2/blueprints/component/files/__path__/index.ts
new file mode 100644
index 000000000000..38c9dbf59603
--- /dev/null
+++ b/addon/ng2/blueprints/component/files/__path__/index.ts
@@ -0,0 +1 @@
+export {<%= classifiedModuleName %>Component} from './<%= dasherizedModuleName %>.component';
\ No newline at end of file
diff --git a/addon/ng2/blueprints/component/index.js b/addon/ng2/blueprints/component/index.js
index 9ea61aa44207..a33914fd6a34 100644
--- a/addon/ng2/blueprints/component/index.js
+++ b/addon/ng2/blueprints/component/index.js
@@ -1,11 +1,14 @@
var path = require('path');
+var Blueprint = require('ember-cli/lib/models/blueprint');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
+var getFiles = Blueprint.prototype.files;
+
module.exports = {
description: '',
availableOptions: [
- { name: 'flat', type: Boolean, default: false, aliases: ['f'] }
+ { name: 'flat', type: Boolean, default: false }
],
normalizeEntityName: function (entityName) {
@@ -16,12 +19,28 @@ module.exports = {
},
locals: function (options) {
+ //TODO: pull value from config
+ this.styleExt = 'css';
+
return {
dynamicPath: this.dynamicPath.dir.replace(this.dynamicPath.appRoot, ''),
- flat: options.flat
+ flat: options.flat,
+ styleExt: this.styleExt,
+ isLazyRoute: !!options.isLazyRoute,
+ isAppComponent: !!options.isAppComponent
};
},
+
+ files: function() {
+ var fileList = getFiles.call(this);
+
+ if (this.options.flat) {
+ fileList = fileList.filter(p => p.indexOf('index.ts') <= 0);
+ }
+ return fileList;
+ },
+
fileMapTokens: function (options) {
// Return custom template variables here.
return {
@@ -29,9 +48,31 @@ module.exports = {
var dir = this.dynamicPath.dir;
if (!options.locals.flat) {
dir += path.sep + options.dasherizedModuleName;
+
+ if (options.locals.isLazyRoute) {
+ var dirParts = dir.split(path.sep);
+ dirParts[dirParts.length - 1] = `+${dirParts[dirParts.length - 1]}`;
+ dir = dirParts.join(path.sep);
+ }
}
+ this.appDir = dir.replace(`src${path.sep}client${path.sep}`, '');
return dir;
+ },
+ __styleext__: () => {
+ return options.locals.styleExt;
}
};
+ },
+
+ afterInstall: function(options) {
+ if (!options.flat) {
+ var filePath = path.join('src', 'client', 'system-config.ts');
+ var barrelUrl = this.appDir.replace(path.sep, '/');
+ return this.insertIntoFile(
+ filePath,
+ ` '${barrelUrl}',`,
+ { before: ' /** @cli-barrel */' }
+ );
+ }
}
};
diff --git a/addon/ng2/blueprints/directive/files/__path__/__name__.spec.ts b/addon/ng2/blueprints/directive/files/__path__/__name__.directive.spec.ts
similarity index 77%
rename from addon/ng2/blueprints/directive/files/__path__/__name__.spec.ts
rename to addon/ng2/blueprints/directive/files/__path__/__name__.directive.spec.ts
index 0e5c50473136..f737809adee4 100644
--- a/addon/ng2/blueprints/directive/files/__path__/__name__.spec.ts
+++ b/addon/ng2/blueprints/directive/files/__path__/__name__.directive.spec.ts
@@ -1,16 +1,17 @@
import {
- it,
- iit,
+ beforeEachProviders,
describe,
ddescribe,
expect,
+ iit,
+ it,
inject,
injectAsync,
- TestComponentBuilder,
- beforeEachProviders
+ ComponentFixture,
+ TestComponentBuilder
} from 'angular2/testing';
import {provide, Component} from 'angular2/core';
-import {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>';
+import {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>.directive';
@Component({
@@ -25,7 +26,7 @@ describe('<%= classifiedModuleName %> Directive', () => {
it('should ...', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
- return tcb.createAsync(TestComponent).then((fixture) => {
+ return tcb.createAsync(TestComponent).then((fixture: ComponentFixture) => {
fixture.detectChanges();
});
}));
diff --git a/addon/ng2/blueprints/directive/files/__path__/__name__.ts b/addon/ng2/blueprints/directive/files/__path__/__name__.directive.ts
similarity index 62%
rename from addon/ng2/blueprints/directive/files/__path__/__name__.ts
rename to addon/ng2/blueprints/directive/files/__path__/__name__.directive.ts
index bcbc6d6e779a..1c6f046ea63f 100644
--- a/addon/ng2/blueprints/directive/files/__path__/__name__.ts
+++ b/addon/ng2/blueprints/directive/files/__path__/__name__.directive.ts
@@ -1,11 +1,7 @@
import {Directive} from 'angular2/core';
-
@Directive({
- selector: '<%= dasherizedModuleName %>',
- providers: [],
- host: {},
-
+ selector: '<%= rawEntityName %>'
})
export class <%= classifiedModuleName %> {
diff --git a/addon/ng2/blueprints/directive/index.js b/addon/ng2/blueprints/directive/index.js
index 2232263768eb..dffdc7455a12 100644
--- a/addon/ng2/blueprints/directive/index.js
+++ b/addon/ng2/blueprints/directive/index.js
@@ -5,20 +5,22 @@ module.exports = {
description: '',
availableOptions: [
- { name: 'flat', type: Boolean, default: false, aliases: ['f'] }
+ { name: 'flat', type: Boolean, default: false }
],
normalizeEntityName: function (entityName) {
var parsedPath = dynamicPathParser(this.project, entityName);
this.dynamicPath = parsedPath;
+ this.rawEntityName = parsedPath.name;
return parsedPath.name;
},
locals: function (options) {
return {
dynamicPath: this.dynamicPath.dir,
- flat: options.flat
+ flat: options.flat,
+ rawEntityName: this.rawEntityName
};
},
diff --git a/addon/ng2/blueprints/ng2/files/karma-test-shim.js b/addon/ng2/blueprints/ng2/files/karma-test-shim.js
index 22254c16f3c8..306a42e61592 100644
--- a/addon/ng2/blueprints/ng2/files/karma-test-shim.js
+++ b/addon/ng2/blueprints/ng2/files/karma-test-shim.js
@@ -1,49 +1,59 @@
/*global jasmine, __karma__, window*/
Error.stackTraceLimit = Infinity;
-
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
__karma__.loaded = function () {
};
-System.config({
- packages: {
- 'base/dist/app': {
- defaultExtension: false,
- format: 'register',
- map: Object.keys(window.__karma__.files)
- .filter(onlyAppFiles)
- .reduce(function (pathsMapping, appPath) {
- var moduleName = appPath.replace(/^\/base\/dist\/app\//, './').replace(/\.js$/, '');
- pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath];
- return pathsMapping;
- }, {})
- }
- }
-});
+var distPath = '/base/dist/';
+var appPath = distPath + 'app/';
-System.import('angular2/testing').then(function (testing) {
- return System.import('angular2/platform/testing/browser').then(function (providers) {
- testing.setBaseTestProviders(providers.TEST_BROWSER_PLATFORM_PROVIDERS,
- providers.TEST_BROWSER_APPLICATION_PROVIDERS);
- });
-}).then(function () {
- return Promise.all(
- Object.keys(window.__karma__.files)
- .filter(onlySpecFiles)
- .map(function (moduleName) {
- return System.import(moduleName);
- }));
-}).then(function () {
- __karma__.start();
-}, function (error) {
- __karma__.error(error.stack || error);
-});
-
-function onlyAppFiles(filePath) {
- return /^\/base\/dist\/app\/(?!.*\.spec\.js$)([a-z0-9-_\.\/]+)\.js$/.test(filePath);
+function isJsFile(path) {
+ return path.slice(-3) == '.js';
}
-function onlySpecFiles(path) {
- return /\.spec\.js$/.test(path);
+function isSpecFile(path) {
+ return path.slice(-8) == '.spec.js';
}
+
+function isAppFile(path) {
+ return isJsFile(path) && (path.substr(0, appPath.length) == appPath);
+}
+
+var allSpecFiles = Object.keys(window.__karma__.files)
+ .filter(isSpecFile)
+ .filter(isAppFile);
+
+// Load our SystemJS configuration.
+System.import('base/dist/system-config.js').then(function(systemJsConfig) {
+ // We need to add the distPrefix to our system config packages.
+ var config = systemJsConfig.config;
+ Object.keys(config.packages).forEach(function(pkgName) {
+ if (pkgName[0] != '/' && pkgName[0] != '.') {
+ var pkg = config.packages[pkgName];
+ delete config.packages[pkgName];
+ config.packages[distPath + pkgName] = pkg;
+ }
+ });
+
+ System.config(config);
+}).then(function() {
+ // Load and configure the TestComponentBuilder.
+ return Promise.all([
+ System.import('angular2/testing'),
+ System.import('angular2/platform/testing/browser')
+ ]).then(function (providers) {
+ var testing = providers[0];
+ var testingBrowser = providers[1];
+
+ testing.setBaseTestProviders(testingBrowser.TEST_BROWSER_PLATFORM_PROVIDERS,
+ testingBrowser.TEST_BROWSER_APPLICATION_PROVIDERS);
+ });
+}).then(function() {
+ // Finally, load all spec files.
+ // This will run the tests directly.
+ return Promise.all(
+ allSpecFiles.map(function (moduleName) {
+ return System.import(moduleName);
+ }));
+}).then(__karma__.start, __karma__.error);
\ No newline at end of file
diff --git a/addon/ng2/blueprints/ng2/files/src/client/app/__name__.__styleext__ b/addon/ng2/blueprints/ng2/files/src/client/app/__name__.__styleext__
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/addon/ng2/blueprints/ng2/files/src/client/app/__name__.ts b/addon/ng2/blueprints/ng2/files/src/client/app/__name__.ts
index d4c097fdde3f..e3beb84f32a7 100644
--- a/addon/ng2/blueprints/ng2/files/src/client/app/__name__.ts
+++ b/addon/ng2/blueprints/ng2/files/src/client/app/__name__.ts
@@ -2,9 +2,11 @@ import {Component} from 'angular2/core';
import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from 'angular2/router';
@Component({
+ moduleId: __moduleName,
selector: '<%= htmlComponentName %>-app',
providers: [ROUTER_PROVIDERS],
- templateUrl: 'app/<%= htmlComponentName %>.html',
+ templateUrl: '<%= htmlComponentName %>.html',
+ styleUrls: ['<%= dasherizedModuleName %>.<%= styleExt %>'],
directives: [ROUTER_DIRECTIVES],
pipes: []
})
diff --git a/addon/ng2/blueprints/ng2/files/src/client/index.html b/addon/ng2/blueprints/ng2/files/src/client/index.html
index 197237d92520..9d10ea642109 100644
--- a/addon/ng2/blueprints/ng2/files/src/client/index.html
+++ b/addon/ng2/blueprints/ng2/files/src/client/index.html
@@ -31,17 +31,14 @@
-
+
+