From 2561ca8bbbd4708dc079f4d519693421ce437319 Mon Sep 17 00:00:00 2001 From: Luke Wilson Date: Sun, 4 Sep 2022 14:57:11 +0100 Subject: [PATCH] arguments for building just one file at a time --- frogasaurus.js | 37 +++++++++++++++++++++++++++++-------- source/build.js | 18 +++++++++++++----- source/main.js | 19 ++++++++++++++++--- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/frogasaurus.js b/frogasaurus.js index 2e20f69..0f6c1be 100644 --- a/frogasaurus.js +++ b/frogasaurus.js @@ -88,7 +88,7 @@ const FrogasaurusFrogasaurus = {} return {success: true, output: scopedSource, exportResults, importResults, path} } - const build = async (projectName) => { + const build = async (projectName, options) => { console.clear() @@ -171,10 +171,18 @@ const FrogasaurusFrogasaurus = {} const importSource = HEADER_TITLE + headerLine + SOURCE_TITLE + transpiledSource + FOOTER_TITLE + exportFooterSource + "\n\nexport " + globalFooterSource const embedSource = HEADER_TITLE + headerLine + SOURCE_TITLE + transpiledSource + FOOTER_TITLE + globalFooterSource const standaloneSource = HEADER_TITLE + headerLine + SOURCE_TITLE + transpiledSource + mainFuncDenoSource - - await writeFile(`${projectName.toLowerCase()}-import.js`, importSource) - await writeFile(`${projectName.toLowerCase()}-embed.js`, embedSource) - await writeFile(`${projectName.toLowerCase()}-standalone.js`, standaloneSource) + + if (options.build === "all") { + await writeFile(`${projectName.toLowerCase()}-import.js`, importSource) + await writeFile(`${projectName.toLowerCase()}-embed.js`, embedSource) + await writeFile(`${projectName.toLowerCase()}-standalone.js`, standaloneSource) + } else if (options.build === "import") { + await writeFile(`${projectName.toLowerCase()}.js`, importSource) + } else if (options.build === "embed") { + await writeFile(`${projectName.toLowerCase()}.js`, embedSource) + } else if (options.build === "standalone") { + await writeFile(`${projectName.toLowerCase()}.js`, standaloneSource) + } console.log("%cFinished build!", YELLOW) console.log("Waiting for file changes...") @@ -248,7 +256,20 @@ const FrogasaurusFrogasaurus = {} { FrogasaurusFrogasaurus["./main.js"] = {} - const main = async () => { + const main = async (...args) => { + + const options = { + build: "all", + } + + for (let i = 0; i < args.length; i++) { + const arg = args[i] + if (arg === "--build" || arg === "-b") { + const nextArg = args[i+1] + options.build = nextArg + } + } + const directory = Deno.cwd() const directoryParts = directory.split("\\") const projectName = directoryParts[directoryParts.length-1] @@ -256,11 +277,11 @@ const FrogasaurusFrogasaurus = {} await Deno.permissions.request({name: "read", path: "."}) await Deno.permissions.request({name: "write", path: "."}) - await build(projectName) + await build(projectName, options) const watcher = Deno.watchFs("./source") for await (const event of watcher) { - await build(projectName) + await build(projectName, options) } } diff --git a/source/build.js b/source/build.js index 369c9d9..f4bb3d2 100644 --- a/source/build.js +++ b/source/build.js @@ -79,7 +79,7 @@ const transpileSource = (source, name, path, projectName) => { return {success: true, output: scopedSource, exportResults, importResults, path} } -export const build = async (projectName) => { +export const build = async (projectName, options) => { console.clear() @@ -162,10 +162,18 @@ export const build = async (projectName) => { const importSource = HEADER_TITLE + headerLine + SOURCE_TITLE + transpiledSource + FOOTER_TITLE + exportFooterSource + "\n\nexport " + globalFooterSource const embedSource = HEADER_TITLE + headerLine + SOURCE_TITLE + transpiledSource + FOOTER_TITLE + globalFooterSource const standaloneSource = HEADER_TITLE + headerLine + SOURCE_TITLE + transpiledSource + mainFuncDenoSource - - await writeFile(`${projectName.toLowerCase()}-import.js`, importSource) - await writeFile(`${projectName.toLowerCase()}-embed.js`, embedSource) - await writeFile(`${projectName.toLowerCase()}-standalone.js`, standaloneSource) + + if (options.build === "all") { + await writeFile(`${projectName.toLowerCase()}-import.js`, importSource) + await writeFile(`${projectName.toLowerCase()}-embed.js`, embedSource) + await writeFile(`${projectName.toLowerCase()}-standalone.js`, standaloneSource) + } else if (options.build === "import") { + await writeFile(`${projectName.toLowerCase()}.js`, importSource) + } else if (options.build === "embed") { + await writeFile(`${projectName.toLowerCase()}.js`, embedSource) + } else if (options.build === "standalone") { + await writeFile(`${projectName.toLowerCase()}.js`, standaloneSource) + } console.log("%cFinished build!", YELLOW) console.log("Waiting for file changes...") diff --git a/source/main.js b/source/main.js index 5e46f84..0e4acab 100644 --- a/source/main.js +++ b/source/main.js @@ -1,6 +1,19 @@ import { build } from "./build.js" -export const main = async () => { +export const main = async (...args) => { + + const options = { + build: "all", + } + + for (let i = 0; i < args.length; i++) { + const arg = args[i] + if (arg === "--build" || arg === "-b") { + const nextArg = args[i+1] + options.build = nextArg + } + } + const directory = Deno.cwd() const directoryParts = directory.split("\\") const projectName = directoryParts[directoryParts.length-1] @@ -8,10 +21,10 @@ export const main = async () => { await Deno.permissions.request({name: "read", path: "."}) await Deno.permissions.request({name: "write", path: "."}) - await build(projectName) + await build(projectName, options) const watcher = Deno.watchFs("./source") for await (const event of watcher) { - await build(projectName) + await build(projectName, options) } }