From 30bc3f689abb85f98964c277938be3d4d6f4b886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 7 Sep 2021 00:33:45 +0200 Subject: [PATCH] Support config flags --- deps.ts | 1 + src/server.ts | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/deps.ts b/deps.ts index 04897b8..0c52b21 100644 --- a/deps.ts +++ b/deps.ts @@ -7,3 +7,4 @@ export { export type { Response as ServerResponse } from "https://deno.land/std@0.106.0/http/server.ts"; export { serveFile } from "https://deno.land/std@0.106.0/http/file_server.ts"; export { posix } from "https://deno.land/std@0.106.0/path/mod.ts"; +export { readAll } from "https://deno.land/std@0.106.0/io/util.ts"; diff --git a/src/server.ts b/src/server.ts index 4a14593..a46476d 100644 --- a/src/server.ts +++ b/src/server.ts @@ -2,6 +2,7 @@ import { listenAndServe, posix, + readAll, serveFile, ServerRequest, ServerResponse, @@ -117,17 +118,35 @@ async function run(...cmd: string[]): Promise { return result.success; } +async function deno(cmd: string, ...args: string[]): Promise { + const flags = await readConfigFlags(cmd); + return await run("deno", cmd, ...flags, ...args); +} + +async function readConfigFlags(cmd: string): Promise { + const path = `config/${cmd}.flags`; + try { + const f = await Sys.open(path); + const content = await readAll(f); + return new TextDecoder() + .decode(content) + .split(" ") + .filter((part) => part && part.startsWith("--")); + } catch { + } + return []; +} + async function bundle( source: string, destination: string, ): Promise { - // TODO add config flags if ( - await run("deno", "bundle", source, destination) && - await run("deno", "fmt", destination) + await deno("bundle", "-q", source, destination) && + await deno("fmt", "-q", destination) ) { - return; + console.log(`Bundled : ${source} -> ${destination}`); } else { - console.log(`Bundle failed for: ${source}`); + console.error(`Bundle failed for: ${source}`); } }