module-butler v1.0.3
module-butler
A CLI that takes in module names and outputs a folder for each module name.
Table of Contents
Geting started
- Install module-butler within your project or globally or use it with
npxdirectly.
yarn add -D module-butleror
npm install -D module-butleror
npx module-butler init- Set up module-butler by running:
module-butler initor
npx module-butler init- Makes changes in
.module-butler/config.js - Make changes to any template in
.module-butler/templates/. - Add your GraphQL fragments in
.module-butler/inpug.graphql. (See example) - Generate your modules by running:
module-butler generateor
npx module-butler generateExample
The following example used the templates that come out-of-the-box when running module-butler init.
Input
// .module-butler/input.graphql
Hello,
World
// Tip: add all your modules to generate all modules at the same time.Outputs
modules/is the default output directory. You can change it by changingoutputDirectoryin.module-butler/config.js.
// modules/Hello/index.js
console.log('module name:', 'Hello');// modules/World/index.js
console.log('module name:', 'World');Tips
Add a script in package.json
It is recommended to add a script in package.json, that runs module-butler generate and any other script, like prettier.
For example:
{
"scripts": {
"module-butler": "module-butler generate && relay-compiler && prettier --write modules/"
}
}Then you can just run npm run module-butler or yarn module-butler.
Adding/removing/customizing templates
By default, running module-butler init, provides you with a default index.js template and you can change it any way you want. You can then, for example, create a utils.ts template for your utility functions. You can even change the file name of the template, like adding the module name, {{name}}, or changing the file extension to .ts instead of .js.
Templates
Templates in .module-butler/templates/ use handlebars as the templating language.
- Both the file name and file content are templatable, and have access to the same handlebars context.
- You can refer to
.module-butler/templateAPI.tsfor the full handlebars context. - You can add or remove templates
- The handlebars file extension of templates (i.e.
.hbs) is removed when generating your modules, but you are free to remove it from the template itself. The.hbsextension is only used for code editors, like VS Code, to recognize that its a handlebars file and give you syntax highlighting for that.
Usage
$ npm install -g module-butler
$ module-butler COMMAND
running command...
$ module-butler (-v|--version|version)
module-butler/1.0.3 darwin-x64 node-v14.17.1
$ module-butler --help [COMMAND]
USAGE
$ module-butler COMMAND
...Commands
module-butler generate [MODULE1] [MODULE2] [MODULE3] [MODULE4] [MODULE5] [MODULE6] [MODULE7] [MODULE8] [MODULE9] [MODULE10]module-butler help [COMMAND]module-butler init
module-butler generate [MODULE1] [MODULE2] [MODULE3] [MODULE4] [MODULE5] [MODULE6] [MODULE7] [MODULE8] [MODULE9] [MODULE10]
generates modules using module names (comma and/or line separated) in .module-butler/input and template files in the templates directory.
USAGE
$ module-butler generate [MODULE1] [MODULE2] [MODULE3] [MODULE4] [MODULE5] [MODULE6] [MODULE7] [MODULE8] [MODULE9]
[MODULE10]
ARGUMENTS
MODULE1 Name of module
MODULE2 Name of module
MODULE3 Name of module
MODULE4 Name of module
MODULE5 Name of module
MODULE6 Name of module
MODULE7 Name of module
MODULE8 Name of module
MODULE9 Name of module
MODULE10 Name of module
OPTIONS
-F, --force forcibly overwrite existing files
-h, --help show help for generate commandSee code: src/commands/generate.ts
module-butler help [COMMAND]
display help for module-butler
USAGE
$ module-butler help [COMMAND]
ARGUMENTS
COMMAND command to show help for
OPTIONS
--all see all commands in CLISee code: @oclif/plugin-help
module-butler init
sets up module-butler by creating config.js, templates/*.hbs files, input in .module-butler/ directory.
USAGE
$ module-butler init
OPTIONS
-h, --help show help for init commandSee code: src/commands/init.ts