๐Ÿ”ฎ Summoner

wizard Build Windows build Hackage MPL-2.0 license

So many of our dreams at first seem impossible, then they seem improbable, and then, when we summon the will, they soon become inevitable.

Christopher Reeve

Summoner is a tool for scaffolding fully configured batteries-included production Haskell projects.

Do you want to create a library that is to be uploaded to Hackage/Stackage, that builds with both Cabal and Stack and supports the latest three major GHC versions? Or you are building a production application which uses a custom prelude and has CI with Travis Linux and AppVeyors Windows checks? Summoner can help you do all that with minimal effort from you - it can even upload the project to GitHub if you wish!

By the way, Summoner operates as either CLI or TUI application, so you can choose what youโ€™re more comfortable with and install only the required one.

Structure

Demo โ†‘

TUI demo โ†‘

TUI demo

CLI demo โ†‘

CLI demo

Scaffolded project structure โ†‘

This is an example of the project hierarchy you can get if youโ€™re running Summoner with all options enabled:

project-name/
โ”œโ”€โ”€ app/
โ”‚ย ย  โ””โ”€โ”€ Main.hs
โ”œโ”€โ”€ benchmark/
โ”‚ย ย  โ””โ”€โ”€ Main.hs
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ ProjectName.hs
โ”‚ย ย  โ””โ”€โ”€ Prelude.hs
โ”œโ”€โ”€ test/
โ”‚ย ย  โ””โ”€โ”€ Spec.hs
โ”œโ”€โ”€ CHANGELOG.md
โ”œโ”€โ”€ CONTRIBUTING.md
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ project-name.cabal
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ Setup.hs
โ”œโ”€โ”€ stack.yaml
โ”œโ”€โ”€ appveyor.yml
โ”œโ”€โ”€ .git
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .stylish-haskell.yaml
โ””โ”€โ”€ .travis.yml

You can also see complete examples in the following folder:

Directory smallProject contains an example of the straightforward package, and fullProject shows a generated project with more advanced structure and more features.

Features โ†‘

Summoner is a tool that combines predefined configurations, command-line arguments and a chosen interface.

To fully understand the power in your hands with the help of Summoner, please check out this section.

Below you can see highlighted features in different categories.

Project โ†‘

  • Support for Cabal and Stack build tools.

  • Ability to pick stanzas (library, executable, test-suite, benchmark).

  • Option to include an alternative prelude, if desired. The project would then use base-noprelude technique, and the Prelude module would be added to the library target.

  • Whole Hackage-upload checklist support.

  • Support for multiple GHC versions, with thoughtful reflection on project meta, base versions (e.g. base >= 4.9 && < 4.12), etc.

  • Different license support: MIT, BSD2, BSD3, GPL-2, GPL-3, LGPL-2.1, LGPL-3, AGPL-3, Apache-2.0, MPL-2.0, None (All Rights Reserved license without file).

  • Creation of the CHANGELOG.md file with PVP versioning policy.

  • Ability to include your .stylish-haskell.yaml file.

  • Usage of the ghc-options field with sensible defaults.

    If warnings are not explicitly stated in the configuration file, then the following list of GHC flags is added to all stanzas:

    -Wall
    -Wincomplete-uni-patterns
    -Wincomplete-record-updates
    -Wcompat
    -Widentities
    -Wredundant-constraints      (ghc >= 8.0)
    -fhide-source-paths          (ghc >= 8.2.2)
    -Wmissing-export-lists       (ghc >= 8.4.1)
    -Wpartial-fields             (ghc >= 8.4.1)
    

    Besides, the following GHC options are added to the executable, tests and benchmark stanzas:

    -threaded
    -rtsopts
    -with-rtsopts=-N
    

