2015-10-17 05:30:14 +08:00
|
|
|
/*jslint node: true, latedef: nofunc*/
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
|
var path = require('path');
|
|
|
|
|
var os = require('os');
|
|
|
|
|
var child_process = require('child_process');
|
|
|
|
|
|
|
|
|
|
var globby = require('globby');
|
|
|
|
|
var jshint = require('gulp-jshint');
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var rimraf = require('rimraf');
|
|
|
|
|
var stripComments = require('strip-comments');
|
|
|
|
|
var mkdirp = require('mkdirp');
|
|
|
|
|
var eventStream = require('event-stream');
|
|
|
|
|
var gulp = require('gulp');
|
|
|
|
|
var gulpInsert = require('gulp-insert');
|
|
|
|
|
var gulpZip = require('gulp-zip');
|
|
|
|
|
var gulpRename = require('gulp-rename');
|
|
|
|
|
var gulpReplace = require('gulp-replace');
|
2015-10-19 01:03:20 +08:00
|
|
|
var Promise = require('bluebird');
|
|
|
|
|
var requirejs = require('requirejs');
|
2015-10-17 05:30:14 +08:00
|
|
|
|
|
|
|
|
var packageJson = require('./package.json');
|
|
|
|
|
|
|
|
|
|
//Gulp doesn't seem to have a way to get the currently running tasks for setting
|
|
|
|
|
//per-task variables. We use the command line argument here to detect which task is being run.
|
2015-10-22 06:08:57 +08:00
|
|
|
var taskName = process.argv[2];
|
|
|
|
|
var noDevelopmentGallery = taskName === 'release' || taskName === 'makeZipFile';
|
|
|
|
|
var copyUnminified = taskName === 'combine' || taskName === 'default' || taskName === undefined;
|
2015-10-23 01:30:43 +08:00
|
|
|
var minifyShaders = taskName === 'minify' || taskName === 'minifyRelease' || taskName === 'release' || taskName === 'makeZipFile' || taskName === 'buildApps';
|
2015-10-17 05:30:14 +08:00
|
|
|
|
2015-10-19 02:36:55 +08:00
|
|
|
var version = packageJson.version;
|
|
|
|
|
if (/\.0$/.test(version)) {
|
|
|
|
|
version = version.substring(0, version.length - 2);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-17 05:30:14 +08:00
|
|
|
var sourceFiles = ['Source/**/*.js',
|
|
|
|
|
'!Source/*.js',
|
|
|
|
|
'!Source/Workers/**',
|
|
|
|
|
'!Source/ThirdParty/Workers/**',
|
|
|
|
|
'Source/Workers/createTaskProcessorWorker.js'];
|
|
|
|
|
|
2015-10-19 06:01:56 +08:00
|
|
|
var buildFiles = ['Specs/**/*.js',
|
|
|
|
|
'!Specs/SpecList.js',
|
|
|
|
|
'Source/Shaders/**/*.glsl'];
|
|
|
|
|
|
2015-10-17 05:30:14 +08:00
|
|
|
var jsHintFiles = ['Source/**/*.js',
|
|
|
|
|
'!Source/Shaders/**',
|
|
|
|
|
'!Source/ThirdParty/**',
|
|
|
|
|
'!Source/Workers/cesiumWorkerBootstrapper.js',
|
|
|
|
|
'Apps/**/*.js',
|
|
|
|
|
'Apps/Sandcastle/gallery/*.html',
|
|
|
|
|
'!Apps/Sandcastle/ThirdParty/**',
|
|
|
|
|
'Specs/**/*.js',
|
2015-10-19 01:03:20 +08:00
|
|
|
'Tools/buildTasks/**/*.js',
|
|
|
|
|
'gulpfile.js'];
|
2015-10-17 05:30:14 +08:00
|
|
|
|
|
|
|
|
var filesToClean = ['Source/Cesium.js',
|
|
|
|
|
'Build',
|
|
|
|
|
'Instrumented',
|
2015-10-23 01:33:59 +08:00
|
|
|
'Source/Shaders/**/*.js',
|
2015-10-17 05:30:14 +08:00
|
|
|
'Specs/SpecList.js',
|
|
|
|
|
'Apps/Sandcastle/.jshintrc',
|
|
|
|
|
'Apps/Sandcastle/jsHintOptions.js',
|
|
|
|
|
'Apps/Sandcastle/gallery/gallery-index.js',
|
|
|
|
|
'Cesium-*.zip'];
|
|
|
|
|
|
|
|
|
|
var filesToSortRequires = ['Source/**/*.js',
|
|
|
|
|
'!Source/Shaders/**',
|
|
|
|
|
'!Source/ThirdParty/**',
|
|
|
|
|
'!Source/Workers/cesiumWorkerBootstrapper.js',
|
|
|
|
|
'!Source/copyrightHeader.js',
|
|
|
|
|
'!Source/Workers/transferTypedArrayTest.js',
|
|
|
|
|
'Apps/**/*.js',
|
|
|
|
|
'!Apps/Sandcastle/ThirdParty/**',
|
|
|
|
|
'!Apps/Sandcastle/jsHintOptions.js',
|
|
|
|
|
'Specs/**/*.js',
|
|
|
|
|
'!Specs/spec-main.js',
|
|
|
|
|
'!Specs/SpecRunner.js',
|
|
|
|
|
'!Specs/SpecList.js',
|
|
|
|
|
'!Apps/Sandcastle/Sandcastle-client.js',
|
|
|
|
|
'!Apps/Sandcastle/Sandcastle-header.js',
|
|
|
|
|
'!Apps/Sandcastle/Sandcastle-warn.js',
|
|
|
|
|
'!Apps/Sandcastle/gallery/gallery-index.js'];
|
|
|
|
|
|
|
|
|
|
gulp.task('default', ['combine']);
|
|
|
|
|
|
|
|
|
|
gulp.task('build', function(done) {
|
|
|
|
|
mkdirp.sync('Build');
|
2015-10-22 06:08:57 +08:00
|
|
|
glslToJavaScript(minifyShaders, 'Build/minifyShaders.state');
|
2015-10-17 05:30:14 +08:00
|
|
|
createCesiumJs();
|
|
|
|
|
createSpecList();
|
|
|
|
|
createGalleryList();
|
|
|
|
|
createSandcastleJsHintOptions();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
2015-10-19 06:01:56 +08:00
|
|
|
gulp.task('build-watch', function() {
|
|
|
|
|
gulp.watch(buildFiles, ['build']);
|
|
|
|
|
});
|
|
|
|
|
|
2015-10-17 05:30:14 +08:00
|
|
|
gulp.task('buildApps', ['combine', 'minifyRelease'], function() {
|
|
|
|
|
return buildCesiumViewer();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('clean', function(done) {
|
|
|
|
|
async.forEach(filesToClean, rimraf, done);
|
|
|
|
|
});
|
|
|
|
|
|
2015-10-19 01:48:20 +08:00
|
|
|
gulp.task('cloc', ['build'], function() {
|
2015-10-22 05:54:08 +08:00
|
|
|
var cmdLine;
|
2015-10-22 23:03:54 +08:00
|
|
|
var clocPath = path.join('Tools', 'cloc-1.60', 'cloc-1.60.pl');
|
2015-10-17 05:30:14 +08:00
|
|
|
var cloc_definitions = path.join('Tools', 'cloc-1.60', 'cloc_definitions');
|
|
|
|
|
|
2015-10-22 05:54:08 +08:00
|
|
|
//Run cloc on primary Source files only
|
|
|
|
|
var source = new Promise(function(resolve, reject) {
|
|
|
|
|
var glsl = globby.sync(['Source/Shaders/*.glsl', 'Source/Shaders/**/*.glsl']).join(' ');
|
|
|
|
|
|
2015-10-22 23:03:54 +08:00
|
|
|
cmdLine = 'perl ' + clocPath + ' --quiet --progress-rate=0 --read-lang-def=' + cloc_definitions +
|
2015-10-22 05:54:08 +08:00
|
|
|
' Source/main.js Source/Core/ Source/DataSources/ Source/Renderer/ Source/Scene/ Source/Widgets/ Source/Workers/ ' + glsl;
|
|
|
|
|
|
|
|
|
|
child_process.exec(cmdLine, function(error, stdout, stderr) {
|
|
|
|
|
if (error) {
|
|
|
|
|
console.log(stderr);
|
|
|
|
|
return reject(error);
|
|
|
|
|
}
|
|
|
|
|
console.log('Source:');
|
|
|
|
|
console.log(stdout);
|
|
|
|
|
resolve();
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-10-19 01:48:20 +08:00
|
|
|
|
2015-10-22 05:54:08 +08:00
|
|
|
//If running cloc on source succeeded, also run it on the tests.
|
|
|
|
|
return source.then(function() {
|
|
|
|
|
return new Promise(function(resolve, reject) {
|
2015-10-22 23:03:54 +08:00
|
|
|
cmdLine = 'perl ' + clocPath + ' --quiet --progress-rate=0 --read-lang-def=' + cloc_definitions + ' Specs/';
|
2015-10-19 01:48:20 +08:00
|
|
|
child_process.exec(cmdLine, function(error, stdout, stderr) {
|
|
|
|
|
if (error) {
|
|
|
|
|
console.log(stderr);
|
|
|
|
|
return reject(error);
|
|
|
|
|
}
|
|
|
|
|
console.log('Specs:');
|
|
|
|
|
console.log(stdout);
|
2015-10-22 05:54:08 +08:00
|
|
|
resolve();
|
2015-10-19 01:48:20 +08:00
|
|
|
});
|
2015-10-22 05:54:08 +08:00
|
|
|
});
|
|
|
|
|
});
|
2015-10-17 05:30:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('combine', ['generateStubs'], function() {
|
2015-10-19 01:03:20 +08:00
|
|
|
var outputDirectory = path.join('Build', 'CesiumUnminified');
|
2015-10-17 05:30:14 +08:00
|
|
|
return combineJavaScript({
|
|
|
|
|
removePragmas : false,
|
2015-10-19 01:03:20 +08:00
|
|
|
optimizer : 'none',
|
|
|
|
|
outputDirectory : outputDirectory
|
|
|
|
|
}).then(function() {
|
|
|
|
|
if (!copyUnminified) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return streamToPromise(gulp.src(outputDirectory + '/**').pipe(gulp.dest(path.join('Build', 'Cesium'))));
|
2015-10-17 05:30:14 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('combineRelease', ['generateStubs'], function() {
|
2015-10-19 01:03:20 +08:00
|
|
|
var outputDirectory = path.join('Build', 'CesiumUnminified');
|
2015-10-17 05:30:14 +08:00
|
|
|
return combineJavaScript({
|
|
|
|
|
removePragmas : true,
|
2015-10-19 01:03:20 +08:00
|
|
|
optimizer : 'none',
|
|
|
|
|
outputDirectory : outputDirectory
|
|
|
|
|
}).then(function() {
|
|
|
|
|
if (!copyUnminified) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return streamToPromise(gulp.src(outputDirectory + '/**').pipe(gulp.dest(path.join('Build', 'Cesium'))));
|
2015-10-17 05:30:14 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//Builds the documentation
|
|
|
|
|
gulp.task('generateDocumentation', function() {
|
|
|
|
|
var envPathSeperator = os.platform() === 'win32' ? ';' : ':';
|
|
|
|
|
|
2015-10-19 01:48:20 +08:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
|
child_process.exec('jsdoc --configure Tools/jsdoc/conf.json', {
|
|
|
|
|
env : {
|
|
|
|
|
PATH : process.env.PATH + envPathSeperator + 'node_modules/.bin',
|
2015-10-19 02:36:55 +08:00
|
|
|
CESIUM_VERSION : version
|
2015-10-19 01:48:20 +08:00
|
|
|
}
|
|
|
|
|
}, function(error, stdout, stderr) {
|
|
|
|
|
if (error) {
|
|
|
|
|
console.log(stderr);
|
|
|
|
|
return reject(error);
|
|
|
|
|
}
|
|
|
|
|
console.log(stdout);
|
|
|
|
|
var stream = gulp.src('Documentation/Images/**').pipe(gulp.dest('Build/Documentation/Images'));
|
|
|
|
|
return streamToPromise(stream).then(resolve);
|
|
|
|
|
});
|
2015-10-17 05:30:14 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('instrumentForCoverage', ['build'], function(done) {
|
2015-10-19 01:03:20 +08:00
|
|
|
var jscoveragePath = path.join('Tools', 'jscoverage-0.5.1', 'jscoverage.exe');
|
|
|
|
|
var cmdLine = jscoveragePath + ' Source Instrumented --no-instrument=./ThirdParty';
|
2015-10-19 06:01:56 +08:00
|
|
|
child_process.exec(cmdLine, function(error, stdout, stderr) {
|
|
|
|
|
if (error) {
|
|
|
|
|
console.log(stderr);
|
|
|
|
|
return done(error);
|
|
|
|
|
}
|
|
|
|
|
console.log(stdout);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-10-17 05:30:14 +08:00
|
|
|
});
|
|
|
|
|
|
2015-10-20 04:20:51 +08:00
|
|
|
gulp.task('jsHint', ['build'], function() {
|
2015-10-17 05:30:14 +08:00
|
|
|
return gulp.src(jsHintFiles)
|
|
|
|
|
.pipe(jshint.extract('auto'))
|
|
|
|
|
.pipe(jshint())
|
|
|
|
|
.pipe(jshint.reporter('jshint-stylish'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('jsHint-watch', function() {
|
|
|
|
|
gulp.watch(jsHintFiles).on('change', function(event) {
|
|
|
|
|
gulp.src(event.path)
|
|
|
|
|
.pipe(jshint.extract('auto'))
|
|
|
|
|
.pipe(jshint())
|
|
|
|
|
.pipe(jshint.reporter('jshint-stylish'));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-10-19 02:36:55 +08:00
|
|
|
gulp.task('makeZipFile', ['release'], function() {
|
2015-10-17 05:30:14 +08:00
|
|
|
var builtSrc = gulp.src([
|
|
|
|
|
'Build/Apps/**',
|
|
|
|
|
'Build/Cesium/**',
|
|
|
|
|
'Build/CesiumUnminified/**',
|
|
|
|
|
'Build/Documentation/**'
|
|
|
|
|
], {
|
|
|
|
|
base : '.'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var staticSrc = gulp.src([
|
|
|
|
|
'Apps/**',
|
2015-10-19 02:36:55 +08:00
|
|
|
'!Apps/Sandcastle/gallery/development/**',
|
2015-10-17 05:30:14 +08:00
|
|
|
'Source/**',
|
|
|
|
|
'Specs/**',
|
|
|
|
|
'ThirdParty/**',
|
|
|
|
|
'logo.png',
|
|
|
|
|
'favicon.ico',
|
|
|
|
|
'gulpfile.js',
|
|
|
|
|
'server.js',
|
|
|
|
|
'package.json',
|
|
|
|
|
'LICENSE.md',
|
|
|
|
|
'CHANGES.md',
|
|
|
|
|
'README.md',
|
|
|
|
|
'web.config'
|
|
|
|
|
], {
|
2015-10-19 02:36:55 +08:00
|
|
|
base : '.',
|
|
|
|
|
nodir : true
|
2015-10-17 05:30:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var indexSrc = gulp.src('index.release.html').pipe(gulpRename("index.html"));
|
|
|
|
|
|
|
|
|
|
return eventStream.merge(builtSrc, staticSrc, indexSrc)
|
|
|
|
|
.pipe(gulpZip('Cesium-' + version + '.zip'))
|
|
|
|
|
.pipe(gulp.dest('.'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('minify', ['generateStubs'], function() {
|
|
|
|
|
return combineJavaScript({
|
|
|
|
|
removePragmas : false,
|
2015-10-19 01:03:20 +08:00
|
|
|
optimizer : 'uglify2',
|
2015-10-17 05:30:14 +08:00
|
|
|
outputDirectory : path.join('Build', 'Cesium')
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('minifyRelease', ['generateStubs'], function() {
|
|
|
|
|
return combineJavaScript({
|
|
|
|
|
removePragmas : true,
|
2015-10-19 01:03:20 +08:00
|
|
|
optimizer : 'uglify2',
|
2015-10-17 05:30:14 +08:00
|
|
|
outputDirectory : path.join('Build', 'Cesium')
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('release', ['buildApps', 'generateDocumentation']);
|
|
|
|
|
|
2015-10-19 01:03:20 +08:00
|
|
|
gulp.task('generateStubs', ['build'], function(done) {
|
2015-10-17 05:30:14 +08:00
|
|
|
mkdirp.sync(path.join('Build', 'Stubs'));
|
|
|
|
|
|
|
|
|
|
var contents = '\
|
|
|
|
|
/*global define,Cesium*/\n\
|
|
|
|
|
(function() {\n\
|
|
|
|
|
"use strict";\n\
|
|
|
|
|
/*jshint sub:true*/\n';
|
|
|
|
|
var modulePathMappings = [];
|
|
|
|
|
|
|
|
|
|
globby.sync(sourceFiles).forEach(function(file) {
|
|
|
|
|
file = path.relative('Source', file);
|
2015-10-20 11:26:00 +08:00
|
|
|
var moduleId = filePathToModuleId(file);
|
2015-10-17 05:30:14 +08:00
|
|
|
|
2015-10-22 06:22:10 +08:00
|
|
|
var propertyName = path.basename(file, path.extname(file));
|
2015-10-22 05:55:46 +08:00
|
|
|
propertyName = "['" + propertyName + "']";
|
2015-10-17 05:30:14 +08:00
|
|
|
|
|
|
|
|
contents += '\
|
|
|
|
|
define(\'' + moduleId + '\', function() {\n\
|
|
|
|
|
return Cesium' + propertyName + ';\n\
|
|
|
|
|
});\n\n';
|
|
|
|
|
|
|
|
|
|
modulePathMappings.push(' \'' + moduleId + '\' : \'../Stubs/Cesium\'');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
contents += '})();';
|
|
|
|
|
|
|
|
|
|
var paths = '\
|
|
|
|
|
/*global define*/\n\
|
|
|
|
|
define(function() {\n\
|
|
|
|
|
"use strict";\n\
|
|
|
|
|
return {\n' + modulePathMappings.join(',\n') + '\n\
|
|
|
|
|
};\n\
|
|
|
|
|
});';
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(path.join('Build', 'Stubs', 'Cesium.js'), contents);
|
|
|
|
|
fs.writeFileSync(path.join('Build', 'Stubs', 'paths.js'), paths);
|
2015-10-19 01:03:20 +08:00
|
|
|
done();
|
2015-10-17 05:30:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('sortRequires', function(done) {
|
|
|
|
|
var noModulesRegex = /[\s\S]*?define\(function\(\)/;
|
|
|
|
|
var requiresRegex = /([\s\S]*?(define|defineSuite|require)\((?:{[\s\S]*}, )?\[)([\S\s]*?)]([\s\S]*?function\s*)\(([\S\s]*?)\) {([\s\S]*)/;
|
|
|
|
|
var splitRegex = /,\s*/;
|
|
|
|
|
var filesChecked = 0;
|
|
|
|
|
|
|
|
|
|
var files = globby.sync(filesToSortRequires);
|
|
|
|
|
async.forEach(files, function(file, callback) {
|
|
|
|
|
if (filesChecked > 0 && filesChecked % 50 === 0) {
|
|
|
|
|
console.log('Sorted requires in ' + filesChecked + ' files');
|
|
|
|
|
}
|
|
|
|
|
++filesChecked;
|
|
|
|
|
|
|
|
|
|
fs.readFile(file, function(err, contents) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = requiresRegex.exec(contents);
|
|
|
|
|
|
|
|
|
|
if (result === null) {
|
|
|
|
|
if (!noModulesRegex.test(contents)) {
|
|
|
|
|
console.log(file + ' does not have the expected syntax.');
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// In specs, the first require is significant,
|
|
|
|
|
// unless the spec is given an explicit name.
|
|
|
|
|
var preserveFirst = false;
|
|
|
|
|
if (result[2] === 'defineSuite' && result[4] === ', function') {
|
|
|
|
|
preserveFirst = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var names = result[3].split(splitRegex);
|
|
|
|
|
if (names.length === 1 && names[0].trim() === '') {
|
|
|
|
|
names.length = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var i;
|
|
|
|
|
for (i = 0; i < names.length; ++i) {
|
|
|
|
|
if (names[i].indexOf('//') >= 0 || names[i].indexOf('/*') >= 0) {
|
|
|
|
|
console.log(file + ' contains comments in the require list. Skipping so nothing gets broken.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var identifiers = result[5].split(splitRegex);
|
|
|
|
|
if (identifiers.length === 1 && identifiers[0].trim() === '') {
|
|
|
|
|
identifiers.length = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < identifiers.length; ++i) {
|
|
|
|
|
if (identifiers[i].indexOf('//') >= 0 || identifiers[i].indexOf('/*') >= 0) {
|
|
|
|
|
console.log(file + ' contains comments in the require list. Skipping so nothing gets broken.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var requires = [];
|
|
|
|
|
|
|
|
|
|
for (i = preserveFirst ? 1 : 0; i < names.length && i < identifiers.length; ++i) {
|
|
|
|
|
requires.push({
|
|
|
|
|
name : names[i].trim(),
|
|
|
|
|
identifier : identifiers[i].trim()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
requires.sort(function(a, b) {
|
|
|
|
|
var aName = a.name.toLowerCase();
|
|
|
|
|
var bName = b.name.toLowerCase();
|
|
|
|
|
if (aName < bName) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (aName > bName) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (preserveFirst) {
|
|
|
|
|
requires.splice(0, 0, {
|
|
|
|
|
name : names[0].trim(),
|
|
|
|
|
identifier : identifiers[0].trim()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert back to separate lists for the names and identifiers, and add
|
|
|
|
|
// any additional names or identifiers that don't have a corresponding pair.
|
|
|
|
|
var sortedNames = requires.map(function(item) {
|
|
|
|
|
return item.name;
|
|
|
|
|
});
|
|
|
|
|
for (i = sortedNames.length; i < names.length; ++i) {
|
|
|
|
|
sortedNames.push(names[i].trim());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sortedIdentifiers = requires.map(function(item) {
|
|
|
|
|
return item.identifier;
|
|
|
|
|
});
|
|
|
|
|
for (i = sortedIdentifiers.length; i < identifiers.length; ++i) {
|
|
|
|
|
sortedIdentifiers.push(identifiers[i].trim());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var outputNames = ']';
|
|
|
|
|
if (sortedNames.length > 0) {
|
|
|
|
|
outputNames = '\r\n ' +
|
|
|
|
|
sortedNames.join(',\r\n ') +
|
|
|
|
|
'\r\n ]';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var outputIdentifiers = '(';
|
|
|
|
|
if (sortedIdentifiers.length > 0) {
|
|
|
|
|
outputIdentifiers = '(\r\n ' +
|
|
|
|
|
sortedIdentifiers.join(',\r\n ');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contents = result[1] +
|
|
|
|
|
outputNames +
|
|
|
|
|
result[4].replace(/^[,\s]+/, ', ').trim() +
|
|
|
|
|
outputIdentifiers +
|
|
|
|
|
') {' +
|
|
|
|
|
result[6];
|
|
|
|
|
|
|
|
|
|
fs.writeFile(file, contents, callback);
|
|
|
|
|
});
|
|
|
|
|
}, done);
|
|
|
|
|
});
|
|
|
|
|
|
2015-10-19 01:03:20 +08:00
|
|
|
function combineCesium(debug, optimizer, combineOutput) {
|
|
|
|
|
return requirejsOptimize({
|
|
|
|
|
wrap : true,
|
|
|
|
|
useStrict : true,
|
|
|
|
|
optimize : optimizer,
|
|
|
|
|
optimizeCss : 'standard',
|
|
|
|
|
pragmas : {
|
|
|
|
|
debug : debug
|
|
|
|
|
},
|
|
|
|
|
baseUrl : 'Source',
|
|
|
|
|
skipModuleInsertion : true,
|
2015-10-19 07:39:12 +08:00
|
|
|
name : path.join('..', 'ThirdParty', 'almond-0.2.6', 'almond'),
|
2015-10-19 01:03:20 +08:00
|
|
|
include : 'main',
|
|
|
|
|
out : path.join(combineOutput, 'Cesium.js')
|
2015-10-17 05:30:14 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 01:03:20 +08:00
|
|
|
function combineWorkers(debug, optimizer, combineOutput) {
|
|
|
|
|
return Promise.join(
|
|
|
|
|
globby(['Source/Workers/cesiumWorkerBootstrapper.js',
|
|
|
|
|
'Source/Workers/transferTypedArrayTest.js',
|
|
|
|
|
'Source/ThirdParty/Workers/*.js']).then(function(files) {
|
|
|
|
|
return Promise.all(files.map(function(file) {
|
|
|
|
|
return requirejsOptimize({
|
|
|
|
|
wrap : false,
|
|
|
|
|
useStrict : true,
|
|
|
|
|
optimize : optimizer,
|
|
|
|
|
optimizeCss : 'standard',
|
|
|
|
|
pragmas : {
|
|
|
|
|
debug : debug
|
|
|
|
|
},
|
2015-10-20 11:26:00 +08:00
|
|
|
baseUrl : 'Source',
|
2015-10-19 01:03:20 +08:00
|
|
|
skipModuleInsertion : true,
|
2015-10-20 11:26:00 +08:00
|
|
|
include : filePathToModuleId(path.relative('Source', file)),
|
2015-10-19 01:03:20 +08:00
|
|
|
out : path.join(combineOutput, path.relative('Source', file))
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
}),
|
|
|
|
|
globby(['Source/Workers/*.js',
|
|
|
|
|
'!Source/Workers/cesiumWorkerBootstrapper.js',
|
|
|
|
|
'!Source/Workers/transferTypedArrayTest.js',
|
2015-10-20 09:52:33 +08:00
|
|
|
'!Source/Workers/createTaskProcessorWorker.js',
|
2015-10-19 01:03:20 +08:00
|
|
|
'!Source/ThirdParty/Workers/*.js']).then(function(files) {
|
|
|
|
|
return Promise.all(files.map(function(file) {
|
|
|
|
|
return requirejsOptimize({
|
|
|
|
|
wrap : true,
|
|
|
|
|
useStrict : true,
|
|
|
|
|
optimize : optimizer,
|
|
|
|
|
optimizeCss : 'standard',
|
|
|
|
|
pragmas : {
|
|
|
|
|
debug : debug
|
|
|
|
|
},
|
2015-10-20 11:26:00 +08:00
|
|
|
baseUrl : 'Source',
|
|
|
|
|
include : filePathToModuleId(path.relative('Source', file)),
|
2015-10-19 01:03:20 +08:00
|
|
|
out : path.join(combineOutput, path.relative('Source', file))
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
})
|
|
|
|
|
);
|
2015-10-17 05:30:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function minifyCSS(outputDirectory) {
|
2015-10-19 01:03:20 +08:00
|
|
|
return globby('Source/**/*.css').then(function(files) {
|
|
|
|
|
return Promise.all(files.map(function(file) {
|
|
|
|
|
return requirejsOptimize({
|
|
|
|
|
wrap : true,
|
|
|
|
|
useStrict : true,
|
|
|
|
|
optimizeCss : 'standard',
|
|
|
|
|
pragmas : {
|
|
|
|
|
debug : true
|
|
|
|
|
},
|
|
|
|
|
cssIn : file,
|
|
|
|
|
out : path.join(outputDirectory, path.relative('Source', file))
|
2015-10-17 05:30:14 +08:00
|
|
|
});
|
2015-10-19 01:03:20 +08:00
|
|
|
}));
|
|
|
|
|
});
|
2015-10-17 05:30:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function combineJavaScript(options) {
|
2015-10-19 01:03:20 +08:00
|
|
|
var optimizer = options.optimizer;
|
2015-10-17 05:30:14 +08:00
|
|
|
var outputDirectory = options.outputDirectory;
|
|
|
|
|
var removePragmas = options.removePragmas;
|
|
|
|
|
|
|
|
|
|
var combineOutput = path.join('Build', 'combineOutput', optimizer);
|
|
|
|
|
var copyrightHeader = fs.readFileSync(path.join('Source', 'copyrightHeader.js'));
|
|
|
|
|
|
2015-10-19 01:03:20 +08:00
|
|
|
var promise = Promise.join(
|
|
|
|
|
combineCesium(!removePragmas, optimizer, combineOutput),
|
|
|
|
|
combineWorkers(!removePragmas, optimizer, combineOutput)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return promise.then(function() {
|
|
|
|
|
var promises = [];
|
|
|
|
|
|
|
|
|
|
//copy to build folder with copyright header added at the top
|
|
|
|
|
var stream = gulp.src([combineOutput + '/**'])
|
|
|
|
|
.pipe(gulpInsert.prepend(copyrightHeader))
|
|
|
|
|
.pipe(gulp.dest(outputDirectory));
|
|
|
|
|
|
|
|
|
|
promises.push(streamToPromise(stream));
|
2015-10-17 05:30:14 +08:00
|
|
|
|
2015-10-19 01:03:20 +08:00
|
|
|
var everythingElse = ['Source/**', '!**/*.js', '!**/*.glsl'];
|
|
|
|
|
|
|
|
|
|
if (optimizer === 'uglify2') {
|
|
|
|
|
promises.push(minifyCSS(outputDirectory));
|
|
|
|
|
everythingElse.push('!**/*.css');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stream = gulp.src(everythingElse, {nodir : true}).pipe(gulp.dest(outputDirectory));
|
|
|
|
|
promises.push(streamToPromise(stream));
|
|
|
|
|
|
|
|
|
|
return Promise.all(promises).then(function() {
|
|
|
|
|
rimraf.sync(combineOutput);
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-10-17 05:30:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function glslToJavaScript(minify, minifyStateFilePath) {
|
|
|
|
|
fs.writeFileSync(minifyStateFilePath, minify);
|
|
|
|
|
var minifyStateFileLastModified = fs.existsSync(minifyStateFilePath) ? fs.statSync(minifyStateFilePath).mtime.getTime() : 0;
|
|
|
|
|
|
|
|
|
|
// collect all currently existing JS files into a set, later we will remove the ones
|
|
|
|
|
// we still are using from the set, then delete any files remaining in the set.
|
|
|
|
|
var leftOverJsFiles = {};
|
|
|
|
|
|
|
|
|
|
globby.sync(['Source/Shaders/**/*.js']).forEach(function(file) {
|
|
|
|
|
leftOverJsFiles[path.normalize(file)] = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var builtinFunctions = [];
|
|
|
|
|
var builtinConstants = [];
|
|
|
|
|
var builtinStructs = [];
|
|
|
|
|
|
|
|
|
|
var glslFiles = globby.sync(['Source/Shaders/**/*.glsl']);
|
|
|
|
|
glslFiles.forEach(function(glslFile) {
|
|
|
|
|
glslFile = path.normalize(glslFile);
|
|
|
|
|
var baseName = path.basename(glslFile, '.glsl');
|
|
|
|
|
var jsFile = path.join(path.dirname(glslFile), baseName) + '.js';
|
|
|
|
|
|
|
|
|
|
// identify built in functions, structs, and constants
|
2015-10-20 07:11:53 +08:00
|
|
|
var baseDir = path.join('Source', 'Shaders', 'Builtin');
|
|
|
|
|
if (glslFile.indexOf(path.normalize(path.join(baseDir, 'Functions'))) === 0) {
|
2015-10-17 05:30:14 +08:00
|
|
|
builtinFunctions.push(baseName);
|
|
|
|
|
}
|
2015-10-20 07:11:53 +08:00
|
|
|
else if (glslFile.indexOf(path.normalize(path.join(baseDir, 'Constants'))) === 0) {
|
2015-10-17 05:30:14 +08:00
|
|
|
builtinConstants.push(baseName);
|
|
|
|
|
}
|
2015-10-20 07:11:53 +08:00
|
|
|
else if (glslFile.indexOf(path.normalize(path.join(baseDir, 'Structs'))) === 0) {
|
2015-10-17 05:30:14 +08:00
|
|
|
builtinStructs.push(baseName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete leftOverJsFiles[jsFile];
|
|
|
|
|
|
|
|
|
|
var jsFileExists = fs.existsSync(jsFile);
|
|
|
|
|
var jsFileModified = jsFileExists ? fs.statSync(jsFile).mtime.getTime() : 0;
|
|
|
|
|
var glslFileModified = fs.statSync(glslFile).mtime.getTime();
|
|
|
|
|
|
|
|
|
|
if (jsFileExists && jsFileModified > glslFileModified && jsFileModified > minifyStateFileLastModified) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var contents = fs.readFileSync(glslFile, 'utf8');
|
|
|
|
|
contents = contents.replace(/\r\n/gm, '\n');
|
|
|
|
|
|
|
|
|
|
var copyrightComments = '';
|
|
|
|
|
var extractedCopyrightComments = contents.match(/\/\*\*(?:[^*\/]|\*(?!\/)|\n)*?@license(?:.|\n)*?\*\//gm);
|
|
|
|
|
if (extractedCopyrightComments) {
|
|
|
|
|
copyrightComments = extractedCopyrightComments.join('\n') + '\n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (minify) {
|
|
|
|
|
contents = stripComments(contents);
|
|
|
|
|
contents = contents.replace(/\s+$/gm, '').replace(/^\s+/gm, '').replace(/\n+/gm, '\n');
|
|
|
|
|
contents += '\n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contents = contents.split('"').join('\\"').replace(/\n/gm, '\\n\\\n');
|
|
|
|
|
contents = copyrightComments + '\
|
|
|
|
|
//This file is automatically rebuilt by the Cesium build process.\n\
|
|
|
|
|
/*global define*/\n\
|
|
|
|
|
define(function() {\n\
|
|
|
|
|
"use strict";\n\
|
|
|
|
|
return "' + contents + '";\n\
|
|
|
|
|
});';
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(jsFile, contents);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// delete any left over JS files from old shaders
|
|
|
|
|
Object.keys(leftOverJsFiles).forEach(rimraf.sync);
|
|
|
|
|
|
|
|
|
|
var generateBuiltinContents = function(contents, builtins, path) {
|
|
|
|
|
var amdPath = contents.amdPath;
|
|
|
|
|
var amdClassName = contents.amdClassName;
|
|
|
|
|
var builtinLookup = contents.builtinLookup;
|
|
|
|
|
for (var i = 0; i < builtins.length; i++) {
|
|
|
|
|
var builtin = builtins[i];
|
|
|
|
|
amdPath = amdPath + ',\n \'./' + path + '/' + builtin + '\'';
|
|
|
|
|
amdClassName = amdClassName + ',\n ' + 'czm_' + builtin;
|
|
|
|
|
builtinLookup = builtinLookup + ',\n ' + 'czm_' + builtin + ' : ' + 'czm_' + builtin;
|
|
|
|
|
}
|
|
|
|
|
contents.amdPath = amdPath;
|
|
|
|
|
contents.amdClassName = amdClassName;
|
|
|
|
|
contents.builtinLookup = builtinLookup;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//generate the JS file for Built-in GLSL Functions, Structs, and Constants
|
|
|
|
|
var contents = {amdPath : '', amdClassName : '', builtinLookup : ''};
|
|
|
|
|
generateBuiltinContents(contents, builtinConstants, 'Constants');
|
|
|
|
|
generateBuiltinContents(contents, builtinStructs, 'Structs');
|
|
|
|
|
generateBuiltinContents(contents, builtinFunctions, 'Functions');
|
|
|
|
|
|
|
|
|
|
contents.amdPath = contents.amdPath.replace(',\n', '');
|
|
|
|
|
contents.amdClassName = contents.amdClassName.replace(',\n', '');
|
|
|
|
|
contents.builtinLookup = contents.builtinLookup.replace(',\n', '');
|
|
|
|
|
|
|
|
|
|
var fileContents = '\
|
|
|
|
|
//This file is automatically rebuilt by the Cesium build process.\n\
|
|
|
|
|
/*global define*/\n\
|
|
|
|
|
define([\n' +
|
|
|
|
|
contents.amdPath +
|
|
|
|
|
'\n ], function(\n' +
|
|
|
|
|
contents.amdClassName +
|
|
|
|
|
') {\n\
|
|
|
|
|
"use strict";\n\
|
|
|
|
|
return {\n' + contents.builtinLookup + '};\n\
|
|
|
|
|
});';
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(path.join('Source', 'Shaders', 'Builtin', 'CzmBuiltins.js'), fileContents);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createCesiumJs() {
|
|
|
|
|
var moduleIds = [];
|
|
|
|
|
var parameters = [];
|
|
|
|
|
var assignments = [];
|
|
|
|
|
|
|
|
|
|
var nonIdentifierRegexp = /[^0-9a-zA-Z_$]/g;
|
|
|
|
|
|
|
|
|
|
globby.sync(sourceFiles).forEach(function(file) {
|
|
|
|
|
file = path.relative('Source', file);
|
2015-10-20 11:26:00 +08:00
|
|
|
var moduleId = file;
|
|
|
|
|
moduleId = filePathToModuleId(moduleId);
|
2015-10-17 05:30:14 +08:00
|
|
|
|
2015-10-22 06:22:10 +08:00
|
|
|
var assignmentName = path.basename(file, path.extname(file));
|
2015-10-17 05:30:14 +08:00
|
|
|
assignmentName = "['" + assignmentName + "']";
|
2015-10-20 11:26:00 +08:00
|
|
|
if (moduleId.indexOf('Source/Shaders/') === 0) {
|
2015-10-17 05:30:14 +08:00
|
|
|
assignmentName = '._shaders' + assignmentName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var parameterName = moduleId.replace(nonIdentifierRegexp, '_');
|
|
|
|
|
|
2015-10-20 11:26:00 +08:00
|
|
|
moduleIds.push("'./" + moduleId + "'");
|
2015-10-17 05:30:14 +08:00
|
|
|
parameters.push(parameterName);
|
|
|
|
|
assignments.push('Cesium' + assignmentName + ' = ' + parameterName + ';');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var contents = '\
|
|
|
|
|
/*global define*/\n\
|
|
|
|
|
define([' + moduleIds.join(', ') + '], function(' + parameters.join(', ') + ') {\n\
|
|
|
|
|
"use strict";\n\
|
|
|
|
|
/*jshint sub:true*/\n\
|
|
|
|
|
var Cesium = {\n\
|
2015-10-19 02:36:55 +08:00
|
|
|
VERSION : "' + packageJson.version + '",\n\
|
2015-10-17 05:30:14 +08:00
|
|
|
_shaders : {}\n\
|
|
|
|
|
};\n\
|
|
|
|
|
' + assignments.join('\n ') + '\n\
|
|
|
|
|
return Cesium;\n\
|
|
|
|
|
});';
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync('Source/Cesium.js', contents);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createSpecList() {
|
|
|
|
|
var specFiles = globby.sync(['Specs/**/*.js', '!Specs/*.js']);
|
|
|
|
|
var specs = [];
|
|
|
|
|
|
|
|
|
|
specFiles.forEach(function(file) {
|
2015-10-22 06:22:10 +08:00
|
|
|
specs.push("'" + filePathToModuleId(file) + "'");
|
2015-10-17 05:30:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var contents = 'var specs = [' + specs.join(',') + '];';
|
|
|
|
|
fs.writeFileSync(path.join('Specs', 'SpecList.js'), contents);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createGalleryList() {
|
|
|
|
|
var demos = [];
|
|
|
|
|
var output = path.join('Apps', 'Sandcastle', 'gallery', 'gallery-index.js');
|
|
|
|
|
|
|
|
|
|
var fileList = ['Apps/Sandcastle/gallery/**/*.html'];
|
|
|
|
|
if (noDevelopmentGallery) {
|
|
|
|
|
fileList.push('!Apps/Sandcastle/gallery/development/**/*.html');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
globby.sync(fileList).forEach(function(file) {
|
2015-10-22 06:22:10 +08:00
|
|
|
var demo = filePathToModuleId(path.relative('Apps/Sandcastle/gallery', file));
|
2015-10-17 05:30:14 +08:00
|
|
|
var demoObject = {
|
2015-10-22 05:55:46 +08:00
|
|
|
name : demo,
|
2015-10-17 05:30:14 +08:00
|
|
|
date : fs.statSync(file).mtime.getTime()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (fs.existsSync(file.replace('.html', '') + '.jpg')) {
|
|
|
|
|
demoObject.img = demo + '.jpg';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
demos.push(JSON.stringify(demoObject, null, 2));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var contents = '\
|
|
|
|
|
// This file is automatically rebuilt by the Cesium build process.\n\
|
|
|
|
|
var gallery_demos = [' + demos.join(', ') + '];';
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(output, contents);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createSandcastleJsHintOptions() {
|
|
|
|
|
var jsHintOptions = JSON.parse(fs.readFileSync('.jshintrc', 'utf8'));
|
|
|
|
|
jsHintOptions.predef = ['JSON', 'require', 'console', 'Sandcastle', 'Cesium'];
|
|
|
|
|
|
|
|
|
|
var contents = JSON.stringify(jsHintOptions, null, 2);
|
2015-10-19 06:01:56 +08:00
|
|
|
fs.writeFileSync(path.join('Apps', 'Sandcastle', '.jshintrc'), contents);
|
2015-10-17 05:30:14 +08:00
|
|
|
|
|
|
|
|
contents = '\
|
|
|
|
|
// This file is automatically rebuilt by the Cesium build process.\n\
|
|
|
|
|
var sandcastleJsHintOptions = ' + contents + ';';
|
2015-10-19 06:01:56 +08:00
|
|
|
fs.writeFileSync(path.join('Apps', 'Sandcastle', 'jsHintOptions.js'), contents);
|
2015-10-17 05:30:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function buildCesiumViewer() {
|
|
|
|
|
var cesiumViewerOutputDirectory = 'Build/Apps/CesiumViewer';
|
|
|
|
|
var cesiumViewerStartup = path.join(cesiumViewerOutputDirectory, 'CesiumViewerStartup.js');
|
2015-10-19 01:03:20 +08:00
|
|
|
var cesiumViewerCss = path.join(cesiumViewerOutputDirectory, 'CesiumViewer.css');
|
2015-10-17 05:30:14 +08:00
|
|
|
mkdirp.sync(cesiumViewerOutputDirectory);
|
|
|
|
|
|
2015-10-19 01:03:20 +08:00
|
|
|
var promise = Promise.join(
|
|
|
|
|
requirejsOptimize({
|
|
|
|
|
wrap : true,
|
|
|
|
|
useStrict : true,
|
|
|
|
|
optimizeCss : 'standard',
|
|
|
|
|
pragmas : {
|
|
|
|
|
debug : false
|
|
|
|
|
},
|
|
|
|
|
optimize : 'uglify2',
|
|
|
|
|
mainConfigFile : 'Apps/CesiumViewer/CesiumViewerStartup.js',
|
|
|
|
|
name : 'CesiumViewerStartup',
|
|
|
|
|
out : cesiumViewerStartup
|
|
|
|
|
}),
|
|
|
|
|
requirejsOptimize({
|
|
|
|
|
wrap : true,
|
|
|
|
|
useStrict : true,
|
|
|
|
|
optimizeCss : 'standard',
|
|
|
|
|
pragmas : {
|
|
|
|
|
debug : false
|
|
|
|
|
},
|
|
|
|
|
cssIn : 'Apps/CesiumViewer/CesiumViewer.css',
|
|
|
|
|
out : cesiumViewerCss
|
|
|
|
|
})
|
|
|
|
|
);
|
2015-10-17 05:30:14 +08:00
|
|
|
|
2015-10-19 01:03:20 +08:00
|
|
|
promise = promise.then(function() {
|
|
|
|
|
var copyrightHeader = fs.readFileSync(path.join('Source', 'copyrightHeader.js'));
|
2015-10-17 05:30:14 +08:00
|
|
|
|
2015-10-19 01:03:20 +08:00
|
|
|
var stream = eventStream.merge(
|
|
|
|
|
gulp.src(cesiumViewerStartup)
|
|
|
|
|
.pipe(gulpInsert.prepend(copyrightHeader))
|
|
|
|
|
.pipe(gulpReplace('../../Source', '.'))
|
|
|
|
|
.pipe(gulpReplace('../../ThirdParty/requirejs-2.1.9', '.')),
|
2015-10-17 05:30:14 +08:00
|
|
|
|
2015-10-19 01:03:20 +08:00
|
|
|
gulp.src(cesiumViewerCss)
|
|
|
|
|
.pipe(gulpReplace('../../Source', '.')),
|
2015-10-17 05:30:14 +08:00
|
|
|
|
2015-10-19 01:03:20 +08:00
|
|
|
gulp.src(['Apps/CesiumViewer/index.html'])
|
|
|
|
|
.pipe(gulpReplace('../../ThirdParty/requirejs-2.1.9', '.')),
|
|
|
|
|
|
|
|
|
|
gulp.src(['Apps/CesiumViewer/**',
|
|
|
|
|
'!Apps/CesiumViewer/index.html',
|
|
|
|
|
'!Apps/CesiumViewer/**/*.js',
|
|
|
|
|
'!Apps/CesiumViewer/**/*.css']),
|
|
|
|
|
|
|
|
|
|
gulp.src(['ThirdParty/requirejs-2.1.9/require.min.js'])
|
|
|
|
|
.pipe(gulpRename('require.js')),
|
|
|
|
|
|
|
|
|
|
gulp.src(['Build/Cesium/Assets/**',
|
|
|
|
|
'Build/Cesium/Workers/**',
|
|
|
|
|
'Build/Cesium/ThirdParty/Workers/**',
|
|
|
|
|
'Build/Cesium/Widgets/**',
|
|
|
|
|
'!Build/Cesium/Widgets/**/*.css'],
|
|
|
|
|
{
|
|
|
|
|
base : 'Build/Cesium',
|
|
|
|
|
nodir : true
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
gulp.src(['Build/Cesium/Widgets/InfoBox/InfoBoxDescription.css'], {
|
2015-10-17 05:30:14 +08:00
|
|
|
base : 'Build/Cesium'
|
2015-10-19 01:03:20 +08:00
|
|
|
}),
|
2015-10-17 05:30:14 +08:00
|
|
|
|
2015-10-19 01:03:20 +08:00
|
|
|
gulp.src(['web.config'])
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return streamToPromise(stream.pipe(gulp.dest(cesiumViewerOutputDirectory)));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-20 11:26:00 +08:00
|
|
|
function filePathToModuleId(moduleId) {
|
|
|
|
|
return moduleId.substring(0, moduleId.lastIndexOf('.')).replace(/\\/g, '/');
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 01:03:20 +08:00
|
|
|
function requirejsOptimize(config) {
|
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
|
requirejs.optimize(config, resolve, reject);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function streamToPromise(stream) {
|
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
|
stream.on('finish', resolve);
|
|
|
|
|
stream.on('end', reject);
|
|
|
|
|
});
|
2015-10-20 04:20:51 +08:00
|
|
|
}
|