feat(cli): remove stdio: 'pipe' option from executeCommand when checking package existence.

This commit is contained in:
melvinchia3636
2026-01-29 11:29:41 +08:00
parent 2b45a41369
commit a0b63d32dc
14 changed files with 50 additions and 73 deletions

View File

@@ -93,9 +93,7 @@ export async function downloadPocketBaseBinary(): Promise<void> {
logger.debug('Download complete, extracting...')
// Extract using unzip command
executeCommand(`unzip -o "${zipPath}" -d "${PB_DIR}"`, {
stdio: ['pipe', 'pipe', 'pipe']
})
executeCommand(`unzip -o "${zipPath}" -d "${PB_DIR}"`)
// Clean up zip file and unnecessary files
fs.unlinkSync(zipPath)

View File

@@ -35,9 +35,7 @@ export function createPocketBaseSuperuser(
try {
const result = executeCommand(
`${PB_BINARY_PATH} superuser create ${PB_KWARGS.join(' ')}`,
{
stdio: ['pipe', 'pipe', 'pipe']
},
{},
[email, password]
)

View File

@@ -30,7 +30,7 @@ export async function startSingleService(
const cwd = config.cwd instanceof Function ? config.cwd() : config.cwd
executeCommand(command, { cwd, stdio: 'inherit' }, extraArgs)
executeCommand(command, { cwd }, extraArgs)
return
}
@@ -39,11 +39,7 @@ export async function startSingleService(
if (service in PROJECTS) {
const projectPath = PROJECTS[service as keyof typeof PROJECTS]
executeCommand(
`cd ${projectPath} && bun run dev`,
{ stdio: 'inherit' },
extraArgs
)
executeCommand(`cd ${projectPath} && bun run dev`, {}, extraArgs)
return
}

View File

@@ -37,8 +37,7 @@ export async function publishLocaleHandler(langCode: string): Promise<void> {
try {
executeCommand(`npm publish --registry ${getRegistryUrl()}`, {
cwd: targetDir,
stdio: 'inherit'
cwd: targetDir
})
logger.success(`Published ${chalk.blue(fullName)}`)

View File

@@ -1,10 +1,9 @@
import executeCommand from '@/utils/commands'
export function initializeGitRepository(modulePath: string): void {
executeCommand('git init', { cwd: modulePath, stdio: 'ignore' })
executeCommand('git add .', { cwd: modulePath, stdio: 'ignore' })
executeCommand('git init', { cwd: modulePath })
executeCommand('git add .', { cwd: modulePath })
executeCommand('git commit -m "feat: initial commit"', {
cwd: modulePath,
stdio: 'ignore'
cwd: modulePath
})
}

View File

@@ -83,8 +83,7 @@ export async function publishModuleHandler(moduleName: string): Promise<void> {
try {
executeCommand(`npm publish --registry ${getRegistryUrl()}`, {
cwd: modulePath,
stdio: 'pipe'
cwd: modulePath
})
logger.success(

View File

@@ -18,8 +18,7 @@ export function executeProjectCommand(
const projectPath = PROJECTS[projectType as ProjectType]
executeCommand(`bun run ${commandType}`, {
cwd: projectPath,
stdio: 'inherit'
cwd: projectPath
})
}
}

View File

@@ -1,4 +1,3 @@
import { LOG_LEVELS, type LogLevel } from '@lifeforge/log'
import { type IOType, spawnSync } from 'child_process'
import fs from 'fs'
import path from 'path'
@@ -53,11 +52,11 @@ export default function executeCommand(
if (logger.level === 'debug') {
if (result.stdout) {
process.stdout.write(result.stdout.toString())
logger.debug(result.stdout.toString())
}
if (result.stderr) {
process.stderr.write(result.stderr.toString())
logger.debug(result.stderr.toString())
}
}
@@ -90,12 +89,7 @@ export default function executeCommand(
*/
export function bunInstall() {
executeCommand('bun install --ignore-scripts', {
cwd: ROOT_DIR,
stdio:
LOG_LEVELS.indexOf(logger.instance.level as LogLevel) >
LOG_LEVELS.indexOf('debug')
? 'pipe'
: 'inherit'
cwd: ROOT_DIR
})
}
@@ -122,12 +116,7 @@ export function installPackage(
logger.debug(`Installing ${fullName} from registry...`)
executeCommand(`bun add ${fullName}@latest --ignore-scripts`, {
cwd: ROOT_DIR,
stdio:
LOG_LEVELS.indexOf(logger.instance.level as LogLevel) >
LOG_LEVELS.indexOf('info')
? 'pipe'
: 'inherit'
cwd: ROOT_DIR
})
const installedPath = path.join(ROOT_DIR, 'node_modules', fullName)

View File

@@ -1,5 +1,3 @@
import { execSync } from 'child_process'
import executeCommand from './commands'
import { isDockerMode } from './helpers'
import logger from './logger'
@@ -11,7 +9,7 @@ const SERVER_CONTAINER = 'lifeforge-server'
*/
export function isDockerRunning(): boolean {
try {
execSync('docker info', { stdio: 'pipe' })
executeCommand('docker info', { exitOnError: false })
return true
} catch {
@@ -24,9 +22,9 @@ export function isDockerRunning(): boolean {
*/
export function isContainerRunning(containerName: string): boolean {
try {
const status = execSync(
const status = executeCommand(
`docker ps --filter "name=${containerName}" --format "{{.Status}}"`,
{ encoding: 'utf8', stdio: 'pipe' }
{ exitOnError: false }
).trim()
return status.length > 0
@@ -58,7 +56,7 @@ export function restartServerContainer(): void {
try {
logger.info('Restarting Docker server container...')
execSync(`docker restart ${SERVER_CONTAINER}`, { stdio: 'inherit' })
executeCommand(`docker restart ${SERVER_CONTAINER}`, { exitOnError: false })
logger.success('Server container restarted')
} catch (error) {
logger.error(`Failed to restart Docker server.`)
@@ -89,7 +87,7 @@ export function stopService(serviceName: string): void {
try {
logger.debug(`Stopping Docker service ${serviceName}...`)
executeCommand(`docker stop ${serviceName}`, { stdio: 'inherit' })
executeCommand(`docker stop ${serviceName}`, { exitOnError: false })
logger.success(`Service ${serviceName} stopped`)
} catch (error) {
logger.error(`Failed to stop Docker service ${serviceName}.`)
@@ -104,7 +102,7 @@ export function startService(serviceName: string): void {
try {
logger.debug(`Starting Docker service ${serviceName}...`)
executeCommand(`docker start ${serviceName}`, { stdio: 'inherit' })
executeCommand(`docker start ${serviceName}`, { exitOnError: false })
logger.success(`Service ${serviceName} started`)
} catch (error) {
logger.error(`Failed to start Docker service ${serviceName}.`)

View File

@@ -6,8 +6,7 @@ export function validateMaintainerAccess(username: string): void {
try {
// Check permission level on the official repo
const result = executeCommand(
`gh api repos/lifeforge-app/lifeforge/collaborators/${username}/permission`,
{ stdio: 'pipe' }
`gh api repos/lifeforge-app/lifeforge/collaborators/${username}/permission`
)
const response = JSON.parse(result) as {
@@ -38,7 +37,7 @@ export function validateMaintainerAccess(username: string): void {
export function getGithubUser(): { name: string; email: string } | null {
try {
// Try getting basic user info first
const basicInfo = executeCommand('gh api user', { stdio: 'pipe' })
const basicInfo = executeCommand('gh api user')
const user = JSON.parse(basicInfo) as { name: string; email: string | null }
@@ -47,9 +46,7 @@ export function getGithubUser(): { name: string; email: string } | null {
// If email is private/null, try fetching from /user/emails
if (!email) {
try {
const emailsJson = executeCommand('gh api user/emails', {
stdio: 'pipe'
})
const emailsJson = executeCommand('gh api user/emails')
const emails = JSON.parse(emailsJson) as Array<{
email: string

View File

@@ -1,4 +1,3 @@
import { spawnSync } from 'child_process'
import prompts from 'prompts'
import executeCommand from './commands'
@@ -84,12 +83,13 @@ export function killExistingProcess(
}
const serverInstance = executeCommand(`pgrep -f "${processKeywordOrPID}"`, {
exitOnError: false,
stdio: 'pipe'
exitOnError: false
})
if (serverInstance) {
executeCommand(`pkill -f "${processKeywordOrPID}"`)
executeCommand(`pkill -f "${processKeywordOrPID}"`, {
exitOnError: false
})
logger.debug(
`Killed process matching keyword: ${processKeywordOrPID} (PID: ${serverInstance})`
@@ -110,12 +110,13 @@ export function killExistingProcess(
*/
export function checkPortInUse(port: number): boolean {
try {
const result = spawnSync('nc', ['-zv', 'localhost', port.toString()], {
stdio: 'pipe',
encoding: 'utf8'
})
executeCommand('nc', { exitOnError: false }, [
'-zv',
'localhost',
port.toString()
])
return result.status === 0
return true
} catch {
return false
}

View File

@@ -33,18 +33,24 @@ export default function initGitRepository(targetDir: string): void {
logger.info(`Initializing git repository...`)
try {
executeCommand('git init', { cwd: targetDir, stdio: 'pipe' })
executeCommand('git init', { cwd: targetDir, exitOnError: false })
executeCommand(`git remote add origin ${repoUrl}`, {
cwd: targetDir,
stdio: 'pipe'
exitOnError: false
})
executeCommand('git fetch origin', { cwd: targetDir, stdio: 'pipe' })
executeCommand('git checkout -b main', { cwd: targetDir, stdio: 'pipe' })
executeCommand('git reset origin/main', { cwd: targetDir, stdio: 'pipe' })
executeCommand('git add .', { cwd: targetDir, stdio: 'pipe' })
executeCommand('git fetch origin', { cwd: targetDir, exitOnError: false })
executeCommand('git checkout -b main', {
cwd: targetDir,
exitOnError: false
})
executeCommand('git reset origin/main', {
cwd: targetDir,
exitOnError: false
})
executeCommand('git add .', { cwd: targetDir, exitOnError: false })
executeCommand(
'git commit --allow-empty -m "feat: update to latest version from forgistry"',
{ cwd: targetDir, stdio: 'pipe' }
{ cwd: targetDir, exitOnError: false }
)
logger.debug(`Git repository initialized with remote: ${repoUrl}`)

View File

@@ -23,8 +23,7 @@ function isValidPocketbaseProcess(pid: number): boolean {
// Verify it's actually a pocketbase process by checking the command
const psResult = executeCommand(`ps -p ${pid} -o comm=`, {
exitOnError: false,
stdio: 'pipe'
exitOnError: false
})
return psResult?.toLowerCase().includes('pocketbase') ?? false
@@ -43,8 +42,7 @@ function isValidPocketbaseProcess(pid: number): boolean {
export function checkRunningPBInstances(exitOnError = true): boolean {
try {
const result = executeCommand(`pgrep -f "pocketbase serve"`, {
exitOnError: false,
stdio: 'pipe'
exitOnError: false
})
if (!result?.trim()) {

View File

@@ -41,7 +41,7 @@ export async function checkPackageExists(
try {
executeCommand(`npm view ${packageName} --registry ${registry}`, {
cwd: ROOT_DIR,
stdio: 'pipe'
exitOnError: false
})
return true
@@ -67,7 +67,7 @@ export async function checkAuth(): Promise<{
`npm whoami --registry ${registry} 2>/dev/null`,
{
cwd: ROOT_DIR,
stdio: 'pipe'
exitOnError: false
}
)