Skip to content

Commit 7aae7e3

Browse files
authored
Merge pull request #12904 from CesiumGS/sandcastle-build-updates
Sandcastle build config updates
2 parents 7d3efcb + c59e106 commit 7aae7e3

37 files changed

+1291
-800
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: deploy
22
on:
33
push:
44
branches-ignore:
5-
- 'cesium.com'
5+
- "cesium.com"
66
- production
77
concurrency:
88
group: deploy-${{ github.ref }}
@@ -22,14 +22,13 @@ jobs:
2222
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2323
GITHUB_REPO: ${{ github.repository }}
2424
GITHUB_SHA: ${{ github.sha }}
25-
BASE_URL: /cesium/${{ github.ref_name }}/
2625
DEPLOYED_URL: https://ci-builds.cesium.com/cesium/${{ github.ref_name }}/
2726
steps:
2827
- uses: actions/checkout@v5
2928
- name: install node 22
3029
uses: actions/setup-node@v6
3130
with:
32-
node-version: '22'
31+
node-version: "22"
3332
- name: npm install
3433
run: npm install
3534
- name: set the version in package.json
@@ -42,8 +41,6 @@ jobs:
4241
run: npm pack --workspaces &> /dev/null
4342
- name: build apps
4443
run: npm run build-apps
45-
- name: build sandcastle v2
46-
run: npm run build-ci -w packages/sandcastle -- -l warn
4744
- uses: ./.github/actions/verify-package
4845
- name: deploy to s3
4946
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}

