Skip to content

Commit d343cf6

Browse files
committed
Get some reading GH reading done
1 parent 627a22c commit d343cf6

File tree

18 files changed

+4503
-560
lines changed

18 files changed

+4503
-560
lines changed

gulpfile.js

Lines changed: 142 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ var http = require('http');
2323
var open = require('open');
2424
var path = require('path');
2525

26+
var execFile = require('child_process').execFile;
27+
var fs = require('fs');
28+
2629
/**
2730
* Tasks:
2831
*
@@ -45,170 +48,208 @@ var path = require('path');
4548
gulp.task('default', ['build']);
4649
gulp.task('build', ['css', 'less', 'bad-scripts', 'workers', 'lint', 'scripts', 'resources', 'html', 'docs']);
4750
gulp.task('develop', ['build', 'serve', 'livereload']);
51+
gulp.task('tdd', ['serve-specs', 'livereload-tests']);
4852

4953

5054
/**
5155
* path globs / expressions for targets below
5256
*/
5357

5458
var paths = {
55-
main : 'js/client.js',
56-
sources : 'js/**/*.js',
57-
jsx : 'js/**/*.jsx',
58-
badScripts: ['vendor/bluebird.js', 'vendor/laz-perf.js'],
59-
workers: 'workers/**',
60-
resources: 'resources/**',
61-
css : 'less/**/*.css',
62-
less : 'less/style.less',
63-
jade : 'client/**/*.jade',
64-
html : '*.html',
65-
docs : 'docs/**/*',
66-
build : './build/'
59+
main : 'js/client.js',
60+
sources : 'js/**/*.js',
61+
jsx : 'js/**/*.jsx',
62+
specs : 'test/spec/specs.js',
63+
badScripts: ['vendor/bluebird.js', 'vendor/laz-perf.js'],
64+
workers: 'workers/**',
65+
resources: 'resources/**',
66+
css : 'less/**/*.css',
67+
less : 'less/style.less',
68+
jade : 'client/**/*.jade',
69+
html : '*.html',
70+
docs : 'docs/**/*',
71+
build : './build/'
6772
};
6873

6974

7075
//clean build directory
7176
gulp.task('clean', function(){
72-
return gulp.src(paths.client.build, {read: false} )
73-
.pipe(clean());
77+
return gulp.src(paths.client.build, {read: false} )
78+
.pipe(clean());
7479
});
7580

7681
gulp.task('resources', function() {
77-
return gulp.src(paths.resources)
78-
.pipe(gulp.dest(paths.build));
82+
return gulp.src(paths.resources)
83+
.pipe(gulp.dest(paths.build));
7984
});
8085

8186
// lint all of our js source files
8287
gulp.task('lint', function (){
83-
return gulp.src(paths.sources)
88+
return gulp.src(paths.sources)
8489
.pipe(jshint({
85-
"smarttabs": true
86-
}))
90+
"smarttabs": true
91+
}))
8792
.pipe(jshint.reporter('default'));
8893
});
8994

