-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathcache.js
More file actions
61 lines (51 loc) · 1.43 KB
/
cache.js
File metadata and controls
61 lines (51 loc) · 1.43 KB
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
// Import Node.js Dependencies
import { styleText } from "node:util";
import { setImmediate } from "node:timers/promises";
// Import Third-party Dependencies
import prettyJson from "@topcli/pretty-json";
import * as i18n from "@nodesecure/i18n";
import { cache, config } from "@nodesecure/server";
export async function main(options) {
const {
list,
clear,
full
} = options;
await i18n.getLocalLang();
if (!(list || clear)) {
console.log(styleText("red", i18n.getTokenSync("cli.commands.cache.missingAction")));
process.exit(1);
}
if (list) {
listCache(full);
}
if (clear) {
await setImmediate();
await clearCache(full);
}
}
async function listCache(full) {
const paylodsList = await cache.payloadsList();
console.log(styleText(["underline"], i18n.getTokenSync("cli.commands.cache.cacheTitle")));
prettyJson(paylodsList);
if (full) {
console.log(styleText(["underline"], i18n.getTokenSync("cli.commands.cache.scannedPayloadsTitle")));
try {
const payloads = cache.availablePayloads();
prettyJson(payloads);
}
catch {
prettyJson([]);
}
}
}
async function clearCache(full) {
if (full) {
cache.availablePayloads().forEach((pkg) => {
cache.removePayload(pkg);
});
}
await config.setDefault();
await cache.initPayloadsList({ logging: false, reset: true });
console.log(styleText("green", i18n.getTokenSync("cli.commands.cache.cleared")));
}