forked from TerriaJS/terriajs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
168 lines (133 loc) · 5.16 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
/*eslint-env node*/
/*eslint no-sync: 0*/
'use strict';
/*global require*/
// Every module required-in here must be a `dependency` in package.json, not just a `devDependency`,
// so that our postinstall script (which runs `gulp post-npm-install`) is able to run without
// the devDependencies available. Individual tasks, other than `post-npm-install` and any tasks it
// calls, may require in `devDependency` modules locally.
var gulp = require('gulp');
gulp.task('default', ['lint', 'build']);
gulp.task('build', ['build-specs', 'copy-cesium-assets']);
gulp.task('release', ['release-specs', 'copy-cesium-assets', 'make-schema']);
gulp.task('watch', ['watch-specs', 'copy-cesium-assets']);
gulp.task('post-npm-install', ['copy-cesium-assets']);
gulp.task('build-specs', function(done) {
var runWebpack = require('./buildprocess/runWebpack.js');
var webpack = require('webpack');
var webpackConfig = require('./buildprocess/webpack.config.js');
runWebpack(webpack, webpackConfig, done);
});
gulp.task('release-specs', function(done) {
var runWebpack = require('./buildprocess/runWebpack.js');
var webpack = require('webpack');
var webpackConfig = require('./buildprocess/webpack.config.js');
runWebpack(webpack, Object.assign({}, webpackConfig, {
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin()
].concat(webpackConfig.plugins || [])
}), done);
});
gulp.task('watch-specs', function(done) {
var watchWebpack = require('./buildprocess/watchWebpack');
var webpack = require('webpack');
var webpackConfig = require('./buildprocess/webpack.config.js');
watchWebpack(webpack, webpackConfig, done);
});
gulp.task('make-schema', function() {
var genSchema = require('generate-terriajs-schema');
return genSchema({
source: '.',
dest: 'wwwroot/schema',
noversionsubdir: true,
quiet: true
});
});
gulp.task('lint', function() {
var runExternalModule = require('./buildprocess/runExternalModule');
runExternalModule('eslint/bin/eslint.js', [
'lib', 'test',
'--ignore-pattern', 'lib/ThirdParty',
'--max-warnings', '0'
]);
});
// Create a single .js file with all of TerriaJS + Cesium!
gulp.task('build-libs', function(done) {
var fs = require('fs');
var glob = require('glob-all');
var path = require('path');
var runWebpack = require('./buildprocess/runWebpack.js');
var webpack = require('webpack');
var webpackConfig = require('./buildprocess/webpack.lib.config.js');
// Build an index.js to export all of the modules.
var index = '';
index += '\'use strict\'\n';
index += '\n';
index += '/*global require*/\n';
index += '\n';
index += 'module.exports = {};\n';
index += 'module.exports.Cesium = require(\'terriajs-cesium/Source/Cesium\');\n';
var modules = glob.sync([
'./lib/**/*.js',
'./lib/**/*.ts',
'!./lib/CopyrightModule.js',
'!./lib/cesiumWorkerBootstrapper.js',
'!./lib/ThirdParty/**',
'!./lib/SvgPaths/**'
]);
var directories = {};
modules.forEach(function(filename) {
var module = filename.substring(0, filename.length - path.extname(filename).length);
var moduleName = path.relative('./lib', module);
moduleName = moduleName.replace(path.sep, '/');
var moduleParts = moduleName.split('/');
for (var i = 0; i < moduleParts.length - 1; ++i) {
var propertyName = moduleParts.slice(0, i + 1).join('.');
if (!directories[propertyName]) {
directories[propertyName] = true;
index += 'module.exports.' + propertyName + ' = {};\n';
}
}
index += 'module.exports.' + moduleParts.join('.') + ' = require(\'' + module + '\');\n';
});
fs.writeFileSync('terria.lib.js', index);
runWebpack(webpack, webpackConfig, done);
});
gulp.task('docs', function() {
var runExternalModule = require('./buildprocess/runExternalModule');
runExternalModule('jsdoc/jsdoc.js', [
'./lib',
'-c', './buildprocess/jsdoc.json'
]);
});
gulp.task('copy-cesium-assets', function() {
var path = require('path');
var cesiumPackage = require.resolve('terriajs-cesium/package.json');
var cesiumRoot = path.dirname(cesiumPackage);
var cesiumWebRoot = path.join(cesiumRoot, 'wwwroot');
return gulp.src([
path.join(cesiumWebRoot, '**')
], {
base: cesiumWebRoot
}).pipe(gulp.dest('wwwroot/build/Cesium'));
});
gulp.task('test-browserstack', function(done) {
runKarma('./buildprocess/karma-browserstack.conf.js', done);
});
gulp.task('test-saucelabs', function(done) {
runKarma('./buildprocess/karma-saucelabs.conf.js', done);
});
gulp.task('test', function(done) {
runKarma('./buildprocess/karma-local.conf.js', done);
});
function runKarma(configFile, done) {
var karma = require('karma').Server;
var path = require('path');
karma.start({
configFile: path.join(__dirname, configFile)
}, function(e) {
return done(e);
});
}