90-
var startServer = function(cb) {
91-
var devApp, devServer, devAddress, devHost, url, log=gutil.log, colors=gutil.colors;
92-
devApp = connect();
93-
devApp.use(connect.logger('dev'));
94-
devApp.use(connect.static(paths.build));
95-
devServer = http.createServer(devApp).listen(8000);
96-
devServer.on('error', function(error) {
97-
log(colors.underline(colors.red('ERROR'))+' Unable to start server!');
98-
cb(error);
99-
});
100-
101-
devServer.on('listening', function() {
102-
devAddress = devServer.address();
103-
devHost = devAddress.address === '0.0.0.0' ? 'localhost' : devAddress.address;
104-
url = 'http://' + devHost + ':' + devAddress.port + '/index.html';
105-
106-
log('');
107-
log('Started dev server at '+colors.magenta(url));
108-
open(url);
109-
cb();
110-
});
95+
var startServer = function(path, cb) {
96+
var devApp, devServer, devAddress, devHost, url, log=gutil.log, colors=gutil.colors;
97+
devApp = connect();
98+
devApp.use(connect.logger('dev'));
99+
devApp.use(connect.static(path));
100+
devServer = http.createServer(devApp).listen(8000);
101+
devServer.on('error', function(error) {
102+
log(colors.underline(colors.red('ERROR'))+' Unable to start server!');
103+
cb(error);
104+
});
105+
106+
devServer.on('listening', function() {
107+
devAddress = devServer.address();
108+
devHost = devAddress.address === '0.0.0.0' ? 'localhost' : devAddress.address;
109+
url = 'http://' + devHost + ':' + devAddress.port + '/' + 'index.html';
110+
111+
log('');
112+
log('Started dev server at '+colors.magenta(url));
113+
open(url);
114+
cb();
115+
});
111116
};
112117

113118
gulp.task('serve', ['build'], function(cb) {
114-
startServer(cb);
119+
startServer('build', cb);
120+
});
121+
122+
gulp.task('serve-specs', ['build-specs'], function(cb) {
123+
startServer('test', cb);
115124
});
116125

117126
gulp.task('watch', ['build'], function() {
118-
// watch all our dirs and reload if any build stuff changes
119-
//
120-
gulp.watch(paths.sources, ['lint', 'scripts']);
121-
gulp.watch(paths.html, ['html']);
122-
gulp.watch(paths.less, ['less']);
123-
gulp.watch(paths.docs, ['docs']);
124-
gulp.watch(paths.workers, ['workers']);
125-
gulp.watch(paths.resources, ['resources']);
126-
})
127+
// watch all our dirs and reload if any build stuff changes
128+
//
129+
gulp.watch(paths.sources, ['lint', 'scripts']);
130+
gulp.watch(paths.html, ['html']);
131+
gulp.watch(paths.less, ['less']);
132+
gulp.watch(paths.docs, ['docs']);
133+
gulp.watch(paths.workers, ['workers']);
134+
gulp.watch(paths.resources, ['resources']);
135+
});
127136

128137
gulp.task('livereload', ['watch'], function() {
129-
var server = livereload();
130-
return gulp.watch(path.join(paths.build, "/**/*"), function(evt) {
131-
server.changed(evt.path);
132-
});
138+
var server = livereload();
139+
return gulp.watch(path.join(paths.build, "/**/*"), function(evt) {
140+
server.changed(evt.path);
141+
});
142+
});
143+
144+
gulp.task('livereload-tests', ['watch-specs'], function() {
145+
var server = livereload();
146+
147+
return gulp.watch("test/build/**/*", function(evt) {
148+
server.changed(evt.path);
149+
});
133150
});
134151

135152
gulp.task('bad-scripts', function() {
136-
return gulp.src(paths.badScripts)
137-
.pipe(concat("bad.js"))
138-
.pipe(gulp.dest(paths.build));
153+
return gulp.src(paths.badScripts)
154+
.pipe(concat("bad.js"))
155+
.pipe(gulp.dest(paths.build));
156+
});
157+
158+
// build client side js app
159+
gulp.task('build-specs', function(){
160+
return gulp.src([paths.specs])
161+
.pipe(browserify())
162+
.on("error", gutil.log)
163+
.on("error", gutil.beep)
164+
.pipe(gulp.dest("test/build"));
165+
});
166+
167+
168+
gulp.task('watch-specs', function() {
169+
gulp.watch([paths.sources, 'test/spec/**/*.js'], ['build-specs']);
139170
});
140171

141172
// build client side js app
142173
gulp.task('scripts', function(){
143-
return gulp.src([paths.main, paths.jsx])
144-
.pipe(browserify({
145-
debug: gulp.env.production,
146-
transform: ['reactify']
147-
}))
148-
.on("error", gutil.log)
149-
.on("error", gutil.beep)
150-
.pipe(gulp.dest(paths.build));
174+
return gulp.src([paths.main, paths.jsx])
175+
.pipe(browserify({
176+
debug: gulp.env.production,
177+
transform: ['reactify']
178+
}))
179+
.on("error", gutil.log)
180+
.on("error", gutil.beep)
181+
.pipe(gulp.dest(paths.build));
151182
});
152183

153184
gulp.task('css', function() {
154-
return gulp.src(paths.css).
155-
pipe(concat('all.css')).
156-
pipe(gulp.dest(path.join(paths.build, 'css')));
185+
return gulp.src(paths.css).
186+
pipe(concat('all.css')).
187+
pipe(gulp.dest(path.join(paths.build, 'css')));
157188
});
158189

159190
gulp.task('less', function() {
160-
return gulp.src(paths.less).
161-
pipe(less({
162-
paths: ['./less/']
163-
})).
164-
pipe(gulp.dest(path.join(paths.build, 'css')));
191+
return gulp.src(paths.less).
192+
pipe(less({
193+
paths: ['./less/']
194+
})).
195+
pipe(gulp.dest(path.join(paths.build, 'css')));
165196
});
166197

