feat(media): add prepare script

This commit is contained in:
Il Harper 2024-09-07 13:53:34 +08:00
parent ddc7473197
commit 3f2c972001
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
2 changed files with 44 additions and 1 deletions

View File

@ -14,12 +14,15 @@
"lib" "lib"
], ],
"scripts": { "scripts": {
"build": "node -r esbuild-register ../../scripts/runOnChanged.cts ./src concurrently -n cjs,dts yarn:build:cjs yarn:build:dts", "prepare": "node -r esbuild-register scripts/prepare.cts",
"build": "yarn prepare && node -r esbuild-register ../../scripts/runOnChanged.cts ./src concurrently -n cjs,dts yarn:build:cjs yarn:build:dts",
"build:cjs": "node -r esbuild-register ../../scripts/build.cts", "build:cjs": "node -r esbuild-register ../../scripts/build.cts",
"build:dts": "tsc -p tsconfig.json" "build:dts": "tsc -p tsconfig.json"
}, },
"devDependencies": { "devDependencies": {
"@chronocat/shell": "workspace:packages/shell", "@chronocat/shell": "workspace:packages/shell",
"@types/adm-zip": "^0.5.0",
"adm-zip": "^0.5.10",
"concurrently": "^8.2.1", "concurrently": "^8.2.1",
"esbuild-register": "^3.5.0", "esbuild-register": "^3.5.0",
"ts-toolbelt": "^9.6.0", "ts-toolbelt": "^9.6.0",

View File

@ -0,0 +1,40 @@
import AdmZip from 'adm-zip'
import { access, mkdir } from 'node:fs/promises'
import { join, resolve } from 'node:path'
const filenames = ['ntsilk-win32-x64.exe', 'ntsilk-linux-x64']
const dstDir = resolve(__dirname, '../../../build/caches')
const dstPath = join(dstDir, 'ntsilk.zip')
export async function exists(path: string): Promise<boolean> {
try {
await access(path)
} catch (_) {
return false
}
return true
}
void (async () => {
await mkdir(dstDir, {
recursive: true,
})
if (await exists(dstPath)) return
const zip = new AdmZip()
await Promise.all(
filenames.map((name) =>
fetch(
`https://raw.githubusercontent.com/ntsilk-userland/binaries/master/${name}`,
)
.then((response) => response.arrayBuffer())
.then((data) => {
zip.addFile(name, Buffer.from(data))
}),
),
)
await zip.writeZipPromise(dstPath)
})()