Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add CI workflow to template. I think this will really help a lot of
people catch mistakes when they happen. As a bonus, they'll catch
errors in the template too.

name: CI

on:
push:
branches: ['main']
pull_request:
branches: ['main']

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7.0.0
- name: Install Node.js
uses: actions/setup-node@v6.4.0
with:
node-version: 22.6.0
- name: Install Dependencies
run: npm install --no-fund
- name: Typecheck
run: npm run test:types
- name: Lint
run: npm run lint
- name: Unit Test
run: npm run test:unit
- name: Build
run: npm run build
10 changes: 4 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
node_modules
.DS_Store
dist
.env
public/*.js
public/*.js.map
/node_modules/
/dist/
/public/*.js*
/.env
1 change: 0 additions & 1 deletion .npmrc

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop .npmrc. NPM prints a warning on engine mismatch. Strict engines
is an error which doesn't seem necessary?

This file was deleted.

1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"recommendations": ["biomejs.biome"]}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.defaultFormatter": "biomejs.biome",
"editor.codeActionsOnSave": {"source.organizeImports.biome": "explicit"},
"js/ts.tsdk.path": "node_modules/typescript/lib"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use installed TypeScript version.

}
23 changes: 0 additions & 23 deletions README.md

This file was deleted.

37 changes: 37 additions & 0 deletions biome.jsonc

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Biome to flag floating promises and format. Unfortunately, most
settings default to off so a config file is necessary. Added two new
NPM scripts too: lint and format.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$schema": "https://biomejs.dev/schemas/2.5.1/schema.json",
"css": {"formatter": {"enabled": true, "quoteStyle": "single"}},
"files": {"includes": ["**", "!dist/", "!public/*.js*"]},
"formatter": {
"bracketSpacing": false,
"enabled": true,
"indentStyle": "space"
},
"html": {"formatter": {"enabled": true}},
"javascript": {
"formatter": {
"arrowParentheses": "asNeeded",
"jsxQuoteStyle": "single",
"quoteStyle": "single",
"semicolons": "asNeeded"
}
},
"linter": {
"domains": {"project": "all"},
"rules": {
"correctness": {
// Biome resolves conditional exports without the browser condition,
// which reports false positives for `@devvit/web/client` named exports.
"noUnresolvedImports": "off"
},
"nursery": {
"noFloatingPromises": "error",
"noMisusedPromises": "error",
"recommended": true
},
"style": {"noInferrableTypes": "off"},
"suspicious": {"noImplicitAnyLet": "off"}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems crazy to me but the recommend rule is to require explicit let local typing which is often overtyping in my opinion

}
},
"vcs": {"enabled": true, "clientKind": "git", "useIgnoreFile": true}
}
19 changes: 6 additions & 13 deletions devvit.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,30 @@
"$schema": "https://developers.reddit.com/schema/config-file.v1.json",
"name": "<% name %>",
"post": {
"dir": "public",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default

"entrypoints": {
"default": {
"inline": true,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default

"entry": "splash.html"
},
"game": {
"entry": "game.html"
}
}
},
"server": {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant post and server defaults in devvit.json.

"dir": "dist/server",
"entry": "index.js"
},
"server": {},
"menu": {
"items": [
{
"label": "Create a new post",
"description": "<% name %>",
"label": "[<% name %>] New Post",
"description": "Create a new <% name %> post.",
"location": "subreddit",
"forUserType": "moderator",
"endpoint": "/internal/menu/post-create"
"endpoint": "/internal/on/menu/new-post"
}
]
},
"triggers": {
"onAppInstall": "/internal/on-app-install"
"onAppInstall": "/internal/on/app/install"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tweak router paths to be more hierarchical.

},
"scripts": {
"dev": "node --experimental-strip-types ./tools/build.ts --watch",
"build": "node --experimental-strip-types ./tools/build.ts --minify"
"dev": "npm run watch"
}
}
37 changes: 21 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
"license": "BSD-3-Clause",
"type": "module",
"scripts": {
"build": "node --experimental-strip-types ./tools/build.ts --minify",
"deploy": "npm run build && devvit upload",
"dev": "devvit playtest",
"login": "devvit login",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop login NPM script since tooling will log you in.

"launch": "npm run build && npm run deploy && devvit publish",
"type-check": "tsc --build"
},
"engines": {
"node": ">=22.6.0"
},
"dependencies": {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move both devvit and @devvit/web to devDependencies. The former
was causing Node.js typing to leak into client types and the latter is
technically bundled.

"@devvit/web": "0.13.0",
"devvit": "0.13.0"
"build": "npm run build:client -- --metafile=dist/client.meta.json --minify && npm run build:server -- --metafile=dist/server.meta.json --minify",
"build:client": "esbuild --bundle --log-level=warning --sourcemap=linked --target=es2023 --format=esm --outdir=public --platform=browser src/client/splash.ts src/client/game.ts",
"build:server": "esbuild --bundle --log-level=warning --sourcemap=linked --target=es2023 --format=cjs --outdir=dist/server --platform=node src/server/index.ts",
Comment on lines +8 to +10

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inlined from tools/build.ts

"clean": "rm -rf dist/ public/*.js*",
"format": "npm run lint -- --fix",
"lint": "biome check --error-on-warnings",
"playtest": "devvit playtest",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename dev to playtest, invoke watch, and reserve dev for dev
usage.

"test": "npm run test:types && npm run lint && npm run test:unit && npm run build",
"test:types": "tsc --build",
"test:unit": "node --experimental-strip-types --no-warnings=ExperimentalWarning --test src/**/*.test.ts",
"publish": "npm run clean && npm run build && devvit publish",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename deploy NPM script to publish which matches NPM (and Devvit)
naming. Clean before building and drop double build step in
devvit.json.

