Browse Source

fix(scripts): Добавлено логгирование в pnpm dev

horanchikk 10 tháng trước cách đây
mục cha
commit
795b46a22b
1 tập tin đã thay đổi với 31 bổ sung4 xóa
  1. 31 4
      scripts/dev.ts

+ 31 - 4
scripts/dev.ts

@@ -1,4 +1,4 @@
-import { exec } from 'node:child_process'
+import { exec, spawn } from 'node:child_process'
 import { promisify } from 'node:util'
 import { Listr } from 'listr2'
 import { logLogo } from './logo'
@@ -53,9 +53,36 @@ new Listr(
     {
       title: 'Launching server',
       task: async (_, task) => {
-        task.title = 'App launched at http://localhost:3000'
-        runCommand('nuxt dev --port 3000', undefined, true)
+        const shouldStop = false
+        const cmd = spawn('nuxt', ['dev', '--port', '3000'])
+
+        task.title = 'Command spawned'
+
+        cmd.stdout.on('data', (data) => {
+          task.output = `${task.output === undefined ? '-----LOGGING STARTED-----' : task.output}\n${data}`
+        })
+
+        cmd.stderr.on('data', (data) => {
+          task.output = `${task.output === undefined ? '-----LOGGING STARTED-----' : task.output}\n${data}`
+        })
+
+        cmd.on('close', (code) => {
+          task.title = `Process stopped with code: ${code}`
+        })
+
+        process.on('SIGINT', async function () {
+          task.title = 'Server stopped'
+          task.skip()
+          cmd.kill()
+          process.exit()
+        })
+
+        while (!shouldStop) {
+          await new Promise(resolve => setTimeout(resolve, 500))
+        }
       },
     },
-  ],
+  ], {
+    registerSignalListeners: false,
+  },
 ).run()