nix: Reset node_modules when Yarn deps change

Signed-off-by: Pedro Pombeiro <pombeirp@users.noreply.github.com>
This commit is contained in:
Pedro Pombeiro 2019-08-14 15:54:06 +02:00
parent 44bc306823
commit bdc0ba2680
No known key found for this signature in database
GPG Key ID: C4A24185B2AA48A1
1 changed files with 20 additions and 14 deletions

View File

@ -22,25 +22,31 @@ deps="$1"
nodeModulesDir="$STATUS_REACT_HOME/node_modules" nodeModulesDir="$STATUS_REACT_HOME/node_modules"
needCopyModules=1 needCopyModules=1
sentinelFilePath="$nodeModulesDir/.copied~"
# Check if node_modules exists and is valid # Check if node_modules exists and is valid
if [ -d "$nodeModulesDir" ]; then if [ -d "$nodeModulesDir" ]; then
if [ -f "$nodeModulesDir/.copied~" ]; then if [ -f "$sentinelFilePath" ]; then
echo "Checking for modifications in node_modules..." existingPath="$(cat $sentinelFilePath)"
modifiedFiles=( $(find $nodeModulesDir -writable -type f -newer $nodeModulesDir/.copied~ \ if [ "${existingPath}" != "${deps}" ]; then
-not \( -path "$nodeModulesDir/react-native/third-party/*" -prune \ echo "Yarn modules changed, copying over new version"
-o -path "$nodeModulesDir/react-native/ReactAndroid/build/*" -prune \
-o -path "$nodeModulesDir/*/android/build/*" -prune \
-o -path "$nodeModulesDir/realm/src/*" -prune \
-o -path './resources/icons/*' -prune \) -print) )
if [ ${#modifiedFiles[@]} -eq 0 ]; then
needCopyModules=0
echo "No modifications detected."
else else
echo "Modifications detected in ${#modifiedFiles[@]} files:\n${modifiedFiles[@]}" echo "Checking for modifications in node_modules..."
modifiedFiles=( $(find $nodeModulesDir -writable -type f -newer $sentinelFilePath \
-not \( -path "$nodeModulesDir/react-native/third-party/*" -prune \
-o -path "$nodeModulesDir/react-native/ReactAndroid/build/*" -prune \
-o -path "$nodeModulesDir/*/android/build/*" -prune \
-o -path "$nodeModulesDir/realm/src/*" -prune \
-o -path './resources/icons/*' -prune \) -print) )
if [ ${#modifiedFiles[@]} -eq 0 ]; then
needCopyModules=0
echo "No modifications detected."
else
echo "Modifications detected in ${#modifiedFiles[@]} files:\n${modifiedFiles[@]}"
fi
fi fi
fi fi
if [ $needCopyModules -eq 1 ]; then if [ $needCopyModules -eq 1 ] && [ -d $nodeModulesDir ]; then
chmod u+w -R $nodeModulesDir chmod u+w -R $nodeModulesDir
rm -rf $nodeModulesDir rm -rf $nodeModulesDir
fi fi
@ -69,7 +75,7 @@ if [ ! -d "$nodeModulesDir" ]; then
time cp -HRf --preserve=all ${deps}/node_modules/. "$nodeModulesDir.tmp" time cp -HRf --preserve=all ${deps}/node_modules/. "$nodeModulesDir.tmp"
chmod -R u+w "$nodeModulesDir.tmp" chmod -R u+w "$nodeModulesDir.tmp"
mv -f "$nodeModulesDir.tmp" $nodeModulesDir mv -f "$nodeModulesDir.tmp" $nodeModulesDir
touch $nodeModulesDir/.copied~ echo -n "${deps}" > $sentinelFilePath
trap - ERR INT HUP trap - ERR INT HUP
echo "Done" echo "Done"
fi fi