12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import { exec } from 'node:child_process'
- import { promisify } from 'node:util'
- import { Listr } from 'listr2'
- import { logLogo } from './logo'
- const execAsync = promisify(exec)
- async function runCommand(
- command: string,
- task?: {
- output: string
- },
- disableStdout: boolean | undefined = false,
- ) {
- try {
- const { stdout, stderr } = await execAsync(command)
- if (!disableStdout) {
- if (stderr) {
- if (task) {
- task.output = stderr
- }
- else { console.log(stderr) }
- }
- else {
- if (task) {
- task.output = stdout
- }
- else { console.log(stdout) }
- }
- }
- }
- catch (error) {
- if (!disableStdout) {
- if (task) {
- task.output = String(error)
- }
- else { console.log(String(error)) }
- }
- }
- }
- logLogo()
- new Listr(
- [
- {
- title: 'Clearing up cache...',
- task: async (_, task) => {
- await runCommand('nuxt cleanup', task)
- },
- },
- {
- title: 'Launching server',
- task: async (_, task) => {
- task.title = 'App launched at http://localhost:3000'
- runCommand('nuxt dev --port 3000', undefined, true)
- },
- },
- ],
- ).run()
|