GitHub โ†‘

  • Initialisation of the git repository inside the project folder.
  • Initial commit creation.
  • Uploading the repository to GitHub.
  • Exhaustive .gitignore file.
  • Formation of the README file with Hackage, Stackage and CI badges.
  • Linking to the GitHub repository in the .cabal file.
  • Ability to include your CONTRIBUTING.md file.

CI โ†‘

  • Generation of the .travis.yml file that runs build and tests on CI under Linux.
  • Configuration matrix on CI to build with multiple GHC versions and various build tools.
  • -Werror is enabled on CI not to miss any warnings.
  • Run HLint checks on CI.
  • Generation of the appveyor.yaml file which runs build and tests on CI under Windows.

Others โ†‘

  • Ability to create a project in offline mode.

Get started โ†‘

Prerequisites โ†‘

To start using Summoner make sure that you have the following tools installed on your machine:

  • git โ€“ to initialize the GitHub repo.
  • hub โ€“ to upload the project to GitHub.
  • curl โ€“ to download licenses.

Installation โ†‘

Summon contains two executables:

  • summon: scaffold projects using interactive CLI mode.
  • summon-tui: scaffold projects using TUI.

Below you can find the description of how to install each of them so you can choose the one you want.

Summon-TUI โ†‘

NOTE: summon-tui is not supported on Windows. See this issue.

TUI: download binary โ†‘

You can download binary directly from GitHub releases.

After downloading binary, make it executable and copy it under convenient location, for example:

chmod +x summon-cli-linux
mv summon-cli-linux ~/.local/bin/summon
TUI: from source โ†‘

Fetch the repo using cabal:

cabal get -s summoner

or clone the directory from GitHub:

git clone https://github.com/kowainik/summoner.git

Step into the directory:

cd summoner

Build and install using cabal:

cabal new-install summoner-tui:exe:summon-tui

Build and install using stack:

stack install summoner-tui:exe:summon-tui

Summon-CLI โ†‘

CLI: download binary โ†‘

You can download binary directly from GitHub releases.

After downloading binary, make it executable and copy it under convenient location, for example:

chmod +x summon-cli-linux
mv summon-cli-linux ~/.local/bin/summon
CLI: from Hackage/Stackage โ†‘

Using cabal:

cabal new-update
cabal new-install summoner

Using stack:

stack install summoner
CLI: from source โ†‘

Fetch the repo using cabal:

cabal get -s summoner

or clone the directory from GitHub:

git clone https://github.com/kowainik/summoner.git

Step into the directory:

cd summoner

Build and install using cabal:

cabal new-install summoner-cli:exe:summon

Build and install using stack:

stack install summoner:exe:summon

Setup โ†‘

You can turn on bash auto-completion by running the following command:

source <(summon --bash-completion-script `which summon`)

Usage โ†‘

To start summoning projects nothing additional is required. However, to tweak your settings further, you can use additional configuration settings. There are several options you can use to set particular configurations for new projects (in increasing order of priority):

  1. Default configuration file (~/.summoner.toml).
  2. Explicitly specified configuration file by --file FILENAME option (used instead of the default one if specified).
  3. Options that are stated by CLI arguments.
  4. User input. It could be
    • TUI โ€“ User data specified in the window of summon-tui.
    • CLI โ€“ Interactively inputted answers during execution of the summon command (for the options that were not specified on previous steps).

To cut a long story short, the configuration uses Partial Options Monoid Pattern.

File configuration โ†‘

Here is the list of the options that can be configured to suit your needs. If options are not specified, they are asked interactively (or some sensible defaults are used).

