mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-15 05:40:47 +08:00
* refactor(ipc): generate bindings with Specta * fix(profile): project IPC inputs to consumed fields * fix(events): remove unused refresh payloads * fix(webdav): return only consumed backup metadata * fix(network): trim unused interface metadata * fix(sysinfo): return only displayed system fields * chore(knip): check generated runtime exports * fix(proxy): confirm runtime chain updates before UI changes * fix(clipboard): propagate proxy environment copy failures * refactor(dns): remove ignored runtime patch * refactor(core): trim unused upgrade response fields * refactor(ipc): avoid redundant response copies * refactor(proxy): clarify automatic proxy query naming * chore(tests): remove added IPC regression tests * refactor(ipc): enforce typed command boundaries * chore(contract): check generated bindings before push * refactor(ipc): remove unused proxy liveness payloads
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
import { execFileSync } from 'node:child_process'
|
|
import fs from 'node:fs'
|
|
import os from 'node:os'
|
|
import path from 'node:path'
|
|
|
|
const ROOT = path.resolve(import.meta.dirname, '..')
|
|
const BINDINGS = path.join(ROOT, 'src/services/bindings.ts')
|
|
const args = process.argv.slice(2)
|
|
if (args.length > 1 || (args.length === 1 && args[0] !== '--check')) {
|
|
console.error('usage: gen-contract.mjs [--check]')
|
|
process.exit(2)
|
|
}
|
|
const check = args[0] === '--check'
|
|
const temporary = check
|
|
? fs.mkdtempSync(path.join(os.tmpdir(), 'verge-contract-'))
|
|
: null
|
|
const output = temporary ? path.join(temporary, 'bindings.ts') : BINDINGS
|
|
try {
|
|
execFileSync(
|
|
'cargo',
|
|
[
|
|
'run',
|
|
'-p',
|
|
'clash-verge',
|
|
'--bin',
|
|
'frontend-contract',
|
|
'--locked',
|
|
'-q',
|
|
...(check ? ['--', output] : []),
|
|
],
|
|
{ cwd: ROOT, stdio: 'inherit' },
|
|
)
|
|
const formatted = execFileSync(
|
|
process.execPath,
|
|
[
|
|
path.join(ROOT, 'node_modules/@biomejs/biome/bin/biome'),
|
|
'format',
|
|
'--stdin-file-path',
|
|
BINDINGS,
|
|
],
|
|
{ cwd: ROOT, input: fs.readFileSync(output) },
|
|
)
|
|
if (check) {
|
|
if (!formatted.equals(fs.readFileSync(BINDINGS))) {
|
|
console.error(
|
|
'IPC bindings are out of date. Run pnpm gen:contract and commit the generated file.',
|
|
)
|
|
process.exitCode = 1
|
|
}
|
|
} else {
|
|
fs.writeFileSync(BINDINGS, formatted)
|
|
}
|
|
} finally {
|
|
if (temporary) fs.rmSync(temporary, { recursive: true, force: true })
|
|
}
|