Skip to content

Commit 0294518

Browse files
authored
Merge pull request #689 from melihkorkmaz/plugins-guidelines
Plugins guidelines
2 parents 6ec582c + 1efaea9 commit 0294518

File tree

5 files changed

+159
-158
lines changed

5 files changed

+159
-158
lines changed

plugins/plugins/api/api.js

+28-27
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ var plugin = {},
22
fs = require('fs'),
33
path = require('path'),
44
common = require('../../../api/utils/common.js'),
5-
async = require('async'),
65
parser = require('properties-parser'),
76
plugins = require('../../pluginManager.js');
87

9-
(function(plugin) {
8+
(function() {
109
plugins.register('/i/plugins', function(ob) {
1110
var params = ob.params;
1211
var validateUserForWriteAPI = ob.validateUserForWriteAPI;
@@ -15,7 +14,7 @@ var plugin = {},
1514
common.returnMessage(params, 401, 'User is not a global administrator');
1615
return false;
1716
}
18-
if (typeof params.qstring.plugin !== 'undefined' && params.qstring.plugin != 'plugins') {
17+
if (typeof params.qstring.plugin !== 'undefined' && params.qstring.plugin !== 'plugins') {
1918
try {
2019
params.qstring.plugin = JSON.parse(params.qstring.plugin);
2120
}
@@ -70,51 +69,53 @@ var plugin = {},
7069
list.forEach(function(file) {
7170
if (!ignore[file]) {
7271
var fullpath = dir + '/' + file;
73-
fs.stat(fullpath, function(err, stat) {
72+
fs.stat(fullpath, function(fsError, stat) {
7473
if (stat && stat.isDirectory()) {
7574
var data;
7675
try {
7776
data = require(fullpath + '/package.json');
7877
}
79-
catch (ex) {}
80-
var ob = {};
78+
catch (ex) {
79+
// Error
80+
}
81+
var resultObj = {};
8182
if (pluginList.indexOf(file) > -1) {
82-
ob.enabled = true;
83+
resultObj.enabled = true;
8384
}
8485
else {
85-
ob.enabled = false;
86+
resultObj.enabled = false;
8687
}
87-
ob.code = file;
88+
resultObj.code = file;
8889
if (data) {
89-
ob.title = data.title || file;
90-
ob.name = data.name || file;
91-
ob.description = data.description || file;
92-
ob.version = data.version || "unknown";
93-
ob.author = data.author || "unknown";
94-
ob.homepage = data.homepage || "";
90+
resultObj.title = data.title || file;
91+
resultObj.name = data.name || file;
92+
resultObj.description = data.description || file;
93+
resultObj.version = data.version || "unknown";
94+
resultObj.author = data.author || "unknown";
95+
resultObj.homepage = data.homepage || "";
9596

9697
//we need to get localization only if plugin is disabled
97-
if (!ob.enabled) {
98-
var local_path = fullpath + "/frontend/public/localization/" + ob.code + ".properties";
99-
if (params.member.lang && params.member.lang != "en") {
100-
local_path = fullpath + "/frontend/public/localization/" + ob.code + "_" + params.member.lang + ".properties";
98+
if (!resultObj.enabled) {
99+
var local_path = fullpath + "/frontend/public/localization/" + resultObj.code + ".properties";
100+
if (params.member.lang && params.member.lang !== "en") {
101+
local_path = fullpath + "/frontend/public/localization/" + resultObj.code + "_" + params.member.lang + ".properties";
101102
}
102103
if (fs.existsSync(local_path)) {
103104
var local_properties = fs.readFileSync(local_path);
104105
local_properties = parser.parse(local_properties);
105-
ob.title = local_properties[ob.code + ".plugin-title"] || local_properties[ob.code + ".title"] || ob.title;
106-
ob.description = local_properties[ob.code + ".plugin-description"] || local_properties[ob.code + ".description"] || ob.description;
106+
resultObj.title = local_properties[resultObj.code + ".plugin-title"] || local_properties[resultObj.code + ".title"] || resultObj.title;
107+
resultObj.description = local_properties[resultObj.code + ".plugin-description"] || local_properties[resultObj.code + ".description"] || resultObj.description;
107108
}
108109
}
109110
}
110111
else {
111-
ob = {name: file, title: file, description: file, version: "unknown", author: "unknown", homepage: "", code: file, enabled: false};
112+
resultObj = {name: file, title: file, description: file, version: "unknown", author: "unknown", homepage: "", code: file, enabled: false};
112113
}
113114
if (global.enclose) {
114115
var eplugin = global.enclose.plugins[file];
115-
ob.prepackaged = eplugin && eplugin.prepackaged;
116+
resultObj.prepackaged = eplugin && eplugin.prepackaged;
116117
}
117-
results.push(ob);
118+
results.push(resultObj);
118119
if (!--pending) {
119120
done(null, results);
120121
}
@@ -174,9 +175,9 @@ var plugin = {},
174175
updateArr.ends = data.frontend.session_timeout * 60 + Math.round(Date.now() / 1000);
175176
updateArr.ttl = data.frontend.session_timeout * 60;
176177
}
177-
if (params.member.settings && params.member.settings.frontend && typeof data.frontend.session_timeout !== "undefined") {}
178+
if (params.member.settings && params.member.settings.frontend && typeof data.frontend.session_timeout !== "undefined") {} //eslint-disable-line no-empty
178179
else { //if not set member value
179-
common.db.collection("auth_tokens").update({"owner": ob.params.member._id + "", "purpose": "LoggedInAuth"}, {$set: updateArr}, function(err, res1) {
180+
common.db.collection("auth_tokens").update({"owner": ob.params.member._id + "", "purpose": "LoggedInAuth"}, {$set: updateArr}, function(err) {
180181
if (err) {
181182
console.log(err);
182183
}
@@ -233,7 +234,7 @@ var plugin = {},
233234
updateArr.ttl = data.frontend.session_timeout * 60;
234235
}
235236

236-
common.db.collection("auth_tokens").update({"owner": ob.params.member._id + "", "purpose": "LoggedInAuth"}, {$set: updateArr}, function(err, res1) {
237+
common.db.collection("auth_tokens").update({"owner": ob.params.member._id + "", "purpose": "LoggedInAuth"}, {$set: updateArr}, function(err) {
237238
if (err) {
238239
console.log(err);
239240
}

plugins/plugins/frontend/app.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
var plugin = {},
2-
plugins = require('../../pluginManager.js');
1+
var exportedPlugin = {};
32

43
(function(plugin) {
5-
plugin.init = function(app, countlyDb) { };
6-
}(plugin));
4+
plugin.init = function() {
75

8-
module.exports = plugin;
6+
};
7+
}(exportedPlugin));
8+
9+
module.exports = exportedPlugin;

plugins/plugins/frontend/public/javascripts/countly.models.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
(function(countlyPlugins, $, undefined) {
1+
/*global countlyCommon,countlyGlobal,jQuery */
2+
(function(countlyPlugins, $) {
23

34
//Private Properties
45
var _pluginsData = {};
@@ -7,7 +8,7 @@
78
var _themeList = [];
89

910
//Public Methods
10-
countlyPlugins.initialize = function(id) {
11+
countlyPlugins.initialize = function() {
1112
return $.ajax({
1213
type: "GET",
1314
url: countlyCommon.API_URL + "/o/plugins",
@@ -46,7 +47,7 @@
4647
});
4748
};
4849

49-
countlyPlugins.initializeConfigs = function(id) {
50+
countlyPlugins.initializeConfigs = function() {
5051
return $.when(
5152
$.ajax({
5253
type: "GET",
@@ -95,7 +96,7 @@
9596
});
9697
};
9798

98-
countlyPlugins.initializeUserConfigs = function(id) {
99+
countlyPlugins.initializeUserConfigs = function() {
99100
return $.when(
100101
$.ajax({
101102
type: "GET",

0 commit comments

Comments
 (0)