forked from scarf005/Marisa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink.ts
More file actions
executable file
·67 lines (57 loc) · 1.92 KB
/
link.ts
File metadata and controls
executable file
·67 lines (57 loc) · 1.92 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
62
63
64
65
66
67
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-env
import { join, resolve } from "https://deno.land/std@0.177.0/path/mod.ts"
import promiseObject from "https://deno.land/x/promise_object@v0.10.0/index.ts"
import { outdent } from "npm:outdent"
import {
brightGreen,
brightRed,
brightYellow,
magenta,
} from "https://deno.land/std@0.177.0/fmt/colors.ts"
const jar = join("build", "libs", "MarisaContinued.jar")
const image = join("docs", "thumbnail", "image.jpg")
const home = Deno.env.get("HOME")!
// deno-fmt-ignore
const mod = join(home, ".steam", "steam", "steamapps", "common", "SlayTheSpire", "MarisaContinued")
type Fmt = {
from: string
fromIno: number
target: string
targetIno: number
}
const fmtOk = ({ from, fromIno, target, targetIno }: Fmt) =>
outdent`
${brightGreen(`${fromIno}`)} :: ${brightGreen(from)}
${brightGreen(`${targetIno}`)} :: ${brightGreen(target)}
`
const fmtErr = ({ from, fromIno, target, targetIno }: Fmt) =>
outdent`
${brightGreen(`${fromIno}`)} :: ${brightYellow(from)}
${brightRed(`${targetIno}`)} :: ${brightYellow(target)}
`
const inode = async (filePath: string) => {
try {
return (await Deno.lstat(filePath)).ino!
} catch {
return -1
}
}
const forceCreateLinkTo = async (from: string, to: string): Promise<void> => {
const target = join(to, from.split("/").pop()!)
// deno-fmt-ignore
const { fromIno, targetIno } =
await promiseObject({ fromIno: inode(from), targetIno: inode(target) })
const fmt = fromIno === targetIno ? fmtOk : fmtErr
console.log(fmt({ from, fromIno, target, targetIno }) + "\n")
if (fromIno == targetIno) return
try {
await Deno.remove(target)
// deno-lint-ignore no-empty
} catch {}
await Deno.link(resolve(from), target)
console.log(magenta(`linked ${resolve(from)} -> ${target}`))
}
await Promise.all([
forceCreateLinkTo(jar, join(mod, "content")),
forceCreateLinkTo(image, mod),
])