Skip to content

Latest commit

 

History

History
133 lines (95 loc) · 3.49 KB

readme.adoc

File metadata and controls

133 lines (95 loc) · 3.49 KB

Acorn

Grow your project tree from acorn!

Acorn is a simple file tree template engine inspired by lazybones project.

The Acorn lets you create archetypes for any kind of project or file structures.

Note
Since 0.3.0 Acorn requires Java 17+

Getting Started

The Acorn has two version: Groovy (Java) library and CLI for it.

Get library for scripts and code

  • group: com.ainrif.acorn

  • artifact: core

  • version: Artifact Version

Get binary to use in system

Usage

; acorn --help

Usage: acorn [-hV] -d=PATH -s=PATH [-p=KEY=VALUE]...
  -d, --dest=PATH         Destination directory. Will be created if absent
  -h, --help              Show this help message and exit.
  -p, --param=KEY=VALUE   Params to render template
  -s, --src=PATH          Template source directory
  -V, --version           Print version information and exit.

Features

Content parametrisation

Replace placeholders with given data in files with extension .tmpl

simple.txt.tmpl
Dear ${user}. You have ${count} thing${count > 1 ? 's' : ''} in your cart.
Total price is \$${totalPrice}

With next params user=Joe, count=2, totalPrice=42 the file above will be resolved into file w/o .tmpl extension

simple.txt
Dear Joe. You have 2 things in your cart.
Total price is $42 (1)
  1. - to escape the $ sign use \

Template scripting

You can use groovy for scripting inside file templates because they are GStringTemplateEngine

advanced.txt.tmpl
Dear <%= user%>. You have <% out << count %> thing<%
 if (count > 1) {
    out << 's'
 }
 %> in your cart.
Total price is \$${totalPrice}

This template will be rendered the same as previous one but uses full-fledged programming language in it

File name parametrisation

Placeholders can be used in plain file and template names

./src
└── ${nameVar}-file.txt
└── ${nameVar}.txt.tmpl

Generate folder path with placeholders

You can generate nested hierarchy by templating folder names

./src
├── ${emptyValue}
│   └── file-in-root.txt
├── ${folderVar}
│   └── nested-file.txt
└── ${nameVar}-file.txt

params: [nameVar: 'named', folderVar: 'one/two/three', emptyValue: '']

./dest
├── file-in-root.txt
├── named-file.txt
└── one
    └── two
        └── three
            └── nested-file.txt

Folder holder

If you store your templates in git you cannot store here empty folder. To keep structure of empty folders use file with name HOLDER. Acorn just ignore them and creates empty folder.

./src
└── empty-folder
    └── HOLDER

Acorn Development

Release

  • configure ~/.gradle/gradle.properties and import Ainrif General GPG.

  • call gw clean build publishToSonatype closeAndReleaseSonatypeStagingRepository to release lib.

  • tag release commit with version git tag <version from build.gradle> && git push --tags

  • create new release with binary in GitHub manually