update_settings.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. DEFAULT_TRUE="'default': true"
  2. DEFAULT_FALSE="'default': false"
  3. TELEMETRY_ENABLE="'telemetry.enableTelemetry':"
  4. TELEMETRY_CRASH_REPORTER="'telemetry.enableCrashReporter':"
  5. replace () {
  6. echo $1
  7. if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
  8. sed -i '' -E "$1" $2
  9. else
  10. sed -i -E "$1" $2
  11. fi
  12. }
  13. update_setting () {
  14. local FILENAME="$2"
  15. # check that the file exists
  16. if [ ! -f $FILENAME ]; then
  17. echo "File to update setting in does not exist ${FILENAME}"
  18. return
  19. fi
  20. # go through lines of file, looking for block that contains setting
  21. local SETTING="$1"
  22. local LINE_NUM=0
  23. while read -r line; do
  24. local LINE_NUM=$(( $LINE_NUM + 1 ))
  25. if [[ $line == *"$SETTING"* ]]; then
  26. local IN_SETTING=1
  27. fi
  28. if [[ $line == *"$DEFAULT_TRUE"* && "$IN_SETTING" == "1" ]]; then
  29. local FOUND=1
  30. break
  31. fi
  32. done < $FILENAME
  33. if [[ "$FOUND" != "1" ]]; then
  34. echo "$DEFAULT_TRUE not found for setting $SETTING in file $FILENAME"
  35. return
  36. fi
  37. # construct line-aware replacement string
  38. local DEFAULT_TRUE_TO_FALSE="${LINE_NUM}s/${DEFAULT_TRUE}/${DEFAULT_FALSE}/"
  39. replace "$DEFAULT_TRUE_TO_FALSE" $FILENAME
  40. }
  41. update_setting "$TELEMETRY_ENABLE" src/vs/platform/telemetry/common/telemetryService.ts
  42. update_setting "$TELEMETRY_CRASH_REPORTER" src/vs/workbench/electron-browser/main.contribution.ts