um-react/support/command.ts
鲁树人 d91e2fffe4
All checks were successful
Build and Deploy / build (push) Successful in 1m45s
chore: bump version to v0.4.7; upgrade deps
2025-03-31 09:37:58 +09:00

18 lines
459 B
TypeScript

import cp from 'node:child_process';
import path from 'node:path';
import url from 'node:url';
const projectRoot = url.fileURLToPath(new URL('../', import.meta.url));
export function command(cmd: string, dir = '') {
return cp.execSync(cmd, { cwd: path.resolve(projectRoot, dir), encoding: 'utf-8' }).trim();
}
export function tryCommand(cmd: string, dir = '', fallback = '') {
try {
return command(cmd, dir);
} catch {
return fallback;
}
}