Skip to content

Commit 7df7c73

Browse files
committed
Merge branch 'master' into publish-script
2 parents 23032ce + a94ef04 commit 7df7c73

File tree

3 files changed

+51
-16
lines changed

3 files changed

+51
-16
lines changed

package-lock.json

Lines changed: 14 additions & 14 deletions
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
@@ -28,11 +28,13 @@
2828
"gh-pages-storybook": "storybook-to-ghpages",
2929
"deploy-storybook": "npm run build-storybook && npm run gh-pages-storybook",
3030
"new": "cd elements && yo --no-insight --no-update-notifier pfelement && npm run post-new",
31-
"post-new": "npm run test-suite-inject && npm run doc-listing-inject && npm run bootstrap"
31+
"post-new": "npm run test-suite-inject && npm run doc-listing-inject && npm run bootstrap",
32+
"leftover-check": "bash scripts/leftover-check.sh"
3233
},
3334
"husky": {
3435
"hooks": {
35-
"pre-commit": "npm run test-suite-inject > /dev/null && pretty-quick --staged"
36+
"pre-commit": "npm run test-suite-inject > /dev/null && pretty-quick --staged",
37+
"post-checkout": "npm run leftover-check"
3638
}
3739
},
3840
"devDependencies": {

scripts/leftover-check.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
DIRS=""
4+
DIRS_COUNT=""
5+
LEFTOVERS=0
6+
7+
package_json_exists() {
8+
find $1 -maxdepth 1 -name "package.json" -type f -print > /dev/null
9+
return $?
10+
}
11+
12+
node_modules_exists() {
13+
find $1 -maxdepth 1 -name "node_modules" -type d -print > /dev/null
14+
return $?
15+
}
16+
17+
# for each element, check for a node_modules dir without a corresponding
18+
# package.json. That indicates the element does not exist in this branch.
19+
for e in elements/*; do
20+
if [[ -d $e/node_modules && !( -f $e/package.json ) ]]; then
21+
if [[ "$LEFTOVERS" == 0 ]]; then
22+
echo -e "INFO: the following \"leftover\" elements were found:\n"
23+
fi
24+
LEFTOVERS=$((LEFTOVERS+1))
25+
echo "$e"
26+
fi
27+
done
28+
29+
if [[ $LEFTOVERS > 0 ]]; then
30+
echo -e "\nA \"leftover\" element arises when you create an element on a branch, then leave that branch, yet the element's directory still exists. This is caused by the element's (untracked) node_modules directory preventing git from fully cleaning up after the branch change. The leftover elements can be safely deleted. However, if you do return to work on the leftover element you will need to \`npm install\` again."
31+
fi
32+
33+
exit 0 # always exist 0 to prevent npm from printing a giant error blurb that takes attention away from these warnings

0 commit comments

Comments
 (0)