feat(cli): supports specifying electron entry file (#270)
This commit is contained in:
parent
8b839872f8
commit
01163866fb
14
src/cli.ts
14
src/cli.ts
|
@ -24,6 +24,7 @@ interface GlobalCLIOptions {
|
||||||
w?: boolean
|
w?: boolean
|
||||||
watch?: boolean
|
watch?: boolean
|
||||||
outDir?: string
|
outDir?: string
|
||||||
|
entry?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DevCLIOptions {
|
interface DevCLIOptions {
|
||||||
|
@ -59,6 +60,7 @@ cli
|
||||||
.option('--ignoreConfigWarning', `[boolean] ignore config warning`)
|
.option('--ignoreConfigWarning', `[boolean] ignore config warning`)
|
||||||
.option('--sourcemap', `[boolean] output source maps for debug (default: false)`)
|
.option('--sourcemap', `[boolean] output source maps for debug (default: false)`)
|
||||||
.option('--outDir <dir>', `[string] output directory (default: out)`)
|
.option('--outDir <dir>', `[string] output directory (default: out)`)
|
||||||
|
.option('--entry <file>', `[string] specify electron entry file`)
|
||||||
|
|
||||||
// dev
|
// dev
|
||||||
cli
|
cli
|
||||||
|
@ -83,6 +85,10 @@ cli
|
||||||
process.env.V8_INSPECTOR_BRK_PORT = typeof options.inspectBrk === 'number' ? `${options.inspectBrk}` : '5858'
|
process.env.V8_INSPECTOR_BRK_PORT = typeof options.inspectBrk === 'number' ? `${options.inspectBrk}` : '5858'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.entry) {
|
||||||
|
process.env.ELECTRON_ENTRY = options.entry
|
||||||
|
}
|
||||||
|
|
||||||
const { createServer } = await import('./server')
|
const { createServer } = await import('./server')
|
||||||
const inlineConfig = createInlineConfig(root, options)
|
const inlineConfig = createInlineConfig(root, options)
|
||||||
|
|
||||||
|
@ -103,6 +109,10 @@ cli.command('build [root]', 'build for production').action(async (root: string,
|
||||||
const { build } = await import('./build')
|
const { build } = await import('./build')
|
||||||
const inlineConfig = createInlineConfig(root, options)
|
const inlineConfig = createInlineConfig(root, options)
|
||||||
|
|
||||||
|
if (options.entry) {
|
||||||
|
process.env.ELECTRON_ENTRY = options.entry
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await build(inlineConfig)
|
await build(inlineConfig)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -120,6 +130,10 @@ cli
|
||||||
const { preview } = await import('./preview')
|
const { preview } = await import('./preview')
|
||||||
const inlineConfig = createInlineConfig(root, options)
|
const inlineConfig = createInlineConfig(root, options)
|
||||||
|
|
||||||
|
if (options.entry) {
|
||||||
|
process.env.ELECTRON_ENTRY = options.entry
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await preview(inlineConfig, { skipBuild: options.skipBuild })
|
await preview(inlineConfig, { skipBuild: options.skipBuild })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { type ChildProcess, spawn } from 'node:child_process'
|
||||||
const _require = createRequire(import.meta.url)
|
const _require = createRequire(import.meta.url)
|
||||||
|
|
||||||
const ensureElectronEntryFile = (root = process.cwd()): void => {
|
const ensureElectronEntryFile = (root = process.cwd()): void => {
|
||||||
|
if (process.env.ELECTRON_ENTRY) return
|
||||||
const pkg = path.join(root, 'package.json')
|
const pkg = path.join(root, 'package.json')
|
||||||
if (fs.existsSync(pkg)) {
|
if (fs.existsSync(pkg)) {
|
||||||
const main = require(pkg).main
|
const main = require(pkg).main
|
||||||
|
@ -133,7 +134,9 @@ export function startElectron(root: string | undefined): ChildProcess {
|
||||||
args.push(`--inspect-brk=${process.env.V8_INSPECTOR_BRK_PORT}`)
|
args.push(`--inspect-brk=${process.env.V8_INSPECTOR_BRK_PORT}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const ps = spawn(electronPath, ['.'].concat(args), { stdio: 'inherit' })
|
const entry = process.env.ELECTRON_ENTRY || '.'
|
||||||
|
|
||||||
|
const ps = spawn(electronPath, [entry].concat(args), { stdio: 'inherit' })
|
||||||
ps.on('close', process.exit)
|
ps.on('close', process.exit)
|
||||||
|
|
||||||
return ps
|
return ps
|
||||||
|
|
Loading…
Reference in a new issue