-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpack.ts
More file actions
58 lines (48 loc) · 1.73 KB
/
Copy pathpack.ts
File metadata and controls
58 lines (48 loc) · 1.73 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
#!/usr/bin/env bun
import { $, Glob } from 'bun'
import { Zippable, zipSync } from 'fflate'
import path from 'path'
import ccmod from './ccmod.json'
await $`rm -f ${ccmod.id}*`.nothrow().quiet()
await $`bun run build`
const tasks: Promise<void>[] = []
const zipFiles: Zippable = {}
async function addGlob(glob: string, minify?: boolean) {
for await (const filePath of new Glob(glob).scan()) {
if (filePath.endsWith('~') || filePath.endsWith('.kra')) continue
if (filePath.endsWith('icon240.png')) continue
tasks.push(
(async () => {
const file = Bun.file(filePath)
let data: Uint8Array
if (
minify &&
(filePath.endsWith('.json') ||
filePath.endsWith('.json.patch') ||
filePath.endsWith('.json.patch.confd'))
) {
data = new TextEncoder().encode(JSON.stringify(await file.json()))
} else {
data = await file.bytes()
}
let obj = zipFiles
for (const dirName of path.dirname(filePath).split(path.sep)) {
if (dirName == '.') continue
obj = (obj[dirName] ??= {}) as Zippable
}
obj[path.basename(filePath)] = data
console.log(' adding: ', filePath)
})()
)
}
}
await Promise.all([
//
addGlob('{LICENSE,plugin.js,ccmod.json}'),
addGlob('icon/icon.png'),
addGlob('assets/**/*', true),
])
await Promise.all(tasks)
const zipData = zipSync(zipFiles)
const zipName = `${ccmod.id}-${ccmod.version}.ccmod`
await Bun.file(`./${zipName}`).write(zipData)