Giter Club home page Giter Club logo

hazel's Introduction

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 [email protected] or --email [email protected] 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__": "[email protected]",
	"__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.

hazel's People

Contributors

pkrll avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.