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 if (process.env.TSS_E2E_SERVER_ENTRY) {
14 const customEntryPath = path.resolve(
15 distDir,
16 'server',
17 `${process.env.TSS_E2E_SERVER_ENTRY}.js`,
18 )
19 if (fs.existsSync(customEntryPath)) {
20 return customEntryPath
21 }
22 }
23β
24 const serverJsPath = path.resolve(distDir, 'server', 'server.js')
25 if (fs.existsSync(serverJsPath)) {
26 return serverJsPath
27 }
28β
29 const indexJsPath = path.resolve(distDir, 'server', 'index.js')
30 if (fs.existsSync(indexJsPath)) {
31 return indexJsPath
32 }
33β
34 return serverJsPath
35}
36β
37export function start() {
38 const child = spawn(
39 'srvx',
40 ['--prod', '-s', resolveDistClientDir(), resolveDistServerEntryPath()],
41 {
42 stdio: 'inherit',
43 shell: process.platform === 'win32',
44 },
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}