#!/bin/bash

# Change your base path for projects
PROJECT_D_BASE_PATH="./src"

### MAIN ALGORITHM ###

if ! [[ -n $(jq --version 2> /dev/null | grep "jq" 2> /dev/null) ]];  then
    echo "Package \"jq\" not installed!"
    exit 1
fi

read -ep "New name directory: $PROJECT_D_BASE_PATH/" PROJECT_D_NEW_DIRECTORY
read -ep "Description: " PROJECT_D_DESCRIPTION

mkdir -p $PROJECT_D_BASE_PATH/$PROJECT_D_NEW_DIRECTORY
cd $PROJECT_D_BASE_PATH/$PROJECT_D_NEW_DIRECTORY

dub init -n > /dev/null

PROJECT_D_ARG='{"description" : "'$PROJECT_D_DESCRIPTION'", "targetPath" : "bin"}'

jq --argjson a "$PROJECT_D_ARG" '. |= . + $a' dub.json > tempdub && mv tempdub dub.json

echo "Created new project \"$PROJECT_D_NEW_DIRECTORY\":"
jq . dub.json
