A CLI that takes in module names and outputs a folder for each module name.
- Install module-butler within your project or globally or use it with
npx
directly.
yarn add -D module-butler
or
npm install -D module-butler
or
npx module-butler init
- Set up module-butler by running:
module-butler init
or
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 generate
or
npx module-butler generate
The following example used the templates that come out-of-the-box when running module-butler init
.
// .module-butler/input.graphql
Hello,
World
// Tip: add all your modules to generate all modules at the same time.
modules/
is the default output directory. You can change it by changingoutputDirectory
in.module-butler/config.js
.
// modules/Hello/index.js
console.log('module name:', 'Hello');
// modules/World/index.js
console.log('module name:', 'World');
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
.
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 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.ts
for 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.hbs
extension is only used for code editors, like VS Code, to recognize that its a handlebars file and give you syntax highlighting for that.
$ 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
...
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 command
See code: src/commands/generate.ts
display help for module-butler
USAGE
$ module-butler help [COMMAND]
ARGUMENTS
COMMAND command to show help for
OPTIONS
--all see all commands in CLI
See code: @oclif/plugin-help
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 command
See code: src/commands/init.ts