2022-12-22 11:31:38 +08:00
|
|
|
import fs from 'node:fs'
|
|
|
|
import path from 'node:path'
|
|
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
import { createRequire } from 'node:module'
|
|
|
|
import { spawn } from 'node:child_process'
|
2022-03-15 08:01:02 +08:00
|
|
|
|
2022-12-22 11:31:38 +08:00
|
|
|
const pkg = createRequire(import.meta.url)('../package.json')
|
2022-03-15 08:01:02 +08:00
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
|
|
|
|
|
|
// write .debug.env
|
2022-08-25 08:20:26 +08:00
|
|
|
const envContent = Object.entries(pkg.debug.env).map(([key, val]) => `${key}=${val}`)
|
2022-03-15 08:01:02 +08:00
|
|
|
fs.writeFileSync(path.join(__dirname, '.debug.env'), envContent.join('\n'))
|
|
|
|
|
|
|
|
// bootstrap
|
2022-06-07 09:49:42 +08:00
|
|
|
spawn(
|
2022-07-22 15:28:23 +08:00
|
|
|
// TODO: terminate `npm run dev` when Debug exits.
|
2022-06-07 09:49:42 +08:00
|
|
|
process.platform === 'win32' ? 'npm.cmd' : 'npm',
|
|
|
|
['run', 'dev'],
|
2022-07-23 07:31:47 +08:00
|
|
|
{
|
|
|
|
stdio: 'inherit',
|
|
|
|
env: Object.assign(process.env, { VSCODE_DEBUG: 'true' }),
|
|
|
|
},
|
2022-12-22 11:31:38 +08:00
|
|
|
)
|