-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mantis-cli): ✨ Dynamization of Actions & Commands Name
Commands name will now be taken from File Name. Actions EntryFunction will be loaded lazily and dynamically using cammand name.
- Loading branch information
1 parent
17699e7
commit 0862793
Showing
3 changed files
with
15 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type ActionFunction = () => any; | ||
|
||
export interface ActionFile { | ||
[key: string]: ActionFunction | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 !'); | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`]); |