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.') 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 37 const decomposed = await Promise.all(_.uniq(dbQsNameA).map(decomposeQsFromSec)) 38 const k8sProxyA = _.filter(decomposed, needsProxyQs) as K8sProxyItem[] 39 k8sPortFwdCtx.enterWith({...k8sPortFwdCtx.getStore(), k8sProxyA}) 42 runNextCtx.enterWith({...runNextCtx.getStore(), pagesDir}) 43 const runNextPath = pathJoin(pagesDir, 'runnext.mjs') 45 await import(runNextPath) // necessary for single-path def of handleRequest 51export const buildsw = async () => { 54buildsw.cliSchema = { watch: { flag: true as const, desc: 'watch mode' } } 55buildsw.cliAdvanced = true 57export const buildworker = async () => { 60buildworker.cliSchema = { watch: { flag: true as const, desc: 'watch mode' } } 61buildworker.cliAdvanced = true 63export const nextbuild = async (_props?: unknown) => { 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) => { 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() 85 const logPath = `${ptTmpDir}/devserver-${appName}${testSuffix}.log` 87 const content = readFileSync(logPath, 'utf8') 88 process.stdout.write(content) 90 process.stdout.write(`No devserver log found at tmp/devserver-${appName}${testSuffix}.log. Start the devserver first.\n`) 93devlogs.cliAdvanced = true