MatchaBot is a code generator written in TypeScript.
You can use matchabot to create an entire project, or to generate code inside an existing project in a consistent way.
This tool has been created to offer a "Ruby on Rail" like programming experience with any projects: React / Vue / Angular, NextJS / Gatsby, etc ...
The complete documentation of the project is available at https://www.matchabot.site/
- β Easy to use in project generator
- β You can create your own generator by project, or use a global templates repository
- β Templating language support: HandleBars and EJS
- β Powerful command line support: automatic CLI arguments and automatic prompts for missing arguments
- β Simplified workflow to create new generators for you own project
- β Debug mode
- β Add new file to your project
- β Modify existing files
- β You can generate any kind of files/projects (NodeJS, typescript, Javascript, SQL, C++, C, Go, ...)
- β Simple and Powerful
- β Save time and Boost your productivity
- β Enforce a consistent project structure
- β Easier team onboarding with a codified best practices stored inside each project
- β Fun to use π¦
- π A code generator is identified by a name
- π A code generator offer one or more commands
- π A command takes a list of arguments as input and execute a list of actions βοΈ.
- π οΈοΈA generator action is specified by one or multiple template written with a templating language such as HandleBars or EJS
- π The generators definition are stored inside your project inside the
./_machatbot
directory as a subdirectory - π commands are defined by a
matchabot.cmd.json
file inside the./_machatbot/--generator-name--
directory
Execute the following command at the root of your project.
yarn add matchabot --dev
or
npm install matchabot --save-dev
π‘ matchabot can be installed globally with
npm install -g matchabot
Execute the following command at the root of your project.
matchabot init
π This command create a local directory ./_matchabot
inside your current project directory
Content of _matchabot
_matchabot
βββ license
βΒ Β βββ add
βΒ Β βΒ Β βββ apache2.md.hbs
βΒ Β βΒ Β βββ bsd.md.hbs
βΒ Β βΒ Β βββ gnu3.md.hbs
βΒ Β βΒ Β βββ matchabot.cmd.json
βΒ Β βΒ Β βββ mit.md.hbs
βΒ Β βββ matchabot.json
βββ react-app
βββ create-app
βΒ Β βββ matchabot.cmd.json
βΒ Β βββ template
βββ create-component
βΒ Β βββ component.tsx.hbs
βΒ Β βββ matchabot.cmd.json
βΒ Β βββ stories.tsx.hbs
βΒ Β βββ style.tsx.hbs
βββ matchabot.json
In this example, the _matchabot
is composed of 2 generators
- license
- react-app
Each generator is defined by a matchabot.json
file
Example for license
{
"name": "license",
"description": "π Add licence to your project",
"version": "1.0.0"
}
Each subdirectory contains a definition of a command associated with a generator
For the react-app
generator we have 2 commands:
create-app
create-component
Each subdirectory contains a matchabot.cmd.json file that defines the commands and list of actions to perform.
Example ./_matchabot/license/add/matchabot.cmd.json
:
{
"name": "add",
"description": "add a licence file to your project",
"version": "1.0.0",
"args": [
{
"name": "CopyRightsHolder",
"alias": "c",
"type": "string",
"default": "{{process.env.LOGNAME}}"
},
{
"name": "ProgramDescription",
"alias": "p",
"type": "string"
},
{
"name": "LicenceType",
"type": "list",
"choices": [
{ "name": "MIT License", "value": "mit" },
{ "name": "BSD License", "value": "bsd" },
{ "name": "Apache License, Version 2.0", "value": "apache2" },
{ "name": "GNU General Public License version 3", "value": "gnu3" }
],
"default": "MIT"
}
],
"actions": [
{
"type": "template",
"name": "Generate Licence",
"source": "{{toLowerCase LicenceType}}.md.hbs",
"target": "LICENCE.md"
}
]
}
In this example, the args
array contains a list of arguments (variables) that will be used in the templates.
Example of template Handlebar syntax
In this example with only have 1 action: select a template from "source": "{{toLowerCase LicenceType}}.md.hbs"
and generates a file "target": "LICENCE.md"
matchabot list
π This command gives the list of defined generators
__ __ _ _ ____ _
| \/ | __ _| |_ ___| |__ __ _ | __ ) ___ | |_
| |\/| |/ _` | __/ __| '_ \ / _` | | _ \ / _ \| __|
| | | | (_| | || (__| | | | (_| | | |_) | (_) | |_
|_| |_|\__,_|\__\___|_| |_|\__,_| |____/ \___/ \__|
Version: 0.3.0 π΅
Availables generators
---------------------
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ¬βββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β name β description β version β location β
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β generator β π€ Built-in generator of generators: create your own generator β 1.0.0 β ./_matchabot/generator β
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β license β π Add licence to your project β 1.0.0 β ./_matchabot/license β
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β react-app β π react app generator β 1.0.0 β ./_matchabot/react-app β
ββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Lists all the commands of the generator react-app
matchabot react-app list
Result
__ __ _ _ ____ _
| \/ | __ _| |_ ___| |__ __ _ | __ ) ___ | |_
| |\/| |/ _` | __/ __| '_ \ / _` | | _ \ / _ \| __|
| | | | (_| | || (__| | | | (_| | | |_) | (_) | |_
|_| |_|\__,_|\__\___|_| |_|\__,_| |____/ \___/ \__|
Version: 0.3.0 π΅
Availables command(s) for react-app
-----------------------------------
ββββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ¬βββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β name β description β version β location β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β create-app β create a typescript react app β 1.0.0 β ./_matchabot/react-app/create-app β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β create-component β generate a Styled React Component, and an associated story β 1.0.0 β ./_matchabot/react-app/create-component β
ββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Creation of a React Application using a template generator
matchabot react-app create-app
Result
__ __ _ _ ____ _
| \/ | __ _| |_ ___| |__ __ _ | __ ) ___ | |_
| |\/| |/ _` | __/ __| '_ \ / _` | | _ \ / _ \| __|
| | | | (_| | || (__| | | | (_| | | |_) | (_) | |_
|_| |_|\__,_|\__\___|_| |_|\__,_| |____/ \___/ \__|
Version: 0.3.0 π΅
? ApplicationName MyReactApp
π΅ Generating files ...
π Created files