Field Type Description
cabal Bool Add Cabal support?
stack Bool Add Stack support?
owner Text GitHub login.
fullName Text Full name.
email Text E-mail address.
license License One of: MIT, BSD2, BSD3, GPL-2, GPL-3, LGPL-2.1, LGPL-3, AGPL-3, Apache-2.0, MPL-2.0, None.
ghcVersions [GHC] summoner uses default GHC-8.4.4. However, additionally you can specify other versions. For each version x.y.z the stack-x.y.z.yaml will be created.
github Bool Turn on GitHub integration by default?
private Bool Create private repository by default? (Ignored if github = false)
travis Bool Turn on Travis integration by default? (Ignored if github = false)
appveyor Bool Turn on AppVeyor integration by default? (Ignored if github = false)
lib Bool Create src folder with simple ProjectName.hs file and library target?
exe Bool Create app folder with simple Main.hs file and executable target?
test Bool Create test folder with simple Spec.hs file and test target?
bench Bool Create benchmark folder with Main.hs file with gauge library usage example?
extensions [Text] List of the default extensions to add into default-extensions section in the .cabal.
warnings [Text] List of the default checks and warnings to add into ghc-options section in the .cabal.
stylish.* Text stylish.file to provide the absolute file path OR stylish.url to download the .stylish-haskell.yaml file to use in the project.
contributing.* Text contributing.file to provide the absolute file path OR contributing.url download OR contribuint.link to link the CONTRIBUTING.md file to use in the project.
[prelude]
package Text The package name of the custom prelude youโ€™d like to use in the project (doesnโ€™t work without module field).
module Text The module name of the custom prelude youโ€™d like to use in the project (doesnโ€™t work without package field).

See the example of the configuration for projects of the Kowainik organization.

Command line arguments โ†‘

Available commands:

Usage:
  summon COMMAND
      Set up your own Haskell project

Available commands:
  new                      Create a new Haskell project
  show                     Show available licenses or ghc versions

Available global options:
  -h, --help               Show this help text
  -v, --version            Show summoner's version

summon new command: โ†‘

Usage:
  summon new PROJECT_NAME [--ignore-config] [--no-upload] [--offline]
             [-f|--file FILENAME]
             [--cabal]
             [--stack]
             [--prelude-package PACKAGE_NAME]
             [--prelude-module MODULE_NAME]
             [with    [OPTIONS]]
             [without [OPTIONS]]

Available options:
  -h, --help               Show this help text
  --ignore-config          Ignore configuration file
  --no-upload              Do not upload to GitHub. Special case of the '--offline' flag.
  --offline                Offline mode: create project with 'All Rights Reserved' license
                           and without uploading to GitHub.
  --cabal                  Cabal support for the project
  --stack                  Stack support for the project
  -f, --file FILENAME      Path to the toml file with configurations. If not
                           specified '~/.summoner.toml' will be used if present
  --prelude-package PACKAGE_NAME
                           Name for the package of the custom prelude to use in
                           the project
  --prelude-module MODULE_NAME
                           Name for the module of the custom prelude to use in
                           the project

Available commands:
  with                     Specify options to enable
  without                  Specify options to disable

Available command options:
  -h, --help               Show this help text
  -g, --github             Github integration
  -p, --private            Create private GitHub repository
  -c, --travis             Travis CI integration
  -w, --app-veyor          AppVeyor CI integration
  -l, --library            Library target
  -e, --exec               Executable target
  -t, --test               Tests
  -b, --benchmark          Benchmarks

summon show command: โ†‘

Usage:
  summon show COMMAND
      Show supported licenses or ghc versions

Available commands:
  ghc                      Show available ghc versions
  license                  Show available licenses
  license [LICENSE_NAME]   Show specific license text

Available options:
  -h, --help               Show this help text

For example, the following command preconfigures the project settings with the custom prelude relude, included library, executable, test stanzas (but without benchmarks), creates a private repository on GitHub with the Travis CI and AppVeyor CI integrated.

summon new my-project with -letgcpw without -b --prelude-package relude --prelude-module Relude

TUI โ†‘

TUI new command โ†‘

summon new TUI

Section 1 โ€“ The main section where user inputs data or changes the configurations.

Section 2 โ€“ The structure of the project that is going to be created with the current configurations. This tree changes on-the-fly.

Section 3 โ€“ Hints, project status, or current errors in the configurations.