"watch": "sh -c 'trap \"kill 0\" exit; npm run build:client -- --watch=forever& npm run build:server -- --watch=forever& wait' --"
},
"devDependencies": {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrade all dependencies.

"@types/node": "22.20.0",
"typescript": "6.0.3",
"esbuild": "0.28.1"
"@biomejs/biome": "2.5.1",
"@devvit/web": "0.13.5",
"@types/node": "22.6.2",
"devvit": "0.13.5",
"esbuild": "0.28.1",
"typescript": "6.0.3"
},
"engines": {
"node": ">=22.6"
}
}
103 changes: 0 additions & 103 deletions public/game.css

This file was deleted.

57 changes: 30 additions & 27 deletions public/game.html
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="game.css" />
<meta charset="UTF-8" />
<meta charset="utf-8">
<meta
name="viewport"
content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width, height=device-height, user-scalable=0"
/>
<title>devvit</title>
content="width=device-width, maximum-scale=1, minimum-scale=1, user-scalable=no"
>
<title>Game</title>
<link rel="modulepreload" href="game.js">
<style>
body {
margin: 0;
width: 100dvw;
height: 100dvh;
overflow: hidden;
display: grid;
place-items: center;
}
main {
display: grid;
gap: 1rem;
justify-items: center;
}
</style>
</head>
<body class="app">
<img class="snoo" src="/snoo.png" alt="Snoo" />
<div class="content">
<h1 class="title" id="title"></h1>
<p class="description">
Edit <span class="code">src/client/game.ts</span> to get started.
</p>
</div>
<div class="counter-row">
<button class="counter-button" id="decrement-button">-</button>
<span class="counter-value" id="counter-value">0</span>
<button class="counter-button" id="increment-button">+</button>
</div>
<footer class="footer">
<div class="docs-link" tabindex="0" id="docs-link">Docs</div>
<span class="divider">|</span>
<div class="docs-link" tabindex="0" id="playtest-link">r/Devvit</div>
<span class="divider">|</span>
<div class="docs-link" tabindex="0" id="discord-link">Discord</div>
</footer>
<script type="module" src="game.js" defer></script>
<body>
<main>
<div class="counter">
<button id="dec-btn" type="button">-</button>
<output id="counter">0</output>
<button id="inc-btn" type="button">+</button>
</div>
</main>
<script src="game.js" type="module"></script>
</body>
</html>
Loading