-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathgulpfile.apps.js
More file actions
167 lines (147 loc) · 4.47 KB
/
Copy pathgulpfile.apps.js
File metadata and controls
167 lines (147 loc) · 4.47 KB
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
import { join } from "path";
import { finished } from "stream/promises";
import gulp from "gulp";
import yargs from "yargs";
import { buildSandcastleApp } from "./scripts/buildSandcastle.js";
import { mkdirp } from "mkdirp";
import { bundleWorkers, defaultESBuildOptions } from "./scripts/build.js";
import { build as esbuild } from "esbuild";
const isProduction = process.env.PROD === "true";
// Print an esbuild warning
function printBuildWarning({ location, text }) {
const { column, file, line, lineText, suggestion } = location;
let message = `\n
> ${file}:${line}:${column}: warning: ${text}
${lineText}
`;
if (suggestion && suggestion !== "") {
message += `\n${suggestion}`;
}
console.log(message);
}
// Ignore `eval` warnings in third-party code we don't have control over
function handleBuildWarnings(result) {
for (const warning of result.warnings) {
if (
!warning.location.file.includes("protobufjs.js") &&
!warning.location.file.includes("Build/Cesium")
) {
printBuildWarning(warning);
}
}
}
export async function buildCesiumViewer() {
const cesiumViewerOutputDirectory = isProduction
? "Build/CesiumViewer"
: "Build/Apps/CesiumViewer";
mkdirp.sync(cesiumViewerOutputDirectory);
const config = defaultESBuildOptions();
config.entryPoints = [
"Apps/CesiumViewer/CesiumViewer.js",
"Apps/CesiumViewer/CesiumViewer.css",
];
config.bundle = true; // Tree-shaking is enabled automatically
config.minify = true;
config.loader = {
".gif": "text",
".png": "text",
};
config.format = "iife";
// Configure Cesium base path to use built
config.define = { CESIUM_BASE_URL: `"."` };
config.outdir = cesiumViewerOutputDirectory;
config.outbase = "Apps/CesiumViewer";
config.logLevel = "error"; // print errors immediately, and collect warnings so we can filter out known ones
const result = await esbuild(config);
handleBuildWarnings(result);
await esbuild({
entryPoints: ["packages/widgets/Source/InfoBox/InfoBoxDescription.css"],
minify: true,
bundle: true,
loader: {
".gif": "text",
".png": "text",
},
outdir: join(cesiumViewerOutputDirectory, "Widgets"),
outbase: "packages/widgets/Source/",
});
await bundleWorkers({
minify: true,
removePragmas: true,
path: cesiumViewerOutputDirectory,
});
const stream = gulp
.src(
[
"Apps/CesiumViewer/**",
"!Apps/CesiumViewer/Images",
"!Apps/CesiumViewer/**/*.js",
"!Apps/CesiumViewer/**/*.css",
],
{
encoding: false,
},
)
.pipe(
gulp.src(
[
"Build/Cesium/Assets/**",
"Build/Cesium/Workers/**",
"Build/Cesium/ThirdParty/**",
"Build/Cesium/Widgets/**",
"!Build/Cesium/Widgets/**/*.css",
],
{
base: "Build/Cesium",
nodir: true,
encoding: false,
},
),
)
.pipe(gulp.src(["web.config"]))
.pipe(gulp.dest(cesiumViewerOutputDirectory));
await finished(stream);
return stream;
}
export async function buildSandcastle() {
const argv = await yargs(process.argv.slice(5))
.options({
"outer-origin": {
type: "string",
description:
"The outer origin for the Sandcastle App. Defaults to localhost:8080 if not specified",
},
"inner-origin": {
type: "string",
description:
"The inner origin for the Sandcastle viewer iframe. Defaults to the outer-origin if not specified or localhost:8081 if neither are specified",
},
embeddings: {
type: "boolean",
default: true,
description:
"Generate semantic search embeddings. Pass --no-embeddings to skip. Can also be set via SANDCASTLE_NO_EMBEDDINGS=1.",
},
})
.help(false)
.version(false)
.strict()
.parse();
let outerOrigin = argv.outerOrigin ?? "http://localhost:8080";
let innerOrigin =
argv.innerOrigin ?? argv.outerOrigin ?? "http://localhost:8081";
if (process.env.SANDCASTLE_ORIGIN) {
outerOrigin = process.env.SANDCASTLE_ORIGIN;
innerOrigin = outerOrigin;
}
const noEmbeddings =
!argv.embeddings || !!process.env.SANDCASTLE_NO_EMBEDDINGS;
return buildSandcastleApp({
outputToBuildDir: isProduction,
includeDevelopment: !isProduction,
outerOrigin,
innerOrigin,
generateEmbeddings: noEmbeddings ? false : undefined,
});
}
export const buildApps = gulp.parallel(buildCesiumViewer, buildSandcastle);