@@ -37,6 +37,15 @@ DRUPAL_PROJECT_REPO="${DRUPAL_PROJECT_REPO:-https://github.com/drupal-composer/d
37
37
38
38
# -------------------------------------------------------------------------------
39
39
40
+ # @formatter:off
41
+ note () { printf " %s\n" " ${1} " ; }
42
+ info () { [ " ${TERM:- } " != " dumb" ] && tput colors > /dev/null 2>&1 && printf " \033[34m[INFO] %s\033[0m\n" " ${1} " || printf " [INFO] %s\n" " ${1} " ; }
43
+ pass () { [ " ${TERM:- } " != " dumb" ] && tput colors > /dev/null 2>&1 && printf " \033[32m[ OK ] %s\033[0m\n" " ${1} " || printf " [ OK ] %s\n" " ${1} " ; }
44
+ fail () { [ " ${TERM:- } " != " dumb" ] && tput colors > /dev/null 2>&1 && printf " \033[31m[FAIL] %s\033[0m\n" " ${1} " || printf " [FAIL] %s\n" " ${1} " ; }
45
+ # @formatter:on
46
+
47
+ # -------------------------------------------------------------------------------
48
+
40
49
echo " ==============================="
41
50
echo " 🏗️ ASSEMBLE "
42
51
echo " ==============================="
45
54
# Make sure Composer doesn't run out of memory.
46
55
export COMPOSER_MEMORY_LIMIT=-1
47
56
48
- echo " > Validate tools."
57
+ info " Validate tools."
49
58
! command -v git > /dev/null && echo " ERROR: Git is required for this script to run." && exit 1
50
59
! command -v php > /dev/null && echo " ERROR: PHP is required for this script to run." && exit 1
51
60
! command -v composer > /dev/null && echo " ERROR: Composer (https://getcomposer.org/) is required for this script to run." && exit 1
52
61
! command -v jq > /dev/null && echo " ERROR: jq (https://stedolan.github.io/jq/) is required for this script to run." && exit 1
62
+ pass " Tools are valid."
53
63
54
64
# Extension name, taken from the .info file.
55
65
extension=" $( basename -s .info.yml -- ./* .info.yml) "
@@ -58,77 +68,95 @@ extension="$(basename -s .info.yml -- ./*.info.yml)"
58
68
# Extension type.
59
69
type=$( grep -q " type: theme" " ${extension} .info.yml" && echo " themes" || echo " modules" )
60
70
61
- echo " > Validate Composer configuration."
71
+ info " Validate Composer configuration."
62
72
composer validate --ansi --strict
63
73
64
74
# Reset the environment.
65
- [ -d " build" ] && echo " > Remove existing build directory." && chmod -Rf 777 " build" && rm -rf " build"
75
+ if [ -d " build" ]; then
76
+ info " Removing existing build directory."
77
+ chmod -Rf 777 " build" > /dev/null || true
78
+ rm -rf " build" > /dev/null || true
79
+ pass " Existing build directory removed."
80
+ fi
66
81
82
+ info " Creating Drupal codebase."
67
83
# Allow installing custom version of Drupal core from drupal-composer/drupal-project,
68
84
# but only coupled with drupal-project SHA (required to get correct dependencies).
69
85
if [ -n " ${DRUPAL_VERSION:- } " ] && [ -n " ${DRUPAL_PROJECT_SHA:- } " ]; then
70
- echo " > Initialise Drupal site from the scaffold repo ${DRUPAL_PROJECT_REPO} commit ${DRUPAL_PROJECT_SHA} ."
86
+ note " Initialising Drupal site from the scaffold repo ${DRUPAL_PROJECT_REPO} commit ${DRUPAL_PROJECT_SHA} ."
71
87
72
88
# Clone Drupal core at the specific commit SHA.
73
89
git clone -n " ${DRUPAL_PROJECT_REPO} " " build"
74
90
git --git-dir=" build/.git" --work-tree=" build" checkout " ${DRUPAL_PROJECT_SHA} "
75
91
rm -rf " build/.git" > /dev/null
76
92
77
- echo " > Pin Drupal to a specific version ${DRUPAL_VERSION} ."
93
+ note " Pin Drupal to a specific version ${DRUPAL_VERSION} ."
78
94
sed_opts=(-i) && [ " $( uname) " == " Darwin" ] && sed_opts=(-i ' ' )
79
95
sed " ${sed_opts[@]} " ' s|\(.*"drupal\/core"\): "\(.*\)",.*|\1: ' " \" $DRUPAL_VERSION \" ,|" " build/composer.json"
80
96
cat " build/composer.json"
81
97
else
82
- echo " > Initialise Drupal site from the latest scaffold."
98
+ note " Initialising Drupal site from the latest scaffold."
83
99
# There are no releases in "drupal-composer/drupal-project", so have to use "@dev".
84
100
composer create-project drupal-composer/drupal-project:@dev " build" --no-interaction --no-install
85
101
fi
102
+ pass " Drupal codebase created."
86
103
87
- echo " > Merge configuration from composer.dev.json."
104
+ info " Merging configuration from composer.dev.json."
88
105
php -r " echo json_encode(array_replace_recursive(json_decode(file_get_contents('composer.dev.json'), true),json_decode(file_get_contents('build/composer.json'), true)),JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);" > " build/composer2.json" && mv -f " build/composer2.json" " build/composer.json"
89
106
90
- echo " > Merge configuration from extension's composer.json."
107
+ info " Merging configuration from extension's composer.json."
91
108
php -r " echo json_encode(array_replace_recursive(json_decode(file_get_contents('composer.json'), true),json_decode(file_get_contents('build/composer.json'), true)),JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);" > " build/composer2.json" && mv -f " build/composer2.json" " build/composer.json"
92
109
93
- echo " > Create GitHub authentication token if provided."
94
- [ -n " ${GITHUB_TOKEN:- } " ] && composer config --global github-oauth.github.com " ${GITHUB_TOKEN} " && echo " Token: " && composer config --global github-oauth.github.com
110
+ if [ -n " ${GITHUB_TOKEN:- } " ]; then
111
+ info " Adding GitHub authentication token if provided."
112
+ composer config --global github-oauth.github.com " ${GITHUB_TOKEN} "
113
+ composer config --global github-oauth.github.com | grep -q " gh" || fail " GitHub token not added."
114
+ pass " GitHub token added."
115
+ fi
95
116
96
- echo " > Create custom directories."
117
+ info " Creating custom directories."
97
118
mkdir -p build/web/modules/custom build/web/themes/custom
98
119
99
- echo " > Install dependencies."
120
+ info " Installing dependencies."
100
121
composer --working-dir=" build" install
122
+ pass " Dependencies installed."
101
123
102
124
# Suggested dependencies allow to install them for testing without requiring
103
125
# them in extension's composer.json.
104
- echo " > Install suggested dependencies from extension's composer.json."
126
+ info " Installing suggested dependencies from extension's composer.json."
105
127
composer_suggests=$( cat composer.json | jq -r ' select(.suggest != null) | .suggest | keys[]' )
106
128
for composer_suggest in $composer_suggests ; do
107
129
composer --working-dir=" build" require " ${composer_suggest} "
108
130
done
131
+ pass " Suggested dependencies installed."
109
132
110
- echo " > Copy tools configuration files."
133
+ info " Copying tools configuration files."
111
134
cp phpcs.xml phpstan.neon phpmd.xml rector.php .twig-cs-fixer.php phpunit.xml " build/"
135
+ pass " Tools configuration files copied."
112
136
113
- echo " > Symlink extension's code."
137
+ info " Symlinking extension's code."
114
138
rm -rf " build/web/${type} /custom" > /dev/null && mkdir -p " build/web/${type} /custom/${extension} "
115
139
ln -s " $( pwd) " /* " build/web/${type} /custom/${extension} " && rm " build/web/${type} /custom/${extension} /build"
140
+ pass " Extension's code symlinked."
116
141
117
142
# If front-end dependencies are used in the project, package-lock.json is
118
143
# expected to be committed to the repository.
119
144
if [ -f " build/web/${type} /custom/${extension} /package-lock.json" ]; then
120
145
pushd " build/web/${type} /custom/${extension} " > /dev/null || exit 1
121
- echo " > Install front-end dependencies."
146
+
147
+ info " Installing front-end dependencies."
122
148
if [ -f " .nvmrc" ]; then nvm use; fi
123
149
if [ ! -d " node_modules" ]; then npm ci; fi
124
150
echo " > Build front-end dependencies."
125
151
npm run build
152
+ pass " Front-end dependencies installed."
153
+
126
154
popd > /dev/null || exit 1
127
155
fi
128
156
129
157
echo
130
158
echo " ==============================="
131
- echo " 🏗 ASSEMBLE COMPLETE "
159
+ echo " 🏗 ASSEMBLE COMPLETE ✅ "
132
160
echo " ==============================="
133
161
echo
134
162
echo " > Next steps:"
0 commit comments