Section 4 โ€“ Useful hotkeys.

The TUI window opens with the pre-filled information received from a config file and command-line arguments. However, itโ€™s possible to change any field as per your needs.

In the screenshot you can see that youโ€™ll be given a few text fields to fill in or some checkboxes that represent boolean values of the configurations. To help you fill in the correct input, there are some โ“˜ info messages in the Status section, which give additional details about the current field.

To help you navigate between the form fields here are the available hotkeys:

Key Action
Esc Abort summoner
Enter If input is valid go to the Confirm window
Tab Change the focus to the next active field
Shift + Tab Change the focus to the previous active field
Space Enable/disable current checkbox or radio button
Ctrl + d Delete the input of the current text field
Ctrl + u Delete the input of the current text field from the cursor position to the beginning
Ctrl + k Delete the input of the current text field from the cursor position to the end
Ctrl + a Move the cursor to the beginning of the current input field
Ctrl + e Move the cursor to the end of the current input field
Up/Down Scroll license list when focused

Note that the form should be valid in order to be able to go to the Confirm window. If there are some errors in the input, you could see details about these errors in the Status section of the form.

TUI show command โ†‘

These commands display the list of supported GHC versions or Licenses. Also, when the license name is specified the window with the scrollable content of the License text is shown.

CLI โ†‘

CLI new command โ†‘

In CLI mode of operation Summoner asks about every project setting. Most of the questions contain a default value, so you can press Enter to choose the default value. If some option is specified via a configuration file or CLI arguments, then the question is skipped and the predefined value is used.

CLI show command โ†‘

These commands display the list of supported GHC versions, or Licenses. Also, when the license name is specified, the content of the License is outputted to the terminal.

For Developers โ†‘

If youโ€™d like to take part in the development processes, here are a few things to keep in mind:

  • Summoner is a multi-package project which has two packages inside: summoner-cli and summoner-tui. We are supporting the same functionality in both of them, so, if itโ€™s possible, you should add/change the code in both of the packages.
  • Summoner uses the custom prelude relude.
  • We are using the Kowainik style guide.
  • To sum up, here is the Contributing guide we use across the repositories.
  • This project is contributor-friendly, so be kind to other people working on the project.

Build โ†‘

To build the project you can use the following commands:

cabal new-build all

for Cabal and

stack build

for Stack.

Test โ†‘

Summoner uses the golden tests technique for assuring the correctness of the generated files. For this purpose, we have the golden folder with two sample projects to test against.

To actually run tests you need to run:

cabal new-test all

or

stack test

Run โ†‘

Building Summoner with the recommended method creates two executables: summon and summon-tui. To run the compiled executable you can use the following commands:

cabal new-exec summon -- SOME_COMMAND
cabal new-exec summon-tui -- SOME_COMMAND

or

stack exec summon -- SOME_COMMAND
stack exec summon-tui -- SOME_COMMAND

Changelog โ†‘

Each package has its own changelog:

Acknowledgments โ†‘

This project was inspired by Aelve/new-hs, which is the tool with the same goal but itโ€™s only for creating cabal projects.

Icons made by Nikita Golubev from Flaticon is licensed by CC 3.0 BY.

Changes

Changelog

summoner uses PVP Versioning. The changelog is available on GitHub.

