This commit is contained in:
@@ -32,6 +32,9 @@ switch (command) {
|
||||
case 'init':
|
||||
await import('./init.ts')
|
||||
break
|
||||
case 'install-browser':
|
||||
await import('./install-browser.ts')
|
||||
break
|
||||
case undefined:
|
||||
case 'help':
|
||||
case '--help':
|
||||
@@ -49,6 +52,7 @@ function printHelp() {
|
||||
|
||||
用法:
|
||||
easy-slides init [directory] [--engine <package-spec>]
|
||||
easy-slides install-browser [--with-deps]
|
||||
easy-slides dev [slug|slides.md]
|
||||
easy-slides present <slug>
|
||||
easy-slides build
|
||||
|
||||
@@ -101,6 +101,7 @@ jobs:
|
||||
node-version: 22
|
||||
cache: pnpm
|
||||
- run: pnpm install --frozen-lockfile
|
||||
- run: pnpm exec easy-slides install-browser --with-deps
|
||||
- run: pnpm check
|
||||
env:
|
||||
PRESENTER_TOKEN: \${{ secrets.PRESENTER_TOKEN }}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { spawn } from 'node:child_process'
|
||||
import { createBrowserInstallCommand } from './lib/browser-install.ts'
|
||||
|
||||
const { command, args } = createBrowserInstallCommand(process.argv.slice(2))
|
||||
const child = spawn(command, args, { stdio: 'inherit' })
|
||||
|
||||
child.once('error', (error) => {
|
||||
console.error(`无法启动 Chromium 安装程序:${error.message}`)
|
||||
process.exitCode = 1
|
||||
})
|
||||
|
||||
child.once('exit', (code, signal) => {
|
||||
if (signal) {
|
||||
process.kill(process.pid, signal)
|
||||
return
|
||||
}
|
||||
process.exitCode = code ?? 1
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import { createRequire } from 'node:module'
|
||||
import path from 'node:path'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
|
||||
export interface BrowserInstallCommand {
|
||||
command: string
|
||||
args: string[]
|
||||
}
|
||||
|
||||
export function createBrowserInstallCommand(args: string[]): BrowserInstallCommand {
|
||||
const unsupported = args.filter(argument => argument !== '--with-deps')
|
||||
const withDepsCount = args.filter(argument => argument === '--with-deps').length
|
||||
|
||||
if (unsupported.length > 0)
|
||||
throw new Error(`install-browser 不支持参数:${unsupported.join(' ')}`)
|
||||
if (withDepsCount > 1)
|
||||
throw new Error('install-browser 的 --with-deps 只能指定一次')
|
||||
|
||||
const packageJson = require.resolve('playwright-chromium/package.json')
|
||||
const playwrightCli = path.join(path.dirname(packageJson), 'cli.js')
|
||||
|
||||
return {
|
||||
command: process.execPath,
|
||||
args: [
|
||||
playwrightCli,
|
||||
'install',
|
||||
...(withDepsCount === 1 ? ['--with-deps'] : []),
|
||||
'chromium',
|
||||
],
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user