Skip to content

Commit 22940ed

Browse files
committed
Refactor template string with handlebars.
- Refactor static routing, template vars. - Fixed issue where JSON entities may be unescaped - Updated web manifest schema, route handler. - Clean up issues surrounding static paths, types. - Removed static path helper. - Fixed issue where locals may change during request handling. - Added missing types. - Fixed issue where body theme color is stale.
1 parent 3f1750c commit 22940ed

37 files changed

+638
-371
lines changed

ci/build/build-code-server.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ main() {
2525
fi
2626

2727
parcel build \
28-
--public-url "." \
28+
--public-url "/static/" \
2929
--out-dir dist \
30-
$([[ $MINIFY ]] || echo --no-minify) \
31-
src/browser/register.ts \
32-
src/browser/serviceWorker.ts \
33-
src/browser/pages/login.ts \
34-
src/browser/pages/vscode.ts
30+
"$([[ $MINIFY ]] || echo --no-minify)" \
31+
src/browser/**/*.ts
3532
}
3633

3734
main "$@"

ci/build/build-release.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ bundle_code_server() {
3838

3939
# For source maps and images.
4040
mkdir -p "$RELEASE_PATH/src/browser"
41-
rsync src/browser/media/ "$RELEASE_PATH/src/browser/media"
42-
mkdir -p "$RELEASE_PATH/src/browser/pages"
43-
rsync src/browser/pages/*.html "$RELEASE_PATH/src/browser/pages"
44-
rsync src/browser/robots.txt "$RELEASE_PATH/src/browser"
41+
rsync -r src/browser/public "$RELEASE_PATH/src/browser"
42+
mkdir -p "$RELEASE_PATH/src/browser/views"
43+
rsync -r src/browser/views "$RELEASE_PATH/src/browser"
4544

4645
# Adds the commit to package.json
4746
jq --slurp '.[0] * .[1]' package.json <(

ci/dev/watch.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,13 @@ class Watcher {
173173
}
174174

175175
private createBundler(out = "dist"): Bundler {
176-
return new Bundler(
177-
[
178-
path.join(this.rootPath, "src/browser/register.ts"),
179-
path.join(this.rootPath, "src/browser/serviceWorker.ts"),
180-
path.join(this.rootPath, "src/browser/pages/login.ts"),
181-
path.join(this.rootPath, "src/browser/pages/vscode.ts"),
182-
],
183-
{
184-
outDir: path.join(this.rootPath, out),
185-
cacheDir: path.join(this.rootPath, ".cache"),
186-
minify: !!process.env.MINIFY,
187-
logLevel: 1,
188-
publicUrl: ".",
189-
},
190-
)
176+
return new Bundler([path.join(this.rootPath, "src/browser/**/*.ts")], {
177+
outDir: path.join(this.rootPath, out),
178+
cacheDir: path.join(this.rootPath, ".cache"),
179+
minify: !!process.env.MINIFY,
180+
logLevel: 1,
181+
publicUrl: "/static/",
182+
})
191183
}
192184
}
193185

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
"devDependencies": {
3333
"@types/body-parser": "^1.19.0",
3434
"@types/cookie-parser": "^1.4.2",
35+
"@types/entities": "^1.1.1",
3536
"@types/express": "^4.17.8",
37+
"@types/express-handlebars": "^3.1.0",
3638
"@types/fs-extra": "^8.0.1",
3739
"@types/http-proxy": "^1.17.4",
3840
"@types/js-yaml": "^3.12.3",
@@ -71,8 +73,10 @@
7173
"@coder/logger": "1.1.16",
7274
"body-parser": "^1.19.0",
7375
"cookie-parser": "^1.4.5",
76+
"entities": "^2.1.0",
7477
"env-paths": "^2.2.0",
7578
"express": "^5.0.0-alpha.8",
79+
"express-handlebars": "^5.2.0",
7680
"fs-extra": "^9.0.1",
7781
"http-proxy": "^1.18.0",
7882
"httpolyglot": "^0.1.2",

src/browser/main.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import "./views/error/index.css"
2+
import "./views/global.css"
3+
import "./views/login/index.css"
4+
5+
import { getOptions, normalize } from "../common/util"
6+
7+
const options = getOptions()
8+
9+
if ("serviceWorker" in navigator) {
10+
const path = normalize(`${options.base}/serviceWorker.js`)
11+
navigator.serviceWorker
12+
.register(path, {
13+
scope: (options.base ?? "") + "/",
14+
})
15+
.then(() => console.debug("[Code Server Service Worker] registered"))
16+
}

src/browser/media/manifest.json

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/browser/pages/login.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/browser/pages/vscode.html

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/browser/pages/vscode.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)