-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
85 lines (78 loc) · 2.56 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env node
import {Command} from "commander";
import {createScreen} from "./commands/createScreen.js";
import {createHook} from "./commands/createHook.js";
import {resourceTypes, CLI_NAME, CLI_VERSION, CLI_DESCRIPTION, commands} from "./constants.js";
import {createComponent} from "./commands/createComponent.js";
import {consoleError} from "./helpers.js";
import {createslice} from "./commands/createSlice.js";
import {createRedux} from "./commands/createRedux.js";
const program = new Command();
program.name(CLI_NAME).description(CLI_DESCRIPTION).version(CLI_VERSION);
program
.command(commands.CREATE_REDUX.command)
.description(commands.CREATE_REDUX.description)
.option(
commands.CREATE_REDUX.options.DRY_RUN,
"Execute the command without creating any file"
)
.action((options) => {
try {
createRedux(options);
} catch (error) {
consoleError(
`An error occurred while executing the script. Please try again.`
);
}
});
program
.command(commands.CREATE.command)
.alias(commands.CREATE.alias)
.description(commands.CREATE.description)
.option(commands.CREATE.options.NO_CONST, "do not create a constants file")
.option(commands.CREATE.options.NO_TEST, "do not create a test file")
.option(commands.CREATE.options.NO_STYLE, "do not create a styles file")
.option(
commands.CREATE.options.PATH,
"custom path for the files, starting from src"
)
.option(
commands.CREATE.options.KEEP_NAME,
"use the resource name provided without modification"
)
.option(
commands.CREATE.options.NO_DIR,
"do not create a separate folder for the files"
)
.option(
commands.CREATE.options.DRY_RUN,
"Execute the command without creating any file"
)
.action((type, name, options) => {
try {
if (type === resourceTypes.SCREEN) {
createScreen(name, options);
} else if (type === resourceTypes.HOOK) {
createHook(name, options);
} else if (type === resourceTypes.COMPONENT) {
createComponent(name, options);
} else if (type === resourceTypes.SLICE) {
createslice(name, options);
} else {
consoleError(`Unsupported resource type: ${type}`);
}
} catch (error) {
consoleError(
`An error occurred while executing the script. Please try again.`
);
}
});
program.exitOverride();
program.on("command:*", () => {
consoleError("invalid command:", program.args.join(" "));
console.log("See --help for available commands.");
process.exit(1);
});
try {
program.parse(process.argv);
} catch (error) {}