Simple code generator for JS/JS applications
Report Bug
Β·
Request Feature
- About the Project
- Getting Started
- Manage generators
- Using a generator
- Roadmap
- Development
- Contributing
- License
- Built With
- Contact
Generilla
is a tool for running generilla code generators
. See below how to make your own generator with Generilla
.
To avoid problems with permissions and sudo
, it is possible to install the package locally and then add it's folder to PATH
variable.
-
Create
~/.node
foldermkdir ~/.node
-
Install the package
yarn global add @generilla/cli --prefix ~/.node
-
Add
~/.node
folder toPATH
export PATH=${PATH}:${HOME}/.node/bin
-
Add the command above to
~/.bashrc
(or~/.bash_profile
in case of MacOS) -
You should be able to run the
generilla
CLI command now
If you followed the way how the installation was done, then do upgrading as following:
yarn global upgrade @generilla/cli --prefix ~/.node
Generilla allows to bootstrap a skeleton generator to boost up the progress. Type
generilla scaffold
to create a new generator in the current folder.
You will see the following file structure:
generator-name/
β-- template/ <-- file templates
βββ index.js <-- generator logic
If you open index.js
for editing, you will see a lifecycle of a generator.
The typical lifecycle of a generator is the following:
- run
async onBeforeExecution()
- ask questions returned by
async getQuestions()
- refine answers by running
async refineAnswers()
- install dependencies, if
async getDependencies()
returned a non-empty list - install dev dependencies, if
async getDevDependencies()
returned a non-empty list - run
async onAfterExecution()
All of these methods are optional, use them only when you need them.
Inside of each file in template/
folder you may use ejs template syntax.
For example, let's say you have two questions: use_react
and generator_name
.
Then in any file you can write something like
Hello, this is <%- generator_name %> speaking!
.
Furthermore, you can inject these templates into the name of the files, by naming the files like this:
hello-[generator_name].js
. All symbols, except [a-zA-Z0-9_-\.]
will be omitted.
You can also conditionally enable or disable rendering of files or sub-folders, by giving names like this:
[?use_react]react/
or [?use_react][generator_name].saga.ts
.
Each function in the lifecycle has access to the following properties of the generator object:
this.answers
- list of answers provided by a userthis.originalAnswers
- list of answers before runningrefineAnswers()
this.context
- an object than contains the following data:generatorPath
- a folder where the generator is locateddestinationPath
- a folder where the output will be placed (by default it is a current folder)
this.util
- an object that contains references to some tools:inquirer
- a reference to inquirerexeca
- a reference to execaejs
- a reference to ejscaseFormatter
- a reference to caseFormattermakeTemplate()
- an internal tool for processing folders other thantemplate/
const template = this.util.makeTemplate(absolutePathToOtherTemplateFolder); await template.copy(absoluteDestinationPath, answers);
Each generator may have package.json
next to index.js
file. In this case, after linking a generator generilla
will automatically run
yarn
or
npm install
on it.
If you need more examples, check out these generators.
A generator created with generilla scaffold
appears in the generator list automatically.
If you have another generator made manually, you can add it by typing
generilla generator add <absolute-path-to-generator>
You can type afterwards
generilla list
to see if the generator is really there.
If you have a generator that is hosted as a GitHUB repository, it is possible to link it by typing
generilla generator add https://github.com/joe/generator
If you have a mono-repository with several generators laying in sub-folders, the following also works:
generilla generator add https://github.com/joe/generators/tree/master/generator/foo/bar
Note that currently only master
branch is supported.
You can also use this syntax:
generilla generator add https://github.com/joe/generators.git|/generator/foo/bar
or:
generilla generator add git@github.com:joe/generators.git|master|/awesome.generator/foo/bar
Whatever works for you better.
βΉοΈ If there is a package.json
file located next to the index.js
file, then when the remote generator is linked, Generilla
will try to install the dependencies automatically.
To pull new changes made on the remotely linked generator, type
generilla generator update <wildcard>
Where <wildcard>
is a wildcard matched against the generator name
or id
.
For instance, to update all remote generators, type
generilla generator update \*
or
generilla generator update gen-*
To remove one or several generators of any type, use
generilla generator remove <wildcard>
Local generators will not be removed physically, they get un-symlinked.
One way or another, as soon as the generator is in the list, type
generilla
You should be able to see your generator in the list. After choosing a generator and answering some questions π΅οΈ the output will be generated in the current folder.
Type generilla -h
to find out about all available commands.
- Bugfixing :)
- Better edge cases handling.
- Allow
generilla
to run a generator without linking it, like this:generilla run /path/to/generator
. - Enable making of
self-executable
generators, that are distributed as annpm package
and export a CLI command that runsgenerilla run <generator>
. This will allow usingyarn create <generator-name>
, which is quite cool.
See the open issues for a list of proposed features (and known issues).
- Clone the repo
git clone https://github.com/gannochenko/generilla.git
- Install NPM packages
cd generilla; yarn; yarn run boostrap;
- Link the
core
packagecd packages/core; yarn link; cd ../cli; yarn link @generilla/core;
- Go back to
core
and start watching for changescd ../core; yarn run build:watch;
- In the other terminal go to
cli
and runyarn start
cd ../cli;
yarn start
executes main cli binary. Use the development version as usual, for exampleyarn start list
will be the same asgenerilla list
and so on. The generated data will appear in the_output
folder, and linked generators - in_generators
folder.
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Sergei Gannochenko - Linkedin
Project Link: https://github.com/gannochenko/generilla