Skip to content

Commit

Permalink
Improve reference file when packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed May 18, 2015
1 parent e686cd3 commit b513589
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ node_modules/
dist/
*.tmp
coverage/
*.d.ts
typings/**/*.d.ts
.tscache
43 changes: 39 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
},
Expand Down Expand Up @@ -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: /(\/\/\/ <reference path="\.\/typings\/tsd.d.ts" \/>)/gi,
replacement: '//$1'
}]
}
},
developmentDependencies: {
files: { "_references.d.ts": "_references.d.ts" },
options: {
replacements: [{
pattern: /\/\/(\/\/\/ <reference path="\.\/typings\/tsd.d.ts" \/>)/gi,
replacement: '$1'
}]
}
}
}
});

Expand All @@ -91,12 +117,21 @@ 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');

grunt.registerTask("default", ["clean", "ts:dev"]);
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"]);
};
1 change: 0 additions & 1 deletion _references.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference path="./typings/tsd.d.ts" />
/// <reference path="./typings/skmatc/skmatc.d.ts" />
/// <reference path="./typings/bluebird/bluebird.d.ts" />
/// <reference path="./typings/concoction/concoction.d.ts" />
3 changes: 2 additions & 1 deletion example/IntelliSense.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import Iridium = require('../index');
/// <reference path="../iridium.d.ts" />
import Iridium = require('iridium');

interface UserDoc {
_id?: string;
Expand Down
5 changes: 5 additions & 0 deletions iridium.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference path="index.ts" />
declare module 'iridium' {
import Iridium = require('iridium/index');
export = Iridium;
}
28 changes: 14 additions & 14 deletions lib/Core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = <string>uri;
this._config = config;
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b513589

Please sign in to comment.