45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
const { execFileSync } = require('node:child_process')
|
|
const { existsSync, mkdirSync, mkdtempSync, cpSync, rmSync } = require('node:fs')
|
|
const { delimiter, join, resolve } = require('node:path')
|
|
const { tmpdir } = require('node:os')
|
|
const root = resolve(__dirname, '..')
|
|
const plugin = (process.env.PATH || '')
|
|
.split(delimiter)
|
|
.map((p) =>
|
|
join(
|
|
p,
|
|
process.platform === 'win32'
|
|
? 'protoc-gen-typescript-http.exe'
|
|
: 'protoc-gen-typescript-http',
|
|
),
|
|
)
|
|
.find(existsSync)
|
|
if (!plugin) throw new Error('Install protoc-gen-typescript-http v0.10.0; see README')
|
|
if (execFileSync('protoc', ['--version'], { encoding: 'utf8' }).trim() !== 'libprotoc 36.0')
|
|
throw new Error('protoc 36.0 is required')
|
|
if (
|
|
!execFileSync('go', ['version', '-m', plugin], { encoding: 'utf8' }).includes(
|
|
'go.einride.tech/protoc-gen-typescript-http\tv0.10.0\t',
|
|
)
|
|
)
|
|
throw new Error('protoc-gen-typescript-http v0.10.0 is required')
|
|
const source = resolve(root, '../evening_detective_server/api')
|
|
const temporary = mkdtempSync(join(tmpdir(), 'screen-proto-'))
|
|
try {
|
|
execFileSync(
|
|
'protoc',
|
|
[
|
|
`--plugin=protoc-gen-typescript-http=${plugin}`,
|
|
`--proto_path=${source}`,
|
|
`--typescript-http_out=${temporary}`,
|
|
join(source, 'main.proto'),
|
|
],
|
|
{ stdio: 'inherit' },
|
|
)
|
|
const target = join(root, 'electron/api/generated')
|
|
mkdirSync(target, { recursive: true })
|
|
cpSync(temporary, target, { recursive: true })
|
|
} finally {
|
|
rmSync(temporary, { recursive: true, force: true })
|
|
}
|