feat: add silky cli tools
This commit is contained in:
		| @@ -105,11 +105,17 @@ export const installApp = async (app: Package, opts: InstallAppOpts = {}) => { | ||||
|     }; | ||||
|   } | ||||
| }; | ||||
| /** | ||||
|  * 检查是否为空,如果为空则删除 | ||||
|  * @param appDir | ||||
|  */ | ||||
| export const checkAppDir = (appDir: string) => { | ||||
|   const files = fs.readdirSync(appDir); | ||||
|   if (files.length === 0) { | ||||
|     fs.rmSync(appDir, { recursive: true }); | ||||
|   } | ||||
|   try { | ||||
|     const files = fs.readdirSync(appDir); | ||||
|     if (files.length === 0) { | ||||
|       fs.rmSync(appDir, { recursive: true }); | ||||
|     } | ||||
|   } catch (error) {} | ||||
| }; | ||||
| export const checkFileExists = (path: string) => { | ||||
|   try { | ||||
| @@ -121,9 +127,10 @@ export const checkFileExists = (path: string) => { | ||||
| }; | ||||
| type UninstallAppOpts = { | ||||
|   appDir?: string; | ||||
|   type?: 'app' | 'web'; | ||||
| }; | ||||
| export const uninstallApp = async (app: Partial<Package>, opts: UninstallAppOpts = {}) => { | ||||
|   const { appDir = '' } = opts; | ||||
|   const { appDir = '', type = 'web' } = opts; | ||||
|   try { | ||||
|     const { user, key } = app; | ||||
|     const keyDir = path.join(appDir, user, key); | ||||
| @@ -140,7 +147,7 @@ export const uninstallApp = async (app: Partial<Package>, opts: UninstallAppOpts | ||||
|     } catch (error) { | ||||
|       console.error(error); | ||||
|     } | ||||
|     checkAppDir(parentDir); | ||||
|     type === 'web' && checkAppDir(parentDir); | ||||
|     return { | ||||
|       code: 200, | ||||
|       message: 'Uninstall app success', | ||||
|   | ||||
| @@ -45,3 +45,12 @@ export const queryLogin = new QueryLoginNode({ | ||||
|     // console.log('onLoad'); | ||||
|   }, | ||||
| }); | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @param url | ||||
|  * @returns | ||||
|  */ | ||||
| export const getUrl = (url: string) => { | ||||
|   return new URL('/api/router', url).href; | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user