🌳
pt0/nextF/deployF/devActionsF.mts
2import * as _ from 'lodash-es'
19import { readFileSync } from 'fs'
21const devServerAppName = () => getAppCfg().name || getAppCfg().appPath?.split('/').pop() || 'unknown'
24const commonStart = async ({dev}: {dev: boolean}) => {
25 if (process.env.OPENCODE === '1' && !process.env.PT_BG_TASK) {
26 throw new Error('devserver must be run via bgtask_start, not directly. Use bgtask_start to start devservers.')
27 }
28 teeDevServerLog(devServerAppName())
29 const {appPath} = getAppCfg()
31 const envConf = getAppCfg().envConf as Record<string, any> || {}
32 const { secretsMapping, dbSecrets } = envConf
33 const dbQsNameA: secretNameType[] = _.compact(_.map({ ...secretsMapping, ...dbSecrets }, (secName) => {
34 if (!_.endsWith(secName, '_qs')) return
35 return secName as secretNameType
36 }))
37 const decomposed = await Promise.all(_.uniq(dbQsNameA).map(decomposeQsFromSec))
38 const k8sProxyA = _.filter(decomposed, needsProxyQs) as K8sProxyItem[]
39 k8sPortFwdCtx.enterWith({...k8sPortFwdCtx.getStore(), k8sProxyA})
40 await wrapProxyMinikNodePorts(async () => {
41 const pagesDir = pathJoin(ptDir, appPath!)
42 runNextCtx.enterWith({...runNextCtx.getStore(), pagesDir})
43 const runNextPath = pathJoin(pagesDir, 'runnext.mjs')
44 if (await fileExists(runNextPath)) {
45 await import(runNextPath) // necessary for single-path def of handleRequest
46 return
47 }
48 })
51export const buildsw = async () => {
52 await doBuildSw({doWatch: cliFlag('--watch')})
54buildsw.cliSchema = { watch: { flag: true as const, desc: 'watch mode' } }
55buildsw.cliAdvanced = true
57export const buildworker = async () => {
58 await doBuildWorker({doWatch: cliFlag('--watch')})
60buildworker.cliSchema = { watch: { flag: true as const, desc: 'watch mode' } }
61buildworker.cliAdvanced = true
63export const nextbuild = async (_props?: unknown) => {
64 const {appPath} = getAppCfg()
65 const appDir = pathJoin(ptDir, appPath!)
66 const nextBin = pathJoin(ptDir, 'node_modules/.bin/next')
67 console.log('nextbuild')
68 await liveSpawnThrow({cmd: `cd ${appDir} && NODE_ENV=production ${nextBin} build`, noOutCmd: true})
71export const buildstart = async (_props?: unknown) => {
72 await nextbuild()
73 await commonStart({dev: false})
75buildstart.cliSchema = killExistingCliSchema
77export const devserver = async () => {
78 await commonStart({dev: true})
80devserver.cliSchema = killExistingCliSchema
82export const devlogs = async () => {
83 const appName = devServerAppName()
84 const testSuffix = getIsTestInstance() ? '-test' : ''
85 const logPath = `${ptTmpDir}/devserver-${appName}${testSuffix}.log`
86 try {
87 const content = readFileSync(logPath, 'utf8')
88 process.stdout.write(content)
89 } catch {
90 process.stdout.write(`No devserver log found at tmp/devserver-${appName}${testSuffix}.log. Start the devserver first.\n`)
91 }
93devlogs.cliAdvanced = true