diff --git a/README.md b/README.md index 15cfee3..e89cf09 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,34 @@ This is an opinionated template for creating Haskell projects. It uses > **TODO** Provide minimum viable documentation. +## Quickstart + +Create your repository from this template, clone it on your computer +and enter its directory. + +Then, run following to configure your project: + +```sh +bash ./run-template.sh +``` + +It will prompt some questions and configure your project according to +your answers. + +Once it is configured, provision `direnv`: + +```sh +direnv allow +``` + +And run the big, long build command as given in the next section. + +Finally, you can remove the `run-template.sh` script: + +```sh +rm run-template.sh +``` + ## Development Big, long build command for the impatient: diff --git a/run-template.sh b/run-template.sh new file mode 100644 index 0000000..cd2e1d2 --- /dev/null +++ b/run-template.sh @@ -0,0 +1,116 @@ +#!/usr/bin/env bash + +## Declare defaults: +_def_name="haskell-template-hebele" +_def_title="Haskell Project Template" +_def_github="vst/haskell-template-hebele" +_def_author="Vehbi Sinan Tunalioglu" +_def_maintainer="vst@vsthost.com" +_def_copyright="Copyright (c) 2023 Vehbi Sinan Tunalioglu" + +## Initialize variables: +_var_name="${_def_name}" +_var_title="${_def_title}" +_var_github="${_def_github}" +_var_author="${_def_author}" +_var_maintainer="${_def_maintainer}" +_var_copyright="${_def_copyright}" + +## Let's start: +cat <&2 echo "Exiting..." +fi +echo + +echo +echo "1/6. Project Name: The project name must be a valid Haskell package name. See ." +echo +read -p "Enter the project name [${_def_name}]: " _var_name +_var_name="${_var_name:-"${_def_name}"}" +echo + +echo +echo "2/6. Project Title: The project title appearing on the README header, CLI header etc..." +echo +read -p "Enter the project title [${_def_title}]: " _var_title +_var_title="${_var_title:-"${_def_title}"}" +echo + +echo +echo "3/6. GitHub Repository: This must be in the form of /." +echo +read -p "Enter the GitHub repository [${_def_github}]: " _var_github +_var_github="${_var_github:-"${_def_github}"}" +echo + +echo +echo "4/6. Author: Who is the author? See " +echo +read -p "Enter the author [${_def_author}]: " _var_author +_var_author="${_var_author:-"${_def_author}"}" +echo + +echo +echo "5/6. Maintainer: Who is the maintainer? See " +echo +read -p "Enter the maintainer [${_def_maintainer}]: " _var_maintainer +_var_maintainer="${_var_maintainer:-"${_def_maintainer}"}" +echo + +echo +echo "6/6. Copyright: What is the copyright notice? See " +echo +read -p "Enter the copyright [${_def_copyright}]: " _var_copyright +_var_copyright="${_var_copyright:-"${_def_copyright}"}" +echo + +## Confirmation: +echo +echo "Here is what you want:" +echo "======================" +echo +cat <&2 echo "Exiting..." +fi +echo + +_files() { + find . -type d \( -path ./dist -o -path ./dist-newstyle -o -path ./.direnv -o -path ./.git \) -prune -o -type f -a -not -name "run-template.sh" -print +} + +_update() { + _file="${1}" + _fpath_def="$(echo "${_def_name}" | sed "s/\-/_/g")" + _fpath_new="$(echo "${_var_name}" | sed "s/\-/_/g")" + sed -i "s|${_def_github}|${_var_github}|g" "${_file}" + sed -i "s|${_def_copyright}|${_var_copyright}|g" "${_file}" + sed -i "s|${_def_author}|${_var_author}|g" "${_file}" + sed -i "s|${_def_maintainer}|${_var_maintainer}|g" "${_file}" + sed -i "s|${_def_name}|${_var_name}|g" "${_file}" + sed -i "s|${_def_title}|${_var_title}|g" "${_file}" + sed -i "s|${_fpath_def}|${_fpath_new}|g" "${_file}" +} + +_files | sort | while read -r _path; do + echo "Processing ${_path}" + _update "${_path}" +done