Skip to content

Commit 74a9ffc

Browse files
committed
Add a side panel Chrome extension within the Adventure Pack
1 parent ab36ea2 commit 74a9ffc

File tree

14 files changed

+95
-27
lines changed

14 files changed

+95
-27
lines changed

workspaces/adventure-pack/package.json

Lines changed: 1 addition & 0 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 .",
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/download-leetcode-submissions/src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fsPromises from "node:fs/promises";
1+
import { mkdir, writeFile } from "node:fs/promises";
22
import path from "node:path";
33
import process from "node:process";
44

@@ -92,10 +92,10 @@ async function main(): Promise<void> {
9292
console.error(`Saving submission ${submission.id} to a file.`);
9393

9494
const dir = getDirnameForSubmission(submission);
95-
await fsPromises.mkdir(dir, { recursive: true });
95+
await mkdir(dir, { recursive: true });
9696

9797
const filename = getFilenameForSubmission(submission);
98-
await fsPromises.writeFile(path.join(dir, filename), code);
98+
await writeFile(path.join(dir, filename), code, { encoding: "utf8" });
9999
});
100100
}
101101

workspaces/download-leetcode-submissions/src/writeSubmissionsMetadataAndHashes.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fsPromises from "node:fs/promises";
1+
import { writeFile } from "node:fs/promises";
22

33
import { METADATA_FILE, HASHES_FILE } from "./constants";
44
import { getFilenameForSubmission } from "./getFilenameForSubmission";
@@ -13,14 +13,15 @@ export async function writeSubmissionsMetadataAndHashes(
1313
);
1414

1515
await Promise.all([
16-
fsPromises.writeFile(
16+
writeFile(
1717
METADATA_FILE,
1818
submissions
1919
.map((submission) => JSON.stringify(submission) + "\n")
2020
.join(""),
21+
{ encoding: "utf8" },
2122
),
2223

23-
fsPromises.writeFile(
24+
writeFile(
2425
HASHES_FILE,
2526
submissions
2627
.map(
@@ -31,6 +32,7 @@ export async function writeSubmissionsMetadataAndHashes(
3132
)}/${getFilenameForSubmission(submission)}\n`,
3233
)
3334
.join(""),
35+
{ encoding: "utf8" },
3436
),
3537
]);
3638
}

0 commit comments

Comments
 (0)