add pm2
This commit is contained in:
		| @@ -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; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user