-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: give each module a namespace and add log module
- Loading branch information
Showing
6 changed files
with
64 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,34 @@ | ||
/// <reference path="./types.d.ts" /> | ||
|
||
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 <script>`, 2); | ||
} | ||
} else { | ||
error(`usage: dzx <script>`, 2); | ||
error(`usage: dzx <script>`); | ||
} | ||
} else if ( | ||
script.startsWith("http://") || script.startsWith("https://") || | ||
script.startsWith("file://") | ||
) { | ||
await import(script); | ||
} else if (script) { | ||
await import("file://" + path.join($.cwd, script)); | ||
} else { | ||
error(`usage: dzx <script>`); | ||
} | ||
} else if ( | ||
script.startsWith("http://") || script.startsWith("https://") || | ||
script.startsWith("file://") | ||
) { | ||
await import(script); | ||
} else if (script) { | ||
await import("file://" + join($.cwd, script)); | ||
} else { | ||
error(`usage: dzx <script>`); | ||
} catch (err) { | ||
error(err); | ||
} | ||
} catch (err) { | ||
error(err); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,38 @@ | ||
import type { | ||
$, | ||
cd as _cd, | ||
parseFlags as _parseFlags, | ||
flags as _flags, | ||
fs as _fs, | ||
io as _io, | ||
log as _log, | ||
path as _path, | ||
quote as _quote, | ||
} from "./mod.ts"; | ||
import type { | ||
ArgParsingOptions as _ArgParsingOptions, | ||
Args as _Args, | ||
basename as _basename, | ||
Buffer as _Buffer, | ||
dirname as _dirname, | ||
extname as _extname, | ||
fromFileUrl as _fromFileUrl, | ||
isAbsolute as _isAbsolute, | ||
iter as _iter, | ||
iterSync as _iterSync, | ||
join as _join, | ||
normalize as _normalize, | ||
readAll as _readAll, | ||
readAllSync as _readAllSync, | ||
readLines as _readLines, | ||
relative as _relative, | ||
resolve as _resolve, | ||
toFileUrl as _toFileUrl, | ||
toNamespacedPath as _toNamespacedPath, | ||
writeAll as _writeAll, | ||
writeAllSync as _writeAllSync, | ||
} from "./deps.ts"; | ||
|
||
declare global { | ||
// dzx | ||
const $: $; | ||
const cd: typeof _cd; | ||
const quote: typeof _quote; | ||
|
||
// std/io | ||
const Buffer: typeof _Buffer; | ||
const iter: typeof _iter; | ||
const iterSync: typeof _iterSync; | ||
const readAll: typeof _readAll; | ||
const readAllSync: typeof _readAllSync; | ||
const readLines: typeof _readLines; | ||
const writeAll: typeof _writeAll; | ||
const writeAllSync: typeof _writeAllSync; | ||
|
||
// std/path | ||
const basename: typeof _basename; | ||
const dirname: typeof _dirname; | ||
const extname: typeof _extname; | ||
const fromFileUrl: typeof _fromFileUrl; | ||
const isAbsolute: typeof _isAbsolute; | ||
const join: typeof _join; | ||
const normalize: typeof _normalize; | ||
const relative: typeof _relative; | ||
const resolve: typeof _resolve; | ||
const toFileUrl: typeof _toFileUrl; | ||
const toNamespacedPath: typeof _toNamespacedPath; | ||
|
||
// std/flags | ||
const parseFlags: typeof _parseFlags; | ||
type ArgParsingOptions = _ArgParsingOptions; | ||
type Args = _Args; | ||
// x | ||
const path: typeof _path; | ||
const io: typeof _io; | ||
const fs: typeof _fs; | ||
const log: typeof _log; | ||
const flags: typeof _flags; | ||
|
||
interface Window { | ||
// dzx | ||
$: $; | ||
cd: typeof _cd; | ||
quote: typeof _quote; | ||
|
||
// std/io | ||
Buffer: typeof _Buffer; | ||
iter: typeof _iter; | ||
iterSync: typeof _iterSync; | ||
readAll: typeof _readAll; | ||
readAllSync: typeof _readAllSync; | ||
readLines: typeof _readLines; | ||
writeAll: typeof _writeAll; | ||
writeAllSync: typeof _writeAllSync; | ||
|
||
// std/path | ||
basename: typeof _basename; | ||
dirname: typeof _dirname; | ||
extname: typeof _extname; | ||
fromFileUrl: typeof _fromFileUrl; | ||
isAbsolute: typeof _isAbsolute; | ||
join: typeof _join; | ||
normalize: typeof _normalize; | ||
relative: typeof _relative; | ||
resolve: typeof _resolve; | ||
toFileUrl: typeof _toFileUrl; | ||
toNamespacedPath: typeof _toNamespacedPath; | ||
|
||
// std/flags | ||
parseFlags: typeof _parseFlags; | ||
// x | ||
path: typeof _path; | ||
io: typeof _io; | ||
fs: typeof _fs; | ||
log: typeof _log; | ||
flags: typeof _flags; | ||
} | ||
} |