Просмотр исходного кода

show plugins list in Admin Page

Yuki Takei 9 лет назад
Родитель
Сommit
a5c9f2e182
3 измененных файлов с 59 добавлено и 0 удалено
  1. 36 0
      lib/plugins/plugin-utils.js
  2. 3 0
      lib/routes/admin.js
  3. 20 0
      lib/views/admin/app.html

+ 36 - 0
lib/plugins/plugin-utils.js

@@ -30,6 +30,42 @@ class PluginUtils {
     }
   }
 
+  /**
+   * list plugin module objects that starts with 'crowi-plugin-'
+   * borrowing from: https://github.com/hexojs/hexo/blob/d1db459c92a4765620343b95789361cbbc6414c5/lib/hexo/load_plugins.js#L17
+   *
+   * @returns array of objects
+   *   [
+   *     { name: 'crowi-plugin-...', version: '1.0.0' },
+   *     { name: 'crowi-plugin-...', version: '1.0.0' },
+   *     ...
+   *   ]
+   *
+   * @memberOf PluginService
+   */
+  listPlugins(rootDir) {
+    var packagePath = path.join(rootDir, 'package.json');
+
+    // Make sure package.json exists
+    if (!fs.existsSync(packagePath)) {
+      return [];
+    }
+
+    // Read package.json and find dependencies
+    const content = fs.readFileSync(packagePath);
+    const json = JSON.parse(content);
+    const deps = json.dependencies || {};
+
+    let objs = {};
+    Object.keys(deps).forEach((name) => {
+      if (/^crowi-plugin-/.test(name)) {
+        objs[name] = deps[name];
+      }
+    });
+
+    return objs;
+  }
+
   /**
    * list plugin module names that starts with 'crowi-plugin-'
    * borrowing from: https://github.com/hexojs/hexo/blob/d1db459c92a4765620343b95789361cbbc6414c5/lib/hexo/load_plugins.js#L17

+ 3 - 0
lib/routes/admin.js

@@ -6,6 +6,8 @@ module.exports = function(crowi, app) {
     , Page = models.Page
     , User = models.User
     , Config = models.Config
+    , PluginUtils = require('../plugins/plugin-utils')
+    , pluginUtils = new PluginUtils()
     , ApiResponse = require('../util/apiResponse')
 
     , MAX_PAGE_LIST = 5
@@ -77,6 +79,7 @@ module.exports = function(crowi, app) {
 
     return res.render('admin/app', {
       settingForm: settingForm,
+      plugins: pluginUtils.listPlugins(crowi.rootDir),
     });
   };
 

+ 20 - 0
lib/views/admin/app.html

@@ -268,6 +268,26 @@
       </fieldset>
       </form>
 
+      <h4>インストールされているプラグイン一覧</h4>
+      <table class="table table-bordered">
+        <th class="text-center">
+          パッケージ名
+        </th>
+        <th class="text-center">
+          指定バージョン
+        </th>
+        <th class="text-center">
+          インストールされているバージョン
+        </th>
+        {% for pluginName in Object.keys(plugins) %}
+        <tr>
+          <td>{{ pluginName }}</td>
+          <td class="text-center">{{ plugins[pluginName] }}</td>
+          <td class="text-center">(TBD)</td>
+        </tr>
+        {% endfor %}
+      </table>
+
     </div>
   </div>