Skip to content

Commit a31077d

Browse files
authored
Single script for building the Adventure Pack web app (#378)
1 parent 92bfd51 commit a31077d

File tree

16 files changed

+89
-48
lines changed

16 files changed

+89
-48
lines changed

.github/workflows/deploy-github-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
- name: Upload artifact
4949
uses: actions/upload-pages-artifact@v3
5050
with:
51-
path: ./workspaces/adventure-pack/dist
51+
path: ./workspaces/adventure-pack/dist/web-app
5252

5353
- name: Deploy to GitHub Pages
5454
id: deployment

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up everything
1616
uses: ./.github/workflows/set-up-everything
1717

18-
- name: Linting
18+
- name: Lint
1919
run: yarn lint
2020
# TODO: Annotations of files that fail lint?
2121
# TODO: Maybe write up a job summary per https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary

workspaces/adventure-pack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"goodies:typescript:format": "prettier --color --write goodies/typescript",
4848
"goodies:typescript:install": "yarn",
4949
"goodies:typescript:test": "jest --color goodies/typescript",
50-
"build-app": "ts-node src/scripts/package-goodies/main.ts && tsx src/scripts/build-html.tsx && webpack && cp css/style.css dist/style.css",
50+
"build-app": "tsx src/scripts/build/main.ts",
5151
"package-goodies:test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --color --testPathIgnorePatterns=\"/goodies/\"",
5252
"format": "yarn goodies:java:format && yarn goodies:kotlin:format && yarn goodies:python3:format && yarn goodies:typescript:format && prettier --color --write .",
5353
"lint": "eslint --color --max-warnings=0 .",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import path from "node:path";
2+
3+
export const WEBAPP_DIST = path.resolve("dist", "web-app");
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { mkdir } from "node:fs/promises";
2+
3+
import { WEBAPP_DIST } from "./constants";
4+
import { runWebpack } from "./runWebpack";
5+
import { writeGoodiesJson } from "./writeGoodiesJson";
6+
import { writeIndexHtml } from "./writeIndexHtml";
7+
import { writeStyleCss } from "./writeStyleCss";
8+
9+
// TODO: Investigate why this script works with `tsx` but not `ts-node`.
10+
11+
async function main(): Promise<void> {
12+
await mkdir(WEBAPP_DIST, { recursive: true });
13+
14+
await Promise.all([
15+
runWebpack(),
16+
writeIndexHtml(),
17+
writeGoodiesJson(),
18+
writeStyleCss(),
19+
]);
20+
}
21+
22+
main().catch((err) => {
23+
console.error(err);
24+
process.exitCode = 1;
25+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { spawnWithSafeStdio } from "@code-chronicles/util/spawnWithSafeStdio";
2+
3+
export async function runWebpack(): Promise<void> {
4+
await spawnWithSafeStdio("webpack", ["--color"]);
5+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { writeFile } from "node:fs/promises";
2+
import path from "node:path";
3+
4+
import { readAllGoodies } from "../package-goodies/readAllGoodies";
5+
import { WEBAPP_DIST } from "./constants";
6+
7+
export async function writeGoodiesJson(): Promise<void> {
8+
const goodies = await readAllGoodies();
9+
10+
await writeFile(
11+
path.join(WEBAPP_DIST, "goodies.json"),
12+
// TODO: pretty print if NODE_ENV is "development"
13+
JSON.stringify(goodies) + "\n",
14+
);
15+
}

workspaces/adventure-pack/src/scripts/build-html.tsx renamed to workspaces/adventure-pack/src/scripts/build/writeIndexHtml.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ import { promisify } from "node:util";
66
import React from "react";
77
import ReactDOMServer from "react-dom/server";
88

9-
import { App } from "../app/components/App";
9+
import { App } from "../../app/components/App";
10+
import { WEBAPP_DIST } from "./constants";
1011

1112
const exec = promisify(execWithCallback);
1213

1314
// TODO: Investigate why this script works with `tsx` but not `ts-node`.
1415

15-
async function main(): Promise<void> {
16+
export async function writeIndexHtml(): Promise<void> {
1617
const commitHash = (await exec("git rev-parse HEAD")).stdout.trim();
1718

18-
await mkdir("dist", { recursive: true });
19+
await mkdir(WEBAPP_DIST, { recursive: true });
1920
await writeFile(
20-
path.join("dist", "index.html"),
21+
path.join(WEBAPP_DIST, "index.html"),
2122
"<!DOCTYPE html>\n" +
2223
ReactDOMServer.renderToStaticMarkup(
2324
<html lang="en-US">
@@ -52,8 +53,3 @@ async function main(): Promise<void> {
5253
"\n",
5354
);
5455
}
55-
56-
main().catch((err) => {
57-
console.error(err);
58-
process.exitCode = 1;
59-
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { copyFile } from "node:fs/promises";
2+
import path from "node:path";
3+
4+
import { WEBAPP_DIST } from "./constants";
5+
6+
export async function writeStyleCss(): Promise<void> {
7+
await copyFile(
8+
path.join("css", "style.css"),
9+
path.join(WEBAPP_DIST, "style.css"),
10+
);
11+
}

workspaces/adventure-pack/src/scripts/package-goodies/main.ts

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

0 commit comments

Comments
 (0)