From 3004c289c7965dca4a1e532462c2bb4fa09de9fa Mon Sep 17 00:00:00 2001 From: Mani Marothu Date: Wed, 18 Sep 2024 15:51:16 -0700 Subject: [PATCH] Create execute-command.ts Added Execute command Signed-off-by: Mani Marothu --- .../backend/src/plugins/execute-command.ts | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 packages/backend/src/plugins/execute-command.ts diff --git a/packages/backend/src/plugins/execute-command.ts b/packages/backend/src/plugins/execute-command.ts new file mode 100644 index 0000000..48be418 --- /dev/null +++ b/packages/backend/src/plugins/execute-command.ts @@ -0,0 +1,48 @@ +import { createTemplateAction } from '@backstage/plugin-scaffolder-node'; +import { executeShellCommand } from '@backstage/plugin-scaffolder-node'; + +export const executeCommand = () => { + return createTemplateAction<{ + command: string; + arguments?: string[]; + }>({ + id: 'cnoe:command:execute', + schema: { + input: { + type: 'object', + required: ['command'], + properties: { + command: { + type: 'string', + title: 'Command to run', + description: 'Command to execute', + }, + arguments: { + type: 'array', + items: { + type: 'string', + }, + title: 'Command Arguments', + description: 'Command arguments list', + }, + }, + }, + output: {}, + }, + async handler(ctx) { + const command = ctx.input.command; + const commandArgs = ctx.input.arguments || []; + + if (!command) { + throw new Error('The command must be provided.'); + } + + // Execute the shell command with optional arguments + await executeShellCommand({ + command: command, + args: commandArgs, + logStream: ctx.logStream, + }); + }, + }); +};