1.2.0 โ€” Nov 30, 2018

  • Make cabal-version: 2.0 default in generated projects.
  • #11: Support offline mode.
  • #199: Add None license with no LICENSE file generation. Add licenses short descriptions text during the interactive mode. Patch summon show license command to show short description about each license.
  • #197 Build with stack lts-12.20, and support GHC 8.4.4 in project generation. Make GHC-8.4.4 the default one for generated project.
  • #37: Add HLint check on Travis CI in generatd projects.
  • #142: Add version bounds to base in the generated .cabal file.
  • #239: Make categories not mandatory.
  • Use defaultDescription for project description if not specified.
  • #185: Add golden tests.
  • #184 Add --no-upload option.
  • #169: Make AppVeyor use the 64bits version of stack and build for 64 bits.
  • #154: Add Link constructor to Source data type.
  • #178: Remove unnecessary new lines and trailing spaces in most places.
  • #168: Upgrade stack intall-cabal optionโ€™s version to 2.2.0.1 in the generated Travis file.
  • #195: Update prompt questions for CLI.
  • Add more documentation to the functions.
  • #155: Bump up to tomland-0.5.0.
  • #202: Bump up to relude-0.4.0.
  • Remove tasty dependencies from tests.
  • Drop support for GHC-8.6.1 on CI. Support GHC-8.6.2 on CI.
  • Drop support for GHC-8.4.3 on CI. Build with GHC-8.4.4 on CI.

1.1.0.1 โ€“ Sep 10, 2018

  • Bump up relude version to 0.3.0.
  • #146: Migrate to base-noprelude.
  • Add -Werror to build option in generated .travis.yml

1.1.0

  • #128: Important: Replace summon with summon new command. To create a project now the following command should be used:
    summon new my-project
    
  • #82: Add stackage badges.
  • #109: Fix travis cache directories.
  • #117: Step into created project properly
  • #110: Print executing command.
  • #91: Add warning fields for ghc.
  • #90: Add TOML test.
  • #120: Bump up dependencies.
  • #58: Make Licence type safer.
  • #124: Print directories bold.
  • #130: Show git revision version under --version command.
  • #63: Add show ghc, show license and show license <LICENSE_NAME> commands.
  • #122: Remove github link from CHANGELOG when github is not chosen.
  • #35: Add config option to add .stylish-haskell.yaml to your project (via URL or file path).
  • Bump up tomland version to 0.4.0.
  • #138: Remove traces of GitHub from .cabal file when GitHub integration is disabled.
  • #31: Add config option to add CONTRIBUTING.md to your project (via URL or file path).
  • #27: Remove b script.

1.0.6

  • Use relude instead of universum.
  • #105: Add --ignore-config option.

1.0.5

  • #100: Bump up to ghc-8.4.3. Add support for Ghc843 in code and make it default.
  • Make CI badges in README be shown depending on the chosen options.
  • #99: UseTravis-specific env variable TRAVIS_BUILD_DIR in created travis file.
  • #97: Add cabal to created travis file.
  • #96: Add option to choose cabal, stack or both.

1.0.4

  • Bump up tomland to version 0.3.

1.0.3

  • #92: Remove -fhide-source-paths from generated stack yaml files for GHC < 8.2

1.0.2

  • #87: Fix Travis matrix for not default ghc versions.

1.0.1

  • #85: Remove base-noprelude from dependencies.

1.0.0

  • Important: Rename hs-init to summoner. Transform the script into the package.
  • #54: Rename on and off commands to with and without.
  • #48:
    • Add ability to write configurations file. Remove Targets data type. Use Config instead for default, file and CLI configurations.
  • #60: Use custom prelude universum.
  • #39: Add option to use custom prelude in CLI and in .toml configuration.
  • #38: Add option to add default extensions to .toml config.
  • #62: Make some parts of output not only colorful, but also bold. This makes output prettier.
  • #67: Add Aswer data type to handle yes-no CLI questions.
  • #61: Add CLI --version option.
  • #73: Make custom prelude be table in toml.
  • #74: Print hierarchy tree for the created project.

hs-init

0.0.4

  • Now works on windows systems as well
  • Add powershell install script for Windows

0.0.3

  • #45: Support AppVeyor CI for created projects.

0.0.2

  • Use metavar for on-off commands.
  • Upgrade lts to 10.3, use ghc 8.2.2 as default value.

0.0.1

  • #36: Add option for creating private repositories โ€” -p | --private.
comments powered byDisqus