Skip to content

Commit 2c34066

Browse files
committed
fix(prod): script run text warn
1 parent 99d848b commit 2c34066

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

bin/deploy.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import fs from 'node:fs'
44
import path, { dirname, resolve } from 'node:path'
55
import process from 'node:process'
6-
import { exec } from 'node:child_process' // 确保导入 exec
6+
import { spawn } from 'node:child_process' // 确保导入 exec
77
import { fileURLToPath } from 'node:url'
88
import { Command } from 'commander'
99

@@ -54,17 +54,7 @@ if (process.argv.length === 2) {
5454
const __dirname = dirname(__filename)
5555
const fullPath = resolve(__dirname, '../dist/index.mjs')
5656

57-
exec(`node ${fullPath}`, (error, stdout, stderr) => {
58-
if (error) {
59-
console.error(`Error executing script: ${error.message}`)
60-
return
61-
}
62-
if (stderr) {
63-
console.error(`Script error: ${stderr}`)
64-
return
65-
}
66-
console.log(stdout)
67-
})
57+
runNodeScript(fullPath)
6858
}
6959
else {
7060
program.parse(process.argv)
@@ -91,3 +81,18 @@ function addToGitignore() {
9181
console.log('.gitignore does not exist.')
9282
}
9383
}
84+
85+
function runNodeScript(fullPath) {
86+
return new Promise((resolve, reject) => {
87+
const child = spawn('node', [fullPath], { stdio: 'inherit' })
88+
89+
child.on('close', (code) => {
90+
if (code === 0) {
91+
resolve()
92+
}
93+
else {
94+
reject(new Error(`Node.js script exited with code ${code}`))
95+
}
96+
})
97+
})
98+
}

0 commit comments

Comments
 (0)