deno.land / x / trex@v1.13.1 / tools / logs.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/** * 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:\\") );};
trex

Version Info

Tagged at
9 months ago