Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Built sandcastle using unminified cesium #5842

Merged
merged 5 commits into from
Sep 29, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 48 additions & 33 deletions Apps/Sandcastle/CesiumSandcastle.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ require({
}, {
name : 'Source',
location : '.'
}, {
name: 'CesiumUnminified',
location : '../../Build/CesiumUnminified',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful here. On line 6 above, baseUrl is set to be the Source folder, and your build script already moves this one level higher in the transformed version of this file. So, line 21 here has one too many parent-folder references, I believe. (On my machine I serve Cesium from a URL path, so I get broken when there are too many .. instances).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change will fix it for me, at least this is the only one I see that looks like it goes up too many levels. I didn't try making the change myself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The location reflects what it should be when the app is copied to the Build/Apps folder. There is no reason to use this location in the unbuilt version, so I used the built path so it didn't need to be modified in the build process, but that not very clear.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But take a look at what actually gets built. The built version of this file, on line 6, you can see baseUrl has been transformed by the build from ../../Source to ../../../Source. So, this URL is then ${built Sandcastle folder}/../../../Source/../../Build/CesiumUnminified. In this case, it correctly finds the Source folder, but then it goes "too high" above Source when looking for Build.

This works on your machine because you bump into the root path there and it doesn't matter how many extra ..s there are. But on my machine, I install Cesium in a sub-folder /Cesium, partly because it is the only way to catch mistakes like these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see!

main: 'Cesium'
}, {
name : 'CodeMirror',
location : '../ThirdParty/codemirror-4.6'
Expand Down Expand Up @@ -43,6 +47,10 @@ require({
'dojo/query',
'dojo/when',
'Sandcastle/LinkButton',
'Source/Core/defined',
'Source/Core/getBaseUri',
'Source/Core/loadJsonp',
'Source/Core/loadWithXhr',
'Source/Cesium',
'CodeMirror/addon/hint/show-hint',
'CodeMirror/addon/hint/javascript-hint',
Expand Down Expand Up @@ -86,11 +94,18 @@ require({
query,
when,
LinkButton,
Cesium) {
defined,
getBaseUri,
loadJsonp,
loadWithXhr,
Cesium
) {
'use strict';

//In order for CodeMirror auto-complete to work, Cesium needs to be defined as a global.
window.Cesium = Cesium;
if (!defined(window.Cesium)) {
window.Cesium = Cesium;
}

parser.parse();

Expand Down Expand Up @@ -214,7 +229,7 @@ require({
}

function openDocTab(title, link) {
if (!Cesium.defined(docTabs[title])) {
if (!defined(docTabs[title])) {
docTabs[title] = new ContentPane({
title : title,
focused : true,
Expand Down Expand Up @@ -271,7 +286,7 @@ require({

function onCursorActivity() {
docNode.style.left = '-999px';
if (Cesium.defined(docTimer)) {
if (defined(docTimer)) {
window.clearTimeout(docTimer);
}
docTimer = window.setTimeout(showDocPopup, 500);
Expand All @@ -295,7 +310,7 @@ require({
}

function closeGalleryTooltip() {
if (Cesium.defined(activeGalleryTooltipDemo)) {
if (defined(activeGalleryTooltipDemo)) {
popup.close(demoTooltips[activeGalleryTooltipDemo.name]);
activeGalleryTooltipDemo = undefined;
}
Expand All @@ -312,7 +327,7 @@ require({
suffix = 'searchDemo';
}

if (Cesium.defined(activeGalleryTooltipDemo)) {
if (defined(activeGalleryTooltipDemo)) {
popup.open({
popup : demoTooltips[activeGalleryTooltipDemo.name],
around : dom.byId(activeGalleryTooltipDemo.name + suffix),
Expand All @@ -324,7 +339,7 @@ require({
function scheduleGalleryTooltip(demo) {
if (demo !== activeGalleryTooltipDemo) {
activeGalleryTooltipDemo = demo;
if (Cesium.defined(galleryTooltipTimer)) {
if (defined(galleryTooltipTimer)) {
window.clearTimeout(galleryTooltipTimer);
}
galleryTooltipTimer = window.setTimeout(openGalleryTooltip, 220);
Expand Down Expand Up @@ -372,7 +387,7 @@ require({
var hints = JSHINT.errors;
for (i = 0, len = hints.length; i < len; ++i) {
var hint = hints[i];
if (hint !== null && Cesium.defined(hint.reason) && hint.line > 0) {
if (hint !== null && defined(hint.reason) && hint.line > 0) {
line = jsEditor.setGutterMarker(scriptLineToEditorLine(hint.line), 'hintGutter', makeLineLabel(hint.reason, 'hintMarker'));
jsEditor.addLineClass(line, 'text', 'hintLine');
errorLines.push(line);
Expand All @@ -383,22 +398,22 @@ require({
}

function scheduleHint() {
if (Cesium.defined(hintTimer)) {
if (defined(hintTimer)) {
window.clearTimeout(hintTimer);
}
hintTimer = setTimeout(clearErrorsAddHints, 550);
highlightRun();
}

function scheduleHintNoChange() {
if (Cesium.defined(hintTimer)) {
if (defined(hintTimer)) {
window.clearTimeout(hintTimer);
}
hintTimer = setTimeout(clearErrorsAddHints, 550);
}

function scrollToLine(lineNumber) {
if (Cesium.defined(lineNumber)) {
if (defined(lineNumber)) {
jsEditor.setCursor(lineNumber);
// set selection twice in order to force the editor to scroll
// to this location if the cursor is already there
Expand Down Expand Up @@ -457,13 +472,13 @@ require({
function registerScroll(demoContainer) {
if (document.onmousewheel !== undefined) {
demoContainer.addEventListener('mousewheel', function(e) {
if (Cesium.defined(e.wheelDelta) && e.wheelDelta) {
if (defined(e.wheelDelta) && e.wheelDelta) {
demoContainer.scrollLeft -= e.wheelDelta * 70 / 120;
}
}, false);
} else {
demoContainer.addEventListener('DOMMouseScroll', function(e) {
if (Cesium.defined(e.detail) && e.detail) {
if (defined(e.detail) && e.detail) {
demoContainer.scrollLeft += e.detail * 70 / 3;
}
}, false);
Expand Down Expand Up @@ -662,7 +677,7 @@ require({
function loadBucket(bucketName) {
if (local.bucketName !== bucketName) {
local.bucketName = bucketName;
if (Cesium.defined(bucketTypes[bucketName])) {
if (defined(bucketTypes[bucketName])) {
local.headers = bucketTypes[bucketName];
} else {
local.headers = '<html><head></head><body data-sandcastle-bucket-loaded="no">';
Expand All @@ -686,13 +701,13 @@ require({
var gistId = ioQuery.queryToObject(window.location.search.substring(1)).gist;
if (window.location.search) {
queryObject = ioQuery.queryToObject(window.location.search.substring(1));
if (Cesium.defined(gistId)) {
if (defined(gistId)) {
queryObject.gistId = gistId;
}
} else {
queryObject.src = 'Hello World.html';
queryObject.label = 'Showcases';
if (Cesium.defined(gistId)) {
if (defined(gistId)) {
queryObject.gistId = gistId;
}
}
Expand Down Expand Up @@ -731,13 +746,13 @@ require({
var scriptCode = scriptMatch[1];
demoCode = scriptCode.replace(/\s/g, '');

if (Cesium.defined(queryObject.gistId)) {
Cesium.loadJsonp('https://api.github.com/gists/' + queryObject.gistId + '?access_token=dd8f755c2e5d9bbb26806bb93eaa2291f2047c60')
if (defined(queryObject.gistId)) {
loadJsonp('https://api.github.com/gists/' + queryObject.gistId + '?access_token=dd8f755c2e5d9bbb26806bb93eaa2291f2047c60')
.then(function(data) {
var files = data.data.files;
var code = files['Cesium-Sandcastle.js'].content;
var htmlFile = files['Cesium-Sandcastle.html'];
var html = Cesium.defined(htmlFile) ? htmlFile.content : defaultHtml; // Use the default html for old gists
var html = defined(htmlFile) ? htmlFile.content : defaultHtml; // Use the default html for old gists
jsEditor.setValue(code);
htmlEditor.setValue(html);
demoCode = code.replace(/\s/g, '');
Expand All @@ -746,7 +761,7 @@ require({
gistHtml = html;
previousCode = code;
previousHtml = html;
sandcastleUrl = Cesium.getBaseUri(window.location.href) + '?src=Hello%20World.html&label=Showcases&gist=' + gistId;
sandcastleUrl = getBaseUri(window.location.href) + '?src=Hello%20World.html&label=Showcases&gist=' + gistId;
CodeMirror.commands.runCesium(jsEditor);
clearRun();
}).otherwise(function(error) {
Expand Down Expand Up @@ -813,14 +828,14 @@ require({
appendConsole('consoleLog', 'Unable to load demo named ' + queryObject.src.replace('.html', '') + '. Redirecting to HelloWorld.\n', true);
}
}
} else if (Cesium.defined(e.data.log)) {
} else if (defined(e.data.log)) {
// Console log messages from the iframe display in Sandcastle.
appendConsole('consoleLog', e.data.log, false);
} else if (Cesium.defined(e.data.error)) {
} else if (defined(e.data.error)) {
// Console error messages from the iframe display in Sandcastle
var errorMsg = e.data.error;
var lineNumber = e.data.lineNumber;
if (Cesium.defined(lineNumber)) {
if (defined(lineNumber)) {
errorMsg += ' (on line ';

if (e.data.url) {
Expand All @@ -835,10 +850,10 @@ require({
}
}
appendConsole('consoleError', errorMsg, true);
} else if (Cesium.defined(e.data.warn)) {
} else if (defined(e.data.warn)) {
// Console warning messages from the iframe display in Sandcastle.
appendConsole('consoleWarn', e.data.warn, true);
} else if (Cesium.defined(e.data.highlight)) {
} else if (defined(e.data.highlight)) {
// Hovering objects in the embedded Cesium window.
highlightLine(e.data.highlight);
}
Expand Down Expand Up @@ -925,12 +940,12 @@ require({
}
}
};
return Cesium.loadWithXhr({
return loadWithXhr({
url : 'https://api.github.com/gists',
data : JSON.stringify(data),
method : 'POST'
}).then(function(content) {
sandcastleUrl = Cesium.getBaseUri(window.location.href) + '?src=Hello%20World.html&label=Showcases&gist=' + JSON.parse(content).id;
sandcastleUrl = getBaseUri(window.location.href) + '?src=Hello%20World.html&label=Showcases&gist=' + JSON.parse(content).id;
textArea.value = sandcastleUrl;
textArea.select();
}).otherwise(function(error) {
Expand All @@ -946,7 +961,7 @@ require({
if (gistIndex !== -1) {
gistId = gistId.substring(gistIndex + gistParameter.length);
}
window.location.href = Cesium.getBaseUri(window.location.href) + '?src=Hello%20World.html&label=Showcases&gist=' + gistId;
window.location.href = getBaseUri(window.location.href) + '?src=Hello%20World.html&label=Showcases&gist=' + gistId;
});

registry.byId('buttonNew').on('click', function() {
Expand Down Expand Up @@ -1093,15 +1108,15 @@ require({
demo.label = labels ? labels : '';

// Select the demo to load upon opening based on the query parameter.
if (Cesium.defined(queryObject.src)) {
if (defined(queryObject.src)) {
var gistDemo = {
name : 'Gist Import',
code : demo.code,
description: 'Code imported from GitHub Gist'
};
if (demo.name === queryObject.src.replace('.html', '')) {
loadFromGallery(demo).then(function() {
if (Cesium.defined(queryObject.gistId)) {
if (defined(queryObject.gistId)) {
window.history.replaceState(gistDemo, gistDemo.name, '?src=Hello World.html&label=' + queryObject.label + '&gist=' + queryObject.gistId);
document.title = 'Gist Import - Cesium Sandcastle';
} else {
Expand All @@ -1126,7 +1141,7 @@ require({

var loading = true;
function setSubtab(tabName) {
currentTab = Cesium.defined(tabName) && !loading ? tabName : queryObject.label;
currentTab = defined(tabName) && !loading ? tabName : queryObject.label;
queryObject.label = tabName;
loading = false;
}
Expand Down Expand Up @@ -1178,7 +1193,7 @@ require({

function createGalleryButton(demo, tabName) {
var imgSrc = 'templates/Gallery_tile.jpg';
if (Cesium.defined(demo.img)) {
if (defined(demo.img)) {
imgSrc = 'gallery/' + demo.img;
}

Expand Down Expand Up @@ -1231,7 +1246,7 @@ require({
}

var promise;
if (!Cesium.defined(gallery_demos)) {
if (!defined(gallery_demos)) {
galleryErrorMsg.textContent = 'No demos found, please run the build script.';
galleryErrorMsg.style.display = 'inline-block';
} else {
Expand Down
6 changes: 3 additions & 3 deletions Apps/Sandcastle/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
<script src="jsHintOptions.js"></script>
<script src="gallery/gallery-index.js"></script>
<script src="CesiumSandcastle.js"></script>
<!-- The next three lines are for autocomplete -->
<!-- Needed for autocomplete -->
<link rel="stylesheet" href="../../ThirdParty/codemirror-4.6/addon/hint/show-hint.css">
<!-- End of autocomplete -->
<meta property="og:title" content="Cesium Sandcastle" />
<meta property="og:description" content="The Cesium Sandcastle provides an interactive environment for testing Cesium code." />
<meta property="og:type" content="website" />
<meta property="og:url" content="http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html" />
<meta property="og:image" content="http://cesiumjs.org/images/Sandcastle.png" />
<meta property="og:url" content="https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/index.html" />
<meta property="og:image" content="https://cesiumjs.org/images/Sandcastle.png" />
<meta property="og:site_name" content="Cesium" />
<meta property="fb:admins" content="1222088662,1322006496" />
</head>
Expand Down
10 changes: 6 additions & 4 deletions Apps/Sandcastle/templates/bucket-requirejs.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="text/javascript">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
if(typeof require === "function") {
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we bump this to 120 or something? I know this PR is about making this faster not slower, but sometimes (especially loading legacy releases off the site) this timeout is too short.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make this a little longer, but this change will only affect future release builds.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the the require call shouldn't happen in the built version regardless, so it will only slow down the dev version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this was kind of a tangential comment, I know you didn't set this value in this PR.

});
}
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Change Log
* `Scene/PerspectiveOffCenterFrustum` has been removed. Use `Core/PerspectiveOffCenterFrustum`.
* Added ability to add an animation to `ModelAnimationCollection` by its index. [#5815](https://github.com/AnalyticalGraphicsInc/cesium/pull/5815)
* Fixed a bug in `ModelAnimationCollection` that caused adding an animation by its name to throw an error. [#5815](https://github.com/AnalyticalGraphicsInc/cesium/pull/5815)
* Running `buildApps` now creates a built version of Sandcastle which uses the built version of Cesium for better performance.
* Zoom about mouse now maintains camera heading, pitch, and roll [#4639](https://github.com/AnalyticalGraphicsInc/cesium/pull/5603)

### 1.37 - 2017-09-01
Expand Down
21 changes: 20 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ gulp.task('build-watch', function() {
});

gulp.task('buildApps', function() {
return buildCesiumViewer();
return buildCesiumViewer()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we can't build these in parallel via a Promise.join instead of then?

.then(function () {
return buildSandcastle();
});
});

gulp.task('clean', function(done) {
Expand Down Expand Up @@ -1153,6 +1156,22 @@ var sandcastleJsHintOptions = ' + JSON.stringify(primary, null, 4) + ';';
fs.writeFileSync(path.join('Apps', 'Sandcastle', 'jsHintOptions.js'), contents);
}

function buildSandcastle() {
return gulp.src([
'Apps/Sandcastle/**'
])
// Replace require Source with pre-built Cesium
.pipe(gulpReplace('../../../ThirdParty/requirejs-2.1.20/require.js', '../../../CesiumUnminified/Cesium.js'))
// Use unminified cesium instead of source
.pipe(gulpReplace('Source/Cesium', 'CesiumUnminified'))
// Fix relative paths for new location
.pipe(gulpReplace('../../Source', '../../../Source'))
.pipe(gulpReplace('../../ThirdParty', '../../../ThirdParty'))
.pipe(gulpReplace('../../SampleData', '../../../../Apps/SampleData'))
.pipe(gulpReplace('Build/Documentation', 'Documentation'))
.pipe(gulp.dest('Build/Apps/Sandcastle'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of the JPGs and PNGs are getting mangled here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the root folder's index.html has a link to the built CesiumViewer, can we add a similar link to built Sandcastle?

}

function buildCesiumViewer() {
var cesiumViewerOutputDirectory = 'Build/Apps/CesiumViewer';
var cesiumViewerStartup = path.join(cesiumViewerOutputDirectory, 'CesiumViewerStartup.js');
Expand Down