Created
January 8, 2013 12:26
-
-
Save binho/4483339 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, os.path, shutil | |
YUI_COMPRESSOR = 'yuicompressor-2.4.2.jar' | |
#_______________________________________________________________________ | |
def compress(in_files, out_file, in_type='js', verbose=False, temp_file='.temp'): | |
temp = open(temp_file, 'w') | |
for f in in_files: | |
fh = open(f) | |
data = fh.read() + '\n' | |
fh.close() | |
temp.write(data) | |
print ' + %s' % f | |
temp.close() | |
options = ['-o "%s"' % out_file, | |
'--type %s' % in_type] | |
if verbose: | |
options.append('-v') | |
if in_type == 'js': | |
options.append('--preserve-semi') | |
cmd = 'java -jar "%s" %s "%s"' % (YUI_COMPRESSOR, | |
' '.join(options), | |
temp_file) | |
print cmd | |
os.system(cmd) | |
org_size = os.path.getsize(temp_file) | |
new_size = os.path.getsize(out_file) | |
print '=> %s' % out_file | |
print 'Original: %.2f kB' % (org_size / 1024.0) | |
print 'Compressed: %.2f kB' % (new_size / 1024.0) | |
print 'Reduction: %.1f%%' % (float(org_size - new_size) / org_size * 100) | |
print '' | |
#_______________________________________________________________________ | |
BASE_PATH = 'C:\\xampp\\htdocs\\baloes-v2\\' | |
# JAVASCRIPT | |
SCRIPTS = [ | |
BASE_PATH + 'js\\config.js', | |
BASE_PATH + 'js\\baloon.js', | |
BASE_PATH + 'js\\engine.js', | |
] | |
SCRIPTS_OUT_DEBUG = BASE_PATH + 'js\\bundle.js' | |
SCRIPTS_OUT = BASE_PATH + 'js\\bundle.min.js' | |
# CSS | |
STYLESHEETS = [ | |
BASE_PATH + 'css\\styles.css', | |
] | |
STYLESHEETS_OUT = BASE_PATH + 'css\\styles.min.css' | |
def main(): | |
print 'Compressing JavaScript...' | |
compress(SCRIPTS, SCRIPTS_OUT, 'js', False, SCRIPTS_OUT_DEBUG) | |
print 'Compressing CSS...' | |
compress(STYLESHEETS, STYLESHEETS_OUT, 'css', False) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment