Skip to content

Commit

Permalink
arguments for building just one file at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
TodePond committed Sep 4, 2022
1 parent 37fb07a commit 2561ca8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
37 changes: 29 additions & 8 deletions frogasaurus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -248,19 +256,32 @@ 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]

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)
}
}

Expand Down
18 changes: 13 additions & 5 deletions source/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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...")
Expand Down
19 changes: 16 additions & 3 deletions source/main.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
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]

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)
}
}

0 comments on commit 2561ca8

Please sign in to comment.