From b513589be6f1fdd18ea0958848b864d25677d421 Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Mon, 18 May 2015 11:34:20 +0200 Subject: [PATCH] Improve reference file when packaging --- .gitignore | 2 +- Gruntfile.js | 43 +++++++++++++++++++++++++++++++++++++---- _references.d.ts | 1 - example/IntelliSense.ts | 3 ++- iridium.d.ts | 5 +++++ lib/Core.ts | 28 +++++++++++++-------------- package.json | 1 + 7 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 iridium.d.ts diff --git a/.gitignore b/.gitignore index 678903b..642c7d3 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,5 @@ node_modules/ dist/ *.tmp coverage/ -*.d.ts +typings/**/*.d.ts .tscache \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index db28dd1..31c12c9 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -9,18 +9,23 @@ module.exports = function (grunt) { dev: { src: tsconfig.files, - watch: 'lib' + options: { + watch: 'lib', + fast: 'never' + } }, test: { src: tsconfig.files, options: { - sourceMap: true + sourceMap: true, + fast: 'never' } }, release: { src: ["lib/**/*.ts"], options: { - sourceMap: false + sourceMap: false, + fast: 'never' } } }, @@ -76,6 +81,27 @@ module.exports = function (grunt) { tagName: "v<%= version %>", commitMessage: "v<%= version %>" } + }, + + 'string-replace': { + packageDependencies: { + files: { "_references.d.ts": "_references.d.ts" }, + options: { + replacements: [{ + pattern: /(\/\/\/ )/gi, + replacement: '//$1' + }] + } + }, + developmentDependencies: { + files: { "_references.d.ts": "_references.d.ts" }, + options: { + replacements: [{ + pattern: /\/\/(\/\/\/ )/gi, + replacement: '$1' + }] + } + } } }); @@ -91,6 +117,7 @@ module.exports = function (grunt) { grunt.loadNpmTasks("grunt-mocha-istanbul"); grunt.loadNpmTasks("grunt-contrib-clean"); grunt.loadNpmTasks("grunt-release"); + grunt.loadNpmTasks("grunt-string-replace"); grunt.renameTask('release', '_release'); @@ -98,5 +125,13 @@ module.exports = function (grunt) { grunt.registerTask("test", ["clean", "ts:test", "mochacli"]); grunt.registerTask("coverage", ["clean", "ts:test", "mocha_istanbul:coverage"]); grunt.registerTask("coveralls", ["clean", "ts:test", "mocha_istanbul:coveralls"]); - grunt.registerTask("release", ["clean", "ts:release", "_release"]); + grunt.registerTask("build", ["clean", "ts:release"]); + grunt.registerTask("build:package", ["clean", "ts:release", "string-replace:packageDependencies"]); + grunt.registerTask("clean:package", ["string-replace:developmentDependencies"]); + + grunt.registerTask("release", ["build:package", "_release", "clean:package"]); + grunt.registerTask("release:prerelease", ["build:package", "_release:prerelease", "clean:package"]); + grunt.registerTask("release:patch", ["build:package", "_release:patch", "clean:package"]); + grunt.registerTask("release:minor", ["build:package", "_release:minor", "clean:package"]); + grunt.registerTask("release:major", ["build:package", "_release:major", "clean:package"]); }; \ No newline at end of file diff --git a/_references.d.ts b/_references.d.ts index 24c6d87..627eb6f 100644 --- a/_references.d.ts +++ b/_references.d.ts @@ -1,4 +1,3 @@ /// /// -/// /// diff --git a/example/IntelliSense.ts b/example/IntelliSense.ts index f50f5a0..b280fbe 100644 --- a/example/IntelliSense.ts +++ b/example/IntelliSense.ts @@ -1,5 +1,6 @@  -import Iridium = require('../index'); +/// +import Iridium = require('iridium'); interface UserDoc { _id?: string; diff --git a/iridium.d.ts b/iridium.d.ts new file mode 100644 index 0000000..2f0553d --- /dev/null +++ b/iridium.d.ts @@ -0,0 +1,5 @@ +/// +declare module 'iridium' { + import Iridium = require('iridium/index'); + export = Iridium; +} \ No newline at end of file diff --git a/lib/Core.ts b/lib/Core.ts index 48a53a7..e403c12 100644 --- a/lib/Core.ts +++ b/lib/Core.ts @@ -70,24 +70,24 @@ class Core { } var hosts = []; - - if(this._config.host) { + + if (this._config.host) { if (this._config.port) hosts.push(this._config.host + ':' + this._config.port); else hosts.push(this._config.host); } - - if(this._config.hosts) { + + if (this._config.hosts) { _.each(this._config.hosts, (host) => { if (host.port) - hosts.push(host.address + ':' + host.port); - else - hosts.push(host.address); + hosts.push(host.address + ':' + host.port); + else + hosts.push(host.address); }); } - - if(hosts.length) + + if (hosts.length) url += _.uniq(hosts).join(','); else url += 'localhost'; @@ -126,14 +126,14 @@ class Core { var args = Array.prototype.slice.call(arguments, 0); uri = config = null; - for(var i = 0; i < args.length; i++) { - if(typeof args[i] == 'string') + for (var i = 0; i < args.length; i++) { + if (typeof args[i] == 'string') uri = args[i]; - else if(typeof args[i] == 'object') + else if (typeof args[i] == 'object') config = args[i]; } - if(!uri && !config) throw new Error("Expected either a URI or config object to be supplied when initializing Iridium"); + if (!uri && !config) throw new Error("Expected either a URI or config object to be supplied when initializing Iridium"); this._url = uri; this._config = config; @@ -159,7 +159,7 @@ class Core { return Bluebird.bind(this).then(function() { if (self._connection) return self._connection; return MongoConnectAsyc(self.url); - }).then(function (db: MongoDB.Db) { + }).then(function(db: MongoDB.Db) { self._connection = db; return self; }).nodeify(callback); diff --git a/package.json b/package.json index 629e6c7..0b47574 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "grunt-mocha-cli": "^1.13.0", "grunt-mocha-istanbul": "^2.4.0", "grunt-release": "^0.12.0", + "grunt-string-replace": "^1.2.0", "grunt-ts": "^4.1.0", "istanbul": "~0.3.13", "jshint": "^2.7.0",