Skip to content

Commit 6772355

Browse files
committed
Primera versión del generador de ficheros añadido correctamente
1 parent 1533564 commit 6772355

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
package-lock.json

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Creador de ficheros mediante CLI
2+
En este proyecto vamos a poder crear un fichero introduciendo el nombre y la extensión que deseamos.
3+
4+
## Instrucciones
5+
Para un correcto uso, hay que seguir estas instrucciones.
6+
7+
### Instalación
8+
9+
* GLOBAL
10+
```
11+
npm install -g cli-file-creator
12+
```
13+
* LOCAL
14+
```
15+
npm install cli-file-creator
16+
```
17+
18+
### Para usarlo
19+
* Global
20+
Ejecutamos **cli-file-creator**
21+
* Local
22+
Añadir en el package.json
23+
```
24+
"scripts": {
25+
"cli-file-creator": "./node_modules/.bin/cli-file-creator"
26+
},
27+
```
28+
Ejecutamos con
29+
```
30+
npm run cli-file-creator
31+
```

index.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env node
2+
3+
const shelljs = require('shelljs');
4+
const chalk = require('chalk');
5+
const figlet = require('figlet');
6+
const inquirer = require('inquirer');
7+
8+
ficheroOK = filepath => {
9+
console.log(
10+
chalk.white.bgGreen.bold(
11+
`¡Muy bien! Fichero correctamente creado en el directorio ${filepath}`
12+
)
13+
);
14+
}
15+
const crearFichero = (nombreFichero, extension) => {
16+
const pathFichero = `${process.cwd()}/${nombreFichero}.${extension}`;
17+
shelljs.touch(pathFichero);
18+
return pathFichero;
19+
}
20+
const hacerPreguntas = () => {
21+
const preguntas = [
22+
{
23+
name: "FICHERO",
24+
type: "input",
25+
message: "¿Cómo se va a llamar tu fichero? (sin la extensión)"
26+
},
27+
{
28+
name: "EXTENSION",
29+
type: "list",
30+
message: "¿Qué extensión tiene tu fichero",
31+
choices: [".rb", ".js", ".kt", ".java", ".ts", ".php"],
32+
filter: function(val) {
33+
return val.split(".")[1];
34+
}
35+
}
36+
];
37+
return inquirer.prompt(preguntas);
38+
}
39+
const iniciar = () => {
40+
console.log(
41+
chalk.green(
42+
figlet.textSync( "Creador Ficheros", {
43+
font: "Bubble",
44+
horizontalLayout: "default",
45+
verticalLayout: "default"
46+
})
47+
)
48+
);
49+
};
50+
const ejecutar = async () => {
51+
// Mostrar la información de la librería en la cabecera, el título con figlet
52+
iniciar();
53+
// Preguntas necesarias para crear el fichero, es decir, el nombre y la extensión
54+
const respuestas = await hacerPreguntas();
55+
const { FICHERO, EXTENSION } = respuestas;
56+
console.log(respuestas);
57+
// Creamos el fichero
58+
const pathFichero = crearFichero(FICHERO, EXTENSION);
59+
// Añadimos mensaje que fichero se ha creado correctamente
60+
ficheroOK(pathFichero);
61+
};
62+
63+
64+
ejecutar();

package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "cli-file-creator",
3+
"version": "1.0.0",
4+
"description": "Proyecto CLI para generar ficheros de manera fácil",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/npm-js-ts-angular-modules-course/proyecto-1d-ficheros-cli.git"
12+
},
13+
"keywords": [
14+
"rb",
15+
"js",
16+
"ts",
17+
"kt",
18+
"java",
19+
"cli generator",
20+
"crear ficheros"
21+
],
22+
"author": "Anartz Mugika <mugan86@gmail.com>",
23+
"license": "MIT",
24+
"bugs": {
25+
"url": "https://github.com/npm-js-ts-angular-modules-course/proyecto-1d-ficheros-cli/issues"
26+
},
27+
"homepage": "https://github.com/npm-js-ts-angular-modules-course/proyecto-1d-ficheros-cli#readme",
28+
"dependencies": {
29+
"chalk": "^2.4.2",
30+
"figlet": "^1.2.1",
31+
"inquirer": "^6.2.2",
32+
"shelljs": "^0.8.3"
33+
},
34+
"bin": "./index.js"
35+
}

0 commit comments

Comments
 (0)