Skip to content

Commit

Permalink
--watch argument
Browse files Browse the repository at this point in the history
  • Loading branch information
TodePond committed Sep 4, 2022
1 parent f64be86 commit 6d9d83b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions frogasaurus.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const FrogasaurusFrogasaurus = {}
}

console.log("%cFinished build!", YELLOW)
console.log("Waiting for file changes...")
if (options.watch) console.log("Waiting for file changes...")
}

FrogasaurusFrogasaurus["./build.js"].build = build
Expand Down Expand Up @@ -263,13 +263,16 @@ const FrogasaurusFrogasaurus = {}

const options = {
build: "all",
watch: false
}

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
} else if (arg === "--watch" || arg === "-w") {
options.watch = true
}
}

Expand All @@ -282,9 +285,11 @@ const FrogasaurusFrogasaurus = {}

await build(projectName, options)

const watcher = Deno.watchFs("./source")
for await (const event of watcher) {
await build(projectName, options)
if (options.watch) {
const watcher = Deno.watchFs("./source")
for await (const event of watcher) {
await build(projectName, options)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,5 @@ export const build = async (projectName, options) => {
}

console.log("%cFinished build!", YELLOW)
console.log("Waiting for file changes...")
if (options.watch) console.log("Waiting for file changes...")
}
11 changes: 8 additions & 3 deletions source/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ export const main = async (...args) => {

const options = {
build: "all",
watch: false
}

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
} else if (arg === "--watch" || arg === "-w") {
options.watch = true
}
}

Expand All @@ -23,8 +26,10 @@ export const main = async (...args) => {

await build(projectName, options)

const watcher = Deno.watchFs("./source")
for await (const event of watcher) {
await build(projectName, options)
if (options.watch) {
const watcher = Deno.watchFs("./source")
for await (const event of watcher) {
await build(projectName, options)
}
}
}

0 comments on commit 6d9d83b

Please sign in to comment.