This commit is contained in:
2024-12-05 20:53:21 +08:00
parent a117281b9e
commit b631ff4a09
5 changed files with 74 additions and 11 deletions

View File

@@ -8,7 +8,36 @@ export const checkPnpm = () => {
return false;
}
};
export const checkPm2 = () => {
try {
spawnSync('pm2', ['--version']);
return true;
} catch (e) {
return false;
}
};
type InstallDepOptions = {
appPath?: string;
dep: string;
isGlobal?: boolean;
sync?: boolean;
};
export const installDep = (opts: InstallDepOptions) => {
const { appPath, dep } = opts;
const params = [];
const syncSpawn = opts.sync ? spawnSync : spawn;
if (opts.isGlobal) {
params.push('-g');
}
if (checkPnpm()) {
params.push('add', dep);
syncSpawn('pnpm', params, { cwd: appPath, stdio: 'inherit', env: process.env });
} else {
params.push('install', dep);
syncSpawn('npm', params, { cwd: appPath, stdio: 'inherit', env: process.env });
}
};
type InstallDepsOptions = {
appPath: string;
isProduction?: boolean;