From a15c4646dc4396651970723546b482a67ead3d19 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Mon, 26 Oct 2015 00:01:14 +0200 Subject: [PATCH] chore(*): automatically build ES5 version of the module and typescript definitions when publishing Based on the following post: https://medium.com/@OCombe/how-to-publish-a-library-for-angular-2-on-npm-5f48cdabf435 --- .gitignore | 4 ++++ .npmignore | 2 -- TimeAgoPipe.spec.ts | 6 ++---- TimeAgoPipe.ts | 9 +++++---- karma.conf.js | 6 +++--- package.json | 16 ++++++++++++---- tsconfig.json | 17 +++++++++++++++++ tsd.json | 15 +++++++++++++++ 8 files changed, 58 insertions(+), 17 deletions(-) delete mode 100644 .npmignore create mode 100644 tsconfig.json create mode 100644 tsd.json diff --git a/.gitignore b/.gitignore index 7a1537b..8c39e59 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ .idea node_modules +typings +TimeAgoPipe.js +TimeAgoPipe.js.map +TimeAgoPipe.d.ts diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 7a1537b..0000000 --- a/.npmignore +++ /dev/null @@ -1,2 +0,0 @@ -.idea -node_modules diff --git a/TimeAgoPipe.spec.ts b/TimeAgoPipe.spec.ts index 6fe4e04..a67d76a 100644 --- a/TimeAgoPipe.spec.ts +++ b/TimeAgoPipe.spec.ts @@ -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); @@ -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'); }); }); }); diff --git a/TimeAgoPipe.ts b/TimeAgoPipe.ts index 997ee41..39dd1d5 100644 --- a/TimeAgoPipe.ts +++ b/TimeAgoPipe.ts @@ -1,15 +1,16 @@ /* angular2-moment / v0.0.3 / (c) 2015 Uri Shaked / MIT Licence */ /// +/// -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 = (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) { @@ -19,7 +20,7 @@ export class TimeAgoPipe implements Pipe { return value instanceof Date || moment.isMoment(value); } - transform(value:Date | moment.Moment, args?:List):any { + transform(value:Date | moment.Moment, args?:any[]):any { let momentInstance = moment(value); this._removeTimer(); let timeToUpdate = this._getSecondsUntilUpdate(momentInstance) * 1000; diff --git a/karma.conf.js b/karma.conf.js index 51e0272..ab0e481 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -23,7 +23,7 @@ module.exports = function (config) { loaders: [ { test: /\.ts$/, - loader: 'typescript-simple?ignoreWarnings[]=2315', + loader: 'typescript-simple', exclude: [/node_modules/] } ] @@ -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: { @@ -52,7 +52,7 @@ module.exports = function (config) { } } }; - + if (process.env.TRAVIS){ _config.browsers = ['Chrome_travis_ci']; } diff --git a/package.json b/package.json index 6e6a3ef..fb5d0f1 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..5bb853f --- /dev/null +++ b/tsconfig.json @@ -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" + ] +} diff --git a/tsd.json b/tsd.json new file mode 100644 index 0000000..f164eca --- /dev/null +++ b/tsd.json @@ -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" + } + } +}