Skip to content

Commit

Permalink
remove generate-with-sommoner.
Browse files Browse the repository at this point in the history
  • Loading branch information
hughjfchen committed Aug 5, 2023
1 parent 9f38582 commit 934ddb5
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 133 deletions.
9 changes: 1 addition & 8 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Based on the above consideration, I create this project generator to quickly coo
This tool has following features at this moment:
- install build and deploy dependencies, including ~nix~, ~docker~, ~docker-compose~ if needed
- multiple platforms supported(currently ~linux~ and ~macos~ are supported, ~windows~ with ~WSL~ may work but not tested)
- generate project based on the tool ~summon~ (*deprecated*, will be removed eventually)
- create project based on existing project templates with [[https://github.com/GianlucaGuarini/rob][rob]]
- currently there are one existing templates
- ~nixos2111-ghc8107-haskell.nix~
Expand Down Expand Up @@ -56,9 +55,7 @@ Following these steps to use this tool:
1. clone the repository.
2. to generate a project skeleton from scratch, run the following command under the clone directory:
#+begin_src sh
./cook.sh <the directory where the project will be put> <the name of the project> generate|template
- generate means generate new project with summon(deprecated, not recommended)
- template means create project based on existing template
./cook.sh <the directory where the project will be put> <the name of the project>
#+end_src
3. to nixify an existing project, run the following command under the clone directory:
#+begin_src sh
Expand All @@ -82,10 +79,6 @@ And if run ~deploy~ and get ~docker or docker-compose not found~, run following
#+end_src
The provision process connect to the official ~nix~ web site and install ~nix~ first, it also set the default ~nix~ channel to the latest stable one. It also install the ~docker~ and ~docker-compose~ packages.

** Generate haskell project (*deprecated*, not recommended)

This tool uses the ~summoner~ to do this job, for more information during the project generation, please refer to the [[https://github.com/kowainik/summoner][official site]].

** Generate the build framework based on the ~haskell.nix~ infrastructure

This tool generates the ready to go build framework for the generated project with following facts:
Expand Down
28 changes: 5 additions & 23 deletions cook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,25 @@ fi
. "$(dirname "$0")"/common/common.sh

usage_and_exit () {
echo "Usage: cook.sh <project parent path> <project name> <generate|template>"
echo "Usage: cook.sh <project parent path> <project name>"
exit 1
}

init_with_root_or_sudo "$0"

SCRIPT_ABS_PATH=$(turn_to_absolute_path "$0")

if [ "$#" != 3 ]; then
if [ "$#" != 2 ]; then
usage_and_exit
fi

begin_banner "Top level" "project cooking"

"${SCRIPT_ABS_PATH}"/prepare-env/do.sh

case $3 in
generate)
warn "This method will be removed in a near future release! Use template instead"
"${SCRIPT_ABS_PATH}"/project-scaffold-generate/do.sh "$1" "$2"

"${SCRIPT_ABS_PATH}"/build-framework/do.sh "$1" "$2"

# copy the common and prepare-env for CI for the generated project
# because it may need to setup env within a CI environment
mkdir -p "$1/$2/ci"
cp -R "${SCRIPT_ABS_PATH}"/common "$1/$2/ci/"
cp -R "${SCRIPT_ABS_PATH}"/prepare-env "$1/$2/ci/"
;;
template)
"${SCRIPT_ABS_PATH}"/project-scaffold-template/do.sh "$1" "$2"

"${SCRIPT_ABS_PATH}"/fix-up/do.sh "$1" "$2"
;;
*)
;;
esac
"${SCRIPT_ABS_PATH}"/project-scaffold-template/do.sh "$1" "$2"

"${SCRIPT_ABS_PATH}"/fix-up/do.sh "$1" "$2"


# everything's done
Expand Down
98 changes: 44 additions & 54 deletions nixify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ fi
. "$(dirname "$0")"/common/common.sh

usage_and_exit () {
echo "Usage: nixify.sh <project root path> <project name> <generate|template>"
echo "Usage: nixify.sh <project root path> <project name>"
exit 1
}

init_with_root_or_sudo "$0"

SCRIPT_ABS_PATH=$(turn_to_absolute_path "$0")

if [ "$#" != 3 ]; then
if [ "$#" != 2 ]; then
usage_and_exit
fi

Expand All @@ -28,59 +28,49 @@ begin_banner "Top level" "project nixifying"
# make a temp dir
quick_cook_nixify_tmp_dir=$(mktemp -d -t quick-cook-nixify-"$(date +%Y%m%d%H%M%S)"-XXXXXXXXXX)

case $3 in
generate)
echo "nixify only support template"

