log('Starting NanoPow CLI')
const server = spawn(process.execPath, [new URL(import.meta.resolve('./server.js')).pathname], { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] })
const port = await new Promise((resolve, reject): void => {
- server.on('message', (msg: { type: string, port: number }): void => {
+ server.on('message', (msg: { type: string, port: number, text: string }): void => {
+ if (msg.type === 'console') {
+ log(msg.text)
+ }
if (msg.type === 'listening') {
if (msg.port != null) {
log(`Server listening on port ${msg.port}`)
dateStyle: 'medium',
timeStyle: 'medium'
}
- console.log(d.toLocaleString(Intl.DateTimeFormat().resolvedOptions().locale ?? 'en-US', opts), `NanoPow[${process.pid}]:`, args)
+ const text = `${d.toLocaleString(Intl.DateTimeFormat().resolvedOptions().locale ?? 'en-US', opts)} NanoPow[${process.pid}]: ${args}`
+ console.log(text)
+ process.send?.({ type: 'console', text })
}
}