feat: 添加publish

This commit is contained in:
2024-12-05 17:31:32 +08:00
parent da6211299b
commit a117281b9e
7 changed files with 141 additions and 39 deletions

30
src/uitls/npm.ts Normal file
View File

@@ -0,0 +1,30 @@
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 = (opts: InstallDepsOptions) => {
const { appPath } = opts;
const isProduction = opts.isProduction ?? true;
const params = ['i'];
if (isProduction) {
params.push('--production');
}
const syncSpawn = opts.sync ? spawnSync : spawn;
if (checkPnpm()) {
syncSpawn('pnpm', params, { cwd: appPath, stdio: 'inherit', env: process.env });
} else {
syncSpawn('npm', params, { cwd: appPath, stdio: 'inherit', env: process.env });
}
};