;;
template)
"${SCRIPT_ABS_PATH}"/project-scaffold-template/do.sh "${quick_cook_nixify_tmp_dir}" "$2"

"${SCRIPT_ABS_PATH}"/fix-up/do.sh "${quick_cook_nixify_tmp_dir}" "$2"

for DIR_NAME1 in "ci" "cd" "nix" "env" "config" "k8s"
do
[ -d "$1/$2/$DIR_NAME1" ] && mv "$1/$2/$DIR_NAME1" "$1/$2/$DIR_NAME1.bak.by.nixify.$(date +%Y%m%d%H%M%S)"
[ -d "${quick_cook_nixify_tmp_dir}/$2/$DIR_NAME1" ] && cp -R "${quick_cook_nixify_tmp_dir}/$2/$DIR_NAME1" "$1/$2"
done

for FILE_NAME1 in "default.nix" "shell.nix" "release.nix" "cross-build.nix" \
"docker.nix" "tarball.nix" ".editorconfig" ".env" \
"hie.yaml" "fourmolu.yaml" ".gitignore" ".dir-locals.el" ".ghci" \
".hlint.yaml" "develop" "build" "deploy" ".ghcid" ".ghcid.lib" ".ghcid.app"
do
[ -f "$1/$2/$FILE_NAME1" ] && mv "$1/$2/$FILE_NAME1" "$1/$2/$FILE_NAME1.nix.bak.by.nixify.$(date +%Y%m%d%H%M%S)"
[ -f "${quick_cook_nixify_tmp_dir}/$2/$FILE_NAME1" ] && cp "${quick_cook_nixify_tmp_dir}/$2/$FILE_NAME1" "$1/$2"
done

[ ! -f "$1/$2/cabal.project.local" ] && [ -f "${quick_cook_nixify_tmp_dir}/$2/cabal.project.local" ] \
&& cp "${quick_cook_nixify_tmp_dir}/$2/cabal.project.local" "$1/$2"
if [ -f "$1/$2/cabal.project" ]; then
THE_INDEX_STATE=$(grep index-state "${quick_cook_nixify_tmp_dir}/$2/cabal.project")
grep -v "index-state" "$1/$2/cabal.project" > "${quick_cook_nixify_tmp_dir}/$2/cabal.project.orig"
echo "${THE_INDEX_STATE}" >> "${quick_cook_nixify_tmp_dir}/$2/cabal.project.orig"
mv "$1/$2/cabal.project" "$1/$2/cabal.project.bak.by.nixify.$(date +%Y%m%d%H%M%S)"
cp "${quick_cook_nixify_tmp_dir}/$2/cabal.project.orig" "$1/$2/cabal.project"
else
[ -f "${quick_cook_nixify_tmp_dir}/$2/cabal.project" ] && cp "${quick_cook_nixify_tmp_dir}/$2/cabal.project" "$1/$2"
fi

mkdir -p "$1/$2/.github/workflows"
[ -f "$1/$2/.github/workflows/nix-ci.yml" ] \
&& mv "$1/$2/.github/workflows/nix-ci.yml" "$1/$2/.github/workflows/nix-ci.yml.bak.by.nixify.$(date +%Y%m%d%H%M%S)"
[ -f "${quick_cook_nixify_tmp_dir}/$2/.github/workflows/nix-ci.yml" ] && cp "${quick_cook_nixify_tmp_dir}/$2/.github/workflows/nix-ci.yml" "$1/$2/.github/workflows/"

if [ -f "$1/$2/$2.cabal" ] && [ -f "$1/$2/stack.yaml" ]; then
mv "$1/$2/stack.yaml" "$1/$2/stack.yaml.bak.by.nixify.$(date +%Y%m%d%H%M%S)"
fi
if [ -f "$1/$2/$2.cabal" ] && [ -f "$1/$2/package.yaml" ]; then
mv "$1/$2/package.yaml" "$1/$2/package.yaml.bak.by.nixify.$(date +%Y%m%d%H%M%S)"
fi
;;
*)
;;
esac
"${SCRIPT_ABS_PATH}"/project-scaffold-template/do.sh "${quick_cook_nixify_tmp_dir}" "$2"

"${SCRIPT_ABS_PATH}"/fix-up/do.sh "${quick_cook_nixify_tmp_dir}" "$2"

