file-fairy
v1.1.1
Published
Magical file generator
Downloads
6
Readme
😽🪄 File Fairy
If you're tired of constantly creating the same files and folders, or you are creating too much boilerplate code, this package will save you time!
You can use default templates with options or create your own.
Install
You have several options:
- Install in your project
- run
npm install file-fairy -D
- add
ff.config.json
in the root folder of your project, if you want to customize the package
- run
- Global install
- run
npm install file-fairy -g
- add
ff.config.json
in the root folder of your project, if you want to customize the package
- run
- Installation in a project with a non-frontend stack
- be sure that you are using node.js higher than 16 version
- run
npm install file-fairy -g
- be sure to add
ff.config.json
in the root folder of your project
Using default templates
Use this command in the terminal: ff g {alias} {path} --{options}
for generate default template, where
alias
- a name of templatepath
- path to the creating fileoptions
- options for this template
E.g.:
ff g rct ./src/components/SomeComponent --nost
- Will create react typescript component without style file
Read more about options for templates on their pages:
- React Typescript component
ff g rct ./src/components/SomeComponent
- React Typescript hook
ff g rht ./src/components/useSomeHook
- Arrow Typescript function
ff g aft ./src/components/someFunction
- React component
ff g rc ./src/components/SomeComponent
- React hook
ff g rh ./src/components/useSomeHook
- Arrow function
ff g af ./src/components/someFunction
Creating custom templates
- Create
.ff-templates
folder in your project (or with your name, see config file options) - Create a new folder for template (a folder name doesn't matter)
- Add templates using handlebars
- Add
config.json
file with contract - Use
ff gc {alias} {path} --{options}
for generate your template, wherealias
- your shortcut from config-jsonpath
- path to the creating fileoptions
- options for this template
E.g.:
ff gc my-temp ./src/Test --myVar=hello --skipTest
- Will create your template with options
We can use the next helpers in template:
uppercaseFirstLetter
- makes the first letter uppercaselowercaseFirstLetter
- makes the first letter lowercase 3toCamelCase
- transform text to camel case 4name
- this name of your file from cli command. E.g.ff gc my-temp ./src/MyCustomComponent
name will be equalMyCustomComponent
5vars
- this object with your options from cli command. E.g.ff gc my-temp ./src/Test --myVar=hello --skipTest
vars will be equal
We can use your variables for options in templates.{ "myVar": "hello", "skipTest": true }
See full custom template example
Config file options
You can create ff.config.json
with following options:
custom-templates-folder
- set another folder with your custom templates (instead of.ff-templates
)templates
(and thencomponent-name
) - set options for default templates, they'll apply to every generate. Read more on the doc page for each template
{
"custom-templates-folder": "my-template-folder",
"templates": {
"react-ts-component": {
"rewriteFiles": [],
"useTypesInComponent": true
}
}
}
CLI commands
ff g {alias} {path} --{options}
- generate default template with optionsff gc {alias} {path}
- generate your custom templateff gc {alias} {path} --KEY=VALUE
- generate template with your variables, they'll be added to the templates
ff version or -v
- show version
If you have any questions or suggestions, text me on linkedin