Skip to content

Commit 91f48a6

Browse files
committed
Proper build for bower with browserify
1 parent 7e38e72 commit 91f48a6

File tree

9 files changed

+181
-69
lines changed

9 files changed

+181
-69
lines changed

gulp/build.js

+20-62
Original file line numberDiff line numberDiff line change
@@ -8,81 +8,39 @@ var buffer = require('vinyl-buffer');
88
var uglify = require('gulp-uglify');
99
var sourcemaps = require('gulp-sourcemaps');
1010
var gutil = require('gulp-util');
11-
var through = require('through2');
12-
var globby = require('globby');
1311
var config = require('./config');
1412

13+
var toplevel = 'gulp/build/toplevel.js';
14+
1515
module.exports = {
1616
browserify: function() {
17-
// gulp expects tasks to return a stream, so we create one here.
18-
var bundledStream = through();
17+
// set up the browserify instance on a task basis
18+
var b = browserify({
19+
entries: toplevel,
20+
debug: true
21+
});
1922

20-
bundledStream
21-
// turns the output bundle stream into a stream containing
22-
// the normal attributes gulp plugins expect.
23+
return b.bundle()
2324
.pipe(source('eid.js'))
24-
// the rest of the gulp task, as you would normally write it.
25-
// here we're copying from the Browserify + Uglify2 recipe.
2625
.pipe(buffer())
27-
.on('error', gutil.log)
28-
.pipe(gulp.dest(config.dist + '/browser/js'));
29-
30-
// "globby" replaces the normal "gulp.src" as Browserify
31-
// creates it's own readable stream.
32-
globby(config.sources).then(function(entries) {
33-
// create the Browserify instance.
34-
var b = browserify({
35-
entries: entries,
36-
debug: true
37-
});
38-
39-
// pipe the Browserify stream into the stream we created earlier
40-
// this starts our gulp pipeline.
41-
b.bundle().pipe(bundledStream);
42-
}).catch(function(err) {
43-
// ensure any errors from globby are handled
44-
bundledStream.emit('error', err);
45-
});
46-
47-
// finally, we return the stream, so gulp knows when this task is done.
48-
return bundledStream;
26+
.on('error', gutil.log)
27+
.pipe(gulp.dest(config.dist + '/browser/toplevel'));
4928
},
5029
minified: function() {
51-
// gulp expects tasks to return a stream, so we create one here.
52-
var bundledStream = through();
30+
// set up the browserify instance on a task basis
31+
var b = browserify({
32+
entries: toplevel,
33+
debug: true
34+
});
5335

54-
bundledStream
55-
// turns the output bundle stream into a stream containing
56-
// the normal attributes gulp plugins expect.
36+
return b.bundle()
5737
.pipe(source('eid.min.js'))
58-
// the rest of the gulp task, as you would normally write it.
59-
// here we're copying from the Browserify + Uglify2 recipe.
6038
.pipe(buffer())
6139
.pipe(sourcemaps.init({loadMaps: true}))
62-
// Add gulp plugins to the pipeline here.
63-
.pipe(uglify())
64-
.on('error', gutil.log)
40+
// Add transformation tasks to the pipeline here.
41+
.pipe(uglify())
42+
.on('error', gutil.log)
6543
.pipe(sourcemaps.write('./'))
66-
.pipe(gulp.dest(config.dist + '/browser/js'));
67-
68-
// "globby" replaces the normal "gulp.src" as Browserify
69-
// creates it's own readable stream.
70-
globby(config.sources).then(function(entries) {
71-
// create the Browserify instance.
72-
var b = browserify({
73-
entries: entries,
74-
debug: true
75-
});
76-
77-
// pipe the Browserify stream into the stream we created earlier
78-
// this starts our gulp pipeline.
79-
b.bundle().pipe(bundledStream);
80-
}).catch(function(err) {
81-
// ensure any errors from globby are handled
82-
bundledStream.emit('error', err);
83-
});
84-
85-
// finally, we return the stream, so gulp knows when this task is done.
86-
return bundledStream;
44+
.pipe(gulp.dest(config.dist + '/browser/toplevel'));
8745
}
8846
};

