Skip to content

Commit 9a3002d

Browse files
committed
Added skipping NPM build if .skip_npm_build flag file exists.
1 parent cc413b9 commit 9a3002d

File tree

7 files changed

+72
-23
lines changed

7 files changed

+72
-23
lines changed

.devtools/assemble.sh

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,21 @@ for composer_suggest in $composer_suggests; do
130130
done
131131
pass "Suggested dependencies installed."
132132

133+
# If front-end dependencies are used in the project, package-lock.json is
134+
# expected to be committed to the repository.
135+
if [ -f "package-lock.json" ]; then
136+
info "Installing front-end dependencies."
137+
if [ -f ".nvmrc" ]; then nvm use; fi
138+
if [ ! -d "node_modules" ]; then npm ci; fi
139+
140+
echo "> Building front-end dependencies."
141+
if [ ! -f ".skip_npm_build" ]; then npm run build; fi
142+
pass "Front-end dependencies installed."
143+
fi
144+
133145
info "Copying tools configuration files."
146+
# Not every tool correctly resolves the path to the configuration file if it is
147+
# symlinked, so we copy them instead.
134148
cp phpcs.xml phpstan.neon phpmd.xml rector.php .twig-cs-fixer.php phpunit.xml "build/"
135149
pass "Tools configuration files copied."
136150

@@ -139,21 +153,6 @@ rm -rf "build/web/${type}/custom" >/dev/null && mkdir -p "build/web/${type}/cust
139153
ln -s "$(pwd)"/* "build/web/${type}/custom/${extension}" && rm "build/web/${type}/custom/${extension}/build"
140154
pass "Extension's code symlinked."
141155

142-
# If front-end dependencies are used in the project, package-lock.json is
143-
# expected to be committed to the repository.
144-
if [ -f "build/web/${type}/custom/${extension}/package-lock.json" ]; then
145-
pushd "build/web/${type}/custom/${extension}" >/dev/null || exit 1
146-
147-
info "Installing front-end dependencies."
148-
if [ -f ".nvmrc" ]; then nvm use; fi
149-
if [ ! -d "node_modules" ]; then npm ci; fi
150-
echo "> Build front-end dependencies."
151-
npm run build
152-
pass "Front-end dependencies installed."
153-
154-
popd >/dev/null || exit 1
155-
fi
156-
157156
echo
158157
echo "==============================="
159158
echo " 🏗 ASSEMBLE COMPLETE ✅ "

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.logs
22
composer.lock
33
build
4+
node_modules

.scaffold/tests/bats/ahoy.bats

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ export BATS_FIXTURE_EXPORT_CODEBASE_ENABLED=1
1818
assert_dir_exists "${BUILD_DIR}/build/vendor"
1919
assert_file_exists "${BUILD_DIR}/build/composer.json"
2020
assert_file_exists "${BUILD_DIR}/build/composer.lock"
21+
assert_dir_exists "${BUILD_DIR}/node_modules"
22+
assert_output_contains "Would run build"
23+
}
24+
25+
@test "ahoy assemble - skip NPM build" {
26+
touch ".skip_npm_build"
27+
28+
run ahoy assemble
29+
assert_success
30+
31+
assert_output_contains "ASSEMBLE COMPLETE"
32+
assert_dir_exists "${BUILD_DIR}/build/vendor"
33+
assert_file_exists "${BUILD_DIR}/build/composer.json"
34+
assert_file_exists "${BUILD_DIR}/build/composer.lock"
35+
assert_dir_exists "${BUILD_DIR}/node_modules"
36+
assert_output_not_contains "Would run build"
2137
}
2238

2339
@test "ahoy start" {

.scaffold/tests/bats/make.bats

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ export BATS_FIXTURE_EXPORT_CODEBASE_ENABLED=1
2424
assert_dir_exists "${BUILD_DIR}/build/vendor"
2525
assert_file_exists "${BUILD_DIR}/build/composer.json"
2626
assert_file_exists "${BUILD_DIR}/build/composer.lock"
27+
assert_dir_exists "${BUILD_DIR}/node_modules"
28+
assert_output_contains "Would run build"
29+
}
30+
31+
@test "make assemble - skip NPM build" {
32+
touch ".skip_npm_build"
33+
34+
run make assemble
35+
assert_success
36+
37+
assert_output_contains "ASSEMBLE COMPLETE"
38+
assert_dir_exists "${BUILD_DIR}/build/vendor"
39+
assert_file_exists "${BUILD_DIR}/build/composer.json"
40+
assert_file_exists "${BUILD_DIR}/build/composer.lock"
41+
assert_dir_exists "${BUILD_DIR}/node_modules"
42+
assert_output_not_contains "Would run build"
2743
}
2844

2945
@test "make start" {

package-lock.json

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
},
1313
"engines": {
1414
"npm": ">=8.0.0",
15-
"node": ">=16.0.0"
15+
"node": ">=18.0.0"
1616
},
17-
"dependencies": {}
17+
"dependencies": {
18+
"is-positive": "^3.1.0"
19+
}
1820
}

phpcs.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222
<exclude-pattern>circle\.yml</exclude-pattern>
2323
<exclude-pattern>\.circle\/config\.yml</exclude-pattern>
2424

25-
<!-- Exclude theme assets. -->
26-
<exclude-pattern>web\/themes\/custom\/.*\/build\/.*</exclude-pattern>
27-
<exclude-pattern>web\/themes\/custom\/.*\/fonts\/.*</exclude-pattern>
28-
<exclude-pattern>web\/themes\/custom\/.*\/images\/.*</exclude-pattern>
29-
<exclude-pattern>web\/themes\/custom\/.*\/node_modules\/.*</exclude-pattern>
25+
<!-- Exclude front-end assets. -->
26+
<exclude-pattern>.*\/node_modules\/.*</exclude-pattern>
3027
<exclude-pattern>*\.min\.*</exclude-pattern>
3128

3229
<!-- Force no empty lines after function opening brace. -->

0 commit comments

Comments
 (0)