From e987caf64b70f7ff43c0105c7cd72f47cf228555 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Thu, 30 Nov 2023 07:13:53 -0700 Subject: [PATCH] Allow mix projects to specify module. --- specs/mix/runner | 16 +++++++++++++++- specs/mix/spec.json | 4 ++++ specs/phoenix/runner | 16 +++++++++++++++- specs/phoenix/spec.json | 4 ++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/specs/mix/runner b/specs/mix/runner index 4317a97..66936e0 100755 --- a/specs/mix/runner +++ b/specs/mix/runner @@ -35,6 +35,18 @@ function cleanup { trap cleanup EXIT +# ============================================================ +# ENVIRONMENT +# ============================================================ + +# Trims away any whitespace around the module name. +MODULE=$(echo "$MODULE" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') +if [ -z "$MODULE" ]; then + MODULE_ARG= +else + MODULE_ARG="--module '$MODULE'" +fi + # ============================================================ # BUILD # ============================================================ @@ -48,7 +60,9 @@ find "$BUILD" -type d -execdir chmod 755 {} + # Generate a new project with the specified name using `mix`. Generate in a # subdirectory to avoid interactive conflict resolution. -nix develop "$BUILD" --command bash -c "mix new $BUILD/project --app '$APP'" +nix develop "$BUILD" \ + --command bash \ + -c "mix new $BUILD/project --app '$APP' $MODULE_ARG" # Copy the generated files into the intermediate build directory. mv -f "$BUILD"/project/* "$BUILD" diff --git a/specs/mix/spec.json b/specs/mix/spec.json index 6c191de..cca219f 100644 --- a/specs/mix/spec.json +++ b/specs/mix/spec.json @@ -2,5 +2,9 @@ "app": { "type": "line", "prompt": "App Name> " + }, + "module": { + "type": "line", + "prompt": "Module (optional)> " } } diff --git a/specs/phoenix/runner b/specs/phoenix/runner index 3e87958..4bd025a 100755 --- a/specs/phoenix/runner +++ b/specs/phoenix/runner @@ -35,6 +35,18 @@ function cleanup { trap cleanup EXIT +# ============================================================ +# ENVIRONMENT +# ============================================================ + +# Trims away any whitespace around the module name. +MODULE=$(echo "$MODULE" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') +if [ -z "$MODULE" ]; then + MODULE_ARG= +else + MODULE_ARG="--module '$MODULE'" +fi + # ============================================================ # BUILD # ============================================================ @@ -48,7 +60,9 @@ find "$BUILD" -type d -execdir chmod 755 {} + # Generate a new project with the specified name using `mix`. Generate in a # subdirectory to avoid interactive conflict resolution. -nix develop "$BUILD" --command bash -c "mix phx.new $BUILD/project --app '$APP'" +nix develop "$BUILD" \ + --command bash \ + -c "mix phx.new $BUILD/project --app '$APP' $MODULE_ARG" # Copy the generated files into the intermediate build directory. mv -f "$BUILD"/project/* "$BUILD" diff --git a/specs/phoenix/spec.json b/specs/phoenix/spec.json index 6c191de..cca219f 100644 --- a/specs/phoenix/spec.json +++ b/specs/phoenix/spec.json @@ -2,5 +2,9 @@ "app": { "type": "line", "prompt": "App Name> " + }, + "module": { + "type": "line", + "prompt": "Module (optional)> " } }