-
Notifications
You must be signed in to change notification settings - Fork 99
/
gulpfile.js
173 lines (134 loc) · 3.94 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
'use strict';
var fs = require('fs');
var path = require('path');
var es = require('event-stream');
var globby = require('globby');
var gulp = require('gulp');
var assign = require('lodash.assign');
// load plugins
var browserSync = require('browser-sync').create();
var concat = require('gulp-concat');
var del = require('del');
var gulpif = require('gulp-if');
var order = require('gulp-order');
var requirejsOptimize = require('gulp-requirejs-optimize');
var runSequence = require('run-sequence');
var size = require('gulp-size');
var xo = require('gulp-xo');
var reload = browserSync.reload;
var generateShims = require('./gulp/generate-shims');
var processShaders = require('./gulp/process-shaders');
var runLint = function(src) {
return gulp.src(src)
.pipe(xo());
};
gulp.task('lint', function() {
return runLint(['lib/**/*.js', 'gulp/**/*.js', 'gulpfile.js']);
});
gulp.task('shaders', function() {
return gulp.src('lib/**/*.glsl')
.pipe(processShaders())
.pipe(gulp.dest('.tmp/shaders'));
});
gulp.task('create-main-js', function() {
return gulp.src(['lib/**/*.js'])
.pipe(gulpif('!main.js', generateShims()))
.pipe(order([
'!main.js',
'main.js'
]))
.pipe(concat('main.js'))
.pipe(gulp.dest('.tmp'));
});
function getCopyrightHeaders() {
var copyrightHeader = fs.readFileSync('lib/copyright-header.js').toString();
var shaderCopyrightHeader = fs.readFileSync('.tmp/shaders/shader-copyright-header.js').toString();
return copyrightHeader + '\n' + shaderCopyrightHeader;
}
function optimize(options) {
var source = path.join(options.baseUrl, options.include) + '.js';
return gulp.src(source)
.pipe(requirejsOptimize(options));
}
gulp.task('scripts', ['create-main-js', 'shaders'], function() {
var copyright = getCopyrightHeaders();
var requirejsOptions = {
name: '../node_modules/almond/almond',
wrap: {
start: copyright + '(function() {',
end: '})();'
},
useStrict: true,
inlineText: true,
stubModules: ['text'],
skipModuleInsertion: true,
baseUrl: 'lib',
include: '../.tmp/main',
paths: {
text: '../node_modules/requirejs-text/text'
}
};
var unminified = optimize(assign({}, requirejsOptions, {
out: 'cesium-sensor-volumes.js',
optimize: 'none'
}));
var minifiedOptions = assign({}, requirejsOptions, {
out: 'cesium-sensor-volumes.min.js',
optimize: 'uglify2'
});
// Use minified versions of shaders
globby.sync(['lib/**/*.glsl']).forEach(function(shader) {
shader = path.relative('lib', shader).replace(/\\/g, '/').replace(/\.glsl$/, '');
minifiedOptions.paths[shader] = path.join('../.tmp/shaders', shader);
});
var minified = optimize(minifiedOptions);
return es.merge(unminified, minified)
.pipe(gulp.dest('dist'));
});
gulp.task('clean', del.bind(null, ['coverage', '.tmp', 'dist']));
gulp.task('test-lint', function() {
return runLint(['test/**/*.js']);
});
function test(done, options) {
var Server = require('karma').Server;
var server = new Server(assign({
configFile: path.join(__dirname, '/test/karma.conf.js'),
singleRun: true
}, options), done);
server.start();
}
gulp.task('test', ['test-lint'], function(done) {
test(done);
});
gulp.task('test-ci', ['test-lint'], function(done) {
test(done, {
browsers: ['Electron'],
client: {
args: [true]
}
});
});
gulp.task('serve', function(done) {
runSequence('build', 'run', 'watch', done);
});
gulp.task('run', function(done) {
browserSync.init({
server: '.'
}, done);
});
gulp.task('watch', function() {
gulp.watch(['examples/**/*.html', 'examples/**/*.czml'], reload);
gulp.watch(['lib/**/*.glsl'], ['build-reload']);
gulp.watch(['lib/**/*.js'], ['build-reload']);
});
gulp.task('build-reload', ['build'], reload);
gulp.task('build', ['lint', 'scripts'], function() {
return gulp.src('dist/**/*')
.pipe(size({ title: 'build', gzip: true }));
});
gulp.task('ci', function(done) {
runSequence('lint', 'test-ci', 'build', done);
});
gulp.task('default', function(done) {
runSequence('clean', 'build', done);
});