deno.land / x / trex@v1.13.1 / tools / logs.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170/** * Copyright (c) Crew Dev. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */
import { getImportMap } from "../handlers/handle_files.ts";import { offLine, Somebybroken } from "../utils/logs.ts";import { Config } from "../handlers/global_configs.ts";import type { importMap } from "../utils/types.ts";import { STD, VERSION } from "../utils/info.ts";import { createGraph } from "deno_graph";import { needProxy, Proxy } from "proxy";import * as colors from "fmt/colors.ts";import { clean, ltr } from "semver";import { wait } from "wait";
const { yellow, cyan, red, white, green } = colors;
/** * show in console the tree dependencies of a module * @param {string[]} ...args The Deno arguments pass in the console * @returns {boolean} return process state or throw a message with an error */
export async function packageTreeInfo( ...args: string[]): Promise<boolean | undefined> { try { const map: importMap = (await getImportMap<importMap>())!;
for (const pkg in map?.imports) { if (STD.includes(args[1])) { const moduleName = `${args[1]}/`;
if (moduleName === pkg) { const _pkg = needProxy(args[1]) ? Proxy(args[1]) : `${map.imports[pkg]}mod.ts`;
try { // create package graph const graph = await createGraph(_pkg);
console.log(graph.toString()); } catch (error: any) { Somebybroken("package information could not be obtained"); }
return true; } } else { const moduleName = args[1];
if (moduleName === pkg) { try { // create package graph const graph = await createGraph(map.imports[pkg]);
console.log(graph.toString()); } catch (error: any) { Somebybroken("package information could not be obtained"); }
return true; } } } } catch (_) { throw new Error( `the ${Config.getConfig("importMap")} file does not have a valid format`, ).message; }}
/** * send update notification */export async function newVersion(): Promise<void> { const response = (await fetch( "https://api.github.com/repos/crewdevio/Trex/releases/latest", ).catch((_) => offLine())) as Response;
const data = (await response.json()) as { tag_name: string };
// check if trex is outdate if ( data?.tag_name !== VERSION.VERSION && ltr(clean(VERSION.VERSION)!, clean(data?.tag_name)!) ) { const versionMessage = white( `Actual ${red(VERSION.VERSION)} -> new ${cyan(data?.tag_name ?? "?")}`, );
const upgradeMessage = white(`use ${green("trex")} upgrade `);
console.log( yellow(` ╭─────────────────────────────────────╮ │ │ │ New version avaliable for trex │ │ │ │ ${versionMessage} │ │ │ │ │ │ ${upgradeMessage} │ │ │ ╰─────────────────────────────────────╯`), ); }}
/** * show a pretty loading instalation message * @param {string} text */export function LoadingSpinner(text: string, show = true) { if (show) { console.clear(); const spinner = wait({ spinner: { frames: [ ". ", ".. ", "... ", ".... ", ".....", " ....", " ...", " ..", " .", ], interval: 50, }, text: "", }).start();
const colors: string[] = [ "red", "green", "yellow", "blue", "magenta", "cyan", "white", ];
spinner.color = colors[Math.floor(Math.random() * 6) + 1]; spinner.text = text;
return spinner; }}
/** * check if a local file. * @param {string} url * @returns {boolean} */export const isLocalFile = (url: string) => { return ( url.startsWith("./") || url.startsWith("../") || url.startsWith("/") || url.startsWith("file:") || url.startsWith("C:\\") );};
Version Info