2
0

setup-grunt 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env bash
  2. echo "Confirming n98-magerun2 is installed..."
  3. bin/n98-magerun2 > /dev/null 2>&1
  4. DEFAULT_THEME_ID="select value from core_config_data where path = 'design/theme/theme_id'"
  5. THEME_PATH="select theme_path from theme where theme_id in ($DEFAULT_THEME_ID);"
  6. VENDOR_THEME=$(bin/n98-magerun2 db:query "$THEME_PATH" | sed -n 2p | cut -d$'\r' -f1)
  7. THEME=$(echo "$VENDOR_THEME" | cut -d'/' -f2)
  8. LOCALE_CODE=$(bin/magento config:show general/locale/code | cut -d$'\r' -f1 | sed 's/ *$//g')
  9. # Generate local-theme.js for custom theme
  10. read -r -d '' GEN_THEME_JS << EOM
  11. var fs = require('fs');
  12. var util = require('util');
  13. var theme = require('./dev/tools/grunt/configs/themes');
  14. theme['$THEME'] = {
  15. area: 'frontend',
  16. name: '$VENDOR_THEME',
  17. locale: '$LOCALE_CODE',
  18. files: [
  19. 'css/styles-m',
  20. 'css/styles-l'
  21. ],
  22. dsl: 'less'
  23. };
  24. fs.writeFileSync('./dev/tools/grunt/configs/local-themes.js', '"use strict"; module.exports = ' + util.inspect(theme), 'utf-8');
  25. EOM
  26. if [ -z "$VENDOR_THEME" ] || [ -z "$THEME" ]; then
  27. echo "Using Magento/luma theme for grunt config"
  28. THEME=luma
  29. bin/clinotty cp ./dev/tools/grunt/configs/themes.js ./dev/tools/grunt/configs/local-themes.js
  30. else
  31. echo "Using $VENDOR_THEME theme for grunt config"
  32. bin/node -e "$GEN_THEME_JS"
  33. fi
  34. # Create files from sample files if they do not yet exist
  35. test -f src/package.json || cp src/package.json.sample src/package.json
  36. test -f src/Gruntfile.js || cp src/Gruntfile.js.sample src/Gruntfile.js
  37. test -f src/grunt-config.json || cp src/grunt-config.json.sample src/grunt-config.json
  38. # Disable grunt-contrib-jasmine on ARM processors (incompatible)
  39. if [ "$(uname -m)" == "arm64" ]; then
  40. sed -e 's/"grunt-contrib-jasmine": "[~.0-9]*",//' src/package.json > package.json \
  41. && mv package.json src/package.json
  42. fi
  43. # Enable these custom files on compose.dev.yaml so custom updates are persisted
  44. sed -e 's/grunt-config.json.sample/grunt-config.json/' compose.dev.yaml > compose.dev.yaml.updated \
  45. && mv compose.dev.yaml.updated compose.dev.yaml
  46. sed -e 's/Gruntfile.js.sample/Gruntfile.js/' compose.dev.yaml > compose.dev.yaml.updated \
  47. && mv compose.dev.yaml.updated compose.dev.yaml
  48. sed -e 's/package.json.sample/package.json/' compose.dev.yaml > compose.dev.yaml.updated \
  49. && mv compose.dev.yaml.updated compose.dev.yaml
  50. bin/restart app phpfpm
  51. bin/npm install ajv@^5.0.0 --save
  52. bin/npm install
  53. bin/magento cache:clean
  54. bin/grunt clean
  55. bin/grunt exec:"$THEME"
  56. bin/grunt less:"$THEME"