Open History to see the last commit
1import fs from 'node:fs'
2import path from 'node:path'
3import { spawn } from 'node:child_process'
4import { pathToFileURL } from 'node:url'
5β
6const distDir = process.env.E2E_DIST_DIR || 'dist'
7β
8function resolveDistClientDir() {
9 return path.resolve(distDir, 'client')
10}
11β
12function resolveDistServerEntryPath() {
13 const serverJsPath = path.resolve(distDir, 'server', 'server.js')
14 if (fs.existsSync(serverJsPath)) return serverJsPath
15β
16 const indexJsPath = path.resolve(distDir, 'server', 'index.js')
17 if (fs.existsSync(indexJsPath)) return indexJsPath
18β
19 return serverJsPath
20}
21β
22export function start() {
23 const child = spawn(
24 'srvx',
25 ['--prod', '-s', resolveDistClientDir(), resolveDistServerEntryPath()],
26 {
27 stdio: 'inherit',
28 shell: process.platform === 'win32',
29 },
30 )
31β
32 child.on('exit', (code, signal) => {
33 if (signal) {
34 process.kill(process.pid, signal)
35 return
36 }
37β
38 process.exit(code ?? 0)
39 })
40}
41β
42if (
43 process.argv[1] &&
44 import.meta.url === pathToFileURL(process.argv[1]).href
45) {
46 start()
47}