Skip to content

Commit e1161d3

Browse files
committed
Aurelia TypeScript build - with working dependencies definitions (jspm) and doc generation - karma tests not yet working
1 parent d0849e0 commit e1161d3

File tree

10 files changed

+144
-143
lines changed

10 files changed

+144
-143
lines changed

build/babel-options.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

build/paths.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
77
module.exports = {
88
root: appRoot,
99
source: appRoot + '**/*.js',
10+
aureliaDependenciesDefinitions: 'jspm_packages/github/aurelia/**/*.d.ts',
1011
html: appRoot + '**/*.html',
1112
style: 'styles/**/*.css',
1213
output: 'dist/',

build/tasks/build.js

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,65 @@
11
var gulp = require('gulp');
22
var runSequence = require('run-sequence');
3-
var to5 = require('gulp-babel');
3+
var ts = require('gulp-typescript');
4+
var sourcemaps = require('gulp-sourcemaps');
5+
var merge = require('merge2');
46
var paths = require('../paths');
5-
var compilerOptions = require('../babel-options');
7+
var compilerOptions = require('../ts-options');
68
var assign = Object.assign || require('object.assign');
79
var rename = require('gulp-rename');
810

9-
var jsName = paths.packageName + '.js';
11+
var tsName = paths.packageName + '.ts';
1012

1113
gulp.task('build-index', function(){
12-
return gulp.src(paths.root + 'index.js')
13-
.pipe(rename(jsName))
14+
return gulp.src(paths.root + 'index.ts')
15+
.pipe(rename(tsName))
1416
.pipe(gulp.dest(paths.output));
1517
});
1618

1719
gulp.task('build-es6', function () {
18-
return gulp.src(paths.output + jsName)
19-
.pipe(gulp.dest(paths.output + 'es6'));
20+
return buildModule('es6', 'es6');
2021
});
2122

2223
gulp.task('build-commonjs', function () {
23-
return gulp.src(paths.output + jsName)
24-
.pipe(to5(assign({}, compilerOptions, {modules:'common'})))
25-
.pipe(gulp.dest(paths.output + 'commonjs'));
24+
return buildModule('es5', 'commonjs');
2625
});
2726

2827
gulp.task('build-amd', function () {
29-
return gulp.src(paths.output + jsName)
30-
.pipe(to5(assign({}, compilerOptions, {modules:'amd'})))
31-
.pipe(gulp.dest(paths.output + 'amd'));
28+
return buildModule('es5', 'amd');
3229
});
3330

3431
gulp.task('build-system', function () {
35-
return gulp.src(paths.output + jsName)
36-
.pipe(to5(assign({}, compilerOptions, {modules:'system'})))
37-
.pipe(gulp.dest(paths.output + 'system'));
32+
return buildModule('es5', 'system');
3833
});
3934

40-
gulp.task('build-dts', function(){
41-
return gulp.src(paths.output + paths.packageName + '.d.ts')
42-
.pipe(rename(paths.packageName + '.d.ts'))
43-
.pipe(gulp.dest(paths.output + 'es6'))
44-
.pipe(gulp.dest(paths.output + 'commonjs'))
45-
.pipe(gulp.dest(paths.output + 'amd'))
46-
.pipe(gulp.dest(paths.output + 'system'));
35+
function buildModule(target, targetName) {
36+
var tsResult = gulp.src([
37+
paths.output + tsName,
38+
paths.aureliaDependenciesDefinitions])
39+
.pipe(sourcemaps.init())
40+
.pipe(ts(assign({}, compilerOptions, {"target":target,"module":targetName})));
41+
42+
return merge([
43+
tsResult.dts.pipe(gulp.dest(paths.output + targetName)),
44+
tsResult.js
45+
.pipe(sourcemaps.write())
46+
.pipe(gulp.dest(paths.output + targetName))
47+
]);
48+
}
49+
50+
gulp.task('copy-dts-for-docs', function () {
51+
return gulp.src([
52+
paths.output + 'es6/*.d.ts'
53+
])
54+
.pipe(gulp.dest(paths.output));
4755
});
4856

4957
gulp.task('build', function(callback) {
5058
return runSequence(
5159
'clean',
5260
'build-index',
5361
['build-es6', 'build-commonjs', 'build-amd', 'build-system'],
54-
'build-dts',
62+
'copy-dts-for-docs',
5563
callback
5664
);
5765
});

build/ts-options.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
"target": "",
3+
"declarationFiles": true,
4+
"noExternalResolve": true,
5+
"noImplicitAny": false,
6+
"noEmitOnError": true,
7+
"experimentalDecorators": true
8+
};

config.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
System.config({
22
defaultJSExtensions: true,
3-
transpiler: "babel",
4-
babelOptions: {
5-
"optional": [
6-
"runtime"
7-
]
8-
},
3+
transpiler: "typescript",
94
paths: {
105
"github:*": "jspm_packages/github/*",
116
"npm:*": "jspm_packages/npm/*"
127
},
138

149
map: {
1510
"aurelia-logging": "github:aurelia/[email protected]",
16-
"babel": "npm:[email protected]",
17-
"babel-runtime": "npm:[email protected]",
1811
"core-js": "npm:[email protected]",
12+
"typescript": "npm:[email protected]",
1913
"github:jspm/[email protected]": {
2014
"process": "npm:[email protected]"
2115
},

karma.conf.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@ module.exports = function(config) {
1212
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
1313
frameworks: ['jspm', 'jasmine'],
1414

15+
plugins: [
16+
'karma-jasmine',
17+
'karma-chrome-launcher',
18+
'karma-typescript-preprocessor'
19+
],
20+
21+
1522
jspm: {
1623
// Edit this to your needs
17-
loadFiles: ['src/**/*.js', 'test/**/*.js']
24+
loadFiles: ['src/**/*.ts', 'test/**/*.ts']
1825
},
1926

2027

@@ -30,19 +37,21 @@ module.exports = function(config) {
3037
// preprocess matching files before serving them to the browser
3138
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
3239
preprocessors: {
33-
'test/**/*.js': ['babel'],
34-
'src/**/*.js': ['babel']
40+
'test/**/*.ts': ['typescript'],
41+
'src/**/*.ts': ['typescript']
3542
},
36-
'babelPreprocessor': {
43+
typescriptPreprocessor: {
3744
options: {
38-
sourceMap: 'inline',
39-
modules: 'system',
40-
moduleIds: false,
41-
loose: "all",
42-
optional: [
43-
"es7.decorators"
44-
]
45-
}
45+
sourceMap: false,
46+
inlineSourceMap: true,
47+
target: 'ES5',
48+
module: 'system',
49+
noExternalResolve: true,
50+
noImplicitAny: false,
51+
noEmitOnError: true,
52+
experimentalDecorators: true
53+
},
54+
typings: ['jspm_packages/**/*.d.ts']
4655
},
4756

4857
// test results reporter to use

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,31 @@
2929
"aurelia-logging": "github:aurelia/logging@^0.8.0"
3030
},
3131
"devDependencies": {
32-
"babel": "npm:babel-core@^5.1.13",
33-
"babel-runtime": "npm:babel-runtime@^5.1.13",
34-
"core-js": "npm:core-js@^0.9.4"
32+
"core-js": "npm:core-js@^0.9.4",
33+
"typescript": "npm:typescript@^1.6.2"
3534
}
3635
},
3736
"devDependencies": {
3837
"aurelia-tools": "^0.1.12",
39-
"babel-dts-generator": "^0.2.9",
40-
"babel-eslint": "^4.1.1",
4138
"conventional-changelog": "0.0.11",
4239
"del": "^1.1.0",
4340
"gulp": "^3.8.10",
4441
"gulp-babel": "^5.2.1",
4542
"gulp-bump": "^0.3.1",
4643
"gulp-eslint": "^1.0.0",
4744
"gulp-rename": "^1.2.2",
45+
"gulp-sourcemaps": "^1.6.0",
4846
"gulp-typedoc": "^1.2.1",
4947
"gulp-typedoc-extractor": "^0.0.8",
48+
"gulp-typescript": "^2.9.2",
5049
"jasmine-core": "^2.1.3",
5150
"karma": "^0.12.28",
5251
"karma-babel-preprocessor": "^5.2.2",
5352
"karma-chrome-launcher": "^0.1.7",
5453
"karma-coverage": "^0.3.1",
5554
"karma-jasmine": "^0.3.5",
5655
"karma-jspm": "^2.0.1",
56+
"merge2": "^0.3.6",
5757
"object.assign": "^1.0.3",
5858
"require-dir": "^0.1.0",
5959
"run-sequence": "^1.0.2",

src/index.js renamed to src/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import * as LogManager from 'aurelia-logging';
33
const logger = LogManager.getLogger('event-aggregator');
44

55
class Handler {
6-
constructor(messageType, callback) {
7-
this.messageType = messageType;
8-
this.callback = callback;
6+
constructor(private messageType: any, private callback: Function) {
97
}
108

119
handle(message) {
@@ -18,7 +16,7 @@ class Handler {
1816
/**
1917
* Represents a disposable subsciption to an EventAggregator event.
2018
*/
21-
interface Subscription {
19+
export interface Subscription {
2220
/**
2321
* Disposes the subscription.
2422
*/
@@ -29,12 +27,13 @@ interface Subscription {
2927
* Enables loosely coupled publish/subscribe messaging.
3028
*/
3129
export class EventAggregator {
30+
private eventLookup: any = {};
31+
private messageHandlers: Handler[] = [];
32+
3233
/**
3334
* Creates an instance of the EventAggregator class.
3435
*/
3536
constructor() {
36-
this.eventLookup = {};
37-
this.messageHandlers = [];
3837
}
3938

4039
/**
@@ -122,7 +121,7 @@ export class EventAggregator {
122121
* Includes EA functionality into an object instance.
123122
* @param obj The object to mix Event Aggregator functionality into.
124123
*/
125-
export function includeEventsIn(obj: Object): EventAggregator {
124+
export function includeEventsIn(obj: any): EventAggregator {
126125
let ea = new EventAggregator();
127126

128127
obj.subscribeOnce = function(event, callback) {
@@ -144,6 +143,6 @@ export function includeEventsIn(obj: Object): EventAggregator {
144143
* Configures a global EA by merging functionality into the Aurelia instance.
145144
* @param config The Aurelia Framework configuration object used to configure the plugin.
146145
*/
147-
export function configure(config: Object): void {
146+
export function configure(config: any): void {
148147
config.instance(EventAggregator, includeEventsIn(config.aurelia));
149148
}

0 commit comments

Comments
 (0)