Giter8 Documentation
repository·develop·Indexed 23 days ago
https://github.com/foundweekends/giter8Giter8 is a command line tool designed to scaffold files and directories using templates stored in Git repositories. It supports GitHub shorthand, full Git URLs, and local file paths. The tool allows for template parameterization via default.properties, conditional logic in files and directories, and programmatic integration into Scala applications via the Giter8 and Runner classes.
What's inside Giter8
- Giter8 is a command line tool used to generate files and directories from templates. These templates can be published on GitHub or any other git repository. While implemented in Scala and typically run via the sbt launcher, it is capable of producing output for any purpose.
Use the $package$ placeholder for directory structures
developIn Giter8 templates, you can use the$package$placeholder in file paths. When the template is instantiated,$package$expands into the directory structure corresponding to the provided package name (e.g.,net.databinderexpands tonet/databinder).Authenticate with Giter8 templates
developGiter8 no longer uses its own internal authentication mechanisms. Instead, it relies on your system's Git configuration. If you can successfully clone a repository using thegitcommand in your terminal, you can apply that template with Giter8.Use the experimental root layout in Giter8
developGiter8 0.7.0 introduces an experimental root layout. By default, Giter8 looks for templates in
src/main/g8. With the root layout enabled, if Giter8 cannot find that directory, it will use the root directory of the specified Git repository as the template directory.Constraints and Behavior:
- The
default.propertiesfile can be placed in either the root directory or theprojectdirectory. - Limitation: You cannot include template fields in files located under the
projectdirectory when using this layout. This makes the root layout primarily suitable for simple templates.
- The
Use template expansion in file and directory names
developGiter8 supports performing template expansion within file and directory names. This allows you to use placeholders (e.g.,
$MainClass$) directly in your file paths within the template structure.src/main/g8/src/main/scala/$MainClass$.scalaCreate a scaffold in a GitHub project
developTo define scaffolds within a GitHub project, place them in the
src/main/scaffoldsdirectory.- Each subdirectory inside
src/main/scaffoldsrepresents a unique scaffold and is accessible in the sbt shell by its directory name. - You can include a
default.propertiesfile in a scaffold directory to define default field values. - The
namefield: If anameproperty is defined in the scaffold, the generated output will be placed in a directory named after that value, preserving the subdirectory layout of the source scaffold.
- Each subdirectory inside
Evaluate truthiness in Giter8 templates
developWhen using the
truthyproperty in conditional expressions, the following evaluation rules apply:- True: `
Use conditionals in templates
developGiter8 supports conditional expressions using the
.truthyproperty of fields. A field is considered truthy if its value is"y","yes", or"true". Any other value is false.Conditional Logic in Files
$if(scala212.truthy)$ scalaVersion := "2.12.3" $elseif(scala211.truthy)$ scalaVersion := "2.11.11" $else$ scalaVersion := "2.10.6" $endif$Conditional Files and Directories
You can use conditionals in file paths to include or exclude files/directories. To skip a directory in the path while keeping its children, use
.as the name:src/main/g8 ├── $name__normalize$ │ ├── $if(jvm.truthy)$jvm$endif$ │ │ └── src │ │ └── main │ │ └── scala │ │ └── $organization__packaged$ │ │ └── $name;format="Camel$".scala$if(scala212.truthy)$ scalaVersion := "2.12.3" $elseif(scala211.truthy)$ scalaVersion := "2.11.11" $else$ scalaVersion := "2.10.6" $endif$Use template comments to hide text from output
developTo include comments for template maintainers that should not appear in the generated files, wrap them in
$!and!$. These comments ignore any internal$substitutions$or invalid tags.$! This comment won't appear in the output ! // This comment will appear in the output $! This multiline comment won't appear either No matter how long it is Internal $substitutions$ are ignored. Even $invalid$ !$Use the `random` formatter for template properties
developGiter8 supports arandomformatter for template properties. This formatter appends random characters to a given string.Install Giter8 using Coursier
developThe recommended way to install Giter8 and other Scala command line tools is via Coursier.
- Install Coursier and ensure the
csbinary is in your systemPATHfollowing the official installation instructions. - Run the following command to install Giter8:
cs install giter8To update your existing Giter8 installation, use:
cs update g8- Install Coursier and ensure the
Authenticate with GitHub using g8 --auth
developYou can authenticate with GitHub using the
g8 --authcommand. This implementation uses GitHub's client-side OAuth support. When using thelogin passwordmethod, your actual password is not stored locally; instead, an OAuth access token is generated and stored in~/.g8/configfor future use.g8 --auth login password