167198
gulp.task('html', function() {
168-
return gulp.src(paths.html).
169-
pipe(gulp.dest(paths.build));
199+
return gulp.src(paths.html).
200+
pipe(gulp.dest(paths.build));
170201
});
171202

172203
gulp.task('clean', function() {
173-
return gulp.src(paths.build, { read: false })
174-
.pipe(clean());
204+
return gulp.src(paths.build, { read: false })
205+
.pipe(clean());
175206
});
176207

177-
gulp.task('uglify-built', ['build'], function() {
178-
return gulp.src(path.join(paths.build, 'client.js')).
179-
pipe(uglify({outSourceMap: true})).
180-
pipe(gulp.dest(paths.build));
208+
gulp.task('optimize', ['build'], function(cb) {
209+
var input = path.join(paths.build, 'client.js');
210+
var tmp = path.join(paths.build, 'client.tmp.js');
211+
212+
execFile('java', [
213+
'-jar', 'vendor/closure-compiler/compiler.jar',
214+
'--js', input,
215+
'--language_in', 'ECMASCRIPT5',
216+
'--compilation_level', 'SIMPLE_OPTIMIZATIONS',
217+
'--js_output_file', tmp],
218+
{maxBuffer: (1000*4096)},
219+
function(err, stdout, stderr) {
220+
if (err)
221+
return cb(err);
222+
223+
fs.unlinkSync(input);
224+
fs.renameSync(tmp, input);
225+
226+
cb();
227+
});
181228
});
182229

183230
gulp.task('docs', function() {
184-
return gulp.src(paths.docs).
185-
pipe(gulp.dest(path.join(paths.build, 'docs')));
231+
return gulp.src(paths.docs).
232+
pipe(gulp.dest(path.join(paths.build, 'docs')));
186233
});
187234

188235
gulp.task('workers', function() {
189-
return gulp.src(paths.workers).
190-
pipe(gulp.dest(path.join(paths.build, 'workers')));
236+
return gulp.src(paths.workers).
237+
pipe(gulp.dest(path.join(paths.build, 'workers')));
191238
});
192239

193-
gulp.task('prod-react-built', ['build'], function() {
194-
return gulp.src(path.join(paths.build, 'index.html')).
195-
pipe(htmlreplace({
196-
reactjs: '//cdnjs.cloudflare.com/ajax/libs/react/0.10.0/react-with-addons.min.js'
197-
})).
198-
pipe(gulp.dest(paths.build));
199-
});
240+
gulp.task('prod-build', ['build', 'optimize']);
200241

201-
gulp.task('publish', ['build', 'uglify-built', 'prod-react-built'], function() {
202-
var homeDir = process.env['HOME'];
203-
var settings = require(path.join(homeDir, ".aws.json"));
242+
gulp.task('publish', ['prod-build'], function() {
243+
var homeDir = process.env['HOME'];
244+
var settings = require(path.join(homeDir, ".aws.json"));
204245

205-
settings.bucket = "plas.io";
246+
settings.bucket = "plas.io";
206247

207-
var publisher = awspublish.create(settings);
248+
var publisher = awspublish.create(settings);
208249

209-
return gulp.src(paths.build + "/**/*")
210-
.pipe(publisher.publish())
211-
.pipe(publisher.sync())
212-
.pipe(awspublish.reporter());
250+
return gulp.src(paths.build + "/**/*")
251+
.pipe(publisher.publish())
252+
.pipe(publisher.sync())
253+
.pipe(awspublish.reporter());
213254
});
214255

index.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ <h5>Pick your own or click the dropdown for some examples</h5>
7171
<a data-toggle="modal" href="#" data-target="#creditsPage">Data Credits</a>
7272
</div>
7373
<h5>Open a Greyhound Source</h5>
74-
<button type="button" class="btn btn-sm btn-block btn-default" id="openGreyhoundButton">
75-
Open
76-
</button>
74+
<div id="openGreyhoundButton">
75+
</div>
7776
</div>
7877

7978
<div class="labeled-controls">
@@ -358,9 +357,6 @@ <h4 class="modal-title">plasio Documentation</h4>
358357
</div>
359358

360359

361-
<!-- build:reactjs -->
362-
<script src="http://fb.me/react-with-addons-0.10.0.js"></script>
363-
<!-- endbuild -->
364360
<script src="bad.js"></script>
365361
<script src="client.js"></script>
366362
<script type="x-shader/x-vertex" id="vertexshader">

0 commit comments

Comments
 (0)