Skip to content

Commit 8079a5c

Browse files
✨ allow user to provided loaded commands
1 parent d77dbb4 commit 8079a5c

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ const config = {
3535
projectName: 'Immersive',
3636
// Will be displayed on CLI start (optional - default to displayName)
3737
displayName: 'Immersive',
38-
// Path to the directory where commands are defined (required)
38+
// Loaded commands (required if commandsDirectory not provided) - Should be valid map of ImmersiveCommand
39+
commands: {
40+
'import-orgs': {
41+
command: 'importOrgs',
42+
description: 'Import organizations',
43+
action: () => {},
44+
},
45+
},
46+
// Path to the directory where commands are defined (required if commands not provided)
3947
commandsDirectory: path.join(__dirname, 'commands'),
4048
// Will be accessible from commands as argument (optional)
4149
helpers: {

index.d.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ declare module 'immersive' {
1515
};
1616
}
1717

18+
export interface ImmersiveCommand {
19+
command: string;
20+
description: string;
21+
action: Function;
22+
}
23+
1824
interface ImmersiveConfiguration {
1925
projectName: string;
2026
displayName?: string;
21-
commandsDirectory: string;
27+
commands?: Record<string, ImmersiveCommand>;
28+
commandsDirectory?: string;
2229
helpers: Record<string, Helper>;
2330
environments: Record<string, ImmersiveEnvironment>;
2431
defaultEnvironment?: string;
@@ -53,7 +60,11 @@ declare module 'immersive' {
5360
clearHistory: () => void;
5461
}
5562

56-
type ImmersiveActionInput<Helpers, EnvironmentNames = string, EnvironmentConfig = ImmersiveEnvironment> = Helpers & {
63+
type ImmersiveActionInput<
64+
Helpers,
65+
EnvironmentNames = string,
66+
EnvironmentConfig = ImmersiveEnvironment
67+
> = Helpers & {
5768
args: Arguments;
5869
commands: Record<string, ImmersiveAction<Helpers, EnvironmentNames>>;
5970
logger: ImmersiveLogger;
@@ -66,8 +77,17 @@ declare module 'immersive' {
6677
envConfig: EnvironmentConfig;
6778
};
6879

69-
type ImmersiveAction<Helpers, EnvironmentNames = string, EnvironmentConfig = ImmersiveEnvironment, ReturnType = any> = (
70-
actionInput: ImmersiveActionInput<Helpers, EnvironmentNames, EnvironmentConfig>,
80+
type ImmersiveAction<
81+
Helpers,
82+
EnvironmentNames = string,
83+
EnvironmentConfig = ImmersiveEnvironment,
84+
ReturnType = any
85+
> = (
86+
actionInput: ImmersiveActionInput<
87+
Helpers,
88+
EnvironmentNames,
89+
EnvironmentConfig
90+
>,
7191
) => ReturnType;
7292

7393
export default function immersive(

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "immersive",
3-
"version": "1.7.0",
3+
"version": "1.8.0",
44
"description": "A framework to build immersive CLIs & great developer tools.",
55
"main": "index.js",
66
"module": "src/main.js",

src/command/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,13 @@ const wrapCommand = (action, config) => (argv, command) => {
109109
});
110110
};
111111

112-
export const loadCommands = ({ commandsDirectory, ...config }) => {
112+
export const loadCommands = ({
113+
commands: userLoadedCommands,
114+
commandsDirectory,
115+
...config
116+
}) => {
113117
const customCommands = parseCommands(
114-
requireDir(commandsDirectory, { recurse: true }),
118+
userLoadedCommands || requireDir(commandsDirectory, { recurse: true }),
115119
);
116120
commands = [
117121
...customCommands,

0 commit comments

Comments
 (0)