Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ elm-stuff
# elm-repl generated files
repl-temp-*
# generated css and js
static/js/*.min.js
static/css/*.min.css
static/js/*
static/css/*
# Node modules
node_modules/
# Wrangler
Expand Down
6 changes: 6 additions & 0 deletions static/_headers → _headers
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@

https://armorylinks.pages.dev/*
X-Robots-Tag: noindex

/static/js/*
Content-Type: application/javascript

/static/css/*
Content-Type: text/css
7 changes: 4 additions & 3 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"tasks": {
"build": "deno run --allow-read --allow-env --allow-write --allow-run build.ts",
"publish": "deno run --allow-read --allow-env --allow-write --allow-run publish.ts",
"run": "deno run --allow-read --allow-env --allow-write --allow-run run.ts"
"build": "deno run --allow-read --allow-env --allow-write --allow-run scripts/build.ts",
"publish": "deno run --allow-read --allow-env --allow-write --allow-run scripts/publish.ts",
"run": "deno run --allow-read --allow-env --allow-write --allow-run scripts/run.ts",
"clean": "deno run --allow-read --allow-env --allow-write --allow-run scripts/clean.ts"
}
}
65 changes: 0 additions & 65 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build.ts → scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function createDirectories() {
async function compileAndMinifyElm() {
try {
const compiledJs = await ElmCompile("./src/Main.elm", { mode: "optimize" });
const minifiedJs = await minify(compiledJs);
const minifiedJs = await minify(compiledJs, { ecma: 2016 });
await Deno.writeTextFile("./static/js/main.min.js", minifiedJs.code ?? "");
} catch (error) {
if (error instanceof Deno.errors.NotFound) {
Expand All @@ -44,7 +44,7 @@ async function compileSass() {
// Only run if the script is run directly, not imported as a module
if (import.meta.main) {
await compile();
console.log("✅ Done!");
console.log("✅ Build complete!");
}

export async function compile() {
Expand Down
26 changes: 26 additions & 0 deletions scripts/clean.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
async function cleanDirectories(directories: string[]) {
for (const dir of directories) {
for await (const item of Deno.readDir(`./static/${dir}`)) {
const filePath = `./static/${dir}/${item.name}`;
await Deno.remove(filePath);
}
}
}

async function removeDirectories(directories: string[]) {
for (const dir of directories) {
await Deno.remove(dir, { recursive: true });
}
}

try {
console.log("🧹 Cleaning generated files...")

await cleanDirectories(["css", "js"]);
await removeDirectories(["dist"]);

console.log("✅ Clean complete!");
} catch (error) {
if (!(error instanceof Deno.errors.NotFound))
throw error;
}
16 changes: 12 additions & 4 deletions publish.ts → scripts/publish.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import * as fs from "jsr:@std/fs";
import { compile } from "./build.ts";

async function deleteExistingDist() {
try {
await Deno.remove("./dist", { recursive: true });
} catch (error) {
if (!(error instanceof Deno.errors.NotFound))
throw error;
}
}

/// Builds and publishes necessary files to `dist/` for deployment.
async function publish() {
console.log("🏗️ Running build step...");
await compile();

console.log("🚀 Publishing files to `dist/`...");
await Deno.mkdir("./dist", { recursive: true });

await deleteExistingDist();
await fs.copy("./static", "./dist/static", { overwrite: true });
await fs.copy("./wrangler.toml", "./dist/wrangler.toml", { overwrite: true });

// Move _headers to the root of dist
await fs.move("./dist/static/_headers", "./dist/_headers");
await fs.copy("./_headers", "./dist/_headers");

console.log("✅ Publish complete!");
}
Expand Down
File renamed without changes.
Loading