36 lines
893 B
TypeScript
36 lines
893 B
TypeScript
import { spawn, spawnSync } from 'child_process';
|
|
|
|
export const checkPnpm = () => {
|
|
try {
|
|
spawnSync('pnpm', ['--version']);
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
|
|
type InstallDepsOptions = {
|
|
appPath: string;
|
|
isProduction?: boolean;
|
|
sync?: boolean;
|
|
};
|
|
|
|
export const installDeps = async (opts: InstallDepsOptions) => {
|
|
const { appPath } = opts;
|
|
const isProduction = opts.isProduction ?? true;
|
|
const isPnpm = checkPnpm();
|
|
const params = ['i'];
|
|
if (isProduction && isPnpm) {
|
|
params.push('--production');
|
|
} else {
|
|
params.push('--omit=dev');
|
|
}
|
|
console.log('installDeps', appPath, params);
|
|
const syncSpawn = opts.sync ? spawnSync : spawn;
|
|
if (isPnpm) {
|
|
syncSpawn('pnpm', params, { cwd: appPath, stdio: 'inherit', env: process.env });
|
|
} else {
|
|
syncSpawn('npm', params, { cwd: appPath, stdio: 'inherit', env: process.env });
|
|
}
|
|
}; |