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..8ba9b34 100644 --- a/scripts/clean.ts +++ b/scripts/clean.ts @@ -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; } \ No newline at end of file diff --git a/scripts/publish.ts b/scripts/publish.ts index 689a002..3314b96 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) { @@ -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(); \ 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 diff --git a/_headers b/static/_headers similarity index 100% rename from _headers rename to static/_headers