update deno common mod
This commit is contained in:
@@ -106,14 +106,16 @@ export class ProcessOutput {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link execCommand} instead
|
||||
*/
|
||||
export async function execCommandAndStdout(
|
||||
command: string,
|
||||
args?: string[],
|
||||
options?: Deno.CommandOptions | SpawnOptionsWithoutStdio,
|
||||
): Promise<string> {
|
||||
const processOutput = await execCommand(command, args, options);
|
||||
processOutput.assertSuccess();
|
||||
return processOutput.stdout.trim();
|
||||
return (await execCommand(command, args, options))
|
||||
.assertSuccess().stdoutThenTrim();
|
||||
}
|
||||
|
||||
export async function execCommand(
|
||||
@@ -132,10 +134,10 @@ export async function execCommand(
|
||||
new TextDecoder().decode(stderr),
|
||||
);
|
||||
}
|
||||
return await execCommandSpawn(command, args, options);
|
||||
return await __execCommandSpawn(command, args, options);
|
||||
}
|
||||
|
||||
async function execCommandSpawn(
|
||||
async function __execCommandSpawn(
|
||||
command: string,
|
||||
args: string[],
|
||||
options?: SpawnOptionsWithoutStdio,
|
||||
@@ -179,10 +181,10 @@ export async function execCommandShell(
|
||||
const cmd = new Deno.Command(command, opts);
|
||||
return (await cmd.spawn().status).code;
|
||||
}
|
||||
return await execCommandShellSpwan(command, args, options);
|
||||
return await __execCommandShellSpawn(command, args, options);
|
||||
}
|
||||
|
||||
async function execCommandShellSpwan(
|
||||
async function __execCommandShellSpawn(
|
||||
command: string,
|
||||
args?: string[],
|
||||
options?: SpawnOptionsWithoutStdio,
|
||||
@@ -547,7 +549,7 @@ const COLOR_MAP: Record<string, string> = {
|
||||
bg_white_bright: "107",
|
||||
};
|
||||
|
||||
function getColorCode(color: string): string {
|
||||
function __getColorCode(color: string): string {
|
||||
if (color.startsWith("#")) {
|
||||
return color.substring(1);
|
||||
}
|
||||
@@ -561,7 +563,7 @@ function renderColorTokens(tokens: ColorToken[]): string {
|
||||
if (token.type === "color") {
|
||||
const color = token.color;
|
||||
if (color) {
|
||||
const colorCode = getColorCode(color);
|
||||
const colorCode = __getColorCode(color);
|
||||
if (!colorCode) {
|
||||
text.push(`[${token.colorStart ? "" : "/"}${color}]`);
|
||||
continue;
|
||||
@@ -579,7 +581,7 @@ function renderColorTokens(tokens: ColorToken[]): string {
|
||||
const colors: string[] = [];
|
||||
for (const [color, colorStack] of colorMapStack) {
|
||||
if (colorStack.length > 0) {
|
||||
const currentColorCode = getColorCode(color);
|
||||
const currentColorCode = __getColorCode(color);
|
||||
if (currentColorCode) {
|
||||
colors.push(currentColorCode);
|
||||
}
|
||||
@@ -664,7 +666,7 @@ class Term {
|
||||
|
||||
export const term = new Term();
|
||||
|
||||
function pad(message: string, length: number): string {
|
||||
function __pad(message: string, length: number): string {
|
||||
if (message.length >= length) {
|
||||
return message;
|
||||
}
|
||||
@@ -672,16 +674,16 @@ function pad(message: string, length: number): string {
|
||||
}
|
||||
const LOGGER_PREFIX_LEN: number = 8;
|
||||
class Logger {
|
||||
_debug: boolean = false;
|
||||
__debug: boolean = false;
|
||||
|
||||
constructor() {
|
||||
this._debug = osEnv("LOGGER") === "*";
|
||||
this.__debug = osEnv("LOGGER") === "*";
|
||||
}
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
success(...data: any[]) {
|
||||
this.log(
|
||||
term.bold(term.green(`[${pad("SUCCESS", LOGGER_PREFIX_LEN)}]`)),
|
||||
term.bold(term.green(`[${__pad("SUCCESS", LOGGER_PREFIX_LEN)}]`)),
|
||||
data,
|
||||
);
|
||||
}
|
||||
@@ -689,7 +691,7 @@ class Logger {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
error(...data: any[]) {
|
||||
this.log(
|
||||
term.bold(term.red(`[${pad("ERROR", LOGGER_PREFIX_LEN)}]`)),
|
||||
term.bold(term.red(`[${__pad("ERROR", LOGGER_PREFIX_LEN)}]`)),
|
||||
data,
|
||||
);
|
||||
}
|
||||
@@ -697,7 +699,7 @@ class Logger {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
warn(...data: any[]) {
|
||||
this.log(
|
||||
term.bold(term.yellow(`[${pad("WARN", LOGGER_PREFIX_LEN)}]`)),
|
||||
term.bold(term.yellow(`[${__pad("WARN", LOGGER_PREFIX_LEN)}]`)),
|
||||
data,
|
||||
);
|
||||
}
|
||||
@@ -706,7 +708,7 @@ class Logger {
|
||||
warning(...data: any[]) {
|
||||
this.log(
|
||||
term.blink(
|
||||
term.bold(term.yellow(`[${pad("WARN", LOGGER_PREFIX_LEN)}]`)),
|
||||
term.bold(term.yellow(`[${__pad("WARN", LOGGER_PREFIX_LEN)}]`)),
|
||||
),
|
||||
data,
|
||||
);
|
||||
@@ -714,13 +716,13 @@ class Logger {
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
info(...data: any[]) {
|
||||
this.log(term.bold(`[${pad("INFO", LOGGER_PREFIX_LEN)}]`), data);
|
||||
this.log(term.bold(`[${__pad("INFO", LOGGER_PREFIX_LEN)}]`), data);
|
||||
}
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
debug(...data: any[]) {
|
||||
if (this._debug) {
|
||||
this.log(`[${pad("DEBUG", LOGGER_PREFIX_LEN)}]`, data);
|
||||
if (this.__debug) {
|
||||
this.log(`[${__pad("DEBUG", LOGGER_PREFIX_LEN)}]`, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -807,11 +809,11 @@ export async function existsPath(path: string): Promise<boolean> {
|
||||
});
|
||||
}
|
||||
|
||||
function isDenoNotFound(e) {
|
||||
function __isDenoNotFound(e) {
|
||||
return e instanceof Error && e.name == "NotFound";
|
||||
}
|
||||
|
||||
function isNodeNotFound(e) {
|
||||
function __isNodeNotFound(e) {
|
||||
return (e.errno ?? 0 === -2) && e.message &&
|
||||
e.message.includes("no such file or directory");
|
||||
}
|
||||
@@ -823,7 +825,7 @@ export async function readFileToString(
|
||||
try {
|
||||
return await Deno.readTextFile(resolveFilename(filename));
|
||||
} catch (e) {
|
||||
if (isDenoNotFound(e)) {
|
||||
if (__isDenoNotFound(e)) {
|
||||
return null;
|
||||
}
|
||||
throw e;
|
||||
@@ -831,7 +833,7 @@ export async function readFileToString(
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
readFile(resolveFilename(filename), "utf8", (err, buffer) => {
|
||||
if (err && isNodeNotFound(err)) {
|
||||
if (err && __isNodeNotFound(err)) {
|
||||
resolve(null);
|
||||
} else {
|
||||
err ? reject(err) : resolve(buffer);
|
||||
@@ -845,7 +847,7 @@ export function readFileToStringSync(filename: string): string | null {
|
||||
try {
|
||||
return Deno.readTextFileSync(resolveFilename(filename));
|
||||
} catch (e) {
|
||||
if (isDenoNotFound(e)) {
|
||||
if (__isDenoNotFound(e)) {
|
||||
return null;
|
||||
}
|
||||
throw e;
|
||||
@@ -854,7 +856,7 @@ export function readFileToStringSync(filename: string): string | null {
|
||||
try {
|
||||
return readFileSync(resolveFilename(filename), "utf8");
|
||||
} catch (err) {
|
||||
if (isNodeNotFound(err)) {
|
||||
if (__isNodeNotFound(err)) {
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
|
||||
Reference in New Issue
Block a user