Skip to content

Commit 101ab02

Browse files
committed
Add configurable WP_THEMES_DIR for non-Bedrock projects, bump setup to 1.0.3
1 parent 7ead52f commit 101ab02

7 files changed

Lines changed: 51 additions & 12 deletions

File tree

packages/webentor-setup/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Webentor Setup Changelog
22

3+
## 1.0.3
4+
5+
- Add configurable `WP_THEMES_DIR` for non-Bedrock project support
6+
37
## 1.0.2
48

59
- Improve init UX

packages/webentor-setup/common.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fi
2525
: "${SETUP_DB_SYNC:=true}"
2626
: "${SETUP_SUBMODULES:=false}"
2727
: "${SETUP_TYPESENSE:=false}"
28+
: "${WP_THEMES_DIR:=web/app/themes}"
2829

2930
run_hook "pre-env"
3031

packages/webentor-setup/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webikon/webentor-setup",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Webentor setup runtime and upgrade CLI",
55
"type": "library",
66
"license": "MIT",

packages/webentor-setup/env-check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ done
2626
# Resolve representative theme package.json dynamically from WP_THEMES.
2727
THEME_NAME="$(first_theme)"
2828
if [ -n "$THEME_NAME" ]; then
29-
PACKAGE_JSON="${WORKSPACE_FOLDER}/web/app/themes/${THEME_NAME}/package.json"
29+
PACKAGE_JSON="${WORKSPACE_FOLDER}/${WP_THEMES_DIR:-web/app/themes}/${THEME_NAME}/package.json"
3030
else
3131
PACKAGE_JSON=""
3232
fi

packages/webentor-setup/helpers/helpers.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,11 @@ update_env_urls() {
236236
# Detect WordPress themes using WP_THEMES from scripts/.env.setup.
237237
discover_themes() {
238238
local themes="${WP_THEMES:-}"
239+
local themes_dir="${WP_THEMES_DIR:-web/app/themes}"
239240

240-
if [ -z "$themes" ] && [ -d "${WORKSPACE_FOLDER}/web/app/themes" ]; then
241+
if [ -z "$themes" ] && [ -d "${WORKSPACE_FOLDER}/${themes_dir}" ]; then
241242
# Fallback for first-run projects where WP_THEMES is not set yet.
242-
themes=$(find "${WORKSPACE_FOLDER}/web/app/themes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | tr '\n' ' ')
243+
themes=$(find "${WORKSPACE_FOLDER}/${themes_dir}" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | tr '\n' ' ')
243244
fi
244245

245246
echo "$themes"
@@ -323,15 +324,16 @@ setup_composer() {
323324

324325
_setup_deps_core() {
325326
local theme
327+
local themes_dir="${WP_THEMES_DIR:-web/app/themes}"
326328
for theme in $(discover_themes); do
327-
if [ -f "${WORKSPACE_FOLDER}/web/app/themes/${theme}/composer.json" ]; then
328-
composer --working-dir="${WORKSPACE_FOLDER}/web/app/themes/${theme}" install --optimize-autoloader
329+
if [ -f "${WORKSPACE_FOLDER}/${themes_dir}/${theme}/composer.json" ]; then
330+
composer --working-dir="${WORKSPACE_FOLDER}/${themes_dir}/${theme}" install --optimize-autoloader
329331
fi
330332

331-
if [ -f "${WORKSPACE_FOLDER}/web/app/themes/${theme}/package.json" ]; then
333+
if [ -f "${WORKSPACE_FOLDER}/${themes_dir}/${theme}/package.json" ]; then
332334
info "Installing ${theme} dependencies via pnpm"
333335
(
334-
cd "${WORKSPACE_FOLDER}/web/app/themes/${theme}"
336+
cd "${WORKSPACE_FOLDER}/${themes_dir}/${theme}"
335337
pnpm install
336338
pnpm build
337339
)

packages/webentor-setup/src/webentor-setup.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ function generateEnvSetup(string $opVaultId, string $opItemId, array $toggles):
286286
$lines[] = '';
287287
$lines[] = 'WP_THEMES="webentor-theme-v2"';
288288
$lines[] = '';
289+
$lines[] = '# Relative path from project root to the themes directory.';
290+
$lines[] = '# Default: web/app/themes (Bedrock). Use wp-content/themes for traditional WP.';
291+
$lines[] = 'WP_THEMES_DIR=web/app/themes';
292+
$lines[] = '';
289293
$lines[] = '# Setup runtime feature toggles.';
290294
$lines[] = '# These values are project-owned and intentionally outside setup subtree updates.';
291295

@@ -676,12 +680,40 @@ function detectConfigsVersion(string $cwd): ?string
676680
}
677681

678682
/**
679-
* Iterate theme directories under web/app/themes and apply $extractor to parsed JSON.
683+
* Read WP_THEMES_DIR from scripts/.env.setup with fallback to web/app/themes.
684+
*/
685+
function resolveThemesDir(string $cwd): string
686+
{
687+
$envSetupPath = "{$cwd}/scripts/.env.setup";
688+
if (file_exists($envSetupPath)) {
689+
$lines = file($envSetupPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
690+
if ($lines !== false) {
691+
foreach ($lines as $line) {
692+
$line = trim($line);
693+
if ($line === '' || str_starts_with($line, '#')) {
694+
continue;
695+
}
696+
if (str_starts_with($line, 'WP_THEMES_DIR=')) {
697+
$value = substr($line, strlen('WP_THEMES_DIR='));
698+
$value = trim($value, "\"' \t");
699+
if ($value !== '') {
700+
return $value;
701+
}
702+
}
703+
}
704+
}
705+
}
706+
707+
return 'web/app/themes';
708+
}
709+
710+
/**
711+
* Iterate theme directories and apply $extractor to parsed JSON.
680712
* Returns the first non-null result.
681713
*/
682714
function scanThemeFiles(string $cwd, string $filename, callable $extractor): ?string
683715
{
684-
$themesPath = "{$cwd}/web/app/themes";
716+
$themesPath = "{$cwd}/" . resolveThemesDir($cwd);
685717
if (!is_dir($themesPath)) {
686718
return null;
687719
}

packages/webentor-setup/win/win-laragon.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ ENV_OK=true
432432
# Set paths
433433
# Resolve the first configured theme from WP_THEMES to avoid hardcoding starter internals.
434434
PRIMARY_THEME="$(first_theme)"
435-
PACKAGE_JSON="$WORKSPACE_FOLDER/web/app/themes/${PRIMARY_THEME}/package.json"
435+
PACKAGE_JSON="$WORKSPACE_FOLDER/${WP_THEMES_DIR:-web/app/themes}/${PRIMARY_THEME}/package.json"
436436
COMPOSER_JSON="$WORKSPACE_FOLDER/composer.json"
437437

438438
# Check Node version
@@ -562,7 +562,7 @@ else
562562
info "Next steps:"
563563
echo "1. Install Composer dependencies: composer install"
564564
if [ -n "$PRIMARY_THEME" ]; then
565-
echo "2. Install theme dependencies: cd web/app/themes/${PRIMARY_THEME} && pnpm install"
565+
echo "2. Install theme dependencies: cd ${WP_THEMES_DIR:-web/app/themes}/${PRIMARY_THEME} && pnpm install"
566566
echo "3. Build theme assets: pnpm build"
567567
else
568568
echo "2. Configure WP_THEMES in scripts/.env.setup, then install theme dependencies."

0 commit comments

Comments
 (0)