|
| 1 | +import { logger, setContext } from '../common'; |
| 2 | +import { startLocalStack } from '../stack/localStack'; |
| 3 | + |
| 4 | +export interface RunLocalOptions { |
| 5 | + stage: string; |
| 6 | + port: number; |
| 7 | + debug: boolean; |
| 8 | + watch: boolean; |
| 9 | +} |
| 10 | + |
| 11 | +export const runLocal = async (stackName: string, opts: RunLocalOptions) => { |
| 12 | + const { stage, port, debug, watch } = opts; |
| 13 | + |
| 14 | + await setContext({ stage }); |
| 15 | + |
| 16 | + logger.info( |
| 17 | + `run-local starting: stack=${stackName} stage=${stage} port=${port} debug=${debug} watch=${watch}`, |
| 18 | + ); |
| 19 | + |
| 20 | + await startLocalStack(); |
| 21 | + |
| 22 | + // if (watch) { |
| 23 | + // const cwd = process.cwd(); |
| 24 | + // try { |
| 25 | + // fs.watch(cwd, { recursive: true }, (eventType, filename) => { |
| 26 | + // if (!filename) return; |
| 27 | + // const filePath = path.join(cwd, filename); |
| 28 | + // logger.info(`file change detected: ${eventType} ${filePath}`); |
| 29 | + // }); |
| 30 | + // logger.info(`watching files under ${process.cwd()}`); |
| 31 | + // } catch (err) { |
| 32 | + // logger.warn(`file watch not available: ${String(err)}`); |
| 33 | + // } |
| 34 | + // } |
| 35 | + // |
| 36 | + // const shutdown = () => { |
| 37 | + // logger.info('shutting down run-local server'); |
| 38 | + // server.close(() => process.exit(0)); |
| 39 | + // }; |
| 40 | + // process.on('SIGINT', shutdown); |
| 41 | + // process.on('SIGTERM', shutdown); |
| 42 | + // |
| 43 | + // // return server for tests if needed |
| 44 | + // return { server, port, stage, debug, watch }; |
| 45 | +}; |
0 commit comments