feat: 添加publish
This commit is contained in:
		
							
								
								
									
										30
									
								
								src/uitls/npm.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								src/uitls/npm.ts
									
									
									
									
									
										Normal 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 }); | ||||
|   } | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user