From 13f4a6186a2819dceda14bbda2742b0197bcf330 Mon Sep 17 00:00:00 2001 From: ArmoryNode <22787155+ArmoryNode@users.noreply.github.com> Date: Fri, 24 Jan 2025 12:03:25 -0800 Subject: [PATCH 1/3] Fixed clean task and standardized how tasks are run as modules --- scripts/build.ts | 13 +++++++------ scripts/clean.ts | 39 ++++++++++++++++++++++++++------------- scripts/publish.ts | 10 +++++++--- scripts/run.ts | 1 + 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/scripts/build.ts b/scripts/build.ts index 111d62a..39aeb98 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -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(); @@ -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!"); +} \ No newline at end of file diff --git a/scripts/clean.ts b/scripts/clean.ts index 8c8cfed..b9212b1 100644 --- a/scripts/clean.ts +++ b/scripts/clean.ts @@ -1,26 +1,39 @@ 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); + } } + } catch (error) { + if (!(error instanceof Deno.errors.NotFound)) { + throw error; + } + } } async function removeDirectories(directories: string[]) { + try { for (const dir of directories) { - await Deno.remove(dir, { recursive: true }); + 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 removeDirectories(["dist"]); +} - 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; } \ No newline at end of file diff --git a/scripts/publish.ts b/scripts/publish.ts index 689a002..d9d6092 100644 --- a/scripts/publish.ts +++ b/scripts/publish.ts @@ -11,7 +11,7 @@ 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(); @@ -22,7 +22,11 @@ async function publish() { await fs.copy("./wrangler.toml", "./dist/wrangler.toml", { overwrite: true }); await fs.copy("./_headers", "./dist/_headers"); - console.log("โœ… Publish complete!"); + } -await publish(); \ No newline at end of file +// Only run if the script is run directly, not imported as a module +if (import.meta.main) { + await publish(); + console.log("โœ… Publish complete!"); +} \ No newline at end of file diff --git a/scripts/run.ts b/scripts/run.ts index 814fa92..72bd6ef 100644 --- a/scripts/run.ts +++ b/scripts/run.ts @@ -24,4 +24,5 @@ async function runTasks() { } } +// This one should be run directly await runTasks(); \ No newline at end of file From 7ab4f9ec28eb9027ab1d5ab645459b0cc144ae2d Mon Sep 17 00:00:00 2001 From: ArmoryNode <22787155+ArmoryNode@users.noreply.github.com> Date: Fri, 24 Jan 2025 12:08:19 -0800 Subject: [PATCH 2/3] Fixed publish script and removed redundant code --- scripts/clean.ts | 16 +++------------- scripts/publish.ts | 10 ++++------ 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/scripts/clean.ts b/scripts/clean.ts index b9212b1..8ba9b34 100644 --- a/scripts/clean.ts +++ b/scripts/clean.ts @@ -1,3 +1,5 @@ +import { removePublishDirectory } from "./publish.ts"; + async function cleanDirectories(directories: string[]) { try { for (const dir of directories) { @@ -13,23 +15,11 @@ async function cleanDirectories(directories: string[]) { } } -async function removeDirectories(directories: string[]) { - try { - for (const dir of directories) { - await Deno.remove(dir, { recursive: true }); - } - } catch (error) { - if (!(error instanceof Deno.errors.NotFound)) { - throw error; - } - } -} - export async function clean() { console.log("๐Ÿงน Cleaning generated files..."); await cleanDirectories(["css", "js"]); - await removeDirectories(["dist"]); + await removePublishDirectory(); } // Only run if the script is run directly, not imported as a module diff --git a/scripts/publish.ts b/scripts/publish.ts index d9d6092..25b1d6f 100644 --- a/scripts/publish.ts +++ b/scripts/publish.ts @@ -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) { @@ -17,12 +17,10 @@ export async function publish() { 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 removePublishDirectory(); + await fs.copy("./static", "./dist/"); + await fs.copy("./wrangler.toml", "./dist/wrangler.toml"); await fs.copy("./_headers", "./dist/_headers"); - - } // Only run if the script is run directly, not imported as a module From 2b5ed37a0eeb42f26d6ef86205266e24b6726342 Mon Sep 17 00:00:00 2001 From: ArmoryNode <22787155+ArmoryNode@users.noreply.github.com> Date: Fri, 24 Jan 2025 12:12:05 -0800 Subject: [PATCH 3/3] Headers file no longer needs to be copied --- scripts/publish.ts | 1 - _headers => static/_headers | 0 2 files changed, 1 deletion(-) rename _headers => static/_headers (100%) diff --git a/scripts/publish.ts b/scripts/publish.ts index 25b1d6f..3314b96 100644 --- a/scripts/publish.ts +++ b/scripts/publish.ts @@ -20,7 +20,6 @@ export async function publish() { await removePublishDirectory(); await fs.copy("./static", "./dist/"); await fs.copy("./wrangler.toml", "./dist/wrangler.toml"); - await fs.copy("./_headers", "./dist/_headers"); } // Only run if the script is run directly, not imported as a module diff --git a/_headers b/static/_headers similarity index 100% rename from _headers rename to static/_headers