Skip to content

Commit

Permalink
Multiple recommended-project versions (#25)
Browse files Browse the repository at this point in the history
13837
  • Loading branch information
paul-m committed Apr 3, 2023
1 parent f196fea commit 81e2fec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
26 changes: 20 additions & 6 deletions commands/host/dkan-init
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#ddev-generated

## Description: Build the Drupal codebase for a DKAN site.
## Usage: dkan-init
## Flags: [{"Name":"moduledev", "Usage":"Set up the file system for DKAN module development."},{"Name":"force", "Usage":"Force init even if there are files present which could be deleted."}]
## Usage: dkan-init [flags]
## Example: dkan-init\ndkan-init --project-version 10.0.x-dev
## Flags: [{"Name":"moduledev", "Usage":"Set up the file system for DKAN module development."},{"Name":"project-version", "Usage":"Specify a Drupal core version. Default 9.5.x-dev."},{"Name":"force", "Usage":"Force init even if there are files present which could be deleted."}]

# Fail early, fail often.
set -euo pipefail
Expand All @@ -12,9 +13,12 @@ export DKAN_REPO=https://github.com/GetDKAN/dkan.git
export DKAN_REPO_BRANCH=2.x
export DKAN_DIRECTORY=dkan

# Glean flag arguments.
# Defaults.
INIT_MODULEDEV=false
INIT_FORCE=false
INIT_PROJECT_VERSION="9.5.x-dev"

# Glean flag arguments.
while :; do
case ${1:-} in
--moduledev)
Expand All @@ -25,7 +29,13 @@ while :; do
;;
--force)
INIT_FORCE=true
echo "forced"
echo "*"
echo "* Forcing initialization"
echo "*"
;;
--project-version*)
shift
INIT_PROJECT_VERSION=$1
;;
--) # End of all options.
break
Expand All @@ -39,6 +49,10 @@ while :; do
shift
done

echo "*"
echo "* Using project version: $INIT_PROJECT_VERSION"
echo "*"

# Determine if there's anything in the directory that we shouldn't remove.
# - look for composer.json
# - look for dkan/.
Expand All @@ -65,9 +79,9 @@ if [ $INIT_MODULEDEV = true ]; then
fi

if [ $INIT_FORCE = true ]; then
ddev composer create getdkan/recommended-project:@dev --no-install -y
ddev composer create getdkan/recommended-project:$INIT_PROJECT_VERSION@dev --no-install -y
else
ddev composer create getdkan/recommended-project:@dev --no-install
ddev composer create getdkan/recommended-project:$INIT_PROJECT_VERSION@dev --no-install
fi

if [ $INIT_MODULEDEV = true ]; then
Expand Down
9 changes: 6 additions & 3 deletions tests/dkan-init.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ teardown() {
run ddev dkan-init --help
assert_output --partial "--moduledev"
assert_output --partial "--force"
assert_output --partial "--project-version"

run ddev dkan-site-install --help
assert_output --partial "ddev dkan-site-install [flags]"

run ddev dkan-init --force
refute_output --partial "Setting up for local DKAN module development"
assert_output --partial "Site codebase initialized."
assert_output --partial "Site codebase initialized"
assert_output --partial "Using project version: 9.5.x-dev"

# Make sure we added our directories.
assert [ -d "docroot/sites/default/files/uploaded_resources" ]
Expand All @@ -51,7 +53,7 @@ teardown() {

run ddev dkan-init --force --moduledev
assert_output --partial "Setting up for local DKAN module development"
assert_output --partial "Site codebase initialized."
assert_output --partial "Site codebase initialized"
}

@test "dkan-init protects existing work" {
Expand All @@ -60,7 +62,8 @@ teardown() {

touch composer.json

run ddev dkan-init
run ddev dkan-init --project-version 9.4.x-dev
assert_output --partial "Using project version: 9.4.x-dev"
assert_output --partial "Found composer.json"
assert_failure

Expand Down

0 comments on commit 81e2fec

Please sign in to comment.