diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f22bd83..660d416 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -35,4 +35,4 @@ jobs: - name: Format run: bun fmt:ci - name: Lint - run: bun install && bun lint + run: bun lint diff --git a/.sample/run.sh b/.sample/run.sh index e0d1afc..2e8401d 100755 --- a/.sample/run.sh +++ b/.sample/run.sh @@ -1,4 +1,7 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh + +# Convert templated variables to shell variables +LOG_PATH=${LOG_PATH} BOLD='\033[0;1m' printf "$${BOLD}Installing MODULE_NAME ...\n\n" @@ -13,6 +16,6 @@ printf "👷 Starting MODULE_NAME in background...\n\n" # 1. Use & to run it in background # 2. redirct stdout and stderr to log files -./app >${LOG_PATH} 2>&1 & +./app > "$${LOG_PATH}" 2>&1 & -printf "check logs at ${LOG_PATH} \n\n" +printf "check logs at %s\n\n" "$${LOG_PATH}" diff --git a/bun.lockb b/bun.lockb index e70b7f3..a8ef95c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/new.sh b/new.sh index 29e4f52..c9e0180 100755 --- a/new.sh +++ b/new.sh @@ -7,15 +7,15 @@ MODULE_NAME=$1 # Check if module name is provided if [ -z "$MODULE_NAME" ]; then - echo "Usage: ./new.sh " - exit 1 + echo "Usage: ./new.sh " + exit 1 fi # Create module directory and exit if it alredy exists if [ -d "$MODULE_NAME" ]; then - echo "Module with name $MODULE_NAME already exists" - echo "Please choose a different name" - exit 1 + echo "Module with name $MODULE_NAME already exists" + echo "Please choose a different name" + exit 1 fi mkdir -p "${MODULE_NAME}" @@ -23,17 +23,17 @@ mkdir -p "${MODULE_NAME}" cp -r .sample/* "${MODULE_NAME}" # Change to module directory -cd "${MODULE_NAME}" +cd "${MODULE_NAME}" || echo "Failed to change directory to ${MODULE_NAME}" && exit 1 # Detect OS if [[ "$OSTYPE" == "darwin"* ]]; then - # macOS - sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" main.tf - sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" README.md + # macOS + sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" main.tf + sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" README.md else - # Linux - sed -i "s/MODULE_NAME/${MODULE_NAME}/g" main.tf - sed -i "s/MODULE_NAME/${MODULE_NAME}/g" README.md + # Linux + sed -i "s/MODULE_NAME/${MODULE_NAME}/g" main.tf + sed -i "s/MODULE_NAME/${MODULE_NAME}/g" README.md fi # Make run.sh executable diff --git a/package.json b/package.json index b1a980c..a7d1cae 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,16 @@ "name": "modules", "scripts": { "test": "bun test", - "fmt": "bun x prettier --plugin prettier-plugin-sh -w **/*.sh **/*.ts **/*.md *.md && terraform fmt **/*.tf", - "fmt:ci": "bun x prettier --plugin prettier-plugin-sh --check **/*.sh **/*.ts **/*.md *.md && terraform fmt -check **/*.tf", - "lint": "bun run lint.ts" + "fmt": "bun x prettier --plugin prettier-plugin-sh -w **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt **/*.tf .sample/main.tf", + "fmt:ci": "bun x prettier --plugin prettier-plugin-sh --check **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt -check **/*.tf .sample/main.tf", + "lint": "bun run lint.ts && bun x shellcheck **/*.sh .sample/run.sh new.sh" }, "devDependencies": { "bun-types": "^1.0.3", "gray-matter": "^4.0.3", "marked": "^9.0.3", - "prettier-plugin-sh": "^0.13.1" + "prettier-plugin-sh": "^0.13.1", + "shellcheck": "^2.2.0" }, "peerDependencies": { "typescript": "^5.0.0"