Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: auto populating plugin data during the initial server setup. #1345

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"apollo-server-express": "^2.25.4",
"axios": "^0.21.4",
"bcryptjs": "^2.4.3",
"body-parser": "^1.20.2",
"cls-bluebird": "^2.1.0",
"cls-hooked": "^4.2.2",
"copy-paste": "^1.3.0",
Expand Down Expand Up @@ -93,12 +94,12 @@
"@types/cls-hooked": "^4.3.3",
"@types/copy-paste": "^1.1.30",
"@types/cors": "^2.8.13",
"@types/express": "^4.17.13",
"@types/express": "^4.17.17",
"@types/express-rate-limit": "^5.1.3",
"@types/graphql-depth-limit": "^1.1.3",
"@types/i18n": "^0.13.3",
"@types/jsonwebtoken": "^8.5.8",
"@types/lodash": "^4.14.182",
"@types/lodash": "^4.14.195",
"@types/mongoose-paginate-v2": "^1.6.5",
"@types/morgan": "^1.9.3",
"@types/node": "^18.11.9",
Expand Down
26 changes: 26 additions & 0 deletions src/config/plugins/loadPlugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Plugin } from "../../models";
import _ from "lodash";
import pluginData from "./pluginData.json";
import { logger } from "../../libraries";
// Only loads plugin data for the time if it's not currently present in the database
const loadPlugins = async (): Promise<void> => {
const res = await Plugin.find();
let databaseTitle = process.env.MONGO_DB_URL || "";
databaseTitle = databaseTitle.split("mongodb.net/")[1].split("?")[0];
SiddheshKukade marked this conversation as resolved.
Show resolved Hide resolved
if (_.isEmpty(res)) {
pluginData.forEach(async (plugin: any) => {
await Plugin.create(plugin);
});
logger.info(
"\x1b[1m\x1b[32m%s\x1b[0m",
`Uploaded Plugins in ${databaseTitle} `
);
} else {
logger.info(
"\x1b[1m\x1b[32m%s\x1b[0m",
`Plugin data already present at ${databaseTitle}`
);
}
};

export default loadPlugins;
SiddheshKukade marked this conversation as resolved.
Show resolved Hide resolved
30 changes: 30 additions & 0 deletions src/config/plugins/pluginData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"pluginInstallStatus": false,
"pluginName": "Posts",
"pluginCreatedBy": "Talawa Team",
"pluginDesc": "Allow users to create, comment and like and share the content in the form of Pictures and Videos.",
"installedOrgs": ["62ccfccd3eb7fd2a30f41601", "62ccfccd3eb7fd2a30f41601"]
},
{
"pluginInstallStatus": false,
"pluginName": "Events22222222",
"pluginCreatedBy": "Talawa Team",
"pluginDesc": "Allow users to register and attend for new events with a inbuilt calendar to keep track of daily events.",
SiddheshKukade marked this conversation as resolved.
Show resolved Hide resolved
"installedOrgs": ["62ccfccd3eb7fd2a30f41601", "62ccfccd3eb7fd2a30f41601"]
},
{
"pluginInstallStatus": false,
"pluginName": "Donation",
"pluginCreatedBy": "Talawa Team",
"pluginDesc": "Enables members of the organization to do one time or reccurinng donations to an organization",
"installedOrgs": ["62ccfccd3eb7fd2a30f41601", "62ccfccd3eb7fd2a30f41601"]
},
{
"pluginInstallStatus": false,
"pluginName": "Chats",
"pluginCreatedBy": "Talawa Team",
"pluginDesc": "User can share messages with other users in a chat user interface.",
"installedOrgs": ["62ccfccd3eb7fd2a30f41601", "62ccfccd3eb7fd2a30f41601"]
}
]
4 changes: 2 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ import { User } from "./models";
import { express as voyagerMiddleware } from "graphql-voyager/middleware";
import { generateErrorMessage } from "zod-error";
import { getEnvIssues } from "./env";

import loadPlugins from "./config/plugins/loadPlugins";
const app = express();

app.use(requestTracing.middleware());

const pubsub = new PubSub();
Expand Down Expand Up @@ -249,3 +248,4 @@ const serverStart = async (): Promise<void> => {
};

serverStart();
loadPlugins();
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
"strict": true /* Enable all strict type-checking options. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
"resolveJsonModule": true /* Allow to import JSON files */
}
}