Create execute-command.ts

Added Execute command

Signed-off-by: Mani Marothu <manikumar.1215@gmail.com>
This commit is contained in:
Mani Marothu 2024-09-18 15:51:16 -07:00
parent 5f3a54f571
commit 3004c289c7

View file

@ -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,
});
},
});
};