Skip to content

Commit

Permalink
feat(mantis-cli): ✨ Dynamization of Actions & Commands Name
Browse files Browse the repository at this point in the history
Commands name will now be taken from File Name. Actions EntryFunction will be loaded lazily and dynamically using cammand name.
  • Loading branch information
orbitturner committed Nov 23, 2023
1 parent 17699e7 commit 0862793
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/actions/actionTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type ActionFunction = () => any;

export interface ActionFile {
[key: string]: ActionFunction
}

4 changes: 3 additions & 1 deletion src/actions/some.action.ts → src/actions/start.action.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { OrbitLogger } from "../utils/orbitLogger.helper";

export const someAction = async () => {
export const startAction = async () => {
// Logic for the action
const matarLogger = new OrbitLogger('DSN');

matarLogger.info('Hello World !');
};


9 changes: 6 additions & 3 deletions src/commands/start.command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Command } from 'commander';
import { someAction } from '../actions/some.action';
import path from 'path';
import { ActionFile } from 'src/actions/actionTypes';

export default new Command('someCommand')
const currentCommandName = path.basename(__filename).split('.').at(0);

export default new Command(currentCommandName)
.description('Description of someCommand')
.action(someAction);
.action((require(`../actions/${currentCommandName}.action`) as ActionFile)[`${currentCommandName}Action`]);

0 comments on commit 0862793

Please sign in to comment.