Skip to content

Commit 9746373

Browse files
committed
chore: update templates to align with the style guide
Implements the majority of style guide #316 Moves systemjs configuration our of index.html #429
1 parent 129601d commit 9746373

37 files changed

+255
-246
lines changed

addon/ng2/blueprints/component/files/__path__/__name__.spec.ts renamed to addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import {
2-
it,
3-
iit,
2+
beforeEachProviders,
43
describe,
54
ddescribe,
65
expect,
6+
iit,
7+
it,
78
inject,
89
injectAsync,
9-
TestComponentBuilder,
10-
beforeEachProviders
10+
ComponentFixture,
11+
TestComponentBuilder
1112
} from 'angular2/testing';
1213
import {provide} from 'angular2/core';
13-
import {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>';
14+
import {<%= classifiedModuleName %>Component} from './<%= dasherizedModuleName %>.component';
1415

1516
describe('<%= classifiedModuleName %> Component', () => {
1617

1718
beforeEachProviders((): any[] => []);
1819

1920

2021
it('should ...', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
21-
return tcb.createAsync(<%= classifiedModuleName %>).then((fixture) => {
22+
return tcb.createAsync(<%= classifiedModuleName %>Component).then((fixture: ComponentFixture) => {
2223
fixture.detectChanges();
2324
});
2425
}));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {Component} from 'angular2/core';
2+
3+
@Component({
4+
moduleId: __moduleName,
5+
selector: '<%= dasherizedModuleName %>',
6+
templateUrl: '<%= dasherizedModuleName %>.component.html',
7+
styleUrls: ['<%= dasherizedModuleName %>.component.<%= styleExt %>']
8+
})
9+
export class <%= classifiedModuleName %>Component {
10+
11+
constructor() {}
12+
13+
ngOnInit() {
14+
}
15+
16+
}

addon/ng2/blueprints/component/files/__path__/__name__.ts

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {<%= classifiedModuleName %>Component} from './<%= dasherizedModuleName %>.component';

addon/ng2/blueprints/component/index.js

+42-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
var path = require('path');
2+
var Blueprint = require('ember-cli/lib/models/blueprint');
23
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
34

5+
var getFiles = Blueprint.prototype.files;
6+
47
module.exports = {
58
description: '',
69

710
availableOptions: [
8-
{ name: 'flat', type: Boolean, default: false, aliases: ['f'] }
11+
{ name: 'flat', type: Boolean, default: false }
912
],
1013

1114
normalizeEntityName: function (entityName) {
@@ -16,22 +19,59 @@ module.exports = {
1619
},
1720

1821
locals: function (options) {
22+
//TODO: pull value from config
23+
this.styleExt = 'css';
24+
1925
return {
2026
dynamicPath: this.dynamicPath.dir.replace(this.dynamicPath.appRoot, ''),
21-
flat: options.flat
27+
flat: options.flat,
28+
styleExt: this.styleExt,
29+
isLazyRoute: !!options.isLazyRoute,
30+
isAppComponent: !!options.isAppComponent
2231
};
2332
},
33+
34+
files: function() {
35+
var fileList = getFiles.call(this);
36+
37+
if (this.options.flat) {
38+
fileList = fileList.filter(p => p.indexOf('index.ts') <= 0);
39+
}
2440

41+
return fileList;
42+
},
43+
2544
fileMapTokens: function (options) {
2645
// Return custom template variables here.
2746
return {
2847
__path__: () => {
2948
var dir = this.dynamicPath.dir;
3049
if (!options.locals.flat) {
3150
dir += path.sep + options.dasherizedModuleName;
51+
52+
if (options.locals.isLazyRoute) {
53+
var dirParts = dir.split(path.sep);
54+
dirParts[dirParts.length - 1] = `+${dirParts[dirParts.length - 1]}`;
55+
dir = dirParts.join(path.sep);
56+
}
3257
}
58+
this.appDir = dir.replace(`src${path.sep}client${path.sep}`, '');
3359
return dir;
60+
},
61+
__styleext__: () => {
62+
return options.locals.styleExt;
3463
}
3564
};
65+
},
66+
67+
afterInstall: function(options) {
68+
if (!options.flat) {
69+
var filePath = path.join('src', 'client', 'system-config.ts');
70+
return this.insertIntoFile(
71+
filePath,
72+
` '${this.appDir}',`,
73+
{ before: ' //barrel registration' }
74+
);
75+
}
3676
}
3777
};

addon/ng2/blueprints/directive/files/__path__/__name__.spec.ts renamed to addon/ng2/blueprints/directive/files/__path__/__name__.directive.spec.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import {
2-
it,
3-
iit,
2+
beforeEachProviders,
43
describe,
54
ddescribe,
65
expect,
6+
iit,
7+
it,
78
inject,
89
injectAsync,
9-
TestComponentBuilder,
10-
beforeEachProviders
10+
ComponentFixture,
11+
TestComponentBuilder
1112
} from 'angular2/testing';
1213
import {provide, Component} from 'angular2/core';
13-
import {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>';
14+
import {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>.directive';
1415

1516

1617
@Component({
@@ -25,7 +26,7 @@ describe('<%= classifiedModuleName %> Directive', () => {
2526

2627

2728
it('should ...', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
28-
return tcb.createAsync(TestComponent).then((fixture) => {
29+
return tcb.createAsync(TestComponent).then((fixture: ComponentFixture) => {
2930
fixture.detectChanges();
3031
});
3132
}));

addon/ng2/blueprints/directive/files/__path__/__name__.ts renamed to addon/ng2/blueprints/directive/files/__path__/__name__.directive.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import {Directive} from 'angular2/core';
22

3-
43
@Directive({
5-
selector: '<%= dasherizedModuleName %>',
6-
providers: [],
7-
host: {},
8-
4+
selector: '<%= rawEntityName %>'
95
})
106
export class <%= classifiedModuleName %> {
117

addon/ng2/blueprints/directive/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@ module.exports = {
55
description: '',
66

77
availableOptions: [
8-
{ name: 'flat', type: Boolean, default: false, aliases: ['f'] }
8+
{ name: 'flat', type: Boolean, default: false }
99
],
1010

1111
normalizeEntityName: function (entityName) {
1212
var parsedPath = dynamicPathParser(this.project, entityName);
1313

1414
this.dynamicPath = parsedPath;
15+
this.rawEntityName = parsedPath.name;
1516
return parsedPath.name;
1617
},
1718

1819
locals: function (options) {
1920
return {
2021
dynamicPath: this.dynamicPath.dir,
21-
flat: options.flat
22+
flat: options.flat,
23+
rawEntityName: this.rawEntityName
2224
};
2325
},
2426

Original file line numberDiff line numberDiff line change
@@ -1,49 +1,59 @@
11
/*global jasmine, __karma__, window*/
22
Error.stackTraceLimit = Infinity;
3-
43
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
54

65
__karma__.loaded = function () {
76
};
87

9-
System.config({
10-
packages: {
11-
'base/dist/app': {
12-
defaultExtension: false,
13-
format: 'register',
14-
map: Object.keys(window.__karma__.files)
15-
.filter(onlyAppFiles)
16-
.reduce(function (pathsMapping, appPath) {
17-
var moduleName = appPath.replace(/^\/base\/dist\/app\//, './').replace(/\.js$/, '');
18-
pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath];
19-
return pathsMapping;
20-
}, {})
21-
}
22-
}
23-
});
8+
var distPath = '/base/dist/';
9+
var appPath = distPath + 'app/';
2410

25-
System.import('angular2/testing').then(function (testing) {
26-
return System.import('angular2/platform/testing/browser').then(function (providers) {
27-
testing.setBaseTestProviders(providers.TEST_BROWSER_PLATFORM_PROVIDERS,
28-
providers.TEST_BROWSER_APPLICATION_PROVIDERS);
29-
});
30-
}).then(function () {
31-
return Promise.all(
32-
Object.keys(window.__karma__.files)
33-
.filter(onlySpecFiles)
34-
.map(function (moduleName) {
35-
return System.import(moduleName);
36-
}));
37-
}).then(function () {
38-
__karma__.start();
39-
}, function (error) {
40-
__karma__.error(error.stack || error);
41-
});
42-
43-
function onlyAppFiles(filePath) {
44-
return /^\/base\/dist\/app\/(?!.*\.spec\.js$)([a-z0-9-_\.\/]+)\.js$/.test(filePath);
11+
function isJsFile(path) {
12+
return path.slice(-3) == '.js';
4513
}
4614

47-
function onlySpecFiles(path) {
48-
return /\.spec\.js$/.test(path);
15+
function isSpecFile(path) {
16+
return path.slice(-8) == '.spec.js';
4917
}
18+
19+
function isAppFile(path) {
20+
return isJsFile(path) && (path.substr(0, appPath.length) == appPath);
21+
}
22+
23+
var allSpecFiles = Object.keys(window.__karma__.files)
24+
.filter(isSpecFile)
25+
.filter(isAppFile);
26+
27+
// Load our SystemJS configuration.
28+
System.import('base/dist/system-config.js').then(function(systemJsConfig) {
29+
// We need to add the distPrefix to our system config packages.
30+
var config = systemJsConfig.config;
31+
Object.keys(config.packages).forEach(function(pkgName) {
32+
if (pkgName[0] != '/' && pkgName[0] != '.') {
33+
var pkg = config.packages[pkgName];
34+
delete config.packages[pkgName];
35+
config.packages[distPath + pkgName] = pkg;
36+
}
37+
});
38+
39+
System.config(config);
40+
}).then(function() {
41+
// Load and configure the TestComponentBuilder.
42+
return Promise.all([
43+
System.import('angular2/testing'),
44+
System.import('angular2/platform/testing/browser')
45+
]).then(function (providers) {
46+
var testing = providers[0];
47+
var testingBrowser = providers[1];
48+
49+
testing.setBaseTestProviders(testingBrowser.TEST_BROWSER_PLATFORM_PROVIDERS,
50+
testingBrowser.TEST_BROWSER_APPLICATION_PROVIDERS);
51+
});
52+
}).then(function() {
53+
// Finally, load all spec files.
54+
// This will run the tests directly.
55+
return Promise.all(
56+
allSpecFiles.map(function (moduleName) {
57+
return System.import(moduleName);
58+
}));
59+
}).then(__karma__.start, __karma__.error);

addon/ng2/blueprints/ng2/files/src/client/app/__name__.__styleext__

Whitespace-only changes.

addon/ng2/blueprints/ng2/files/src/client/app/__name__.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import {Component} from 'angular2/core';
22
import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from 'angular2/router';
33

44
@Component({
5+
moduleId: __moduleName,
56
selector: '<%= htmlComponentName %>-app',
67
providers: [ROUTER_PROVIDERS],
7-
templateUrl: 'app/<%= htmlComponentName %>.html',
8+
templateUrl: '<%= htmlComponentName %>.html',
9+
styleUrls: ['<%= dasherizedModuleName %>.<%= styleExt %>'],
810
directives: [ROUTER_DIRECTIVES],
911
pipes: []
1012
})

addon/ng2/blueprints/ng2/files/src/client/index.html

+7-10
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,14 @@
3131
<script src="vendor/angular2/bundles/angular2.dev.js"></script>
3232
<script src="vendor/angular2/bundles/http.dev.js"></script>
3333
<script src="vendor/angular2/bundles/router.dev.js"></script>
34-
34+
35+
<script src="system-config.js"></script>
3536
<script>
36-
System.config({
37-
packages: {
38-
app: {
39-
format: 'register',
40-
defaultExtension: 'js'
41-
}
42-
}
43-
});
44-
System.import('app.js').then(null, console.error.bind(console));
37+
System.import('system-config.js').then(function(systemConfig) {
38+
System.config(systemConfig.config);
39+
}).then(function () {
40+
System.import('main.js')
41+
}).catch(console.error.bind(console));
4542
</script>
4643
</body>
4744
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const barrels: string[] = [
2+
'app',
3+
//barrel registration
4+
];
5+
6+
function createPackageConfig(barrels: string[]): any {
7+
return barrels.reduce((barrelConfig: any, barrelName: string) => {
8+
barrelConfig[barrelName] = {
9+
format: 'register',
10+
defaultExtension: 'js',
11+
main: 'index'
12+
};
13+
return barrelConfig;
14+
}, {});
15+
}
16+
17+
18+
// Add your custom SystemJS configuration here.
19+
export const config: any = {
20+
packages: Object.assign({
21+
// Add your custom SystemJS packages here.
22+
}, createPackageConfig(barrels))
23+
};
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/// <reference path="../../typings/browser.d.ts" />
2+
3+
declare var __moduleName: string;

0 commit comments

Comments
 (0)