chore: add Cloudron PackageTemplate, helper script; add .gitattributes/.editorconfig; refine .gitignore; improve workspace scripts

This commit is contained in:
2025-09-12 14:18:41 -05:00
parent 1a2f9bae6d
commit 8bb6d00b0f
14 changed files with 314 additions and 18 deletions

53
scripts/new-package.sh Executable file
View File

@@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
Usage: scripts/new-package.sh <AppName> [--id <com.example.app>] [--title <Title>] [--port <port>]
Creates CloudronPackages/<AppName> from PackageTemplate and replaces placeholders:
__APP_ID__, __APP_TITLE__, __HTTP_PORT__
Examples:
scripts/new-package.sh MyApp --id com.example.myapp --title "My App" --port 3000
EOF
}
if [[ $# -lt 1 ]]; then
usage; exit 1
fi
APP_NAME="$1"; shift
APP_ID="com.example.${APP_NAME,,}"
APP_TITLE="$APP_NAME"
HTTP_PORT="3000"
while [[ $# -gt 0 ]]; do
case "$1" in
--id) APP_ID="$2"; shift 2;;
--title) APP_TITLE="$2"; shift 2;;
--port) HTTP_PORT="$2"; shift 2;;
-h|--help) usage; exit 0;;
*) echo "Unknown argument: $1"; usage; exit 1;;
esac
done
SRC_DIR="CloudronPackages/PackageTemplate"
DEST_DIR="CloudronPackages/${APP_NAME}"
[[ -d "$SRC_DIR" ]] || { echo "Template not found: $SRC_DIR"; exit 1; }
[[ -e "$DEST_DIR" ]] && { echo "Destination already exists: $DEST_DIR"; exit 1; }
mkdir -p "$DEST_DIR"
cp -a "$SRC_DIR"/. "$DEST_DIR"/
# Replace placeholders in text files
find "$DEST_DIR" -type f \( -name "*" ! -name "*.png" \) -print0 | while IFS= read -r -d '' f; do
sed -i "s#__APP_ID__#${APP_ID}#g" "$f"
sed -i "s#__APP_TITLE__#${APP_TITLE}#g" "$f"
sed -i "s#__HTTP_PORT__#${HTTP_PORT}#g" "$f"
done
echo "Created package at: $DEST_DIR"
echo "Next steps: edit Dockerfile and start.sh to run your app. Add logo.png if desired."