Kaynağa Gözat

WIP: impl detectPlugins

Yuki Takei 3 yıl önce
ebeveyn
işleme
e6c467f63a
1 değiştirilmiş dosya ile 29 ekleme ve 6 silme
  1. 29 6
      packages/app/src/server/service/plugin.ts

+ 29 - 6
packages/app/src/server/service/plugin.ts

@@ -19,12 +19,35 @@ export class PluginService {
     return;
   }
 
-  static detectPlugins(origin: GrowiPluginOrigin, installedPath: string): GrowiPlugin[] {
-    // const plugins: GrowiPlugin[] = [];
-
-    // const package = require(path.resolve(installedPath, 'package.json'));
-
-    // return scopedPackages;
+  static async detectPlugins(origin: GrowiPluginOrigin, installedPath: string): Promise<GrowiPlugin[]> {
+    const packageJson = await import(path.resolve(pluginStoringPath, installedPath, 'package.json'));
+
+    const {
+      growiPlugin, name: packageName, description: packageDesc, author: packageAuthor,
+    } = packageJson;
+
+    if (growiPlugin == null) {
+      throw new Error('This package does not include \'growiPlugin\' section.');
+    }
+
+    if (growiPlugin.isMonorepo && growiPlugin.packages != null) {
+      return growiPlugin.packages.flatmap(async(subPackagePath) => {
+        const subPackageInstalledPath = path.resolve(pluginStoringPath, installedPath, subPackagePath);
+        return this.detectPlugins(origin, subPackageInstalledPath);
+      });
+    }
+
+    return [{
+      isEnabled: true,
+      installedPath,
+      origin,
+      meta: {
+        name: growiPlugin.name ?? packageName,
+        desc: growiPlugin.desc ?? packageDesc,
+        author: growiPlugin.author ?? packageAuthor,
+        types: [],
+      },
+    }];
   }
 
   // /**