33set -euo pipefail
44
55# Generates a child theme from the Whisk starter source and proves the result is
6- # installable. This is intentionally a Drupal Starterkit smoke test, not a
7- # frontend build test; it guards the PHP/theme metadata contract that release
8- # consumers hit before Node tooling runs.
6+ # installable, renderable, and compatible with the Vite-based build workflow
7+ # powered by Emulsify Core 4.
98if [ " $# " -lt 2 ]; then
109 echo " Usage: $0 <fixture-dir> <output-dir>" >&2
1110 exit 1
1211fi
1312
1413fixture_dir=" $1 "
1514output_dir=" $2 "
16- generated_theme=" emulsify_fixture"
15+ generated_theme=" ${EMULSIFY_STARTERKIT_THEME :- emulsify_fixture} "
1716generated_theme_dir=" ${fixture_dir} /web/themes/custom/${generated_theme} "
17+ generated_theme_info=" ${generated_theme_dir} /${generated_theme} .info.yml"
1818script_dir=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
19+ artifact_info=" ${output_dir} /generated-theme-info.yml"
20+ npm_install_log=" ${output_dir} /npm-install.log"
21+ npm_build_log=" ${output_dir} /npm-build.log"
22+ storybook_build_log=" ${output_dir} /storybook-build.log"
1923
2024mkdir -p " $output_dir "
25+ printf ' npm install has not run yet.\n' > " $npm_install_log "
26+ printf ' npm run build has not run yet.\n' > " $npm_build_log "
27+ printf ' npm run storybook-build has not run.\n' > " $storybook_build_log "
28+
29+ fail () {
30+ echo " $1 " >&2
31+ exit 1
32+ }
33+
34+ show_log_tail () {
35+ local log_file=" $1 "
36+
37+ if [ -f " $log_file " ]; then
38+ echo " --- ${log_file} tail ---" >&2
39+ tail -n 160 " $log_file " >&2 || true
40+ fi
41+ }
42+
43+ run_logged () {
44+ local log_file=" $1 "
45+ shift
46+
47+ if ! " $@ " > " $log_file " 2>&1 ; then
48+ echo " Command failed: $* " >&2
49+ show_log_tail " $log_file "
50+ exit 1
51+ fi
52+ }
53+
54+ assert_missing_file () {
55+ local relative_path=" $1 "
56+
57+ if [ -e " ${generated_theme_dir} /${relative_path} " ]; then
58+ fail " Starterkit output should not include ${relative_path} ."
59+ fi
60+ }
61+
62+ assert_missing_glob () {
63+ local glob_pattern=" $1 "
64+
65+ if compgen -G " ${generated_theme_dir} /${glob_pattern} " > /dev/null; then
66+ fail " Starterkit output should not include files matching ${glob_pattern} ."
67+ fi
68+ }
2169
2270(
2371 cd " $fixture_dir "
@@ -26,21 +74,27 @@ mkdir -p "$output_dir"
2674 php web/core/scripts/drupal generate-theme " $generated_theme " --starterkit whisk --path themes/custom -n
2775)
2876
29- test -f " ${generated_theme_dir} / ${generated_theme} .info.yml "
30- grep -Eq " ^('?base theme'?): emulsify$ " " ${generated_theme_dir} / ${generated_theme} .info.yml "
77+ test -f " $generated_theme_info "
78+ cp " $generated_theme_info " " $artifact_info "
3179
32- # Generated themes must be visible/installable and should not carry the source
33- # theme's private project config marker into consumer projects.
34- if grep -q ' ^hidden: true$' " ${generated_theme_dir} /${generated_theme} .info.yml" ; then
35- echo " Generated theme should not remain hidden." >&2
36- exit 1
80+ if ! grep -Eq " ^('?base theme'?): emulsify$" " $generated_theme_info " ; then
81+ fail " Generated theme must use emulsify as its runtime parent theme."
3782fi
3883
39- if [ -e " ${generated_theme_dir} /project.emulsify.json" ]; then
40- echo " Starterkit output should not include project.emulsify.json." >&2
41- exit 1
84+ # Generated themes must be visible/installable and should not carry the source
85+ # theme's private starter metadata into consumer projects.
86+ if grep -Eq ' ^hidden:[[:space:]]*true[[:space:]]*$' " $generated_theme_info " ; then
87+ fail " Generated theme should not remain hidden."
4288fi
4389
90+ assert_missing_file " project.emulsify.json"
91+ assert_missing_file " whisk.starterkit.yml"
92+ assert_missing_file " whisk.info.emulsify.yml"
93+ assert_missing_file " ${generated_theme} .starterkit.yml"
94+ assert_missing_file " ${generated_theme} .info.emulsify.yml"
95+ assert_missing_glob " *.starterkit.yml"
96+ assert_missing_glob " *.info.emulsify.yml"
97+
4498(
4599 cd " $fixture_dir "
46100 ./vendor/bin/drush theme:enable " $generated_theme " -y
49103)
50104
51105# Finish by rendering representative pages through the generated theme. This
52- # catches missing libraries, broken base -theme inheritance, and template issues
106+ # catches missing libraries, broken parent -theme inheritance, and template issues
53107# that pure file assertions cannot see.
54108bash " ${script_dir} /render-reference-pages.sh" " $fixture_dir " " $output_dir "
109+
110+ (
111+ cd " $generated_theme_dir "
112+ install_args=(install --no-audit --no-fund)
113+ if [ -f package-lock.json ]; then
114+ install_args=(ci --no-audit --no-fund)
115+ fi
116+
117+ run_logged " $npm_install_log " npm " ${install_args[@]} "
118+ run_logged " $npm_build_log " npm run build
119+
120+ if [ " ${EMULSIFY_STARTERKIT_STORYBOOK_BUILD:- 0} " = " 1" ]; then
121+ run_logged " $storybook_build_log " npm run storybook-build
122+ fi
123+ )
0 commit comments