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)) {
15 return serverJsPath
16 }
17β
18 const indexJsPath = path.resolve(distDir, 'server', 'index.js')
19 if (fs.existsSync(indexJsPath)) {
20 return indexJsPath
21 }
22β
23 return serverJsPath
24}
25β
26export function resolveStartCommand() {
27 const distClientDir = resolveDistClientDir()
28 const distServerEntryPath = resolveDistServerEntryPath()
29 return `srvx --prod -s ${JSON.stringify(distClientDir)} ${JSON.stringify(distServerEntryPath)}`
30}
31β
32export function start() {
33 const child = spawn(
34 'srvx',
35 ['--prod', '-s', resolveDistClientDir(), resolveDistServerEntryPath()],
36 {
37 stdio: 'inherit',
38 shell: process.platform === 'win32',
39 },
40 )
41β
42 child.on('error', (error) => {
43 console.error('Failed to start srvx:', error)
44 process.exit(1)
45 })
46β
47 child.on('exit', (code, signal) => {
48 if (signal) {
49 process.kill(process.pid, signal)
50 return
51 }
52β
53 process.exit(code ?? 0)
54 })
55}
56β
57if (
58 process.argv[1] &&
59 import.meta.url === pathToFileURL(process.argv[1]).href
60) {
61 start()
62}