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
13 changes: 7 additions & 6 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ async function compileSass() {
});
}

// Only run if the script is run directly, not imported as a module
if (import.meta.main) {
await compile();
console.log("✅ Build complete!");
}

export async function compile() {
await createDirectories();

Expand All @@ -56,3 +50,10 @@ export async function compile() {
console.log("🌳 Compiling Elm...");
await compileAndMinifyElm();
}


// Only run if the script is run directly, not imported as a module
if (import.meta.main) {
await compile();
console.log("✅ Build complete!");
}
37 changes: 20 additions & 17 deletions scripts/clean.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { removePublishDirectory } from "./publish.ts";

async function cleanDirectories(directories: string[]) {
try {
for (const dir of directories) {
for await (const item of Deno.readDir(`./static/${dir}`)) {
const filePath = `./static/${dir}/${item.name}`;
await Deno.remove(filePath);
}
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 });
} catch (error) {
if (!(error instanceof Deno.errors.NotFound)) {
throw error;
}
}
}

try {
console.log("🧹 Cleaning generated files...")
export async function clean() {
console.log("🧹 Cleaning generated files...");

await cleanDirectories(["css", "js"]);
await removePublishDirectory();
}

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

// Only run if the script is run directly, not imported as a module
if (import.meta.main) {
await clean();
console.log("✅ Clean complete!");
} catch (error) {
if (!(error instanceof Deno.errors.NotFound))
throw error;
}
19 changes: 10 additions & 9 deletions scripts/publish.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "jsr:@std/fs";
import { compile } from "./build.ts";

async function deleteExistingDist() {
export async function removePublishDirectory() {
try {
await Deno.remove("./dist", { recursive: true });
} catch (error) {
Expand All @@ -11,18 +11,19 @@ async function deleteExistingDist() {
}

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

console.log("🚀 Publishing files to `dist/`...");

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

console.log("✅ Publish complete!");
await removePublishDirectory();
await fs.copy("./static", "./dist/");
await fs.copy("./wrangler.toml", "./dist/wrangler.toml");
}

await publish();
// Only run if the script is run directly, not imported as a module
if (import.meta.main) {
await publish();
console.log("✅ Publish complete!");
}
1 change: 1 addition & 0 deletions scripts/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ async function runTasks() {
}
}

// This one should be run directly
await runTasks();
File renamed without changes.
Loading