Skip to content

Commit e285151

Browse files
committed
Fix template fallback and switch generated app folder to src
1 parent 8e2f8df commit e285151

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ curl -fsSL https://raw.githubusercontent.com/psfs/core/master/install.sh | bash
6666

6767
- Detects `local` runtime (`php` + `composer`) and `docker` runtime (`docker compose`).
6868
- If both are available in interactive mode, prompts for runtime selection.
69-
- Generates PSFS base structure (`config`, `html`, `modules`, `cache`, `logs`, `locale`).
69+
- Generates PSFS base structure (`config`, `html`, `src`, `cache`, `logs`, `locale`).
7070
- Generates initial `composer.json`.
7171
- For Docker runtime, generates `docker-compose.yml`, `docker/php.ini`, and `.env.example`.
7272
- Does not auto-run dependency install or container startup.

scripts/create-psfs-project.sh

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -euo pipefail
44
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
55
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
66
TEMPLATE_DIR="${REPO_ROOT}/templates/project"
7+
REPO_RAW_BASE="${REPO_RAW_BASE:-https://raw.githubusercontent.com/psfs/core/master}"
78

89
PROJECT_NAME=""
910
TARGET_PATH=""
@@ -51,6 +52,37 @@ require_template() {
5152
[[ -f "${TEMPLATE_DIR}/${file}" ]] || die "Template not found: ${TEMPLATE_DIR}/${file}"
5253
}
5354

55+
download_file() {
56+
local source="$1"
57+
local destination="$2"
58+
mkdir -p "$(dirname "${destination}")"
59+
60+
if command_exists curl; then
61+
curl -fsSL "${source}" -o "${destination}"
62+
return
63+
fi
64+
if command_exists wget; then
65+
wget -qO "${destination}" "${source}"
66+
return
67+
fi
68+
69+
die "Unable to download templates: neither curl nor wget is available."
70+
}
71+
72+
ensure_templates_available() {
73+
if [[ -f "${TEMPLATE_DIR}/composer.json.tpl" ]]; then
74+
return
75+
fi
76+
77+
# Fallback for standalone execution (e.g., script piped/downloaded without repo layout).
78+
local fallback_dir="${SCRIPT_DIR}/.psfs-templates/project"
79+
download_file "${REPO_RAW_BASE}/templates/project/composer.json.tpl" "${fallback_dir}/composer.json.tpl"
80+
download_file "${REPO_RAW_BASE}/templates/project/docker-compose.yml.tpl" "${fallback_dir}/docker-compose.yml.tpl"
81+
download_file "${REPO_RAW_BASE}/templates/project/.env.example.tpl" "${fallback_dir}/.env.example.tpl"
82+
download_file "${REPO_RAW_BASE}/templates/project/docker/php.ini.tpl" "${fallback_dir}/docker/php.ini.tpl"
83+
TEMPLATE_DIR="${fallback_dir}"
84+
}
85+
5486
escape_sed() {
5587
printf '%s' "$1" | sed -e 's/[\/&]/\\&/g'
5688
}
@@ -239,7 +271,7 @@ validate_inputs() {
239271
}
240272

241273
init_project_tree() {
242-
mkdir -p "${TARGET_PATH}"/{config,html,modules,cache,logs,locale}
274+
mkdir -p "${TARGET_PATH}"/{config,html,src,cache,logs,locale}
243275
if [[ "${RUNTIME}" == "docker" ]]; then
244276
mkdir -p "${TARGET_PATH}/docker"
245277
fi
@@ -340,6 +372,7 @@ main() {
340372
derive_defaults
341373
prompt_project_meta
342374
validate_inputs
375+
ensure_templates_available
343376
init_project_tree
344377
render_composer_json
345378
render_docker_bundle

templates/project/composer.json.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"autoload": {
1616
"psr-4": {
17-
"App\\": "modules/"
17+
"App\\": "src/"
1818
}
1919
},
2020
"scripts": {

0 commit comments

Comments
 (0)