setup-grunt 2.4 KB

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