Migrate project from typing_practiceweb
This commit is contained in:
69
html5-tower-defense-master/tools/compressor.py
Normal file
69
html5-tower-defense-master/tools/compressor.py
Normal file
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/python2.6
|
||||
# @author: allenm, oldj
|
||||
#
|
||||
# @link: https://github.com/allenm/js-css-compressor
|
||||
# @link: https://github.com/oldj/js-css-compressor
|
||||
#
|
||||
|
||||
import httplib
|
||||
import urllib
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Define the parameters for the POST request and encode them in
|
||||
# a URL-safe format.
|
||||
|
||||
|
||||
def compressor(savename, filenames):
|
||||
''' compressor and combine the javascript files. This script use the google closure REST API '''
|
||||
|
||||
filenames = (v.strip() for v in filenames.split(";"))
|
||||
code = []
|
||||
for fn in filenames:
|
||||
if fn.startswith('http://'):
|
||||
# url
|
||||
code.append(('code_url', fn))
|
||||
else:
|
||||
# local file
|
||||
if not os.path.isfile(fn):
|
||||
print 'ERROR: "%s" is not a valid file!' % fn
|
||||
return False
|
||||
code.append(('js_code', open(fn).read()))
|
||||
|
||||
code.extend([
|
||||
('compilation_level', 'SIMPLE_OPTIMIZATIONS'),
|
||||
('output_format', 'text'),
|
||||
('output_info', 'compiled_code'),
|
||||
])
|
||||
|
||||
params = urllib.urlencode(code)
|
||||
|
||||
# Always use the following value for the Content-type header.
|
||||
headers = {'Content-type': 'application/x-www-form-urlencoded'}
|
||||
conn = httplib.HTTPConnection('closure-compiler.appspot.com')
|
||||
conn.request('POST', '/compile', params, headers)
|
||||
response = conn.getresponse()
|
||||
data = response.read()
|
||||
print 'DATA:'
|
||||
print '-' * 50
|
||||
print data.rstrip()
|
||||
conn.close()
|
||||
|
||||
donefile = open(savename, 'w')
|
||||
donefile.write(data)
|
||||
donefile.close()
|
||||
|
||||
print '-' * 50
|
||||
print '>> out: %s (%.2fK)' % (savename, len(data) / 1024.0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
if sys.argv.__len__() >= 3:
|
||||
compressor(sys.argv[1], sys.argv[2])
|
||||
else:
|
||||
print '''This script must contain at least two parameters.
|
||||
The first one is the filename which you want store the data after compress,
|
||||
the second is the urls or filenames of javascript file which you want compress,
|
||||
if you have more than one file to compress,
|
||||
use ";" to partition them.'''
|
||||
14
html5-tower-defense-master/tools/countjslines.py
Normal file
14
html5-tower-defense-master/tools/countjslines.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# 统计指定文件夹下的 js 一共有多少行
|
||||
|
||||
import os
|
||||
from glob import glob
|
||||
|
||||
src_folder = "../src/js"
|
||||
|
||||
if __name__ == "__main__":
|
||||
print "lines: %d" % sum(len(open(fn).readlines()) for \
|
||||
fn in glob(os.path.join(src_folder.replace("/", os.sep), "*.js")))
|
||||
raw_input("")
|
||||
|
||||
79
html5-tower-defense-master/tools/deploy.py
Normal file
79
html5-tower-defense-master/tools/deploy.py
Normal file
@@ -0,0 +1,79 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
u"""
|
||||
发布脚本
|
||||
|
||||
此脚本把 src 目录下的 js 合并成一个,压缩,放到 build 目录下,
|
||||
再更新 build/td.html 里 .js 文件的时间戳以防止浏览器缓存。
|
||||
"""
|
||||
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
|
||||
from compressor import compressor
|
||||
|
||||
|
||||
def updateHTML():
|
||||
u"更新 td.html 中 js 文件的时间戳,以防止最终访问页面时的缓存"
|
||||
|
||||
tdh = "../build/td.html"
|
||||
tdh = tdh.replace("/", os.sep)
|
||||
html = open(tdh).read()
|
||||
html = re.sub(r"\.js\?fmts=[\d\.]+", ".js?fmts=%.1f" % time.time(), html)
|
||||
open(tdh, "w").write(html)
|
||||
|
||||
|
||||
def compress(fn):
|
||||
u"压缩合并后的文件,需要网络支持"
|
||||
|
||||
print "compressing..."
|
||||
path, filename = os.path.split(fn)
|
||||
compressed_fn = os.path.join(path, filename.replace("-pkg.js", "-pkg-min.js"))
|
||||
compressor(compressed_fn, fn)
|
||||
print "compressed!"
|
||||
|
||||
|
||||
def merge():
|
||||
u"合并文件"
|
||||
|
||||
src_folder = "../src/js"
|
||||
files = [
|
||||
"td.js", "td-lang.js", "td-event.js",
|
||||
"td-stage.js", "td-element.js",
|
||||
"td-obj-map.js", "td-obj-grid.js",
|
||||
"td-obj-building.js", "td-obj-monster.js",
|
||||
"td-obj-panel.js", "td-data-stage-1.js",
|
||||
"td-cfg-buildings.js", "td-cfg-monsters.js",
|
||||
"td-render-buildings.js", "td-msg.js",
|
||||
"td-walk.js",
|
||||
]
|
||||
build_folder = "../build"
|
||||
build_name = "td-pkg.js"
|
||||
|
||||
print "merging..."
|
||||
src_folder = src_folder.replace("/", os.sep)
|
||||
build_folder = build_folder.replace("/", os.sep)
|
||||
c = "/** %s */" % build_name
|
||||
|
||||
for fn in files:
|
||||
fn = os.path.join(src_folder, fn)
|
||||
if os.path.isfile(fn):
|
||||
c = "%s\n\n%s" % (c, open(fn).read())
|
||||
else:
|
||||
print "ERROR: '%s' is not a file!" % fn
|
||||
return
|
||||
|
||||
build_path = os.path.join(build_folder, build_name)
|
||||
print "save to '%s'" % build_path
|
||||
open(build_path, "w").write(c)
|
||||
|
||||
print "merged!"
|
||||
|
||||
return build_path
|
||||
|
||||
if __name__ == "__main__":
|
||||
fn = merge()
|
||||
compress(fn)
|
||||
updateHTML()
|
||||
print "done!"
|
||||
Reference in New Issue
Block a user