dev.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { exec } from 'node:child_process'
  2. import { promisify } from 'node:util'
  3. import { Listr } from 'listr2'
  4. import { logLogo } from './logo'
  5. const execAsync = promisify(exec)
  6. async function runCommand(
  7. command: string,
  8. task?: {
  9. output: string
  10. },
  11. disableStdout: boolean | undefined = false,
  12. ) {
  13. try {
  14. const { stdout, stderr } = await execAsync(command)
  15. if (!disableStdout) {
  16. if (stderr) {
  17. if (task) {
  18. task.output = stderr
  19. }
  20. else { console.log(stderr) }
  21. }
  22. else {
  23. if (task) {
  24. task.output = stdout
  25. }
  26. else { console.log(stdout) }
  27. }
  28. }
  29. }
  30. catch (error) {
  31. if (!disableStdout) {
  32. if (task) {
  33. task.output = String(error)
  34. }
  35. else { console.log(String(error)) }
  36. }
  37. }
  38. }
  39. logLogo()
  40. new Listr(
  41. [
  42. {
  43. title: 'Clearing up cache...',
  44. task: async (_, task) => {
  45. await runCommand('nuxt cleanup', task)
  46. },
  47. },
  48. {
  49. title: 'Launching server',
  50. task: async (_, task) => {
  51. task.title = 'App launched at http://localhost:3000'
  52. runCommand('nuxt dev --port 3000', undefined, true)
  53. },
  54. },
  55. ],
  56. ).run()