Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typescript version of event aggregator #13

Closed
wants to merge 2 commits into from
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
2 changes: 1 addition & 1 deletion build/babel-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
"es7.classProperties"
],
plugins: [
"babel-dts-generator"
//"babel-dts-generator"
],
extra: {
dts: {
Expand Down
6 changes: 5 additions & 1 deletion build/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ var fs = require('fs');

var appRoot = 'src/';
var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
var outputRoot = 'dist/';

module.exports = {
root: appRoot,
tsSource: outputRoot + pkg.name + '.ts',
jspmDefinitions: 'jspm_packages/**/*.d.ts',
typings: 'typings/**/*.d.ts',
source: appRoot + '**/*.js',
html: appRoot + '**/*.html',
style: 'styles/**/*.css',
output: 'dist/',
output: outputRoot,
doc:'./doc',
e2eSpecsSrc: 'test/e2e/src/*.js',
e2eSpecsDist: 'test/e2e/dist/',
Expand Down
68 changes: 48 additions & 20 deletions build/tasks/build.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,83 @@
var gulp = require('gulp');
var runSequence = require('run-sequence');
var to5 = require('gulp-babel');
var sourcemaps = require('gulp-sourcemaps');
var paths = require('../paths');
var compilerOptions = require('../babel-options');
var assign = Object.assign || require('object.assign');
var rename = require('gulp-rename');

var merge = require('merge2');
var jsName = paths.packageName + '.js';
var ts = require('gulp-typescript');
var tsProject = ts.createProject('tsconfig.json', {
typescript: require('typescript')
});

gulp.task('build-index', function(){
return gulp.src(paths.root + 'index.js')
.pipe(rename(jsName))
// copies src/index.ts to dist/<package-name>.ts
gulp.task('build-index', function() {
return gulp.src(paths.root + 'index.ts')
.pipe(rename(function (file) { file.basename = paths.packageName; }))
.pipe(gulp.dest(paths.output));
});

// gulp-typescript compiles TS files into ES6
gulp.task('build-ts', function () {
var tsResult = gulp.src([paths.tsSource, paths.typings, paths.jspmDefinitions])
.pipe(sourcemaps.init())
.pipe(ts(tsProject));
return merge([
tsResult.js
.pipe(sourcemaps.write({includeContent: false, sourceRoot: paths.sourceMapRelativePath}))
.pipe(gulp.dest(paths.output)),
tsResult.dts
.pipe(gulp.dest(paths.output))
]);
});

function buildModule(moduleType, dirName) {
return gulp.src(paths.output + jsName)
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(to5(assign({}, compilerOptions, { modules: moduleType })))
.pipe(sourcemaps.write({includeContent: true}))
.pipe(gulp.dest(paths.output + dirName));
}

// copies js file from ts output for ES6 build
gulp.task('build-es6', function () {
return gulp.src(paths.output + jsName)
.pipe(gulp.dest(paths.output + 'es6'));
});

// builds js file as ES5 with CommonJS module
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('common', 'commonjs');
});

// builds js file as ES5 with AMD module
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('amd', 'amd');
});

// builds js file as ES5 with SystemJS module
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('system', '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'));
// copies the ts declaration file for each module build
gulp.task('build-dts', function() {
return gulp.src([paths.output + paths.packageName + '.d.ts', paths.typings])
.pipe(gulp.dest(paths.output + 'es6'))
.pipe(gulp.dest(paths.output + 'commonjs'))
.pipe(gulp.dest(paths.output + 'amd'))
.pipe(gulp.dest(paths.output + 'system'));
});

// main build task
gulp.task('build', function(callback) {
return runSequence(
'clean',
'build-index',
'build-ts',
['build-es6', 'build-commonjs', 'build-amd', 'build-system'],
'build-dts',
callback
Expand Down
3 changes: 3 additions & 0 deletions dist/amd/Interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Constructor<T> {
new (...args: any[]): T;
}
111 changes: 55 additions & 56 deletions dist/amd/aurelia-event-aggregator.d.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,61 @@
declare module 'aurelia-event-aggregator' {
import * as LogManager from 'aurelia-logging';

/**
* Represents a disposable subsciption to an EventAggregator event.
*/
export interface Subscription {

/**
* Represents a disposable subsciption to an EventAggregator event.
*/
export interface Subscription {
/**
* Disposes the subscription.
*/
* Disposes the subscription.
*/
dispose(): void;
}
class Handler {
constructor(messageType: any, callback: any);
handle(message: any): any;
}

/**
* Enables loosely coupled publish/subscribe messaging.
*/
export class EventAggregator {

}
/**
* Enables loosely coupled publish/subscribe messaging.
*/
export declare class EventAggregator {
private eventLookup;
private messageHandlers;
/**
* Creates an instance of the EventAggregator class.
*/
constructor();

* Publishes a message.
* @param event The message data type to publish to.
*/
publish<T>(event: T): void;
/**
* Publishes a message.
* @param event The event or channel to publish to.
* @param data The data to publish on the channel.
*/
publish(event: string | any, data?: any): void;

* Publishes a message.
* @param event The message channel to publish to.
* @param data The data to publish on the channel.
*/
publish(event: string, data?: any): void;
/**
* Subscribes to a message channel or message type.
* @param event The event channel or event data type.
* @param callback The callback to be invoked when when the specified message is published.
*/
subscribe(event: string | Function, callback: Function): Subscription;

* Subscribes to a message type.
* @param event The message data Type to subscribe to.
* @param callback The callback to be invoked when the specified message is published.
*/
subscribe<T>(event: Constructor<T>, callback: (message: T) => void): Subscription;
/**
* Subscribes to a message channel or message type, then disposes the subscription automatically after the first message is received.
* @param event The event channel or event data type.
* @param callback The callback to be invoked when when the specified message is published.
*/
subscribeOnce(event: string | Function, callback: Function): Subscription;
}

/**
* Includes EA functionality into an object instance.
* @param obj The object to mix Event Aggregator functionality into.
*/
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;
}
* Subscribes to a message channel.
* @param event The message channel to subscribe to.
* @param callback The callback to be invoked when the specified message is published.
*/
subscribe(event: string, callback: (message: any, event?: string) => void): Subscription;
/**
* Subscribes to a message type, then disposes the subscription automatically after the first message is received.
* @param event The message data Type to subscribe to.
* @param callback The callback to be invoked when when the specified message is published.
*/
subscribeOnce<T>(event: Constructor<T>, callback: (message: T) => void): Subscription;
/**
* Subscribes to a message channel, then disposes the subscription automatically after the first message is received.
* @param event The message channel to subscribe to.
* @param callback The callback to be invoked when when the specified message is published.
*/
subscribeOnce(event: string, callback: (message: any, event?: string) => void): Subscription;
}
/**
* Includes Event Aggregator functionality into an object instance.
* @param obj The object to mix Event Aggregator functionality into.
*/
export declare function includeEventsIn(obj: any): EventAggregator;
/**
* Configures a global Event Aggregator by merging functionality into the Aurelia instance.
* @param config The Aurelia Framework configuration object used to configure the plugin.
*/
export declare function configure(config: any): void;
Loading