install_dev.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. set -e
  3. prod=$1
  4. info() {
  5. printf "\e[34m[➧]\e[0m ${1}\n"
  6. }
  7. error() {
  8. printf "\e[31m[✘]\e[0m ${1}\n"
  9. }
  10. success() {
  11. printf "\e[32m[✔]\e[0m ${1}\n"
  12. }
  13. function toWinPath() {
  14. echo "$1" | sed -e 's/^\///' -e 's/\//\\/g' -e 's/^./\0:/'
  15. }
  16. function toPosixPath() {
  17. echo "/$1" | sed -e 's/\\/\//g' -e 's/://' -e 's/\/\//\//g'
  18. }
  19. globalDirForWin=$(npm config get prefix)
  20. currentDirForPosix=$(pwd)
  21. currentDirForWin=$(toWinPath $currentDirForPosix)
  22. globalDirForPosix=$(toPosixPath $globalDirForWin)
  23. os="win"
  24. uname=$(uname)
  25. if [ "$uname"x = "Darwin"x ]; then
  26. os="mac"
  27. globalDirForPosix="$globalDirForPosix/bin"
  28. fi
  29. # Generate dev and debug bin file
  30. array=( dev debug )
  31. for mod in "${array[@]}"
  32. do
  33. params=""
  34. if [ "$mod"x = "debug"x ]; then
  35. params=" --inspect-brk"
  36. fi
  37. cat > "$globalDirForPosix/wepy-$mod" <<- EOF
  38. #!/bin/sh
  39. basedir=\$(dirname "\$(echo "\$0" | sed -e 's,\\\\,/,g')")
  40. case \`uname\` in
  41. *CYGWIN*) basedir=\`cygpath -w "\$basedir"\`;;
  42. esac
  43. if [ -x "\$basedir/node" ]; then
  44. "\$basedir/node"$params "$currentDirForPosix/packages/cli/bin/wepy.js" "\$@"
  45. ret=\$?
  46. else
  47. node$params "$currentDirForPosix/packages/cli/bin/wepy.js" "\$@"
  48. ret=\$?
  49. fi
  50. exit \$ret
  51. EOF
  52. chmod +x "$globalDirForPosix/wepy-$mod"
  53. success "generated: $globalDirForPosix/wepy-$mod"
  54. # If it's win then generate cmd file
  55. if [ "$os"x = "win"x ]; then
  56. cat > "$globalDirForPosix/wepy-$mod.cmd" <<- EOF
  57. @IF EXIST "%~dp0\node.exe" (
  58. "%~dp0\node.exe"$params "$currentDirForWin\packages\cli\bin\wepy.js" %*
  59. ) ELSE (
  60. @SETLOCAL
  61. @SET PATHEXT=%PATHEXT:;.JS;=;%
  62. node$params "$currentDirForWin\packages\cli\bin\wepy.js" %*
  63. )
  64. EOF
  65. success "generated: $globalDirForPosix/wepy-$mod.cmd"
  66. fi
  67. done