From cd6e4e3c25b2eb77cedeb966ae82caa21ef2408f Mon Sep 17 00:00:00 2001 From: sakshi godspeed Date: Thu, 12 Dec 2024 19:05:43 +0530 Subject: [PATCH 1/2] fix: plugins list json --- pluginsList.json | 68 ++++++++++++++++++++++++++ src/commands/plugin/index.ts | 93 +++++++++++++++++++++--------------- 2 files changed, 123 insertions(+), 38 deletions(-) create mode 100644 pluginsList.json diff --git a/pluginsList.json b/pluginsList.json new file mode 100644 index 0000000..1f86f85 --- /dev/null +++ b/pluginsList.json @@ -0,0 +1,68 @@ + [ + { + "value": "@godspeedsystems/plugins-express-as-http", + "name": "plugins-express-as-http", + "description": "Express as HTTP server plugin for Godspeed Framework." + }, + + { + "value": "@godspeedsystems/plugins-cron-as-eventsource", + "name": "plugins-cron-as-eventsource", + "description": "Cron as eventsource plugin for Godspeed Framework." + }, + { + "value": "@godspeedsystems/plugins-graphql-as-eventsource", + "name": "plugins-graphql-as-eventsource", + "description": "Graphql as eventsource plugin for Godspeed Framework." + }, + { + "value": "@godspeedsystems/plugins-prisma-as-datastore", + "name": "plugins-prisma-as-datastore", + "description": "Prisma as a datasource plugin for Godspeed Framework." + }, + { + "value": "@godspeedsystems/plugins-aws-as-datasource", + "name": "plugins-aws-as-datasource", + "description": "AWS as a datasource plugin for Godspeed Framework." + }, + { + "value": "@godspeedsystems/plugins-axios-as-datasource", + "name": "plugins-axios-as-datasource", + "description": "Axios as a datasource plugin for Godspeed Framework." + }, + { + "value": "@godspeedsystems/plugins-excel-as-datasource", + "name": "plugins-excel-as-datasource", + "description": "Excel as a datasource plugin for Godspeed Framework." + }, + { + "value": "@godspeedsystems/plugins-mailer-as-datasource", + "name": "plugins-mailer-as-datasource", + "description": "Mailer as a datasource plugin for Godspeed Framework." + }, + { + "value": "@godspeedsystems/plugins-mongoose-as-datasource", + "name": "plugins-mongoose-as-datasource", + "description": "Mongoose as a datasource plugin for Godspeed Framework." + }, + { + "value": "@godspeedsystems/plugins-redis-as-datasource", + "name": "plugins-redis-as-datasource", + "description": "Redis as a datasource plugin for Godspeed Framework." + }, + { + "value": "@godspeedsystems/plugins-kafka-as-datasource-as-eventsource", + "name": "plugins-kafka-as-datasource-as-eventsource", + "description": "Kafka as a datasource and eventsource plugin for Godspeed Framework." + }, + { + "value": "@godspeedsystems/plugins-elasticgraph-as-datasource", + "name": "plugins-elasticgraph-as-datasource", + "description": "Elasticgraph as a datasource plugin for Godspeed Framework." + }, + { + "value": "@godspeedsystems/plugins-salesforce-as-datasource-as-eventsource", + "name": "plugins-salesforce-as-datasource-as-eventsource", + "description": "Salesforce as a datasource plugin for Godspeed Framework." + } + ] \ No newline at end of file diff --git a/src/commands/plugin/index.ts b/src/commands/plugin/index.ts index 0b06ec9..a8d377a 100644 --- a/src/commands/plugin/index.ts +++ b/src/commands/plugin/index.ts @@ -78,7 +78,7 @@ const addAction = async (pluginsList: string[]) => { let yamlFileName = Module.CONFIG_FILE_NAME as string; let defaultConfig = Module.DEFAULT_CONFIG || ({} as PlainObject); - switch (moduleType) { + switch (moduleType) { case "BOTH": { mkdirSync( @@ -212,16 +212,25 @@ const add = program .action(async (pluginName: string) => { let givenPluginName = pluginName; - const command = "npm search @godspeedsystems/plugins --json"; - const stdout = execSync(command, { encoding: "utf-8" }); - const availablePlugins = JSON.parse(stdout.trim()); - const pluginNames = availablePlugins.map( - (plugin: { value: any; name: any; description: any }) => ({ - value: plugin.name, - Name: plugin.name.split("plugins-")[1], - Description: plugin.description, - }) - ); + // Search the plugins list from npm + + // const command = "npm search @godspeedsystems/plugins --json"; + // const stdout = execSync(command, { encoding: "utf-8" }); + // const availablePlugins = JSON.parse(stdout.trim()); + + // Load the plugins list from JSON file + const pluginsFilePath = path.resolve(__dirname, '../../../pluginsList.json'); + const pluginsData = fs.readFileSync(pluginsFilePath, { encoding: 'utf-8' }); + const availablePlugins = JSON.parse(pluginsData); + + // Map to the format expected by the UI + const pluginNames = availablePlugins.map((plugin: { value: any; name: any; description: any }) => ({ + value: plugin.value, + Name: plugin.name.split("plugins-")[1], + Description: plugin.description, + })); + + console.log("Available plugins:", pluginNames); let pkgPath = path.join(cwd(), "package.json"); let localpluginsList = existsSync(pkgPath) @@ -473,8 +482,22 @@ const remove = program return; } - const command = "npm search @godspeedsystems/plugins --json"; - const stdout = execSync(command, { encoding: "utf-8" }); + // const command = "npm search @godspeedsystems/plugins --json"; + // const stdout = execSync(command, { encoding: "utf-8" }); + // const availablePlugins = JSON.parse(stdout.trim()); + + // Load the plugins list from JSON file + const pluginsFilePath = path.resolve(__dirname, '../../../pluginsList.json'); + const pluginsData = fs.readFileSync(pluginsFilePath, { encoding: 'utf-8' }); + const availablePlugins = JSON.parse(pluginsData); + + // Map to the format expected by the UI + const pluginNames = availablePlugins.map((plugin: { value: any; name: any; description: any }) => ({ + value: plugin.value, + Name: plugin.name.split("plugins-")[1], + Description: plugin.description, + })); + let pkgPath = path.join(cwd(), "package.json"); pluginsList = existsSync(pkgPath) ? JSON.parse(readFileSync(pkgPath, { encoding: "utf-8" })).dependencies @@ -485,17 +508,6 @@ const remove = program !isGSPlugin && delete pluginsList[pluginName]; } - // console.log(pluginsList) - const availablePlugins = JSON.parse(stdout.trim()); - - const pluginNames = availablePlugins.map( - (plugin: { value: any; name: any; description: any }) => ({ - value: plugin.name, - Name: plugin.name.split("plugins-")[1], - Description: plugin.description, - }) - ); - const commonPlugins = pluginNames.filter( (plugin: { value: string | number }) => pluginsList[plugin.value] ); @@ -504,7 +516,7 @@ const remove = program const tableCheckboxPrompt = { type: "search-table", name: "gsPlugin", - message: "Please select godspeed plugin to install:", + message: "Please select godspeed plugin to uninstall:", wordWrap: true, pageSize: 5, searchable: true, @@ -599,8 +611,23 @@ const update = program } } - const command = "npm search @godspeedsystems/plugins --json"; - const stdout = execSync(command, { encoding: "utf-8" }); + // const command = "npm search @godspeedsystems/plugins --json"; + // const stdout = execSync(command, { encoding: "utf-8" }); + // const availablePlugins = JSON.parse(stdout.trim()); + + // Load the plugins list from JSON file + const pluginsFilePath = path.resolve(__dirname, '../../../pluginsList.json'); + const pluginsData = fs.readFileSync(pluginsFilePath, { encoding: 'utf-8' }); + const availablePlugins = JSON.parse(pluginsData); + + // Map to the format expected by the UI + const pluginNames = availablePlugins.map((plugin: { value: any; name: any; description: any }) => ({ + value: plugin.value, + Name: plugin.name.split("plugins-")[1], + Description: plugin.description, + })); + + let pkgPath = path.join(cwd(), "package.json"); pluginsList = existsSync(pkgPath) ? JSON.parse(readFileSync(pkgPath, { encoding: "utf-8" })).dependencies @@ -612,16 +639,6 @@ const update = program } // console.log(pluginsList) - const availablePlugins = JSON.parse(stdout.trim()); - - const pluginNames = availablePlugins.map( - (plugin: { value: string; name: string; description: string }) => ({ - value: plugin.name, - Name: plugin.name.split("plugins-")[1], - Description: plugin.description, - }) - ); - const commonPlugins = pluginNames.filter( (plugin: any) => pluginsList[plugin.value] ); @@ -631,7 +648,7 @@ const update = program const tableCheckboxPrompt = { type: "search-table", name: "gsPlugin", - message: "Please select godspeed plugin to install:", + message: "Please select godspeed plugin to update:", wordWrap: true, pageSize: 5, searchable: true, From 3d7606dee9cd3aa135d0c298561bd057387b1087 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 25 Dec 2024 14:12:16 +0530 Subject: [PATCH 2/2] test-case updated --- test/commands/plugin/add.ts | 10 +++++++--- test/commands/plugin/remove.ts | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/test/commands/plugin/add.ts b/test/commands/plugin/add.ts index 57f6510..d4358c4 100644 --- a/test/commands/plugin/add.ts +++ b/test/commands/plugin/add.ts @@ -11,9 +11,13 @@ export const pluginAdd = () => { const tempDirectory = "sandbox"; let cliOp: string; // Declare cliOp outside before() to make it accessible - const command = "npm search @godspeedsystems/plugins --json"; - const stdout = execSync(command, { encoding: "utf-8" }); - const availablePlugins = JSON.parse(stdout); + // const command = "npm search @godspeedsystems/plugins --json"; + // const stdout = execSync(command, { encoding: "utf-8" }); + // const availablePlugins = JSON.parse(stdout); + const pluginsFilePath = path.resolve(__dirname, '../../../pluginsList.json'); + const pluginsData = fs.readFileSync(pluginsFilePath, { encoding: 'utf-8' }); + const availablePlugins = JSON.parse(pluginsData); + const folderPath = path.join(process.cwd(), tempDirectory, folderName); const pluginNames = availablePlugins.map((plugin: any) => plugin.name); // checking installation of plugin in package.json diff --git a/test/commands/plugin/remove.ts b/test/commands/plugin/remove.ts index e455f72..ae0acd4 100644 --- a/test/commands/plugin/remove.ts +++ b/test/commands/plugin/remove.ts @@ -12,9 +12,13 @@ export const pluginRemove = () => { const folderName = "godspeed"; const tempDirectory = "sandbox"; - const command = "npm search @godspeedsystems/plugins --json"; - const stdout = execSync(command, { encoding: "utf-8" }); - const availablePlugins = JSON.parse(stdout); + // const command = "npm search @godspeedsystems/plugins --json"; + // const stdout = execSync(command, { encoding: "utf-8" }); + // const availablePlugins = JSON.parse(stdout); + const pluginsFilePath = path.resolve(__dirname, '../../../pluginsList.json'); + const pluginsData = fs.readFileSync(pluginsFilePath, { encoding: 'utf-8' }); + const availablePlugins = JSON.parse(pluginsData); + const folderPath = path.join(process.cwd(), tempDirectory, folderName); const pluginNames = availablePlugins.map((plugin: any) => plugin.name); for (const pluginName of pluginNames) {