Skip to content

Commit 8f895f7

Browse files
committed
Preconditions implemented
1 parent b5a9269 commit 8f895f7

5 files changed

Lines changed: 334 additions & 29 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ coverage
2121

2222
# Compiled binary addons (http://nodejs.org/api/addons.html)
2323
build/Release
24+
dist
2425

2526
# Dependency directory
2627
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git

‎gulpfile.js‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ var gulp = require('gulp');
55
var eslint = require('gulp-eslint');
66
var mocha = require('gulp-mocha');
77
var cover = require('gulp-coverage');
8+
var browserify = require('browserify');
9+
var source = require('vinyl-source-stream');
10+
var buffer = require('vinyl-buffer');
11+
var uglify = require('gulp-uglify');
12+
var sourcemaps = require('gulp-sourcemaps');
13+
var gutil = require('gulp-util');
14+
var through = require('through2');
15+
var globby = require('globby');
816

917
var sources = ['./lib/**/*.js'];
1018
var testSources = ['./test/**/*.js'];
@@ -35,4 +43,42 @@ gulp.task('test', [], function (done) {
3543
gulp.task('watch', function() {
3644
gulp.watch(sources.concat(testSources), ['test']);
3745
});
38-
gulp.task('default', ['lint', 'test']);
46+
gulp.task('build', function() {
47+
// gulp expects tasks to return a stream, so we create one here.
48+
var bundledStream = through();
49+
50+
bundledStream
51+
// turns the output bundle stream into a stream containing
52+
// the normal attributes gulp plugins expect.
53+
.pipe(source('eid.js'))
54+
// the rest of the gulp task, as you would normally write it.
55+
// here we're copying from the Browserify + Uglify2 recipe.
56+
.pipe(buffer())
57+
.pipe(sourcemaps.init({loadMaps: true}))
58+
// Add gulp plugins to the pipeline here.
59+
.pipe(uglify())
60+
.on('error', gutil.log)
61+
.pipe(sourcemaps.write('./'))
62+
.pipe(gulp.dest('./dist/js/'));
63+
64+
// "globby" replaces the normal "gulp.src" as Browserify
65+
// creates it's own readable stream.
66+
globby(['./lib/**/*.js']).then(function(entries) {
67+
// create the Browserify instance.
68+
var b = browserify({
69+
entries: entries,
70+
debug: true
71+
});
72+
73+
// pipe the Browserify stream into the stream we created earlier
74+
// this starts our gulp pipeline.
75+
b.bundle().pipe(bundledStream);
76+
}).catch(function(err) {
77+
// ensure any errors from globby are handled
78+
bundledStream.emit('error', err);
79+
});
80+
81+
// finally, we return the stream, so gulp knows when this task is done.
82+
return bundledStream;
83+
});
84+
gulp.task('default', ['lint', 'test', 'build']);

‎lib/eid/exceptions.js‎

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
'use strict';
22

33
var Eid = require('../eid');
4-
4+
var commonExConstructor = function(eid, message) {
5+
if (!(eid instanceof Eid)) {
6+
eid = new Eid(eid.toString());
7+
}
8+
this.message = message !== undefined ? (eid + " " + message) : eid;
9+
this.eid = eid;
10+
}
511
var EidRuntimeException = (function() {
612
/**
713
* <strong>This class shouldn't be used in any public API or library.</strong> It is designed to be used for in-house development
@@ -22,12 +28,8 @@ var EidRuntimeException = (function() {
2228
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
2329
*/
2430
function EidRuntimeException(eid, message) {
25-
if (!(eid instanceof Eid)) {
26-
eid = new Eid(eid.toString());
27-
}
2831
this.name = 'EidRuntimeException';
29-
this.message = eid + " " + message;
30-
this.eid = eid;
32+
commonExConstructor.apply(this, [eid, message]);
3133
}
3234
EidRuntimeException.prototype = new Error();
3335
return EidRuntimeException;
@@ -48,12 +50,8 @@ var EidNullPointerException = (function() {
4850
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
4951
*/
5052
function EidNullPointerException(eid, message) {
51-
if (!(eid instanceof Eid)) {
52-
eid = new Eid(eid.toString());
53-
}
5453
this.name = 'EidNullPointerException';
55-
this.message = eid + " " + message;
56-
this.eid = eid;
54+
commonExConstructor.apply(this, [eid, message]);
5755
}
5856
EidNullPointerException.prototype = EidRuntimeException.prototype;
5957
return EidNullPointerException;
@@ -74,12 +72,8 @@ var EidIllegalArgumentException = (function() {
7472
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
7573
*/
7674
function EidIllegalArgumentException(eid, message) {
77-
if (!(eid instanceof Eid)) {
78-
eid = new Eid(eid.toString());
79-
}
8075
this.name = 'EidIllegalArgumentException';
81-
this.message = eid + " " + message;
82-
this.eid = eid;
76+
commonExConstructor.apply(this, [eid, message]);
8377
}
8478
EidIllegalArgumentException.prototype = EidRuntimeException.prototype;
8579
return EidIllegalArgumentException;
@@ -100,12 +94,8 @@ var EidIllegalStateException = (function() {
10094
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
10195
*/
10296
function EidIllegalStateException(eid, message) {
103-
if (!(eid instanceof Eid)) {
104-
eid = new Eid(eid.toString());
105-
}
10697
this.name = 'EidIllegalStateException';
107-
this.message = eid + " " + message;
108-
this.eid = eid;
98+
commonExConstructor.apply(this, [eid, message]);
10999
}
110100
EidIllegalStateException.prototype = EidRuntimeException.prototype;
111101
return EidIllegalStateException;
@@ -126,12 +116,8 @@ var EidIndexOfOfBoundsException = (function() {
126116
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
127117
*/
128118
function EidIndexOfOfBoundsException(eid, message) {
129-
if (!(eid instanceof Eid)) {
130-
eid = new Eid(eid.toString());
131-
}
132119
this.name = 'EidIndexOfOfBoundsException';
133-
this.message = eid + " " + message;
134-
this.eid = eid;
120+
commonExConstructor.apply(this, [eid, message]);
135121
}
136122
EidIndexOfOfBoundsException.prototype = EidRuntimeException.prototype;
137123
return EidIndexOfOfBoundsException;

0 commit comments

Comments
 (0)