-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·55 lines (48 loc) · 1.52 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
#!/usr/bin/env node
import { program } from "commander";
import inquirer from "inquirer";
import chalk from "chalk";
import { createComponentsTemplates, createFiles } from "./utilities/index.js";
import { TYPES, translateType } from "./constants/index.js";
program
.version("1.0.0")
.description("CLI para crear un template de un componente de React");
program
.command("create <name>")
.alias("c")
.description("Crear un componente de React")
.action((name) => {
const questions = [
{
type: "input",
name: "componentPath",
message: `¿Cuál es el path del componente? ${chalk.gray(`(ej: ${name} o src/components/${name}/${name})`)}`,
default: name,
suffix: ":",
},
{
type: "list",
name: "componentType",
message: "¿Qué tipo de componente deseas crear?",
choices: [TYPES.ALL, TYPES.JSX, TYPES.TEST, TYPES.STORY, TYPES.CSS],
},
{
type: "confirm",
name: "hasTypescript",
message: "¿Deseas usar Typescript?",
default: true,
},
];
inquirer.prompt(questions).then((answers) => {
const { componentPath, componentType, hasTypescript } = answers;
const translatedComponentType = hasTypescript
? translateType(componentType)
: componentType;
const componentTemplates = createComponentsTemplates(
translatedComponentType,
hasTypescript
);
createFiles(componentPath, componentTemplates);
});
});
program.parse(process.argv);