build.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/usr/bin/env bash
  2. REL_SCRIPT_DIR="`dirname \"$0\"`"
  3. SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`"
  4. PROJECT_DIR="`( cd \"$SCRIPT_DIR/..\" && pwd )`"
  5. build_help()
  6. {
  7. echo "build.sh <action>"
  8. echo " full - build and test of all implementations"
  9. echo " all - build of both implementations"
  10. echo " js - build of javascript"
  11. echo " py - build of python"
  12. echo " alltest - test both implementations, js and python"
  13. echo " pytest - test python implementation"
  14. echo " jstest - test javascript implementation"
  15. }
  16. build_ci()
  17. {
  18. build_full
  19. build_git_status
  20. }
  21. build_full()
  22. {
  23. build_all
  24. build_alltest
  25. }
  26. build_all()
  27. {
  28. build_py
  29. build_js
  30. }
  31. build_py()
  32. {
  33. echo Building python module...
  34. pip install -e ./python || exit 1
  35. }
  36. build_js()
  37. {
  38. echo Building javascript...
  39. npm install || exit 1
  40. generate_tests
  41. # jshint
  42. $PROJECT_DIR/node_modules/.bin/jshint 'js' 'test' || exit 1
  43. # beautify test and data
  44. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/js/test/amd-beautify-tests.js || exit 1
  45. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/js/test/node-beautify-html-perf-tests.js || exit 1
  46. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/js/test/node-beautify-perf-tests.js || exit 1
  47. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/js/test/node-beautify-tests.js || exit 1
  48. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/js/test/sanitytest.js || exit 1
  49. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/test/data/css/tests.js || exit 1
  50. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/test/data/html/tests.js || exit 1
  51. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/test/data/javascript/inputlib.js || exit 1
  52. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/test/data/javascript/tests.js || exit 1
  53. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/test/generate-tests.js || exit 1
  54. # beautify product code
  55. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/js/lib/unpackers/javascriptobfuscator_unpacker.js || exit 1
  56. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/js/lib/unpackers/myobfuscate_unpacker.js || exit 1
  57. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/js/lib/unpackers/p_a_c_k_e_r_unpacker.js || exit 1
  58. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/js/lib/unpackers/urlencode_unpacker.js || exit 1
  59. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/js/lib/beautify-css.js || exit 1
  60. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/js/lib/beautify-html.js || exit 1
  61. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/js/lib/beautify.js || exit 1
  62. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/js/lib/cli.js || exit 1
  63. $PROJECT_DIR/js/bin/js-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r $PROJECT_DIR/js/index.js || exit 1
  64. # html not ready yet
  65. # $PROJECT_DIR/js/bin/html-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r index.html
  66. # jshint again to make sure things haven't changed
  67. $PROJECT_DIR/node_modules/.bin/jshint 'js' 'test' || exit 1
  68. }
  69. generate_tests()
  70. {
  71. node test/generate-tests.js || exit 1
  72. }
  73. build_alltest()
  74. {
  75. build_jstest
  76. build_pytest
  77. }
  78. build_pytest()
  79. {
  80. echo Testing python implementation...
  81. generate_tests
  82. cd python
  83. python --version
  84. ./jsbeautifier/tests/shell-smoke-test.sh || exit 1
  85. }
  86. build_jstest()
  87. {
  88. echo Testing javascript implementation...
  89. generate_tests
  90. node --version
  91. ./js/test/shell-smoke-test.sh || exit 1
  92. }
  93. build_git_status()
  94. {
  95. $SCRIPT_DIR/git-status-clear.sh || exit 1
  96. }
  97. build_update-codemirror()
  98. {
  99. rm -rf node_modules/codemirror
  100. npm install codemirror
  101. rm -rf ./web/third-party/codemirror/*
  102. cp ./node_modules/codemirror/LICENSE ./web/third-party/codemirror/
  103. cp ./node_modules/codemirror/README.md ./web/third-party/codemirror/
  104. cp -r ./node_modules/codemirror/lib ./web/third-party/codemirror/
  105. mkdir -p ./web/third-party/codemirror/mode
  106. cp -r ./node_modules/codemirror/mode/javascript ./web/third-party/codemirror/mode/
  107. git add -Av ./web/third-party/codemirror
  108. }
  109. main() {
  110. cd $PROJECT_DIR
  111. local ACTION
  112. ACTION=build_${1:-full}
  113. if [ -n "$(type -t $ACTION)" ] && [ "$(type -t $ACTION)" = "function" ]; then
  114. $ACTION
  115. else
  116. build_help
  117. fi
  118. }
  119. (main $*)