Skip to content

Commit

Permalink
Revert "upgrade to vite"
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed Jun 23, 2022
1 parent 8ece28b commit 094523f
Show file tree
Hide file tree
Showing 30 changed files with 3,924 additions and 3,418 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/node_modules/
dist
dev-dist
/public/build/

.DS_Store
_test/
3 changes: 1 addition & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/_test/
/dist/
/dev-dist/
/public/build/
/generate-color-css.js
/public/global.css
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"bracketSameLine": true,
"svelteBracketNewLine": false,
"svelteIndentScriptAndStyle": false
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The Hitchhiker's Guide to the Cataclysm

<img src="src/assets/dont_panic.png" width=300 align="right" />
<img src="public/dont_panic.png" width=300 align="right" />

The Hitchhiker's Guide to the Cataclysm is a guide to the zombie survival roguelike game [Cataclysm: Dark Days Ahead](https://cataclysmdda.org/). You can search for things in the game, like items, or monsters, and find useful information about them. The data in the Guide comes directly from the JSON files in the game itself.

Expand Down
15 changes: 5 additions & 10 deletions fetch-fixtures.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import * as fs from "fs/promises";
import { createWriteStream, createReadStream, readFileSync } from "fs";
import * as crypto from "crypto";
import * as url from "url";
import fetch from "node-fetch";
const { buildNum, sha } = JSON.parse(
readFileSync("./_test/all.meta.json", "utf8")
);
const fs = require("fs/promises");
const { createWriteStream, createReadStream } = require("fs");
const crypto = require("crypto");
const { buildNum, sha } = require("./_test/all.meta.json");
const update = process.argv[2] === "latest";
const dataUrl = `https://raw.githubusercontent.com/nornagon/cdda-data/main/data/${
update ? "latest" : buildNum
}/all.json`;
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));

