Skip to content

Commit

Permalink
Prettified Code!
Browse files Browse the repository at this point in the history
  • Loading branch information
renhiyama authored and actions-user committed Mar 25, 2024
1 parent 3748acc commit d929e82
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
53 changes: 41 additions & 12 deletions src/cli/cmds/cacheinfo.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,59 @@
import CacheMapReader from "@reejs/utils/cacheMapReader.js";
import { reejsDir } from "@reejs/imports/env.js";
export default async function (prog,opts) {
export default async function (prog, opts) {
prog
.command("cache-info [name]")
.describe("Tells you the original file URL of the cached file name you provide")
.describe(
"Tells you the original file URL of the cached file name you provide"
)
.action(async function (name) {
let reader1 = new CacheMapReader(reejsDir);
if(!name) {
if (!name) {
console.log("Please provide a file name to get the original URL");
return;
}
let map1 = reader1.read();
//find the key in the map whose value is the name
let result = Object.keys(map1).find(key => map1[key] === name.includes(".") ? name : name + ".js").replace("|"," [")+"]";
if(result) {
let result =
Object.keys(map1)
.find(key => (map1[key] === name.includes(".") ? name : name + ".js"))
.replace("|", " [") + "]";
if (result) {
// console.log(`Original URL for ${name} is ${result}, found in ${reader1.url()}`);
console.log(`%c[CACHE] %cOriginal URL: %c${result}\n%c[INFO] %cFound in: %c${reader1.url()}`, "color: green", "", "color: #f59e0b; font-weight: bold", "color: #f59e0b", "", "color: #f59e0b; font-weight: bold");
console.log(
`%c[CACHE] %cOriginal URL: %c${result}\n%c[INFO] %cFound in: %c${reader1.url()}`,
"color: green",
"",
"color: #f59e0b; font-weight: bold",
"color: #f59e0b",
"",
"color: #f59e0b; font-weight: bold"
);
} else {
let reader2 = new CacheMapReader(globalThis?.process?.cwd?.() || Deno.cwd());
let reader2 = new CacheMapReader(
globalThis?.process?.cwd?.() || Deno.cwd()
);
let map2 = reader2.read();
let result = Object.keys(map2).find(key => map2[key] === name.includes(".") ? name : name + ".js").replace("|"," [")+"]";
if(result) {
console.log(`%c[CACHE] %cOriginal URL: %c${result}\n%c[INFO] %cFound in: %c${reader2.url()}`, "color: green", "", "color: #f59e0b; font-weight: bold", "color: #f59e0b", "", "color: #f59e0b; font-weight: bold");

let result =
Object.keys(map2)
.find(key =>
map2[key] === name.includes(".") ? name : name + ".js"
)
.replace("|", " [") + "]";
if (result) {
console.log(
`%c[CACHE] %cOriginal URL: %c${result}\n%c[INFO] %cFound in: %c${reader2.url()}`,
"color: green",
"",
"color: #f59e0b; font-weight: bold",
"color: #f59e0b",
"",
"color: #f59e0b; font-weight: bold"
);
} else {
console.log(`File ${name} not found in cache. Please run this command in the project directory where the file is located.`);
console.log(
`File ${name} not found in cache. Please run this command in the project directory where the file is located.`
);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/cacheMapReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class CacheMapReader {
console.log(e);
}
}
url(){
url() {
return this.cacheMapPath;
}
}

0 comments on commit d929e82

Please sign in to comment.