gulp/build/toplevel.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2016 Wave Software
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
(function(wnd) {
18+
'use strict';
19+
20+
wnd.Eid = require('../../lib/eid');
21+
wnd.EidNullPointerException = require('../../lib/eid/exceptions').EidNullPointerException;
22+
wnd.EidIllegalArgumentException = require('../../lib/eid/exceptions').EidIllegalArgumentException;
23+
wnd.EidIllegalStateException = require('../../lib/eid/exceptions').EidIllegalStateException;
24+
wnd.EidIndexOutOfBoundsException = require('../../lib/eid/exceptions').EidIndexOutOfBoundsException;
25+
wnd.EidRuntimeException = require('../../lib/eid/exceptions').EidRuntimeException;
26+
wnd.EidPreconditions = require('../../lib/eid/preconditions');
27+
})(window);

gulp/clean.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ var deleteFolderRecursive = function(path) {
2323
module.exports = function() {
2424
deleteFolderRecursive(config.target);
2525
deleteFolderRecursive(config.dist);
26-
}
26+
};

gulp/config.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
/* eslint-disable no-var, strict, prefer-arrow-callback */
22
'use strict';
33

4-
module.exports = {
5-
sources: ['lib/**/*.js'],
6-
testSources: ['test/**/*.js'],
4+
var directory = {
5+
lib: 'lib',
6+
test: 'test',
77
target: 'target',
88
dist: 'dist'
99
};
10+
11+
module.exports = {
12+
sources: [ directory.lib + '/**/*.js' ],
13+
testSources: [ directory.test + '/**/*.js' ],
14+
lib: directory.lib,
15+
test: directory.test,
16+
target: directory.target,
17+
dist: directory.dist
18+
};

gulp/serve.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint-disable no-var, strict, prefer-arrow-callback */
2+
'use strict';
3+
4+
var serve = require('gulp-serve');
5+
var config = require('./config');
6+
7+
module.exports = serve([ config.test, config.dist ]);

gulp/tests.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ module.exports = {
1616
strict: 2
1717
},
1818
env: {
19-
node: true
19+
node: true,
20+
browser: true
2021
}
2122
}))
2223
.pipe(eslint.format())
@@ -25,8 +26,9 @@ module.exports = {
2526
specs: function (done) {
2627
var prependToAll = function(path, globs) {
2728
var ret = [];
28-
for (var v of globs) {
29-
ret.push(path + '/' + v);
29+
for (var i = 0; i < globs.length; i++) {
30+
var value = globs[i];
31+
ret.push(path + '/' + value);
3032
}
3133
return ret;
3234
};

gulpfile.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var gulp = require('gulp');
66
var tests = require('./gulp/tests');
77
var build = require('./gulp/build');
88
var clean = require('./gulp/clean');
9+
var serve = require('./gulp/serve');
910

1011
gulp.task('clean', clean);
1112
gulp.task('lint', tests.lint);
@@ -16,5 +17,6 @@ gulp.task('watch', function() {
1617
});
1718
gulp.task('build-browser', ['test'], build.browserify);
1819
gulp.task('build-minified', ['test'], build.minified);
20+
gulp.task('serve', serve);
1921
gulp.task('build', ['build-browser', 'build-minified']);
2022
gulp.task('default', ['test', 'build']);

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"gulp-coverage": "^0.3.38",
1616
"gulp-eslint": "^1.1.1",
1717
"gulp-mocha": "^2.2.0",
18+
"gulp-serve": "^1.2.0",
1819
"gulp-sourcemaps": "^1.6.0",
1920
"gulp-uglify": "^1.5.1",
2021
"gulp-util": "^3.0.7",

test/index.html

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>ExceptionID.js - manual test page</title>
6+
<link rel="stylesheet" type="text/css" href="https://raw.githubusercontent.com/twbs/bootstrap/master/dist/css/bootstrap.min.css" />
7+
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/styles/default.min.css">
8+
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/highlight.min.js"></script>
9+
<script type="application/javascript" src="browser/toplevel/eid.min.js"></script>
10+
<style type="text/css">
11+
@import url(https://fonts.googleapis.com/css?family=PT+Sans|Source+Code+Pro);
12+
body {
13+
font-family: 'PT Sans', sans-serif;
14+
font-size: 1.3em;
15+
padding: 1em;
16+
}
17+
pre, code {
18+
font-family: 'Source Code Pro', monospace;
19+
}
20+
pre#console {
21+
display:block;
22+
font:normal 1em/1.5em 'Source Code Pro', monospace;
23+
color: #CFDBEC;
24+
background-color:#2f2f2f;
25+
background-image:-webkit-repeating-linear-gradient(top, #353535 0em, #353535 1.5em, #2f2f2f 1.5em, #2f2f2f 3em);
26+
background-image:-moz-repeating-linear-gradient(top, #353535 0em, #353535 1.5em, #2f2f2f 1.5em, #2f2f2f 3em);
27+
background-image:-ms-repeating-linear-gradient(top, #353535 0em, #353535 1.5em, #2f2f2f 1.5em, #2f2f2f 3em);
28+
background-image:-o-repeating-linear-gradient(top, #353535 0em, #353535 1.5em, #2f2f2f 1.5em, #2f2f2f 3em);
29+
background-image:repeating-linear-gradient(top, #353535 0em, #353535 1.5em, #2f2f2f 1.5em, #2f2f2f 3em);
30+
padding:0em 1em;
31+
overflow:auto;
32+
white-space: pre-wrap;
33+
}
34+
</style>
35+
</head>
36+
<body>
37+
<h1>ExceptionID.js - showcase</h1>
38+
39+
<h3>Code:</h3>
40+
<pre><code class="javascript" id="code">
41+
try {
42+
// Example entity objects
43+
var users = [];
44+
for (var i = 0; i < 5; i++) {
45+
var user = { id: 67112 - i };
46+
user.toString = function() { return '[User id=' + this.id + ']'; };
47+
users.push(user);
48+
}
49+
50+
// logging support
51+
for (var i = 0; i < users.length; i++) {
52+
var user = users[i];
53+
var eid = new Eid('20160111:223928', 'WJS-17');
54+
log.debug(eid.makeLogMessage('An entity: %s', user));
55+
log.debug(eid.makeLogMessage('%s has even ID: %s', user, user.id % 2 === 0));
56+
}
57+
58+
// preconditions!
59+
EidPreconditions.checkArgument(true, '20160111:223749');
60+
EidPreconditions.checkState(false, '20160111:224215', 'A extra message');
61+
} catch(e) {
62+
// Top level of your application
63+
log.error(e.toString() + ' - ' + e.stack);
64+
// or better save your exceptions!
65+
logGateway.put(e, {eid: e.eid});
66+
}
67+
</code></pre>
68+
<h3>Console:</h3>
69+
<pre id="console"></pre>
70+
<script type="application/javascript">
71+
(function() {
72+
var line = 1;
73+
function pad(n, width, z) {
74+
z = z || '0';
75+
n = n + '';
76+
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
77+
}
78+
var println = function(message) {
79+
var pre = document.getElementById('console');
80+
pre.textContent += message + "\n";
81+
};
82+
var logentry = function(level, msg) {
83+
var date = new Date().toISOString().slice(0, 23);
84+
println(pad(line, 3) + ': ' + level + ' ' + date + ' ' + msg);
85+
line += 1;
86+
};
87+
var log = {
88+
debug: function(message) {
89+
logentry('DEBUG', message);
90+
},
91+
error: function(message) {
92+
logentry('ERROR', message);
93+
}
94+
};
95+
var logGateway = {
96+
put: function(ex, extra) {
97+
logentry('INFO', 'LogzGetewayFake.io sucessfully PUT an exception: `' + ex.toString() + '` with extra data of: `' + JSON.stringify(extra) + '`');
98+
}
99+
};
100+
var code = document.getElementById('code').textContent;
101+
eval(code);
102+
hljs.initHighlightingOnLoad();
103+
})();
104+
</script>
105+
</body>
106+
</html>

0 commit comments

Comments
 (0)