deno.land / x / trex@v1.13.1 / utils / 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/** * 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 type { CommandNotFoundParams, HelpCommandParams } from "./types.ts";import { didYouMean } from "../tools/did_you_mean.ts";import { helpsInfo, VERSION } from "./info.ts";import exec from "../tools/install_tools.ts";import * as colors from "fmt/colors.ts";
const { cyan, red, green, yellow } = colors;
/** * print trex version * @param {string} version */export function Version(version: string) { console.log( `${green("trex:")}\n ${yellow(version)} \n${ green( "Deno:", ) }\n ${yellow(`v${Deno.version.deno}`)}`, );}
/** * show help info * @param helpsInfo */export function LogHelp(helpsInfo: string[]) { console.log(helpsInfo.join(""));}
/** * update trex */export async function updateTrex(): Promise<void> { // * get the version of the repo in github const response = (await fetch( "https://api.github.com/repos/crewdevio/Trex/releases/latest", ).catch((_) => offLine())) as Response;
// * get the latest release const repoVersion = (await response.json()) as { tag_name: string };
const isCanary = Deno.args[1]?.trim() === "--canary"; const canaryURL = "https://denopkg.com/crewdevio/trex@dev"; const standarURL = `https://deno.land/x/trex@${repoVersion.tag_name}`; // check if is a canary update const url = isCanary ? canaryURL : standarURL;
if (repoVersion.tag_name !== VERSION.VERSION || isCanary) { setTimeout(async () => { await exec({ config: { permissions: [ "-A", "-r", "--no-check", "--import-map", `${url}/import_map.json`, "--unstable", "-n", "trex", ], url: `${url}/cli.ts`, }, });
console.log( cyan(`trex ${green(repoVersion.tag_name)} is now installed.`), ); }, 1000); } else { console.log(cyan(`you have the last version trex ${repoVersion.tag_name}`)); }}
/** * show off line message */export function offLine() { throw new Error( red( "something went wrong when making the request, maybe you're offline, check your connection.", ), ).message;}
/** * show error message * @param {string} message */export function Somebybroken(message: string = "some process is broken.") { throw new Error(red(message)).message;}
/** * show install error message */export function ErrorInstalling() { const logError = `${red("something went wrong\n")}${ green( "maybe this package is missing a mod.ts file, use custom install.\n", ) }${yellow("trex --custom module=moduleUrl\n")}`;
throw new Error(logError).message;}
export function HelpCommand({ command, flags }: HelpCommandParams) { console.log( green(`${red("action: ")} ${command.description}\n`), yellow("\nuse:\n"), green( `trex [${command.alias.map((cmd) => yellow(cmd))}] ${ flags.map((flag) => `[${flag.alias.map((name) => yellow(name))}]`.replace(",", ", ") ) }\n`.replace(",", " or "), ), yellow(flags.length ? "\nflags:\n" : ""), green( `${ flags.map( (flag) => ` ${red("*")} [${ flag.alias.map((sub) => yellow(sub)) }] : ${flag.description}\n`, ) }`.replaceAll(",", " "), ), );}
export function CommandNotFound({ commands, flags }: CommandNotFoundParams) { const { args } = Deno;
const [command = "", flag = ""] = args;
if (!args.length) { LogHelp(helpsInfo); Deno.exit(0); }
if (!commands.includes(command)) { console.log( red("Command not found:\n"), green( `\n${red("trex")} ${ yellow( command ?? "empty command", ) }: unknown command\n`, ), green( `\nuse ${red("trex")} ${yellow("--help")} to see available commands\n`, ), );
console.log(didYouMean(command, commands));
Deno.exit(0); }
if (!flags.includes(flag)) { console.log( red("Command flag not found:\n"), green( `\n${red("trex")} ${yellow(command ?? "empty command")} ${ yellow( flag, ) }: unknown command flag\n`, ), green( `\nuse ${red("trex")} ${yellow(command ?? "empty command")} ${ yellow( "--help", ) } to see available command flags\n`, ), );
console.log(didYouMean(flag, flags, command));
Deno.exit(0); }}
/** * log packages list * @param map */export function LogPackages(map: Object, message = true) { console.group("Package list: "); for (const pkg in map) { console.log("|- ", cyan(pkg)); } console.groupEnd();
if (message) { console.log(green("Happy Coding")); } console.log();}
trex

Version Info

Tagged at
9 months ago