pkrll / Hazel

🌰 A scaffolding tool that'll help you kickstart new projects with ease

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status codecov

Hazel is a cross-platform project scaffolding tool that makes it easier to start new projects. The CLI application generates the directory structure and boilerplate code for your projects, based on predefined templates, and can easily be customized and extended.

  • Generate project structure based on templates
  • Support for macOS
  • Support for Linux (tested on Raspbian Stretch Lite)

Table of contents

Installation

Hazel has been tested on macOS High Sierra (10.13) and Mojave (10.14).

Prerequisites

  • Swift 4.0

Install with Homebrew

This is currently not working, as of Homebrew 2.0.0. Please install with Make, instead.

Tap into my personal repository of Homebrew formulas, and install using the --no-sandbox flag.

$ brew tap pkrll/tap
$ brew install hazel --no-sandbox

Install with Make

Clone this repository, and run make install:

$ git clone https://github.com/pkrll/Hazel
$ cd Hazel
$ make install

This will install Hazel in /usr/local/bin, along with its templates files in ~/.hazel.

Usage

Run Hazel inside the root folder for your project with the init command, along with the --template, or -t, flag to generate the directory structure and the files:

$ mkdir SomeApp && cd SomeApp
$ hazel init --template c

Created obj
Created bin
Created tests
Created src
Created obj/.gitkeep
Created bin/.gitkeep
Created Makefile
Created tests/SomeApp_test.c
Created src/SomeApp.c
Created .editorconfig

Customization

Hazel generates new projects based on predefined templates, placed in ~/.hazel/templates. You can add your own templates by simply creating a desired directory structure, along with the files you want to be automatically generated, in a subdirectory to ~/.hazel/templates.

The name of the subdirectory will serve as the name of the template.

Example

Let's create a (very) simple template for Swift projects.

$ cd ~/.hazel/templates

$ mkdir Swift && cd Swift
$ touch README.md
$ mkdir src
$ touch src/__PROJECTNAME__.swift

# __PROJECTNAME__ is a placeholder that will be
# replaced by the project name when running hazel

$ tree
.
β”œβ”€β”€ README.md
β”œβ”€β”€ src
    └── __PROJECTNAME__.swift

To generate new projects based on the above template, we can now initiate a new project with template swift:

$ mkdir AwesomeApp && cd AwesomeApp
$ hazel init --template swift

Created README.md
Created src
Created src/AwesomeApp.c
Created .editorconfig

Placeholders

When generating new projects, Hazel will replace all occurrences of certain placeholder variables in the template files with appropriate values. This includes both file and directory names as well as the actual contents of the template files.

As of now, built-in support exists for the placeholders shown below, but more can be added manually in the file ~/.hazel/placeholders.json.

Placeholder Description
__PROJECTNAME__ All occurrences of this placeholder will be replaced with the name of the project.
__AUTHORNAME__ All occurrences of this placeholder will be replaced with the name of the author (default value set in placeholders.json will be overridden if flags -a "Name Nameson" or --author "Name Nameson" are present).
__AUTHORMAIL__ All occurrences of this placeholder will be replaced with the e-mail of the author (default value set in placeholders.json will be overridden if flag -e name@example.org or --email name@example.org are present).
__DATE__ All occurrences of this placeholder will be replaced with the current date.
Custom placeholders

To add custom placeholders (or add default values for __AUTHORNAME__ or __AUTHORMAIL__), simply edit the file placeholders.json located in ~/.hazel:

{
	"__AUTHORNAME__": "Dave Grohl",
	"__AUTHORMAIL__": "david@grohlson.com",
	"__LICENSE__": "MIT",
	"FOO": "BAR!"
}

Commandline options

Currently, Hazel offers one command.

$ hazel --help
Usage: hazel [command] [argument]

Commands:
  init           Initiate a new project

Options:
  -h, --help     Print help message and exit
  -v, --version  Print version information and exit
  -q, --quiet    Silent mode


$ hazel init --help
Usage: hazel init [argument]

Options:
  -t, --template  Choose project template (required)
  -n, --name      Set the project name (leave empty to use the current directory name)
  -a, --author    Set author name
  -e, --email     Set e-mail
  --no-config     Do not generate .editorconfig
  -h, --help      Print help message and exit

Tab completion

Hazel comes equipped with tab completion for bash and zsh. If you've installed it manually (not with Homebrew), then you need to add the following to your startup script (.bashrc, .zshrc, etc...) to enable tab completion:

which hazel > /dev/null && . "$( hazel --completion-path )"

Acknowledgements

Hazel was created by Ardalan Samimi. This project is licensed under the terms of the MIT license. The hazel nut icon was designed by Flaticon.

About

🌰 A scaffolding tool that'll help you kickstart new projects with ease

License:MIT License


Languages

Language:Swift 82.9%Language:Makefile 12.5%Language:Shell 3.3%Language:Dockerfile 0.9%Language:C 0.4%