Skip to content

Commit 58cab60

Browse files
committed
Merge branch 'main' into upgrade-ts-592
2 parents 6414236 + 3370f4f commit 58cab60

File tree

6 files changed

+1113
-1294
lines changed

6 files changed

+1113
-1294
lines changed

buildprocess/configureWebpackForPlugins.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const path = require("path");
44
const fs = require("fs");
5-
65
/**
76
* RegExp pattern used for matching plugin package names for applying various rules.
87
*
@@ -19,7 +18,7 @@ function configureWebpackForPlugins(config) {
1918
}
2019

2120
/**
22-
* Creates a webpack rule for processing svg icons from terriajs plugins using `svg-sprite-loader`.
21+
* Creates a webpack rule for processing svg icons from terriajs plugins using terriajs `svg-sprite-loader`.
2322
* We check two things to decide whether to include an icon:
2423
* 1. The icon belongs to assets/icons folder
2524
* 2. assets/icons/../../package.json has a name field with `terriajs-plugin-` prefix
@@ -48,15 +47,12 @@ function createPluginIconsRule() {
4847
packageNames[svgPath] = packageName;
4948
return isTerriaJsPlugin;
5049
},
51-
loader: require.resolve("svg-sprite-loader"),
50+
loader: require.resolve("terriajs/buildprocess/svgs/svg-sprite-loader.js"),
5251
options: {
53-
esModule: false,
54-
symbolId: (svgPath) => {
52+
namespace: (svgPath) => {
5553
// Generate a symbolId by concatenating the package name and the icon name
56-
const packageName = packageNames[svgPath] || "terriajs-plugin-";
57-
const iconName = path.basename(svgPath, ".svg");
58-
const symbolId = `${packageName}-${iconName}`;
59-
return symbolId;
54+
const packageName = packageNames[svgPath] || "terriajs-plugin";
55+
return packageName;
6056
}
6157
}
6258
};

buildprocess/webpack.config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ const configureWebpackForPlugins = require("./configureWebpackForPlugins");
66
const defaultBabelLoader = require("terriajs/buildprocess/defaultBabelLoader");
77
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
88
const path = require("path");
9+
const HtmlPlugin = require("html-webpack-plugin");
910

1011
/**
1112
* Webpack config for building terriamap
1213
*/
13-
module.exports = function (devMode) {
14+
module.exports = function ({ devMode, baseHref = "/" }) {
1415
// Base configuration
1516
const config = {
1617
mode: devMode ? "development" : "production",
@@ -112,6 +113,13 @@ module.exports = function (devMode) {
112113
new MiniCssExtractPlugin({
113114
filename: "TerriaMap.css",
114115
ignoreOrder: true
116+
}),
117+
new HtmlPlugin({
118+
filename: path.resolve(__dirname, "..", "wwwroot", "index.html"),
119+
template: path.resolve(__dirname, "..", "wwwroot", "index.ejs"),
120+
templateParameters: {
121+
baseHref: baseHref
122+
}
115123
})
116124
],
117125
resolve: {

gulpfile.js

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ var watchOptions = {
1919
interval: 1000
2020
};
2121

22+
const getBaseHref = () => {
23+
var minimist = require("minimist");
24+
// Arguments written in skewer-case can cause problems (unsure why), so stick to camelCase
25+
var options = minimist(process.argv.slice(2), {
26+
string: ["baseHref"],
27+
default: { baseHref: "/" }
28+
});
29+
30+
return options.baseHref;
31+
};
32+
2233
gulp.task("check-terriajs-dependencies", function (done) {
2334
var appPackageJson = require("./package.json");
2435
var terriaPackageJson = require("terriajs/package.json");
@@ -70,33 +81,19 @@ gulp.task("write-version", function (done) {
7081
done();
7182
});
7283

73-
gulp.task("render-index", function renderIndex(done) {
74-
var ejs = require("ejs");
75-
var minimist = require("minimist");
76-
// Arguments written in skewer-case can cause problems (unsure why), so stick to camelCase
77-
var options = minimist(process.argv.slice(2), {
78-
string: ["baseHref"],
79-
default: { baseHref: "/" }
80-
});
81-
82-
var index = fs.readFileSync("wwwroot/index.ejs", "utf8");
83-
var indexResult = ejs.render(index, { baseHref: options.baseHref });
84-
85-
fs.writeFileSync(path.join("wwwroot", "index.html"), indexResult);
86-
done();
87-
});
88-
8984
gulp.task(
9085
"build-app",
9186
gulp.parallel(
92-
"render-index",
9387
gulp.series(
9488
"check-terriajs-dependencies",
9589
"write-version",
9690
function buildApp(done) {
9791
var runWebpack = require("terriajs/buildprocess/runWebpack.js");
9892
var webpack = require("webpack");
99-
var webpackConfig = require("./buildprocess/webpack.config.js")(true);
93+
var webpackConfig = require("./buildprocess/webpack.config.js")({
94+
devMode: true,
95+
baseHref: getBaseHref()
96+
});
10097

10198
checkForDuplicateCesium();
10299

@@ -109,14 +106,16 @@ gulp.task(
109106
gulp.task(
110107
"release-app",
111108
gulp.parallel(
112-
"render-index",
113109
gulp.series(
114110
"check-terriajs-dependencies",
115111
"write-version",
116112
function releaseApp(done) {
117113
var runWebpack = require("terriajs/buildprocess/runWebpack.js");
118114
var webpack = require("webpack");
119-
var webpackConfig = require("./buildprocess/webpack.config.js")(false);
115+
var webpackConfig = require("./buildprocess/webpack.config.js")({
116+
devMode: false,
117+
baseHref: getBaseHref()
118+
});
120119

121120
checkForDuplicateCesium();
122121

@@ -132,25 +131,17 @@ gulp.task(
132131
)
133132
);
134133

135-
gulp.task(
136-
"watch-render-index",
137-
gulp.series("render-index", function watchRenderIndex() {
138-
gulp.watch(["wwwroot/index.ejs"], gulp.series("render-index"));
139-
})
140-
);
141-
142134
gulp.task(
143135
"watch-app",
144136
gulp.parallel(
145-
"watch-render-index",
146137
gulp.series("check-terriajs-dependencies", function watchApp(done) {
147138
var fs = require("fs");
148139
var watchWebpack = require("terriajs/buildprocess/watchWebpack");
149140
var webpack = require("webpack");
150-
var webpackConfig = require("./buildprocess/webpack.config.js")(
151-
true,
152-
false
153-
);
141+
var webpackConfig = require("./buildprocess/webpack.config.js")({
142+
devMode: true,
143+
baseHref: getBaseHref()
144+
});
154145

155146
checkForDuplicateCesium();
156147

@@ -290,10 +281,24 @@ gulp.task("terriajs-server", terriajsServerGulpTask(3001));
290281
gulp.task("build", gulp.series("copy-terriajs-assets", "build-app"));
291282
gulp.task("release", gulp.series("copy-terriajs-assets", "release-app"));
292283
gulp.task("watch", gulp.parallel("watch-terriajs-assets", "watch-app"));
293-
// Run render-index before starting terriajs-server because terriajs-server won't
294-
// start if index.html isn't present
284+
// Simple task that waits for index.html then starts server
295285
gulp.task(
296286
"dev",
297-
gulp.parallel(gulp.series("render-index", "terriajs-server"), "watch")
287+
gulp.parallel("watch", function startServerWhenReady(done) {
288+
const indexFile = path.join(__dirname, "wwwroot", "index.html");
289+
290+
if (fs.existsSync(indexFile)) {
291+
terriajsServerGulpTask(3001)(done);
292+
return;
293+
}
294+
var watcher = gulp.watch(
295+
path.join(__dirname, "wwwroot", "index.html"),
296+
watchOptions
297+
);
298+
watcher.on("add", function () {
299+
watcher.close();
300+
terriajsServerGulpTask(3001)(done);
301+
});
302+
})
298303
);
299304
gulp.task("default", gulp.series("lint", "build"));

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"@typescript-eslint/parser": "^8.24.0",
4646
"babel-loader": "^10.0.0",
4747
"css-loader": "^7.1.2",
48-
"ejs": "^3.1.10",
4948
"eslint": "^8.57.1",
5049
"eslint-config-prettier": "^9.1.0",
5150
"eslint-plugin-react": "^7.37.4",
@@ -55,6 +54,7 @@
5554
"fork-ts-checker-webpack-plugin": "^9.0.2",
5655
"fs-extra": "^7.0.1",
5756
"gulp": "^5.0.0",
57+
"html-webpack-plugin": "^5.6.3",
5858
"husky": "^8.0.3",
5959
"is-subdir": "^1.2.0",
6060
"json5": "^2.1.0",
@@ -71,9 +71,9 @@
7171
"sass": "^1.81.0",
7272
"sass-loader": "^16.0.3",
7373
"style-loader": "^4.0.0",
74-
"svg-sprite-loader": "^6.0.11",
75-
"terriajs": "terriajs/terriajs#upgrade-ts-592",
76-
"terriajs-cesium": "20.0.1",
74+
"terriajs": "8.11.0",
75+
"terriajs-cesium": "21.0.0",
76+
"svg-sprite": "^2.0.4",
7777
"terriajs-plugin-api": "0.0.1-alpha.17",
7878
"terriajs-plugin-sample": "0.0.1-alpha.7",
7979
"typescript": "^5.9.2",

wwwroot/index.ejs

Lines changed: 95 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,104 @@
11
<!DOCTYPE html>
22
<html lang="en" class="terria">
3-
<head>
4-
<base href="<%= baseHref %>">
5-
<meta charset="utf-8">
6-
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> <!-- Use Chrome Frame in IE -->
7-
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
8-
<meta name="description" content="A web map built on Terria Map">
9-
<meta name="apple-mobile-web-app-capable" content="yes">
3+
<head>
4+
<base href="<%= baseHref %>" />
5+
<meta charset="utf-8" />
6+
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
7+
<!-- Use Chrome Frame in IE -->
8+
<meta
9+
name="viewport"
10+
content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
11+
/>
12+
<meta name="description" content="A web map built on Terria Map" />
13+
<meta name="apple-mobile-web-app-capable" content="yes" />
1014

11-
<link rel="apple-touch-icon" sizes="57x57" href="favicons/apple-icon-57x57.png">
12-
<link rel="apple-touch-icon" sizes="60x60" href="favicons/apple-icon-60x60.png">
13-
<link rel="apple-touch-icon" sizes="72x72" href="favicons/apple-icon-72x72.png">
14-
<link rel="apple-touch-icon" sizes="76x76" href="favicons/apple-icon-76x76.png">
15-
<link rel="apple-touch-icon" sizes="114x114" href="favicons/apple-icon-114x114.png">
16-
<link rel="apple-touch-icon" sizes="120x120" href="favicons/apple-icon-120x120.png">
17-
<link rel="apple-touch-icon" sizes="144x144" href="favicons/apple-icon-144x144.png">
18-
<link rel="apple-touch-icon" sizes="152x152" href="favicons/apple-icon-152x152.png">
19-
<link rel="apple-touch-icon" sizes="180x180" href="favicons/apple-icon-180x180.png">
20-
<link rel="icon" type="image/png" sizes="192x192" href="favicons/android-icon-192x192.png">
21-
<link rel="icon" type="image/png" sizes="32x32" href="favicons/favicon-32x32.png">
22-
<link rel="icon" type="image/png" sizes="96x96" href="favicons/favicon-96x96.png">
23-
<link rel="icon" type="image/png" sizes="16x16" href="favicons/favicon-16x16.png">
24-
<link rel="manifest" href="favicons/manifest.json">
25-
<meta name="msapplication-TileColor" content="#282D32">
26-
<meta name="msapplication-TileImage" content="favicons/ms-icon-144x144.png">
27-
<meta name="theme-color" content="#282D32">
15+
<link
16+
rel="apple-touch-icon"
17+
sizes="57x57"
18+
href="favicons/apple-icon-57x57.png"
19+
/>
20+
<link
21+
rel="apple-touch-icon"
22+
sizes="60x60"
23+
href="favicons/apple-icon-60x60.png"
24+
/>
25+
<link
26+
rel="apple-touch-icon"
27+
sizes="72x72"
28+
href="favicons/apple-icon-72x72.png"
29+
/>
30+
<link
31+
rel="apple-touch-icon"
32+
sizes="76x76"
33+
href="favicons/apple-icon-76x76.png"
34+
/>
35+
<link
36+
rel="apple-touch-icon"
37+
sizes="114x114"
38+
href="favicons/apple-icon-114x114.png"
39+
/>
40+
<link
41+
rel="apple-touch-icon"
42+
sizes="120x120"
43+
href="favicons/apple-icon-120x120.png"
44+
/>
45+
<link
46+
rel="apple-touch-icon"
47+
sizes="144x144"
48+
href="favicons/apple-icon-144x144.png"
49+
/>
50+
<link
51+
rel="apple-touch-icon"
52+
sizes="152x152"
53+
href="favicons/apple-icon-152x152.png"
54+
/>
55+
<link
56+
rel="apple-touch-icon"
57+
sizes="180x180"
58+
href="favicons/apple-icon-180x180.png"
59+
/>
60+
<link
61+
rel="icon"
62+
type="image/png"
63+
sizes="192x192"
64+
href="favicons/android-icon-192x192.png"
65+
/>
66+
<link
67+
rel="icon"
68+
type="image/png"
69+
sizes="32x32"
70+
href="favicons/favicon-32x32.png"
71+
/>
72+
<link
73+
rel="icon"
74+
type="image/png"
75+
sizes="96x96"
76+
href="favicons/favicon-96x96.png"
77+
/>
78+
<link
79+
rel="icon"
80+
type="image/png"
81+
sizes="16x16"
82+
href="favicons/favicon-16x16.png"
83+
/>
84+
<link rel="manifest" href="favicons/manifest.json" />
85+
<meta name="msapplication-TileColor" content="#282D32" />
86+
<meta
87+
name="msapplication-TileImage"
88+
content="favicons/ms-icon-144x144.png"
89+
/>
90+
<meta name="theme-color" content="#282D32" />
2891

2992
<title>Terria Map</title>
30-
<link rel="stylesheet" type="text/css" href="build/TerriaMap.css">
3193

3294
<!-- Leaflet -->
33-
<script>L_PREFER_CANVAS = true;</script>
34-
</head>
95+
<script>
96+
L_PREFER_CANVAS = true;
97+
</script>
98+
</head>
3599

36-
<body>
37-
38-
<div id='ui'></div>
39-
<script src="build/TerriaMap.js"></script>
40-
</body>
100+
<body>
101+
<div id="svg-sprites" style="display: none"></div>
102+
<div id="ui"></div>
103+
</body>
41104
</html>

0 commit comments

Comments
 (0)