Templating, scaffolding and generation tool
Genesis is a templating and scaffolding tool.
A Genesis template is a manifest of options and files written in yaml or json. Option values can be provided in various ways otherwise you will be interactively asked for inputs. Template files are written in Stencil. The list of files can make use of dynamic paths and be generated multiple times depending on the format of the input.
The very simple example:
options:
- name: project
description: The name of the project
question: What is the name of your project?
required: true
type: string
files:
- template: project.stencil
path: "{{ project }}.project"
And then run like this:
$ genesis generate template.yml
What is the name of your project? MyProject
Generated files:
MyProject.project
Or you can provide the required options via arguments
$ genesis generate template.yml --options name:MyProject
Generated files:
MyProject.project
Much more powerful templates are possible. See more complete documentation here
Make sure Xcode 13 is installed first.
$ mint install yonaskolb/genesis
$ git clone https://github.com/yonaskolb/Genesis.git
$ cd Genesis
$ make
Use CLI
$ git clone https://github.com/yonaskolb/Genesis.git
$ cd Genesis
$ swift run mint
Use as dependency
Add the following to your Package.swift file’s dependencies:
.package(url: "https://github.com/yonaskolb/Genesis.git", from: "0.1.0"),
And then import GenesisKit
. See GenesisKit for more information.
Run genesis help
for usage instructions
Usage: genesis generate <templatePath> [options]
Options:
-d, --destination <value> Path to the directory where output will be generated. Defaults to the current directory
-h, --help Show help information for this command
-n, --non-interactive Do not prompt for required options
-o, --options <value> Provide option overrides, in the format --options "option1: value 2, option2: value 2.
-p, --option-path <value> Path to a yaml or json file containing options
Options will be passed to the template in the following order, merging along the way, with duplicate options overriding the previous ones.
Set any environment variables before you call generate, or use already existing ones from your development environment
name="My Name" genesis generate template.yml
Pass a path to a json or yaml file with --option-file
This can include more structures and complex data. For example:
name: MyProject
targets:
- name: MyTarget
type: application
- name: MyFramework
type: framework
Pass specific options with --options
like this
-- options "option1: value 2, option2: value 2"
Genesis will ask you for any missing options if they are required. You can turn off interactive input with --non-interactive
.
Each option can have a default value
which be used as a fallback.
If an option is required and still hasn’t received a value from anywhere, generation will fail.
A genesis template is a yaml or json file that includes a list of options
and files
Options are structured input for the Stencil
templates. They serve as documentation and allow for Genesis to interactively ask for input.
string
but can be any one of the following:
string
a simple stringboolean
a booleanchoice
a string from a list of choices. Requires choices
to be definedarray
an array of other options. If child options
are defined, if will be an array of options, otherwise it will split a string by command, removing any whitespace betweenarray
type contains objectsStencil
tags to make it dynamic.path
to differentiate them.{% if type == 'framework' %}
you would write type == 'framework'
Each Stencil template has all the filters available in StencilSwiftKit, and has access to all the options. See Stencil for more info about tags.
Small example:
{% if name %}
name: {{ name }}
{% endif %}
The library GenesisKit
can be used to easily provide generation in your own tools.
import GenesisKit
// create a context
let context: [String: Any] = ["name": "hello"]
// create a template, either from a file or programmatically
let template = try GenesisTemplate(path: "template.yml")
// Create the generator
let generator = try TemplateGenerator(template: template)
// generate the files
let generationResult = try generator.generate(context: context, interactive: false)
// write the files to disk
try generationResult.writeFiles(path: "destination")
Pull requests and issues are welcome
Genesis is licensed under the MIT license. See LICENSE for more info.