do.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # coding: utf-8
  2. '''
  3. Created on Apr 12, 2018
  4. Update on 2018-04-13
  5. @author: Mashiro @ https://2heng.xin
  6. Desc: Auto compress & minfy JavaScript codes and CSS style sheet
  7. '''
  8. import os
  9. from os import listdir
  10. from os.path import isfile, join
  11. from jsmin import jsmin
  12. from csscompressor import compress
  13. import time
  14. import codecs
  15. localtime = time.asctime( time.localtime(time.time()) )
  16. print (localtime)
  17. patchall = '../'
  18. pathCSS = patchall + 'css/src/'
  19. pathCSSroot = patchall + 'css/'
  20. cssfiles = [f for f in listdir(pathCSS) if isfile(join(pathCSS, f))]
  21. strCSS = '/*! Generate by mirai-mamori. ' + localtime + '*/'
  22. for f in cssfiles:
  23. with codecs.open(pathCSS + f, 'r', encoding='utf-8') as file:
  24. data = file.read()
  25. strCSS = strCSS + data
  26. print(f)
  27. CSSminified = compress(strCSS)
  28. with codecs.open(pathCSSroot + "lib.css", "w", encoding='utf-8') as text_file:
  29. print(CSSminified, file=text_file)
  30. print('------------------CSS Done------------------')
  31. key = input('Press any key to quit')
  32. quit()