Support config flags
This commit is contained in:
parent
0a9301037e
commit
30bc3f689a
1
deps.ts
1
deps.ts
|
@ -7,3 +7,4 @@ export {
|
||||||
export type { Response as ServerResponse } from "https://deno.land/std@0.106.0/http/server.ts";
|
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 { 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 { 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";
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
import {
|
import {
|
||||||
listenAndServe,
|
listenAndServe,
|
||||||
posix,
|
posix,
|
||||||
|
readAll,
|
||||||
serveFile,
|
serveFile,
|
||||||
ServerRequest,
|
ServerRequest,
|
||||||
ServerResponse,
|
ServerResponse,
|
||||||
|
@ -117,17 +118,35 @@ async function run(...cmd: string[]): Promise<boolean> {
|
||||||
return result.success;
|
return result.success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function deno(cmd: string, ...args: string[]): Promise<boolean> {
|
||||||
|
const flags = await readConfigFlags(cmd);
|
||||||
|
return await run("deno", cmd, ...flags, ...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function readConfigFlags(cmd: string): Promise<string[]> {
|
||||||
|
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(
|
async function bundle(
|
||||||
source: string,
|
source: string,
|
||||||
destination: string,
|
destination: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// TODO add config flags
|
|
||||||
if (
|
if (
|
||||||
await run("deno", "bundle", source, destination) &&
|
await deno("bundle", "-q", source, destination) &&
|
||||||
await run("deno", "fmt", destination)
|
await deno("fmt", "-q", destination)
|
||||||
) {
|
) {
|
||||||
return;
|
console.log(`Bundled : ${source} -> ${destination}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Bundle failed for: ${source}`);
|
console.error(`Bundle failed for: ${source}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue