|
@@ -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-'
|
|
* list plugin module names that starts with 'crowi-plugin-'
|
|
|
* borrowing from: https://github.com/hexojs/hexo/blob/d1db459c92a4765620343b95789361cbbc6414c5/lib/hexo/load_plugins.js#L17
|
|
* borrowing from: https://github.com/hexojs/hexo/blob/d1db459c92a4765620343b95789361cbbc6414c5/lib/hexo/load_plugins.js#L17
|