-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathdeploy.py
More file actions
79 lines (60 loc) · 1.8 KB
/
deploy.py
File metadata and controls
79 lines (60 loc) · 1.8 KB
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
# -*- 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!"