-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
handle_cache.ts
91 lines (77 loc) 路 2.1 KB
/
handle_cache.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
/**
* 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 { green, red } from "https://deno.land/std/fmt/colors.ts";
import { ErrorInstalling } from "../utils/logs.ts";
import { needProxy, Proxy } from "../deps.ts";
import { STD } from "../utils/info.ts";
import { denoApidb } from "../utils/db.ts";
/**
* caches packages.
* @param {string} pkgName - name the package.
* @param {string} pkgUrl - package url.
* @return void
*/
async function cached(pkgName: string, pkgUrl: string) {
const ID = "trex_Cache_Map";
let process: Deno.Process;
console.log(green("cache package... \n"));
if (STD.includes(pkgName) && (await denoApidb(pkgName)).length) {
process = Deno.run({
cmd: [
"deno",
"install",
"-f",
"-n",
ID,
"--unstable",
needProxy(pkgName) ? Proxy(pkgName) : pkgUrl + "mod.ts",
],
});
if (!(await process.status()).success) {
process.close();
ErrorInstalling();
}
}
// * install standar party package by defaul use mod.ts
else if (STD.includes(pkgName)) {
process = Deno.run({
cmd: [
"deno",
"install",
"-f",
"-n",
ID,
"--unstable",
needProxy(pkgName) ? Proxy(pkgName) : pkgUrl + "mod.ts",
],
});
if (!(await process.status()).success) {
process.close();
ErrorInstalling();
}
console.log(green("\n Done. \n"));
}
// * install third party package
else if ((await denoApidb(pkgName)).length) {
process = Deno.run({
cmd: ["deno", "install", "-f", "-n", ID, "--unstable", pkgUrl],
});
// * if cannot download package, throw error message
if (!(await process.status()).success) {
process.close();
ErrorInstalling();
}
console.log(green("\n Done. \n"));
}
// * log error if package is not found
else if (!STD.includes(pkgName) && !(await denoApidb(pkgName)).length) {
console.error(red("package not found."));
return;
}
}
export default cached;