Skip to content

Commit

Permalink
Aurelia TypeScript build - with working dependencies definitions (jsp…
Browse files Browse the repository at this point in the history
…m) and doc generation - karma tests not yet working
  • Loading branch information
Lakerfield committed Nov 9, 2015
1 parent d0849e0 commit e1161d3
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 143 deletions.
35 changes: 0 additions & 35 deletions build/babel-options.js

This file was deleted.

1 change: 1 addition & 0 deletions build/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
module.exports = {
root: appRoot,
source: appRoot + '**/*.js',
aureliaDependenciesDefinitions: 'jspm_packages/github/aurelia/**/*.d.ts',

This comment has been minimized.

Copy link
@atsu85

atsu85 Nov 9, 2015

Why don't You just use tsconfig.json for gulp also (so that You don't have to maintain more than one configuration for typeScript compiler).
I guess You want all d.ts files to be included from the project, except node_modules, so this can be achieved using simple "exclude": ["node_modules"] as seen from @ctoran pull request: https://github.com/aurelia/event-aggregator/pull/13/files#diff-e5e546dd2eb0351f813d63d1b39dbc48R9 .
See also https://github.com/aurelia/event-aggregator/pull/13/files#diff-40e62be8220b9aeab02f5a664980bd73R12 to use the same tsconfig.json file for gulp (with exactly the same setup) that is used for IDE
var tsProject = ts.createProject('tsconfig.json', {
and then use it in build-ts task:
.pipe(ts(tsProject))
as shown here:
https://github.com/aurelia/event-aggregator/pull/13/files#diff-40e62be8220b9aeab02f5a664980bd73R24

html: appRoot + '**/*.html',
style: 'styles/**/*.css',
output: 'dist/',
Expand Down
56 changes: 32 additions & 24 deletions build/tasks/build.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,65 @@
var gulp = require('gulp');
var runSequence = require('run-sequence');
var to5 = require('gulp-babel');
var ts = require('gulp-typescript');
var sourcemaps = require('gulp-sourcemaps');
var merge = require('merge2');
var paths = require('../paths');
var compilerOptions = require('../babel-options');
var compilerOptions = require('../ts-options');
var assign = Object.assign || require('object.assign');
var rename = require('gulp-rename');

var jsName = paths.packageName + '.js';
var tsName = paths.packageName + '.ts';

gulp.task('build-index', function(){
return gulp.src(paths.root + 'index.js')
.pipe(rename(jsName))
return gulp.src(paths.root + 'index.ts')
.pipe(rename(tsName))
.pipe(gulp.dest(paths.output));
});

gulp.task('build-es6', function () {
return gulp.src(paths.output + jsName)
.pipe(gulp.dest(paths.output + 'es6'));
return buildModule('es6', 'es6');
});

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

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

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

gulp.task('build-dts', function(){
return gulp.src(paths.output + paths.packageName + '.d.ts')
.pipe(rename(paths.packageName + '.d.ts'))
.pipe(gulp.dest(paths.output + 'es6'))
.pipe(gulp.dest(paths.output + 'commonjs'))
.pipe(gulp.dest(paths.output + 'amd'))
.pipe(gulp.dest(paths.output + 'system'));
function buildModule(target, targetName) {
var tsResult = gulp.src([
paths.output + tsName,
paths.aureliaDependenciesDefinitions])
.pipe(sourcemaps.init())
.pipe(ts(assign({}, compilerOptions, {"target":target,"module":targetName})));

return merge([
tsResult.dts.pipe(gulp.dest(paths.output + targetName)),
tsResult.js
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.output + targetName))
]);
}

gulp.task('copy-dts-for-docs', function () {
return gulp.src([
paths.output + 'es6/*.d.ts'
])
.pipe(gulp.dest(paths.output));
});

gulp.task('build', function(callback) {
return runSequence(
'clean',
'build-index',
['build-es6', 'build-commonjs', 'build-amd', 'build-system'],
'build-dts',
'copy-dts-for-docs',
callback
);
});
8 changes: 8 additions & 0 deletions build/ts-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
"target": "",
"declarationFiles": true,
"noExternalResolve": true,
"noImplicitAny": false,
"noEmitOnError": true,
"experimentalDecorators": true
};
10 changes: 2 additions & 8 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
System.config({
defaultJSExtensions: true,
transpiler: "babel",
babelOptions: {
"optional": [
"runtime"
]
},
transpiler: "typescript",
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*"
},

map: {
"aurelia-logging": "github:aurelia/logging@0.8.0",
"babel": "npm:babel-core@5.4.7",
"babel-runtime": "npm:babel-runtime@5.4.7",
"core-js": "npm:core-js@0.9.11",
"typescript": "npm:typescript@1.6.2",
"github:jspm/nodelibs-process@0.1.1": {
"process": "npm:process@0.10.1"
},
Expand Down
33 changes: 21 additions & 12 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ module.exports = function(config) {
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jspm', 'jasmine'],

plugins: [
'karma-jasmine',
'karma-chrome-launcher',
'karma-typescript-preprocessor'
],


jspm: {
// Edit this to your needs
loadFiles: ['src/**/*.js', 'test/**/*.js']
loadFiles: ['src/**/*.ts', 'test/**/*.ts']
},


Expand All @@ -30,19 +37,21 @@ module.exports = function(config) {
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test/**/*.js': ['babel'],
'src/**/*.js': ['babel']
'test/**/*.ts': ['typescript'],
'src/**/*.ts': ['typescript']
},
'babelPreprocessor': {
typescriptPreprocessor: {
options: {
sourceMap: 'inline',
modules: 'system',
moduleIds: false,
loose: "all",
optional: [
"es7.decorators"
]
}
sourceMap: false,
inlineSourceMap: true,
target: 'ES5',
module: 'system',
noExternalResolve: true,
noImplicitAny: false,
noEmitOnError: true,
experimentalDecorators: true
},
typings: ['jspm_packages/**/*.d.ts']
},

// test results reporter to use
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@
"aurelia-logging": "github:aurelia/logging@^0.8.0"
},
"devDependencies": {
"babel": "npm:babel-core@^5.1.13",
"babel-runtime": "npm:babel-runtime@^5.1.13",
"core-js": "npm:core-js@^0.9.4"
"core-js": "npm:core-js@^0.9.4",
"typescript": "npm:typescript@^1.6.2"
}
},
"devDependencies": {
"aurelia-tools": "^0.1.12",
"babel-dts-generator": "^0.2.9",
"babel-eslint": "^4.1.1",
"conventional-changelog": "0.0.11",
"del": "^1.1.0",
"gulp": "^3.8.10",
"gulp-babel": "^5.2.1",
"gulp-bump": "^0.3.1",
"gulp-eslint": "^1.0.0",
"gulp-rename": "^1.2.2",
"gulp-sourcemaps": "^1.6.0",
"gulp-typedoc": "^1.2.1",
"gulp-typedoc-extractor": "^0.0.8",
"gulp-typescript": "^2.9.2",
"jasmine-core": "^2.1.3",
"karma": "^0.12.28",
"karma-babel-preprocessor": "^5.2.2",
"karma-chrome-launcher": "^0.1.7",
"karma-coverage": "^0.3.1",
"karma-jasmine": "^0.3.5",
"karma-jspm": "^2.0.1",
"merge2": "^0.3.6",
"object.assign": "^1.0.3",
"require-dir": "^0.1.0",
"run-sequence": "^1.0.2",
Expand Down
15 changes: 7 additions & 8 deletions src/index.js → src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import * as LogManager from 'aurelia-logging';
const logger = LogManager.getLogger('event-aggregator');

class Handler {
constructor(messageType, callback) {
this.messageType = messageType;
this.callback = callback;
constructor(private messageType: any, private callback: Function) {
}

handle(message) {
Expand All @@ -18,7 +16,7 @@ class Handler {
/**
* Represents a disposable subsciption to an EventAggregator event.
*/
interface Subscription {
export interface Subscription {
/**
* Disposes the subscription.
*/
Expand All @@ -29,12 +27,13 @@ interface Subscription {
* Enables loosely coupled publish/subscribe messaging.
*/
export class EventAggregator {
private eventLookup: any = {};
private messageHandlers: Handler[] = [];

/**
* Creates an instance of the EventAggregator class.
*/
constructor() {
this.eventLookup = {};
this.messageHandlers = [];
}

/**
Expand Down Expand Up @@ -122,7 +121,7 @@ export class EventAggregator {
* Includes EA functionality into an object instance.
* @param obj The object to mix Event Aggregator functionality into.
*/
export function includeEventsIn(obj: Object): EventAggregator {
export function includeEventsIn(obj: any): EventAggregator {
let ea = new EventAggregator();

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

0 comments on commit e1161d3

Please sign in to comment.