소스 검색

clean code

jam411 3 년 전
부모
커밋
6423238bbc
1개의 변경된 파일11개의 추가작업 그리고 10개의 파일을 삭제
  1. 11 10
      packages/app/src/server/service/plugin.ts

+ 11 - 10
packages/app/src/server/service/plugin.ts

@@ -104,19 +104,20 @@ export class PluginService implements IPluginService {
     const renamePath = async(oldPath: fs.PathLike, newPath: fs.PathLike) => {
     const renamePath = async(oldPath: fs.PathLike, newPath: fs.PathLike) => {
       if (fs.existsSync(newPath)) {
       if (fs.existsSync(newPath)) {
         // if a repository already exists, delete old repository before rename path
         // if a repository already exists, delete old repository before rename path
-        // delete old repository
-        await fs.promises.rm(newPath, { recursive: true });
-
-        // delete old document
         const GrowiPlugin = mongoose.model<GrowiPlugin>('GrowiPlugin');
         const GrowiPlugin = mongoose.model<GrowiPlugin>('GrowiPlugin');
-        await GrowiPlugin.deleteOne({ url: `https://github.com/${ghOrganizationName}/${ghReposName}` });
 
 
-        // rename new repository
-        fs.renameSync(oldPath, newPath);
-      }
-      else {
-        fs.renameSync(oldPath, newPath);
+        try {
+          // delete old repository
+          await fs.promises.rm(newPath, { recursive: true });
+          // delete old document
+          await GrowiPlugin.deleteOne({ url: `https://github.com/${ghOrganizationName}/${ghReposName}` });
+        }
+        catch (err) {
+          throw new Error(err);
+        }
       }
       }
+      // rename new repository
+      fs.renameSync(oldPath, newPath);
     };
     };
 
 
     const downloadFile = async(requestUrl: string, filePath: string) => {
     const downloadFile = async(requestUrl: string, filePath: string) => {