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