minify_css_js.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/share/python3
  2. #
  3. # Copyright (C) 2020 Jorge Maldonado Ventura <jorgesumle@freakspot.net>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. import os
  18. import subprocess
  19. # Ajústalo según te convenga
  20. OUTPUT_DIR = '../html/'
  21. # Comprime archivos CSS
  22. css_dirs = []
  23. for directory in ['theme', 'css', 'de/css', 'en/css', 'eo/css']:
  24. css_dirs.append(OUTPUT_DIR + directory)
  25. for root_dir in css_dirs:
  26. for directory, subdirectories, files in os.walk(root_dir):
  27. for _file in files:
  28. if os.path.splitext(_file)[1] == '.css':
  29. subprocess.run(['uglifycss', '--output',
  30. os.path.join(directory, _file),
  31. os.path.join(directory, _file)])
  32. # Comprime archivos JavaScript
  33. js_dirs = []
  34. for directory in ['theme/js', 'js/', 'de/js/', 'en/js/', 'eo/js/']:
  35. js_dirs.append(OUTPUT_DIR + directory)
  36. for root_dir in js_dirs:
  37. for directory, subdirectories, files in os.walk(root_dir):
  38. for _file in files:
  39. if os.path.splitext(_file)[1] == '.js' and os.path.splitext(_file)[0][-4:] != '.min':
  40. min_file = os.path.splitext(_file)[0] + '.min' + os.path.splitext(_file)[1]
  41. subprocess.run(['uglifyjs', '--output',
  42. os.path.join(directory, min_file),
  43. os.path.join(directory, _file)])