Skip to content

Commit 1ff9d73

Browse files
authored
Upgrade website (#131)
* Working playground * Proper playground tsWorker fix * prettier * Remove js that wasnt meant to be checked in * Ignore cdn'd JS from prettier
1 parent 5a8fa51 commit 1ff9d73

15 files changed

+9782
-14803
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ jobs:
99

1010
steps:
1111
- uses: actions/checkout@v2
12-
- name: Use Node.js 12
12+
- name: Use Node.js 16
1313
uses: actions/setup-node@v1
1414
with:
15-
node-version: 12
15+
node-version: 16
1616
- run: npm ci
1717
- run: npm run build
1818
- run: npm run lint

.github/workflows/deploy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ jobs:
2020

2121
steps:
2222
- uses: actions/checkout@v2
23-
- name: Use Node.js 12
23+
- name: Use Node.js 16
2424
uses: actions/setup-node@v1
2525
with:
26-
node-version: 12
26+
node-version: 16
2727
- run: npm ci
2828
- run: npm run build
2929
- name: Create gh-pages artifact

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
.docusaurus
33
/build
4-
.DS_Store
4+
.DS_Store
5+
static/cdn.tsWorker.js

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.docusaurus
22
/build
3+
/static/cdn.tsWorker.js

docusaurus-plugin.js

+3-25
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,15 @@ module.exports = () => ({
1616
},
1717
resolve: {
1818
alias: {
19-
// Replace vendored monaco-typescript services build with typescript, already used by typescript-to-lua
20-
[require.resolve("monaco-editor/esm/vs/language/typescript/lib/typescriptServices.js")]:
21-
require.resolve("typescript"),
22-
23-
// Exclude builtin monaco-typescript libs
24-
[require.resolve("monaco-editor/esm/vs/language/typescript/lib/lib.js")]: resolve(
25-
"src/monaco-typescript-lib-stub.ts",
26-
),
19+
// tsWorker downloaded by fetch-tsworker.js for our current TS version
20+
["cdn.tsWorker"]: resolve("static/cdn.tsWorker.js"),
2721

2822
// Stub file resolution for playground
2923
[require.resolve("typescript-to-lua/dist/transpilation/resolve.js")]:
3024
resolve("src/resolve-stub.ts"),
3125
},
3226
fallback: {
27+
os: false,
3328
fs: false,
3429
perf_hooks: false,
3530
buffer: require.resolve("buffer"),
@@ -38,23 +33,6 @@ module.exports = () => ({
3833
path: require.resolve("path-browserify"),
3934
},
4035
},
41-
module: {
42-
rules: [
43-
{ test: /\.ttf$/, loader: "file-loader" },
44-
{
45-
test: /\.scss$/,
46-
exclude: /\.module\.scss$/,
47-
use: [...config.module.rules.find((r) => String(r.test) === "/\\.css$/").use, "sass-loader"],
48-
},
49-
{
50-
test: /\.module\.scss$/,
51-
use: [
52-
...config.module.rules.find((r) => String(r.test) === "/\\.module\\.css$/").use,
53-
"sass-loader",
54-
],
55-
},
56-
],
57-
},
5836
plugins: [
5937
new ProvidePlugin({
6038
process: "process/browser",

docusaurus.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ module.exports = {
8888
darkTheme: require("prism-react-renderer/themes/vsDark"),
8989
},
9090
algolia: {
91+
appId: "BH4D9OD16A",
9192
apiKey: "c0cf59beed38709e9ed6b0ac80b24ee5",
9293
indexName: "typescripttolua",
9394
},
@@ -109,5 +110,5 @@ module.exports = {
109110
},
110111
],
111112
],
112-
plugins: [require.resolve("./docusaurus-plugin")],
113+
plugins: ["docusaurus-plugin-sass", require.resolve("./docusaurus-plugin")],
113114
};

fetch-tsworker.mjs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import fetch from "node-fetch";
2+
import fs from "fs";
3+
import path from "path";
4+
import process from "process";
5+
import ts from "typescript";
6+
7+
// Fetch tsWorker for our TypeScript version from the CDN. This is required for the playground
8+
const SCRIPT_URL = `https://typescript.azureedge.net/cdn/${ts.version}/monaco/min/vs/language/typescript/tsWorker.js`;
9+
const TARGET_FILE = path.join("static", "cdn.tsWorker.js");
10+
11+
async function fetchPlaygroundTsWorker() {
12+
const response = await fetch(SCRIPT_URL);
13+
14+
if (response.ok) {
15+
const writeStream = fs.createWriteStream(TARGET_FILE);
16+
await new Promise((resolve, reject) => {
17+
response.body.pipe(writeStream);
18+
response.body.on("error", reject);
19+
writeStream.on("finish", resolve);
20+
});
21+
} else {
22+
throw new Error(
23+
`Failed to fetch TS worker from ${SCRIPT_URL} (${response.status}):\n ${await response.text()}`,
24+
);
25+
}
26+
}
27+
28+
console.log(`Fetching latest tsWorker for TS ${ts.version}`);
29+
30+
fetchPlaygroundTsWorker()
31+
.then(() => console.log(`Done! Wrote ${TARGET_FILE}`))
32+
.catch((err) => {
33+
console.error(`${err}`);
34+
process.exitCode = 1;
35+
});

0 commit comments

Comments
 (0)