Skip to content

Commit e8a7763

Browse files
authored
Add a side panel Chrome extension within the Adventure Pack (#380)
A starting point for adding in the Adventure Pack!
1 parent 6cecf2c commit e8a7763

File tree

26 files changed

+304
-227
lines changed

26 files changed

+304
-227
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"devDependencies": {
2727
"@code-chronicles/eslint-config": "0.0.1",
28-
"eslint": "9.9.0",
28+
"eslint": "9.9.1",
2929
"prettier": "3.3.3"
3030
},
3131
"packageManager": "yarn@4.4.1"

workspaces/adventure-pack/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"goodies:typescript:install": "yarn",
4949
"goodies:typescript:test": "jest --color goodies/typescript",
5050
"build-app": "tsx src/scripts/build/main.ts",
51+
"build-chrome-extension": "ts-node src/scripts/build/buildChromeExtension.ts",
5152
"package-goodies:test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --color --testPathIgnorePatterns=\"/goodies/\"",
5253
"format": "yarn goodies:java:format && yarn goodies:kotlin:format && yarn goodies:python3:format && yarn goodies:typescript:format && prettier --color --write .",
5354
"lint": "eslint --color --max-warnings=0 .",
@@ -67,22 +68,22 @@
6768
"@code-chronicles/eslint-config": "0.0.1",
6869
"@code-chronicles/util": "0.0.1",
6970
"@jest/globals": "29.7.0",
70-
"@types/node": "22.5.0",
71-
"@types/react": "18.3.3",
71+
"@types/node": "22.5.1",
72+
"@types/react": "18.3.5",
7273
"@types/react-dom": "18.3.0",
7374
"@types/react-syntax-highlighter": "15.5.13",
7475
"cross-env": "7.0.3",
75-
"eslint": "9.9.0",
76+
"eslint": "9.9.1",
7677
"invariant": "2.2.4",
7778
"jest": "29.7.0",
7879
"prettier": "3.3.3",
7980
"prettier-plugin-java": "2.6.4",
80-
"ts-jest": "29.2.4",
81+
"ts-jest": "29.2.5",
8182
"ts-loader": "9.5.1",
8283
"ts-morph": "23.0.0",
8384
"ts-node": "10.9.2",
84-
"tsx": "4.17.0",
85-
"type-fest": "4.24.0",
85+
"tsx": "4.19.0",
86+
"type-fest": "4.26.0",
8687
"typescript": "5.5.4",
8788
"webpack": "5.94.0",
8889
"webpack-cli": "5.1.4",
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { mkdir, writeFile } from "node:fs/promises";
2+
import path from "node:path";
3+
4+
import { CHROME_EXTENSION_DIST } from "./constants";
5+
6+
async function main(): Promise<void> {
7+
await mkdir(CHROME_EXTENSION_DIST, { recursive: true });
8+
9+
await writeFile(
10+
path.join(CHROME_EXTENSION_DIST, "manifest.json"),
11+
JSON.stringify(
12+
{
13+
name: "Adventure Pack",
14+
// TODO: get a nice description from the package.json perhaps
15+
description: "TODO: add a nice description",
16+
// TODO: get a version from the package.json perhaps
17+
version: "0.0.1",
18+
19+
// eslint-disable-next-line camelcase
20+
manifest_version: 3,
21+
// eslint-disable-next-line camelcase
22+
side_panel: {
23+
// eslint-disable-next-line camelcase
24+
default_path: "index.html",
25+
},
26+
permissions: ["sidePanel"],
27+
},
28+
null,
29+
2,
30+
) + "\n",
31+
{ encoding: "utf8" },
32+
);
33+
34+
await writeFile(
35+
path.join(CHROME_EXTENSION_DIST, "index.html"),
36+
`
37+
<!DOCTYPE html>
38+
<html lang="en-US">
39+
<head>
40+
<meta charset="utf-8" />
41+
<title>Adventure Pack</title>
42+
</head>
43+
<body>
44+
<div id="main">Hello World!</div>
45+
</body>
46+
</html>
47+
`,
48+
{ encoding: "utf8" },
49+
);
50+
}
51+
52+
main().catch((err) => {
53+
console.error(err);
54+
process.exitCode = 1;
55+
});
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import path from "node:path";
22

3-
export const WEBAPP_DIST = path.resolve("dist", "web-app");
3+
export const CHROME_EXTENSION_DIST = path.resolve("dist", "chrome-extension");
4+
export const WEB_APP_DIST = path.resolve("dist", "web-app");

workspaces/adventure-pack/src/scripts/build/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { mkdir } from "node:fs/promises";
22

3-
import { WEBAPP_DIST } from "./constants";
3+
import { WEB_APP_DIST } from "./constants";
44
import { runWebpack } from "./runWebpack";
55
import { writeGoodiesJson } from "./writeGoodiesJson";
66
import { writeIndexHtml } from "./writeIndexHtml";
@@ -9,7 +9,7 @@ import { writeStyleCss } from "./writeStyleCss";
99
// TODO: Investigate why this script works with `tsx` but not `ts-node`.
1010

1111
async function main(): Promise<void> {
12-
await mkdir(WEBAPP_DIST, { recursive: true });
12+
await mkdir(WEB_APP_DIST, { recursive: true });
1313

1414
await Promise.all([
1515
runWebpack(),

workspaces/adventure-pack/src/scripts/build/writeGoodiesJson.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import prettier from "prettier";
66
import { isEnvironmentDev } from "@code-chronicles/util/isEnvironmentDev";
77

88
import { readAllGoodies } from "../package-goodies/readAllGoodies";
9-
import { WEBAPP_DIST } from "./constants";
9+
import { WEB_APP_DIST } from "./constants";
1010

1111
async function readAllGoodiesAsString(): Promise<string> {
1212
const goodies = await readAllGoodies();
@@ -24,5 +24,7 @@ async function readAllGoodiesAsString(): Promise<string> {
2424
export async function writeGoodiesJson(): Promise<void> {
2525
const text = await readAllGoodiesAsString();
2626

27-
await writeFile(path.join(WEBAPP_DIST, "goodies.json"), text);
27+
await writeFile(path.join(WEB_APP_DIST, "goodies.json"), text, {
28+
encoding: "utf8",
29+
});
2830
}

workspaces/adventure-pack/src/scripts/build/writeIndexHtml.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { exec as execWithCallback } from "node:child_process";
2-
import { mkdir, writeFile } from "node:fs/promises";
2+
import { writeFile } from "node:fs/promises";
33
import path from "node:path";
44
import { promisify } from "node:util";
55

66
import React from "react";
77
import ReactDOMServer from "react-dom/server";
88

99
import { App } from "../../app/components/App";
10-
import { WEBAPP_DIST } from "./constants";
10+
import { WEB_APP_DIST } from "./constants";
1111

1212
const exec = promisify(execWithCallback);
1313

@@ -16,9 +16,8 @@ const exec = promisify(execWithCallback);
1616
export async function writeIndexHtml(): Promise<void> {
1717
const commitHash = (await exec("git rev-parse HEAD")).stdout.trim();
1818

19-
await mkdir(WEBAPP_DIST, { recursive: true });
2019
await writeFile(
21-
path.join(WEBAPP_DIST, "index.html"),
20+
path.join(WEB_APP_DIST, "index.html"),
2221
"<!DOCTYPE html>\n" +
2322
ReactDOMServer.renderToStaticMarkup(
2423
<html lang="en-US">
@@ -51,5 +50,6 @@ export async function writeIndexHtml(): Promise<void> {
5150
</html>,
5251
) +
5352
"\n",
53+
{ encoding: "utf8" },
5454
);
5555
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { copyFile } from "node:fs/promises";
22
import path from "node:path";
33

4-
import { WEBAPP_DIST } from "./constants";
4+
import { WEB_APP_DIST } from "./constants";
55

66
export async function writeStyleCss(): Promise<void> {
77
await copyFile(
88
path.join("css", "style.css"),
9-
path.join(WEBAPP_DIST, "style.css"),
9+
path.join(WEB_APP_DIST, "style.css"),
1010
);
1111
}

workspaces/adventure-pack/webpack.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ import path from "node:path";
33

44
import webpack, { type Configuration } from "webpack";
55

6-
import { WEBAPP_DIST } from "./src/scripts/build/constants";
6+
import { WEB_APP_DIST } from "./src/scripts/build/constants";
77

88
const commitHash = execSync("git rev-parse HEAD").toString().trim();
99

1010
const config: Configuration = {
1111
target: "web",
12+
// TODO: for Chrome extension we will need devtool: "cheap-source-map" since we can't eval.
1213
entry: "./src/app/main.tsx",
1314
output: {
1415
filename: "[name].js",
15-
path: path.resolve(__dirname, WEBAPP_DIST),
16+
path: path.resolve(__dirname, WEB_APP_DIST),
1617
},
1718

1819
module: {

workspaces/chrome-extension-hello-world/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"devDependencies": {
1818
"@code-chronicles/eslint-config": "0.0.1",
19-
"@types/node": "22.5.0",
19+
"@types/node": "22.5.1",
2020
"prettier": "3.3.3",
2121
"ts-loader": "9.5.1",
2222
"typescript": "5.5.4",

0 commit comments

Comments
 (0)