|
|
@@ -1,40 +1,34 @@
|
|
|
const path = require('path');
|
|
|
-const fs = require('hexo-fs');
|
|
|
+const fs = require('graceful-fs');
|
|
|
|
|
|
class PluginUtils {
|
|
|
|
|
|
/**
|
|
|
- * return a array of definition objects that has following structure:
|
|
|
+ * return a definition objects that has following structure:
|
|
|
*
|
|
|
- * [
|
|
|
- * {
|
|
|
- * name: 'crowi-plugin-X',
|
|
|
- * meta: require('crowi-plugin-X'),
|
|
|
- * entries: [
|
|
|
- * require('crowi-plugin-X/lib/client-entry')
|
|
|
- * ]
|
|
|
- * },
|
|
|
- * ]
|
|
|
+ * {
|
|
|
+ * name: 'crowi-plugin-X',
|
|
|
+ * meta: require('crowi-plugin-X'),
|
|
|
+ * entries: [
|
|
|
+ * require('crowi-plugin-X/lib/client-entry')
|
|
|
+ * ]
|
|
|
+ * }
|
|
|
*
|
|
|
- * @param {string} rootDir Crowi Project root dir
|
|
|
+ * @param {string} pluginName
|
|
|
* @return
|
|
|
* @memberOf PluginService
|
|
|
*/
|
|
|
- generatePluginDefinitions(rootDir, isForClient = false) {
|
|
|
- return this.listPluginNames(rootDir)
|
|
|
- .map((name) => {
|
|
|
- const meta = require(name);
|
|
|
- const entries = (isForClient) ? meta.clientEntries : meta.serverEntries;
|
|
|
-
|
|
|
- return {
|
|
|
- name: name,
|
|
|
- meta: meta,
|
|
|
- entries: entries.map((entryPath) => {
|
|
|
- return require(entryPath);
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
+ generatePluginDefinition(pluginName, isForClient = false) {
|
|
|
+ const meta = require(pluginName);
|
|
|
+ const entries = (isForClient) ? meta.clientEntries : meta.serverEntries;
|
|
|
+
|
|
|
+ return {
|
|
|
+ name: pluginName,
|
|
|
+ meta: meta,
|
|
|
+ entries: entries.map((entryPath) => {
|
|
|
+ return require(entryPath);
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -49,16 +43,15 @@ class PluginUtils {
|
|
|
var packagePath = path.join(rootDir, 'package.json');
|
|
|
|
|
|
// Make sure package.json exists
|
|
|
- return fs.exists(packagePath).then(function(exist) {
|
|
|
- if (!exist) return [];
|
|
|
-
|
|
|
- // Read package.json and find dependencies
|
|
|
- return fs.readFile(packagePath).then(function(content) {
|
|
|
- var json = JSON.parse(content);
|
|
|
- var deps = json.dependencies || {};
|
|
|
- return Object.keys(deps);
|
|
|
- });
|
|
|
- }).filter(function(name) {
|
|
|
+ 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 || {};
|
|
|
+ return Object.keys(deps).filter((name) => {
|
|
|
// Ignore plugins whose name is not started with "crowi-"
|
|
|
return /^crowi-plugin-/.test(name);
|
|
|
});
|