1
0

get-vscode-usages.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env bash
  2. set -eu
  3. FILES=$(git ls-files src|grep -v test|grep -v vscode|grep -v extension.ts|grep -v evals|grep -v standalone|grep -v /dev/)
  4. DEST_DIR=dist-standalone
  5. SDK_DEST=$DEST_DIR/vscode-sdk-uses.txt
  6. CSS_DEST=$DEST_DIR/vscode-css-uses.txt
  7. TMP=/tmp/vscode-sdk-uses.txt.tmp
  8. mkdir -p $DEST_DIR
  9. if [[ ${1:-} == "-v" ]]; then
  10. grep -Er --color=always 'vscode[?]?\.' $FILES
  11. fi
  12. {
  13. grep -Ehr 'vscode[?]?\.' $FILES |
  14. grep -Ev '//.*vscode' | # remove commented out code
  15. grep -v vscode.commands.executeCommand | # executeCommand is handled separately
  16. #grep -Ev '"vscode' | # remove command strings that get included because they start with vscode
  17. sed 's|.*vscode|vscode|'| # remove everything before vscode.
  18. sed 's|?||g' | # remove ? from vcode?.env?.foo
  19. sed 's/[^a-zA-Z0-9_.?].*$//' | # remove everything after last identifier
  20. grep -E '\.[a-z][^.]+$' | # remove types (last part of identifier should be lowercase)
  21. cat > $TMP
  22. }
  23. {
  24. grep -hr 'vscode.commands.executeCommand' $FILES |
  25. perl -ne 'print if /["\x27"]/' | # Remove occurrences where the command is not on the same line (line doesnt contain quote chars) :(
  26. sed -n 's|.*\(vscode.commands.executeCommand[^,]*\).*|\1|p'| # Remove all params after the first one
  27. sed 's|\(".*"\).*|\1)|'| # Close the parantheses
  28. cat >> $TMP
  29. }
  30. # Count occurrences
  31. cat $TMP | sort | uniq -c | sort -n > $SDK_DEST
  32. rm $TMP
  33. echo Wrote uses of the vscode SDK to $(realpath $SDK_DEST)
  34. {
  35. grep -rh -- --vscode- webview-ui/build/ |
  36. sed 's/--vscode/\n--vscode/g' | # One var per line
  37. grep -- --vscode | # Remove lines that don't have vars.
  38. sed 's/[),"\\].*$//' | # remove from the end of the var name to the end of the line.
  39. sort | uniq > $CSS_DEST
  40. }
  41. echo Wrote vscode vars used to $(realpath $CSS_DEST)