sff-tool
v0.1.4
Published
Scaffolding Tool - CLI
Downloads
7
Maintainers
Readme
SFF Tool (Scaffolding Tool)
SFF-Tool es un CLI escrito en Node JS, nos permite generar código a partir de plantillas y de funciones de node js, tiene como objetivo estructura un proyecto, conservando el estilo de arquitectura o patron dado.
Motivación
Diseña un código una vez y permite que este CLI construya la estructura que puede ser repetible, escalable y mantenible. Puedes diseñar una forma de generar código sin limitarse a los CLI que existe actualmente. No existirá limitaciones sobre lo que podrás definir.
Instalar de forma Global
npm install sff-tool -g
sff-tool -v
Iniciar
Para iniciar debes construir la estructura de carpetas para el scaffolding, debe estar a nivel de tu proyecto o nivel superior, usa el siguiente comando:
sff-tool -c
Definiciones de carpetas
Scaffolds
En esta carpeta se diseñan las entradas que se requiren para la generación del código, son input para las ejecuciones del script del comando. Esta función debe tener la siguiente estructura:
scaffolds/react-component.js
module.exports = {
templates: ["index"],
command: "generater-component",
questions:
[
{
name: "component",
type: "input",
message: "¿Nombre del component?",
transformer: (data) => {
return data.charAt(0).toUpperCase() + data.slice(1)
}
}
]
};
- El atributo questions es el prompt del modulo Inquirer.
- El atributo command hace referencia al script de la carpeta commands
- Y el atributo templates es un arreglos donde se mapea las variables de entrada con un .tpl que esta definido en la carpeta templates.
Commands
La carpeta commands es donde se guarda las funciones que se deben ejecutar según varias entradas.
commands/generater-component.js
module.exports = (shell, temps, answers) => {
const dir = "src/component/"+answers['component'];
shell.mkdir("-p", dir);
shell.ShellString(temps["index"]).to(dir+"/index.js");
return "OK";
}
ARGUMENTOS
- shell: este objecto hace referencia al modulo Shell donde puedes realizar diferentes instrucciones de comandos.
- temps: es una lista mapeada de todos los templates.
- answers: es un mapa que contiene las respuestas del prompt.
Templates
En este directorio encontramos todos los templates que puede ser usados para generar código o esqueletos. Un .tpl tiene la siguiente forma:
templates/index.tpl
import react from "react";
class {{component}}Component extends react.Component {
construct(){
}
render(){
return <p />
}
}
Las variables de las entradas del prompt, y son definidas con las llaves. Son archivos planos.
¿Cómo lanzar el scaffolding?
El nombre del archivo que se tiene en la carpeta scaffolds es el nombre del comando que se debe lanzar, ejemplo:
sff-tool react-component
Donde react-component hace referencia a scaffolds/react-component.js
NOTA: Puedes ver todos los comandos usando:
sff-tool --help