import colors from 'colors' import { spawn } from 'node:child_process' import { IndexState } from '../types' import { log, tickLog } from '../helpers' export const Watch = async (state: IndexState) => { tickLog('Watching all changes in the API folder', 'green', 'white', state, true) // console.log(`The user's Node.js version is ${process.version}`) let errorLength = 0 const watch = spawn( 'esbuild', [ './API/*/*/*/index.ts', '--bundle', '--outdir=./dist/API', '--platform=node', '--target=node18', '--minify-whitespace', '--watch', ], { shell: true, }, ) watch.stdout.on('data', (data) => { log(`${data}`, null, state, true) }) watch.stderr.on('data', (data) => { errorLength += 1 log(`${data}`, null, state, true) }) watch.on('close', (code) => { if (errorLength === 0) { console.info(colors.green('\n No Watching errors. Nice work! \n\n')) } if (code !== 0) { console.info(`Something went wrong.. Exit code: ${code}`) } }) } export default Watch