function computeSha(file) {
return new Promise((resolve) => {
Expand Down Expand Up @@ -42,7 +37,7 @@ async function matchesSha(file, sha) {
} else {
return;
}
const res = await fetch(dataUrl);
const res = await require("node-fetch")(dataUrl);
const dest = createWriteStream(filename);
res.body.pipe(dest);
res.body.on("end", async () => {
Expand Down
64 changes: 35 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,63 @@
{
"name": "svelte-app",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public",
"validate": "svelte-check",
"test": "node fetch-fixtures.js && npm run lint && npm run validate && jest src",
"test:latest": "node fetch-fixtures.js latest && npm run validate && jest src",
"test:watch": "npm run test -- --watch",
"update-test-data": "node fetch-fixtures.js latest",
"deploy": "npm run build && gh-pages -d dist",
"deploy": "npm run build && gh-pages -d public",
"lint": "prettier -c .",
"lint:fix": "prettier -w .",
"precommit": "lint-staged",
"prepare": "husky install",
"check": "svelte-check --tsconfig ./tsconfig.json"
"prepare": "husky install"
},
"devDependencies": {
"@fontsource/unifont": "^4.5.5",
"@sentry/browser": "^7.2.0",
"@sentry/tracing": "^7.2.0",
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"@rollup/plugin-typescript": "^8.0.0",
"@sentry/browser": "^6.2.1",
"@sentry/tracing": "^6.2.1",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/svelte": "^3.0.3",
"@tsconfig/svelte": "^2.0.1",
"@types/jest": "^28.1.3",
"@tsconfig/svelte": "^1.0.0",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.31",
"@types/node-fetch": "^2.5.8",
"ajv": "^8",
"babel-jest": "^28.1.1",
"fuzzysort": "^2.0.1",
"babel-jest": "^26.6.3",
"fuzzysort": "^1.1.4",
"gh-pages": "^3.1.0",
"husky": "^7.0.4",
"jest": "^28.1.1",
"jest-environment-jsdom": "^28.1.1",
"jest": "^26.6.3",
"lint-staged": "^12.3.2",
"node-fetch": "^2.6.1",
"postcss": "^8.3.6",
"postcss-url": "^10.1.3",
"prettier": "^2.3.2",
"prettier-plugin-svelte": "^2.4.0",
"svelte": "^3.44.0",
"svelte-check": "^2.2.7",
"rollup": "^2.3.4",
"rollup-plugin-css-only": "^3.1.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-postcss": "^4.0.1",
"rollup-plugin-svelte": "^7.0.0",
"rollup-plugin-terser": "^7.0.0",
"svelte": "^3.0.0",
"svelte-check": "^1.0.0",
"svelte-jester": "^1.3.0",
"svelte-preprocess": "^4.9.8",
"ts-jest": "^28.0.5",
"tslib": "^2.3.1",
"typescript": "^4.5.4",
"typescript-json-schema": "^0.50.0",
"vite": "^2.9.9",
"vite-plugin-pwa": "^0.12.0"
"svelte-preprocess": "^4.6.9",
"ts-jest": "^26.5.3",
"tslib": "^2.0.0",
"typescript": "^4.0.0",
"typescript-json-schema": "^0.50.0"
},
"dependencies": {
"@fontsource/unifont": "^4.5.1",
"sirv-cli": "^1.0.0"
},
"jest": {
"transform": {
Expand All @@ -60,8 +67,7 @@
"preprocess": true
}
],
"^.+\\.ts$": "ts-jest",
"^.+\\.mjs$": "babel-jest"
"^.+\\.ts$": "ts-jest"
},
"setupFilesAfterEnv": [
"@testing-library/jest-dom/extend-expect"
Expand Down
File renamed without changes
11 changes: 7 additions & 4 deletions index.html → public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta
property="og:title"
content="The Hitchhiker's Guide to the Cataclysm" />
content="The Hitchhiker's Guide to the Cataclysm"
/>

<title>The Hitchhiker's Guide to the Cataclysm</title>

<link rel="icon" type="image/png" href="/favicon.png" />
<link rel="stylesheet" href="/global.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<link rel="stylesheet" href="global.css" />
<link rel="stylesheet" href="build/bundle.css" />
<link rel="manifest" href="manifest.json" />
<link rel="apple-touch-icon" href="icon-192.png" />

<script type="module" defer src="/src/main.ts"></script>
<script defer src="build/bundle.js"></script>
</head>

<body></body>
Expand Down
20 changes: 20 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"short_name": "Cataclysm Guide",
"name": "The Hitchhiker's Guide to the Cataclysm",
"icons": [
{
"src": "icon-192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "icon-512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": "./",
"theme_color": "#202020",
"background_color": "#1c1c1c",
"display": "standalone"
}
117 changes: 117 additions & 0 deletions public/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
const CURRENT_CACHES = {
data: "data-v1",
app: "app-v2",
};

const appUrls = [
"./build/bundle.js",
"./build/bundle.css",
"./favicon.png",
"./global.css",
"./dont_panic.png",
"./build/files/unifont-latin-400-normal.woff2",
"./",
];

self.addEventListener("install", (event) => {
event.waitUntil(
Promise.all([
(async () => {
const cache = await caches.open(CURRENT_CACHES.app);
await cache.addAll(appUrls);
})(),
])
);
});

self.addEventListener("activate", function (event) {
// Delete all caches that aren't named in CURRENT_CACHES.
// While there is only one cache in this example, the same logic will handle the case where
// there are multiple versioned caches.
var expectedCacheNamesSet = new Set(Object.values(CURRENT_CACHES));
event.waitUntil(
caches
.keys()
.then(function (cacheNames) {
return Promise.all(
cacheNames.map(function (cacheName) {
if (!expectedCacheNamesSet.has(cacheName)) {
// If this cache name isn't present in the set of "expected" cache names, then delete it.
console.log("Deleting out of date cache:", cacheName);
return caches.delete(cacheName);
}
})
);
})
.then(() => {
self.clients.claim();
})
);
});

self.addEventListener("fetch", (event) => {
if (event.request.method !== "GET") {
return event.respondWith(fetch(event.request));
}
const url = new URL(event.request.url);
if (url.hostname === "raw.githubusercontent.com") {
if (
url.pathname.endsWith(
"/all.json" && !url.pathname.endsWith("/latest/all.json")
)
) {
// all.json is same forever
return event.respondWith(
(async () => {
const cache = await caches.open(CURRENT_CACHES.data);
const cacheResponse = await cache.match(event.request);
if (cacheResponse) return cacheResponse;

const networkResponse = await fetch(event.request.clone());
if (networkResponse && networkResponse.status < 400)
cache.put(event.request, networkResponse.clone());
return networkResponse;
})()
);
} else {
// for other files, e.g. latest/all.json, try fetching, if we can't get it then try the cache.
return event.respondWith(
(async () => {
try {
const response = await fetch(event.request.clone());
const clonedResponse = response.clone();
event.waitUntil(
caches.open(CURRENT_CACHES.data).then((cache) => {
cache.put(event.request, clonedResponse);
})
);
return response;
} catch (err) {
const cache = await caches.open(CURRENT_CACHES.data);
return await cache.match(event.request);
}
})()
);
}
} else {
return event.respondWith(
(async () => {
try {
const response = await fetch(event.request.clone());
if (response.type === "basic") {
const clonedResponse = response.clone();
event.waitUntil(
caches.open(CURRENT_CACHES.app).then((cache) => {
cache.put(event.request, clonedResponse);
})
);
}
return response;
} catch (err) {
const cache = await caches.open(CURRENT_CACHES.app);
return await cache.match(event.request);
}
})()
);
}
});
Loading

0 comments on commit 094523f

Please sign in to comment.