Skip to content

Commit

Permalink
chore(*): automatically build ES5 version of the module and typescrip…
Browse files Browse the repository at this point in the history
…t definitions when publishing

Based on the following post: https://medium.com/@OCombe/how-to-publish-a-library-for-angular-2-on-npm-5f48cdabf435
  • Loading branch information
urish committed Oct 25, 2015
1 parent 11f50d1 commit a15c464
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
.idea
node_modules
typings
TimeAgoPipe.js
TimeAgoPipe.js.map
TimeAgoPipe.d.ts
2 changes: 0 additions & 2 deletions .npmignore

This file was deleted.

6 changes: 2 additions & 4 deletions TimeAgoPipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import {TimeAgoPipe} from './TimeAgoPipe.ts';
describe('TimeAgo', () => {

describe('TimeAgoPipe', () => {
var subject;
var result;
var pipe;
var pipe:TimeAgoPipe;

beforeEach(() => {
pipe = new TimeAgoPipe(null);
Expand Down Expand Up @@ -37,7 +35,7 @@ describe('TimeAgo', () => {

describe('#transform', () => {
it('should transform the current date to "a few seconds ago"', () => {
expect(pipe.transform(new Date())).toBe("a few seconds ago");
expect(pipe.transform(new Date())).toBe('a few seconds ago');
});
});
});
Expand Down
9 changes: 5 additions & 4 deletions TimeAgoPipe.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/* angular2-moment / v0.0.3 / (c) 2015 Uri Shaked / MIT Licence */

/// <reference path="node_modules/angular2/bundles/typings/angular2/angular2.d.ts" />
/// <reference path="typings/moment/moment.d.ts" />

import {Pipe, ChangeDetectorRef} from 'angular2/angular2';
import {Pipe, ChangeDetectorRef, PipeTransform} from 'angular2/angular2';
import * as moment_ from 'moment';

// under systemjs, moment is actually exported as the default export, so we account for that
const moment = moment_['default'] || moment_;
const moment:moment.MomentStatic = (<any>moment_)['default'] || moment_;

@Pipe({name: 'amTimeAgo', pure: false})
export class TimeAgoPipe implements Pipe {
export class TimeAgoPipe implements PipeTransform {
private _currentTimer:number;

constructor(private _cdRef:ChangeDetectorRef) {
Expand All @@ -19,7 +20,7 @@ export class TimeAgoPipe implements Pipe {
return value instanceof Date || moment.isMoment(value);
}

transform(value:Date | moment.Moment, args?:List<any>):any {
transform(value:Date | moment.Moment, args?:any[]):any {
let momentInstance = moment(value);
this._removeTimer();
let timeToUpdate = this._getSecondsUntilUpdate(momentInstance) * 1000;
Expand Down
6 changes: 3 additions & 3 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function (config) {
loaders: [
{
test: /\.ts$/,
loader: 'typescript-simple?ignoreWarnings[]=2315',
loader: 'typescript-simple',
exclude: [/node_modules/]
}
]
Expand All @@ -43,7 +43,7 @@ module.exports = function (config) {
autoWatch: false,
browsers: ['Chrome'],
singleRun: true,

// See http://stackoverflow.com/a/27873086/830623
customLaunchers: {
Chrome_travis_ci: {
Expand All @@ -52,7 +52,7 @@ module.exports = function (config) {
}
}
};

if (process.env.TRAVIS){
_config.browsers = ['Chrome_travis_ci'];
}
Expand Down
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
"name": "angular2-moment",
"version": "0.0.3",
"description": "Moment.JS pipes for Angular2 (timeago and more)",
"main": "TimeAgoPipe.ts",
"main": "TimeAgoPipe.js",
"typings": "./TimeAgoPipe.d.ts",
"files": [
"TimeAgoPipe.js",
"TimeAgoPipe.js.map",
"TimeAgoPipe.d.ts",
"TimeAgoPipe.ts",
"CHANGELOG.md"
],
"scripts": {
"test": "karma start"
"test": "tsd install && tsc && karma start",
"prepublish": "tsd install && tsc"
},
"repository": {
"type": "git",
Expand All @@ -31,11 +40,10 @@
"karma": "^0.13.9",
"karma-chrome-launcher": "^0.2.0",
"karma-jasmine": "^0.3.6",
"karma-phantomjs-launcher": "^0.2.1",
"karma-sourcemap-loader": "^0.3.5",
"karma-webpack": "^1.7.0",
"phantomjs": "^1.9.18",
"reflect-metadata": "0.1.1",
"tsd": "^0.6.5",
"typescript": "1.6.2",
"typescript-simple-loader": "0.3.7",
"webpack": "^1.11.0"
Expand Down
17 changes: 17 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"noImplicitAny": true,
"module": "commonjs",
"target": "ES5",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"declaration": true
},
"files": [
"TimeAgoPipe.ts"
],
"exclude": [
"node_modules"
]
}
15 changes: 15 additions & 0 deletions tsd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"moment/moment.d.ts": {
"commit": "3191f6e0088eee07c4d8fd24e4d27a40a60d9eb9"
},
"moment/moment-node.d.ts": {
"commit": "3191f6e0088eee07c4d8fd24e4d27a40a60d9eb9"
}
}
}

0 comments on commit a15c464

Please sign in to comment.