.github/workflows/prod.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,17 @@ jobs:
4141
run: npm install
4242
- name: build website release
4343
run: npm run website-release
44-
- name: build apps
45-
run: npm run build-apps
4644
- name: build types
4745
run: npm run build-ts
48-
- name: build prod sandcastle
49-
run: npm run build-prod -w packages/sandcastle -- -l warn
46+
- name: build apps
47+
run: npm run build-apps
5048
- name: deploy to cesium.com
5149
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
50+
# Download zip from the Github release and unzip to Build/release/
51+
# Publish that unzipped code to the bucket for https://cesium.com/downloads/cesiumjs/releases/[version]/... urls
52+
# Publish the documentation files to the bucket for https://cesium.com/learn/cesiumjs/ref-doc/
53+
# Publish the simple viewer app to the bucket for https://cesium.com/cesiumjs/cesium-viewer/
54+
# Publish sandcastle to the bucket for https://sandcastle.cesium.com/
5255
run: |
5356
curl -LO $(curl https://api.github.com/repos/CesiumGS/cesium/releases/latest -H "Authorization: ${GITHUB_TOKEN}" | jq -r '.assets[0].browser_download_url')
5457
unzip Cesium-$(cat package.json | jq -r '.version' | sed 's/\.0$//').zip -d Build/release/ -x "Apps"

.github/workflows/sandcastle-dev.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: sandcastle-dev
22
on:
33
push:
44
branches:
5-
- 'cesium.com'
5+
- "main"
66
jobs:
77
deploy:
88
runs-on: ubuntu-latest
@@ -20,15 +20,15 @@ jobs:
2020
- name: install node 22
2121
uses: actions/setup-node@v6
2222
with:
23-
node-version: '22'
23+
node-version: "22"
2424
- name: npm install
2525
run: npm install
2626
- name: build website release
2727
run: npm run website-release
2828
- name: build types
2929
run: npm run build-ts
3030
- name: build prod sandcastle
31-
run: npm run build-prod -w packages/sandcastle -- -l warn
31+
run: npm run build-sandcastle
3232
- name: deploy to dev-sandcastle.cesium.com
3333
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
3434
run: |

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
/scripts/
2424
/favicon.ico
2525
/gulpfile.js
26+
/gulpfile.apps.js
27+
/gulpfile.makezip.js
2628
/index.html
2729
/index.release.html
2830
/launches

Documentation/Contributors/BuildGuide/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ npm start
7777
Then browse to [http://localhost:8080/](http://localhost:8080/). The landing page includes apps and tools commonly used during development, including:
7878

7979
- **Hello World** : an example for how to create a 3D globe. [Tutorial here](https://cesium.com/learn/cesiumjs-learn/cesiumjs-quickstart/)
80-
- **Sandcastle** : an app for viewing and creating [code examples](https://sandcastle.cesium.com?src=Hello%20World.html&label=Showcases), complete with a live preview
80+
- **Sandcastle** : an app for viewing and creating [code examples](https://sandcastle.cesium.com), complete with a live preview
8181
- **Test Suites** : tests using [Jasmine](https://jasmine.github.io/). [Testing guide here.](https://github.com/CesiumGS/cesium/blob/main/Documentation/Contributors/TestingGuide/README.md#testing-guide)
8282
- **Documentation** : reference documentation built from source. [Documentation guide here.](https://github.com/CesiumGS/cesium/blob/main/Documentation/Contributors/DocumentationGuide/README.md#documentation-guide)
8383

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export default [
4848
"scripts/**/*.js",
4949
"packages/sandcastle/scripts/**/*.js",
5050
"gulpfile.js",
51+
"gulpfile.apps.js",
52+
"gulpfile.makezip.js",
5153
"server.js",
5254
],
5355
...configCesium.configs.node,

gulpfile.apps.js

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
import { join } from "path";
2+
import { finished } from "stream/promises";
3+
4+
import gulp from "gulp";
5+
import gulpReplace from "gulp-replace";
6+
import { buildSandcastleApp } from "./scripts/buildSandcastle.js";
7+
import { mkdirp } from "mkdirp";
8+
import { bundleWorkers, defaultESBuildOptions } from "./scripts/build.js";
9+
import { build as esbuild } from "esbuild";
10+
11+
const isProduction = process.env.PROD === "true";
12+
13+
// Print an esbuild warning
14+
function printBuildWarning({ location, text }) {
15+
const { column, file, line, lineText, suggestion } = location;
16+
17+
let message = `\n
18+
> ${file}:${line}:${column}: warning: ${text}
19+
${lineText}
20+
`;
21+
22+
if (suggestion && suggestion !== "") {
23+
message += `\n${suggestion}`;
24+
}
25+
26+
console.log(message);
27+
}
28+
29+
// Ignore `eval` warnings in third-party code we don't have control over
30+
function handleBuildWarnings(result) {
31+
for (const warning of result.warnings) {
32+
if (
33+
!warning.location.file.includes("protobufjs.js") &&
34+
!warning.location.file.includes("Build/Cesium")
35+
) {
36+
printBuildWarning(warning);
37+
}
38+
}
39+
}
40+
41+
async function buildLegacySandcastle() {
42+
const streams = [];
43+
let appStream = gulp.src(
44+
[
45+
"Apps/Sandcastle/**",
46+
"!Apps/Sandcastle/load-cesium-es6.js",
47+
"!Apps/Sandcastle/images/**",
48+
"!Apps/Sandcastle/gallery/**.jpg",
49+
],
50+
{
51+
encoding: false,
52+
},
53+
);
54+
55+
if (isProduction) {
56+
// Remove swap out ESM modules for the IIFE build
57+
appStream = appStream
58+
.pipe(
59+
gulpReplace(
60+
' <script type="module" src="../load-cesium-es6.js"></script>',
61+
' <script src="../CesiumUnminified/Cesium.js"></script>\n' +
62+
' <script>window.CESIUM_BASE_URL = "../CesiumUnminified/";</script>',
63+
),
64+
)
65+
.pipe(
66+
gulpReplace(
67+
' <script type="module" src="load-cesium-es6.js"></script>',
68+
' <script src="CesiumUnminified/Cesium.js"></script>\n' +
69+
' <script>window.CESIUM_BASE_URL = "CesiumUnminified/";</script>',
70+
),
71+
)
72+
// Fix relative paths for new location
73+
.pipe(gulpReplace("../../../Build", ".."))
74+
.pipe(gulpReplace("../../../Source", "../CesiumUnminified"))
75+
.pipe(gulpReplace("../../Source", "."))
76+
.pipe(gulpReplace("../../../ThirdParty", "./ThirdParty"))
77+
.pipe(gulpReplace("../../ThirdParty", "./ThirdParty"))
78+
.pipe(gulpReplace("../ThirdParty", "./ThirdParty"))
79+
.pipe(gulpReplace("../Apps/Sandcastle", "."))
80+
.pipe(gulpReplace("../../SampleData", "../SampleData"))
81+
.pipe(
82+
gulpReplace("../../Build/Documentation", "/learn/cesiumjs/ref-doc/"),
83+
)
84+
.pipe(gulp.dest("Build/Sandcastle"));
85+
} else {
86+
// Remove swap out ESM modules for the IIFE build
87+
appStream = appStream
88+
.pipe(
89+
gulpReplace(
90+
' <script type="module" src="../load-cesium-es6.js"></script>',
91+
' <script src="../../../Build/CesiumUnminified/Cesium.js"></script>\n' +
92+
' <script>window.CESIUM_BASE_URL = "../../../Build/CesiumUnminified/";</script>',
93+
),
94+
)
95+
.pipe(
96+
gulpReplace(
97+
' <script type="module" src="load-cesium-es6.js"></script>',
98+
' <script src="../../CesiumUnminified/Cesium.js"></script>\n' +
99+
' <script>window.CESIUM_BASE_URL = "../../CesiumUnminified/";</script>',
100+
),
101+
)
102+
// Fix relative paths for new location
103+
.pipe(gulpReplace("../../../Build", "../../.."))
104+
.pipe(gulpReplace("../../Source", "../../../Source"))
105+
.pipe(gulpReplace("../../ThirdParty", "../../../ThirdParty"))
106+
.pipe(gulpReplace("../../SampleData", "../../../../Apps/SampleData"))
107+
.pipe(gulpReplace("Build/Documentation", "Documentation"))
108+
.pipe(gulp.dest("Build/Apps/Sandcastle"));
109+
}
110+
streams.push(appStream);
111+
112+
let imageStream = gulp.src(
113+
["Apps/Sandcastle/gallery/**.jpg", "Apps/Sandcastle/images/**"],
114+
{
115+
base: "Apps/Sandcastle",
116+
encoding: false,
117+
},
118+
);
119+
if (isProduction) {
120+
imageStream = imageStream.pipe(gulp.dest("Build/Sandcastle"));
121+
} else {
122+
imageStream = imageStream.pipe(gulp.dest("Build/Apps/Sandcastle"));
123+
}
124+
streams.push(imageStream);
125+
126+
if (isProduction) {
127+
const fileStream = gulp
128+
.src(["ThirdParty/**"], { encoding: false })
129+
.pipe(gulp.dest("Build/Sandcastle/ThirdParty"));
130+
streams.push(fileStream);
131+
132+
const dataStream = gulp
133+
.src(["Apps/SampleData/**"], { encoding: false })
134+
.pipe(gulp.dest("Build/Sandcastle/SampleData"));
135+
streams.push(dataStream);
136+
}
137+
138+
let standaloneStream = gulp
139+
.src(["Apps/Sandcastle/standalone.html"])
140+
.pipe(gulpReplace("../../../", "."))
141+
.pipe(
142+
gulpReplace(
143+
' <script type="module" src="load-cesium-es6.js"></script>',
144+
' <script src="../CesiumUnminified/Cesium.js"></script>\n' +
145+
' <script>window.CESIUM_BASE_URL = "../CesiumUnminified/";</script>',
146+
),
147+
)
148+
.pipe(gulpReplace("../../Build", "."));
149+
if (isProduction) {
150+
standaloneStream = standaloneStream.pipe(gulp.dest("Build/Sandcastle"));
151+
} else {
152+
standaloneStream = standaloneStream.pipe(
153+
gulp.dest("Build/Apps/Sandcastle"),
154+
);
155+
}
156+
streams.push(standaloneStream);
157+
158+
return Promise.all(streams.map((s) => finished(s)));
159+
}
160+
161+
async function buildCesiumViewer() {
162+
const cesiumViewerOutputDirectory = isProduction
163+
? "Build/CesiumViewer"
164+
: "Build/Apps/CesiumViewer";
165+
mkdirp.sync(cesiumViewerOutputDirectory);
166+
167+
const config = defaultESBuildOptions();
168+
config.entryPoints = [
169+
"Apps/CesiumViewer/CesiumViewer.js",
170+
"Apps/CesiumViewer/CesiumViewer.css",
171+
];
172+
config.bundle = true; // Tree-shaking is enabled automatically
173+
config.minify = true;
174+
config.loader = {
175+
".gif": "text",
176+
".png": "text",
177+
};
178+
config.format = "iife";
179+
// Configure Cesium base path to use built
180+
config.define = { CESIUM_BASE_URL: `"."` };
181+
config.outdir = cesiumViewerOutputDirectory;
182+
config.outbase = "Apps/CesiumViewer";
183+
config.logLevel = "error"; // print errors immediately, and collect warnings so we can filter out known ones
184+
const result = await esbuild(config);
185+
186+
handleBuildWarnings(result);
187+
188+
await esbuild({
189+
entryPoints: ["packages/widgets/Source/InfoBox/InfoBoxDescription.css"],
190+
minify: true,
191+
bundle: true,
192+
loader: {
193+
".gif": "text",
194+
".png": "text",
195+
},
196+
outdir: join(cesiumViewerOutputDirectory, "Widgets"),
197+
outbase: "packages/widgets/Source/",
198+
});
199+
200+
await bundleWorkers({
201+
minify: true,
202+
removePragmas: true,
203+
path: cesiumViewerOutputDirectory,
204+
});
205+
206+
const stream = gulp
207+
.src(
208+
[
209+
"Apps/CesiumViewer/**",
210+
"!Apps/CesiumViewer/Images",
211+
"!Apps/CesiumViewer/**/*.js",
212+
"!Apps/CesiumViewer/**/*.css",
213+
],
214+
{
215+
encoding: false,
216+
},
217+
)
218+
.pipe(
219+
gulp.src(
220+
[
221+
"Build/Cesium/Assets/**",
222+
"Build/Cesium/Workers/**",
223+
"Build/Cesium/ThirdParty/**",
224+
"Build/Cesium/Widgets/**",
225+
"!Build/Cesium/Widgets/**/*.css",
226+
],
227+
{
228+
base: "Build/Cesium",
229+
nodir: true,
230+
encoding: false,
231+
},
232+
),
233+
)
234+
.pipe(gulp.src(["web.config"]))
235+
.pipe(gulp.dest(cesiumViewerOutputDirectory));
236+
237+
await finished(stream);
238+
return stream;
239+
}
240+
241+
export async function buildSandcastle() {
242+
return buildSandcastleApp({
243+
outputToBuildDir: isProduction,
244+
includeDevelopment: !isProduction,
245+
});
246+
}
247+
248+
export const buildApps = gulp.parallel(
249+
buildCesiumViewer,
250+
buildLegacySandcastle,
251+
buildSandcastle,
252+
);

0 commit comments

Comments
 (0)