From ee95ee532e314af7b63442a88b7756ab9cf368d0 Mon Sep 17 00:00:00 2001 From: Benjamin Fischer Date: Mon, 10 May 2021 16:15:53 +0200 Subject: [PATCH] refactor: give each module a namespace and add log module --- deps.ts | 37 +++------------- dzx.ts | 102 +++++++++++---------------------------------- mod.ts | 66 +++++++---------------------- src/exec.ts | 3 +- src/parse_flags.ts | 11 ----- types.d.ts | 93 ++++++++--------------------------------- 6 files changed, 64 insertions(+), 248 deletions(-) delete mode 100644 src/parse_flags.ts diff --git a/deps.ts b/deps.ts index 3259efe..645386f 100644 --- a/deps.ts +++ b/deps.ts @@ -1,32 +1,7 @@ -export { - basename, - dirname, - extname, - fromFileUrl, - isAbsolute, - join, - normalize, - relative, - resolve, - SEP, - SEP_PATTERN, - toFileUrl, - toNamespacedPath, -} from "https://deno.land/std@0.93.0/path/mod.ts"; +export * as path from "https://deno.land/std@0.93.0/path/mod.ts"; +export * as io from "https://deno.land/std@0.93.0/io/mod.ts"; +export * as fs from "https://deno.land/std@0.93.0/fs/mod.ts"; +export * as log from "https://deno.land/std@0.93.0/log/mod.ts"; +export * as flags from "https://deno.land/std@0.93.0/flags/mod.ts"; export { colors } from "https://deno.land/x/cliffy@v0.18.2/ansi/colors.ts"; -export { - iter, - iterSync, - readAll, - readAllSync, - writeAll, - writeAllSync, -} from "https://deno.land/std@0.93.0/io/util.ts"; -export { Buffer } from "https://deno.land/std@0.93.0/io/buffer.ts"; -export { readLines } from "https://deno.land/std@0.93.0/io/bufio.ts"; -export { default as escapeStr } from "https://esm.sh/shq@1.0.2"; -export { parse as parseFlags } from "https://deno.land/std@0.93.0/flags/mod.ts"; -export type { - ArgParsingOptions, - Args, -} from "https://deno.land/std@0.93.0/flags/mod.ts"; +export { default as shq } from "https://esm.sh/shq@1.0.2"; diff --git a/dzx.ts b/dzx.ts index de9ca6e..7a98a3a 100755 --- a/dzx.ts +++ b/dzx.ts @@ -1,88 +1,34 @@ /// - +import { $, io, path } from "./mod.ts"; import { error } from "./src/_utils.ts"; -import { - $, - basename, - Buffer, - cd, - dirname, - extname, - fromFileUrl, - isAbsolute, - iter, - iterSync, - join, - normalize, - parseFlags, - quote, - readAll, - readAllSync, - readLines, - relative, - resolve, - toFileUrl, - toNamespacedPath, - writeAll, - writeAllSync, -} from "./mod.ts"; - -// dzx -window.$ = $; -window.cd = cd; - -// std/io -window.Buffer = Buffer; -window.iter = iter; -window.iterSync = iterSync; -window.quote = quote; -window.readAll = readAll; -window.readAllSync = readAllSync; -window.readLines = readLines; -window.writeAll = writeAll; -window.writeAllSync = writeAllSync; - -// std/path -window.basename = basename; -window.dirname = dirname; -window.extname = extname; -window.fromFileUrl = fromFileUrl; -window.isAbsolute = isAbsolute; -window.join = join; -window.normalize = normalize; -window.relative = relative; -window.resolve = resolve; -window.toFileUrl = toFileUrl; -window.toNamespacedPath = toNamespacedPath; - -window.parseFlags = parseFlags; - -const script: string | undefined = Deno.args[0]; -try { - if (!script) { - if (!Deno.isatty(Deno.stdin.rid)) { - const data = new TextDecoder().decode(await readAll(Deno.stdin)); - if (data) { - await import( - `data:application/typescript,${encodeURIComponent(data)}` - ); +if (import.meta.main) { + const script: string | undefined = Deno.args[0]; + try { + if (!script) { + if (!Deno.isatty(Deno.stdin.rid)) { + const data = new TextDecoder().decode(await io.readAll(Deno.stdin)); + if (data) { + await import( + `data:application/typescript,${encodeURIComponent(data)}` + ); + } else { + error(`usage: dzx