1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#!/usr/bin/python
# -*- encoding: utf-8 -*-
# © 2012, David Paleino <dapal@debian.org>
import json
import sys
import os
# the multiple-times copyright statement to remove
copyright_stmt = """/*!
* Ext JS Library 3.4.0
* Copyright(c) 2006-2011 Sencha Inc.
* licensing@sencha.com
* http://www.sencha.com/license
*/
"""
script = json.load(open(sys.argv[1]))
for pkg in script['pkgs']:
included_copyright = False
debug = pkg.get('isDebug', False)
if debug:
out = pkg['file'][:-3] + '-debug.js'
else:
out = pkg['file']
print out,
# make sure the directory exists
if out.rfind('/') != -1:
os.system('mkdir -p %s' % out[:out.rfind('/')])
output = open(out, 'w')
# only include pkgDeps for ext-all.css and ext-all.js
if pkg.has_key('pkgDeps') and 'ext-all' in pkg['file']:
if not pkg.get('includeDeps', True):
pass
else:
# first, dependencies
for inc in pkg['pkgDeps']:
if debug:
inc = inc[:-3] + '-debug.js'
with open(inc) as f:
if included_copyright:
# we already included the copyright statement,
# drop it.
s = f.read()
s = s.replace(copyright_stmt, '')
output.write(s)
else:
output.writelines(f.readlines())
included_copyright = True
# then, files to include.
for inc in pkg['fileIncludes']:
if inc['text'].endswith('.js'):
if debug:
f = inc['path'] + inc['text']
else:
f = inc['path'] + inc['text'][:-3] + '-debug.js'
else:
f = inc['path'] + inc['text']
with open(f) as f:
if included_copyright:
# we already included the copyright statement,
# drop it.
s = f.read()
s = s.replace(copyright_stmt, '')
output.write(s)
else:
output.writelines(f.readlines())
included_copyright = True
output.close()
print 'done.'
if debug:
# minify
minout = out.replace('-debug', '')
print minout,
os.system('yui-compressor -o %s %s' % (minout, out))
print 'minified OK.'
|