for DIR_NAME1 in "ci" "cd" "nix" "env" "config" "k8s"
do
[ -d "$1/$2/$DIR_NAME1" ] && mv "$1/$2/$DIR_NAME1" "$1/$2/$DIR_NAME1.bak.by.nixify.$(date +%Y%m%d%H%M%S)"
[ -d "${quick_cook_nixify_tmp_dir}/$2/$DIR_NAME1" ] && cp -R "${quick_cook_nixify_tmp_dir}/$2/$DIR_NAME1" "$1/$2"
done

for FILE_NAME1 in "default.nix" "shell.nix" "release.nix" "cross-build.nix" \
"docker.nix" "tarball.nix" ".editorconfig" ".env" \
"hie.yaml" "fourmolu.yaml" ".gitignore" ".dir-locals.el" ".ghci" \
".hlint.yaml" "develop" "build" "deploy" ".ghcid" ".ghcid.lib" ".ghcid.app"
do
[ -f "$1/$2/$FILE_NAME1" ] && mv "$1/$2/$FILE_NAME1" "$1/$2/$FILE_NAME1.nix.bak.by.nixify.$(date +%Y%m%d%H%M%S)"
[ -f "${quick_cook_nixify_tmp_dir}/$2/$FILE_NAME1" ] && cp "${quick_cook_nixify_tmp_dir}/$2/$FILE_NAME1" "$1/$2"
done

[ ! -f "$1/$2/cabal.project.local" ] && [ -f "${quick_cook_nixify_tmp_dir}/$2/cabal.project.local" ] \
&& cp "${quick_cook_nixify_tmp_dir}/$2/cabal.project.local" "$1/$2"

if [ -f "$1/$2/cabal.project" ]; then
THE_INDEX_STATE=$(grep index-state "${quick_cook_nixify_tmp_dir}/$2/cabal.project")
grep -v "index-state" "$1/$2/cabal.project" > "${quick_cook_nixify_tmp_dir}/$2/cabal.project.orig"
echo "${THE_INDEX_STATE}" >> "${quick_cook_nixify_tmp_dir}/$2/cabal.project.orig"
mv "$1/$2/cabal.project" "$1/$2/cabal.project.bak.by.nixify.$(date +%Y%m%d%H%M%S)"
cp "${quick_cook_nixify_tmp_dir}/$2/cabal.project.orig" "$1/$2/cabal.project"
else
[ -f "${quick_cook_nixify_tmp_dir}/$2/cabal.project" ] && cp "${quick_cook_nixify_tmp_dir}/$2/cabal.project" "$1/$2"
fi

mkdir -p "$1/$2/.github/workflows"
[ -f "$1/$2/.github/workflows/nix-ci.yml" ] \
&& mv "$1/$2/.github/workflows/nix-ci.yml" "$1/$2/.github/workflows/nix-ci.yml.bak.by.nixify.$(date +%Y%m%d%H%M%S)"
[ -f "${quick_cook_nixify_tmp_dir}/$2/.github/workflows/nix-ci.yml" ] && cp "${quick_cook_nixify_tmp_dir}/$2/.github/workflows/nix-ci.yml" "$1/$2/.github/workflows/"

if [ -f "$1/$2/$2.cabal" ] && [ -f "$1/$2/stack.yaml" ]; then
mv "$1/$2/stack.yaml" "$1/$2/stack.yaml.bak.by.nixify.$(date +%Y%m%d%H%M%S)"
fi
if [ -f "$1/$2/$2.cabal" ] && [ -f "$1/$2/package.yaml" ]; then
mv "$1/$2/package.yaml" "$1/$2/package.yaml.bak.by.nixify.$(date +%Y%m%d%H%M%S)"
fi

# clean up
rm -fr "${quick_cook_nixify_tmp_dir}"
Expand Down
33 changes: 0 additions & 33 deletions project-scaffold-generate/do.sh

This file was deleted.

Binary file removed project-scaffold-generate/summon
Binary file not shown.
14 changes: 0 additions & 14 deletions project-scaffold-generate/undo.sh

This file was deleted.

2 changes: 1 addition & 1 deletion project-scaffold-template/do.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ begin_banner "Top level" "project scaffold based on template"

#set +u to temp work around the nix script
set +u
[[ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]] && . $HOME/.nix-profile/etc/profile.d/nix.sh
[[ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]] && . "$HOME"/.nix-profile/etc/profile.d/nix.sh
set -u

# define a function to handle paths which are provided by a find command
Expand Down

0 comments on commit 934ddb5

Please sign in to comment.