29 lines
1.2 KiB
JavaScript
29 lines
1.2 KiB
JavaScript
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
import crypto from 'node:crypto'
|
|
|
|
const root = path.resolve(import.meta.dirname, '..')
|
|
const target = path.join(root, 'release/server-artifact')
|
|
|
|
fs.rmSync(target, { recursive: true, force: true })
|
|
fs.mkdirSync(path.join(target, 'app'), { recursive: true })
|
|
fs.mkdirSync(path.join(target, 'protocol'), { recursive: true })
|
|
fs.cpSync(path.join(root, 'dist'), path.join(target, 'app'), { recursive: true })
|
|
for (const name of ['module-registry.json', 'update-authority.json', 'deployment-profile.json']) {
|
|
fs.copyFileSync(path.join(root, 'protocol', name), path.join(target, 'protocol', name))
|
|
}
|
|
|
|
const files = []
|
|
function collect(directory) {
|
|
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
const absolute = path.join(directory, entry.name)
|
|
if (entry.isDirectory()) collect(absolute)
|
|
else files.push(absolute)
|
|
}
|
|
}
|
|
collect(target)
|
|
const manifest = files.sort().map((file) => ({
|
|
path: path.relative(target, file),
|
|
sha256: crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex'),
|
|
}))
|
|
fs.writeFileSync(path.join(target, 'ARTIFACT-MANIFEST.json'), `${JSON.stringify({ schema: 'guanghu.artifact-manifest/v1', sourceIncluded: false, files: manifest }, null, 2)}\n`)
|