mirror of https://github.com/axmolengine/axmol.git
issue #1841, improve tools/closure-compiler/obfuscate.py to general usage, with input params
This commit is contained in:
parent
0d73934f5c
commit
582e35014f
|
@ -2,87 +2,88 @@
|
|||
<project name="Javascript compress project" basedir="." default="compile">
|
||||
|
||||
<taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask"
|
||||
classpath="/workspace/cocos2d-x/tools/closure-compiler/compiler.jar"/>
|
||||
classpath="../../..//tools/closure-compiler/compiler.jar"/>
|
||||
|
||||
<target name="compile">
|
||||
<!--advanced / simple-->
|
||||
<jscomp compilationLevel="advanced" warning="quiet"
|
||||
debug="false" output="/workspace/cocos2d-x/samples/Javascript/TestJavascript/main.js">
|
||||
<externs dir="/workspace/cocos2d-x/scripting/javascript/bindings/obfuscate">
|
||||
debug="false" output="/workspace/cocos2d-x/samples/Javascript/TestJavascript/./main.js">
|
||||
<externs dir="../../..//scripting/javascript/bindings/obfuscate">
|
||||
<file name="obfuscate_exclude_cocos2d.js"/>
|
||||
<file name="obfuscate_exclude_chipmunk.js"/>
|
||||
</externs>
|
||||
<sources dir="/workspace/cocos2d-x/samples/Javascript/Shared/tests">
|
||||
<file name="main.js"/>
|
||||
<file name="tests-boot-html5.js"/>
|
||||
<file name="tests-boot-jsb.js"/>
|
||||
<file name="tests-main.js"/>
|
||||
<file name="tests_resources-html5.js"/>
|
||||
<file name="tests_resources-jsb.js"/>
|
||||
<file name="ActionManagerTest/ActionManagerTest.js"/>
|
||||
<file name="ActionsTest/ActionsTest.js"/>
|
||||
<file name="BaseTestLayer/BaseTestLayer.js"/>
|
||||
<file name="Box2dTest/Box2dTest.js"/>
|
||||
<file name="ChipmunkTest/ChipmunkTest.js"/>
|
||||
<file name="ClickAndMoveTest/ClickAndMoveTest.js"/>
|
||||
<file name="CocosDenshionTest/CocosDenshionTest.js"/>
|
||||
<file name="CocosNodeTest/CocosNodeTest.js"/>
|
||||
<file name="CurrentLanguageTest/CurrentLanguageTest.js"/>
|
||||
<file name="DrawPrimitivesTest/DrawPrimitivesTest.js"/>
|
||||
<file name="EaseActionsTest/EaseActionsTest.js"/>
|
||||
<file name="EffectsTest/EffectsTest.js"/>
|
||||
<file name="EventTest/EventTest.js"/>
|
||||
<file name="ExtensionsTest/ExtensionsTest.js"/>
|
||||
<file name="ExtensionsTest/CocosBuilderTest/CocosBuilderTest.js"/>
|
||||
<file name="ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsTestLayer.js"/>
|
||||
<file name="ExtensionsTest/CocosBuilderTest/ButtonTest/ButtonTestLayer.js"/>
|
||||
<file name="ExtensionsTest/CocosBuilderTest/HelloCocosBuilder/HelloCocosBuilderLayer.js"/>
|
||||
<file name="ExtensionsTest/CocosBuilderTest/LabelTest/LabelTestLayer.js"/>
|
||||
<file name="ExtensionsTest/CocosBuilderTest/MenuTest/MenuTestLayer.js"/>
|
||||
<file name="ExtensionsTest/CocosBuilderTest/ParticleSystemTest/ParticleSystemTestLayer.js"/>
|
||||
<file name="ExtensionsTest/CocosBuilderTest/ScrollViewTest/ScrollViewTestLayer.js"/>
|
||||
<file name="ExtensionsTest/CocosBuilderTest/SpriteTest/SpriteTestLayer.js"/>
|
||||
<file name="ExtensionsTest/CocosBuilderTest/TestHeader/TestHeaderLayer.js"/>
|
||||
<file name="ExtensionsTest/ControlExtensionTest/CCControlScene.js"/>
|
||||
<file name="ExtensionsTest/ControlExtensionTest/CCControlSceneManager.js"/>
|
||||
<file name="ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.js"/>
|
||||
<file name="ExtensionsTest/EditBoxTest/EditBoxTest.js"/>
|
||||
<file name="ExtensionsTest/S9SpriteTest/S9SpriteTest.js"/>
|
||||
<file name="ExtensionsTest/TableViewTest/TableViewTestScene.js"/>
|
||||
<file name="FileUtils/FileUtilsTest.js"/>
|
||||
<file name="FontTest/FontTest.js"/>
|
||||
<file name="IntervalTest/IntervalTest.js"/>
|
||||
<file name="LabelTest/LabelTest.js"/>
|
||||
<file name="LayerTest/LayerTest.js"/>
|
||||
<file name="MenuTest/MenuTest.js"/>
|
||||
<file name="OpenGLTest/OpenGLTest.js"/>
|
||||
<file name="ParallaxTest/ParallaxTest.js"/>
|
||||
<file name="ParticleTest/ParticleTest.js"/>
|
||||
<file name="PerformanceTest/PerformanceAnimationTest.js"/>
|
||||
<file name="PerformanceTest/PerformanceNodeChildrenTest.js"/>
|
||||
<file name="PerformanceTest/PerformanceParticleTest.js"/>
|
||||
<file name="PerformanceTest/PerformanceSpriteTest.js"/>
|
||||
<file name="PerformanceTest/PerformanceSpriteTest2.js"/>
|
||||
<file name="PerformanceTest/PerformanceTest.js"/>
|
||||
<file name="PerformanceTest/PerformanceTextureTest.js"/>
|
||||
<file name="PerformanceTest/PerformanceTouchesTest.js"/>
|
||||
<file name="PerformanceTest/seedrandom.js"/>
|
||||
<file name="Presentation/Presentation.js"/>
|
||||
<file name="ProgressActionsTest/ProgressActionsTest.js"/>
|
||||
<file name="RenderTextureTest/RenderTextureTest.js"/>
|
||||
<file name="RotateWorldTest/RotateWorldTest.js"/>
|
||||
<file name="SceneTest/SceneTest.js"/>
|
||||
<file name="SchedulerTest/SchedulerTest.js"/>
|
||||
<file name="SpriteTest/SpriteTest.js"/>
|
||||
<file name="SysTest/SysTest.js"/>
|
||||
<file name="TextInputTest/TextInputTest.js"/>
|
||||
<file name="TextureCacheTest/TextureCacheTest.js"/>
|
||||
<file name="TileMapTest/TileMapTest.js"/>
|
||||
<file name="TouchesTest/Ball.js"/>
|
||||
<file name="TouchesTest/Paddle.js"/>
|
||||
<file name="TouchesTest/TouchesTest.js"/>
|
||||
<file name="TransitionsTest/TransitionsTest.js"/>
|
||||
<file name="UnitTest/UnitTest.js"/>
|
||||
<sources dir="./">
|
||||
<file name="../Shared/tests//main.js"/>
|
||||
<file name="../Shared/tests//tests-boot-html5.js"/>
|
||||
<file name="../Shared/tests//tests-boot-jsb.js"/>
|
||||
<file name="../Shared/tests//tests-main.js"/>
|
||||
<file name="../Shared/tests//tests_resources-html5.js"/>
|
||||
<file name="../Shared/tests//tests_resources-jsb.js"/>
|
||||
<file name="../Shared/tests/ActionManagerTest/ActionManagerTest.js"/>
|
||||
<file name="../Shared/tests/ActionsTest/ActionsTest.js"/>
|
||||
<file name="../Shared/tests/BaseTestLayer/BaseTestLayer.js"/>
|
||||
<file name="../Shared/tests/Box2dTest/Box2dTest.js"/>
|
||||
<file name="../Shared/tests/ChipmunkTest/ChipmunkTest.js"/>
|
||||
<file name="../Shared/tests/ClickAndMoveTest/ClickAndMoveTest.js"/>
|
||||
<file name="../Shared/tests/CocosDenshionTest/CocosDenshionTest.js"/>
|
||||
<file name="../Shared/tests/CocosNodeTest/CocosNodeTest.js"/>
|
||||
<file name="../Shared/tests/CurrentLanguageTest/CurrentLanguageTest.js"/>
|
||||
<file name="../Shared/tests/DrawPrimitivesTest/DrawPrimitivesTest.js"/>
|
||||
<file name="../Shared/tests/EaseActionsTest/EaseActionsTest.js"/>
|
||||
<file name="../Shared/tests/EffectsTest/EffectsTest.js"/>
|
||||
<file name="../Shared/tests/EventTest/EventTest.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/ExtensionsTest.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/CocosBuilderTest/CocosBuilderTest.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsTestLayer.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/CocosBuilderTest/ButtonTest/ButtonTestLayer.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/CocosBuilderTest/HelloCocosBuilder/HelloCocosBuilderLayer.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/CocosBuilderTest/LabelTest/LabelTestLayer.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/CocosBuilderTest/MenuTest/MenuTestLayer.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/CocosBuilderTest/ParticleSystemTest/ParticleSystemTestLayer.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/CocosBuilderTest/ScrollViewTest/ScrollViewTestLayer.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/CocosBuilderTest/SpriteTest/SpriteTestLayer.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/CocosBuilderTest/TestHeader/TestHeaderLayer.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/ControlExtensionTest/CCControlScene.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/EditBoxTest/EditBoxTest.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/S9SpriteTest/S9SpriteTest.js"/>
|
||||
<file name="../Shared/tests/ExtensionsTest/TableViewTest/TableViewTestScene.js"/>
|
||||
<file name="../Shared/tests/FileUtils/FileUtilsTest.js"/>
|
||||
<file name="../Shared/tests/FontTest/FontTest.js"/>
|
||||
<file name="../Shared/tests/IntervalTest/IntervalTest.js"/>
|
||||
<file name="../Shared/tests/LabelTest/LabelTest.js"/>
|
||||
<file name="../Shared/tests/LayerTest/LayerTest.js"/>
|
||||
<file name="../Shared/tests/MenuTest/MenuTest.js"/>
|
||||
<file name="../Shared/tests/OpenGLTest/OpenGLTest.js"/>
|
||||
<file name="../Shared/tests/ParallaxTest/ParallaxTest.js"/>
|
||||
<file name="../Shared/tests/ParticleTest/ParticleTest.js"/>
|
||||
<file name="../Shared/tests/PerformanceTest/PerformanceAnimationTest.js"/>
|
||||
<file name="../Shared/tests/PerformanceTest/PerformanceNodeChildrenTest.js"/>
|
||||
<file name="../Shared/tests/PerformanceTest/PerformanceParticleTest.js"/>
|
||||
<file name="../Shared/tests/PerformanceTest/PerformanceSpriteTest.js"/>
|
||||
<file name="../Shared/tests/PerformanceTest/PerformanceSpriteTest2.js"/>
|
||||
<file name="../Shared/tests/PerformanceTest/PerformanceTest.js"/>
|
||||
<file name="../Shared/tests/PerformanceTest/PerformanceTextureTest.js"/>
|
||||
<file name="../Shared/tests/PerformanceTest/PerformanceTouchesTest.js"/>
|
||||
<file name="../Shared/tests/PerformanceTest/seedrandom.js"/>
|
||||
<file name="../Shared/tests/Presentation/Presentation.js"/>
|
||||
<file name="../Shared/tests/ProgressActionsTest/ProgressActionsTest.js"/>
|
||||
<file name="../Shared/tests/RenderTextureTest/RenderTextureTest.js"/>
|
||||
<file name="../Shared/tests/RotateWorldTest/RotateWorldTest.js"/>
|
||||
<file name="../Shared/tests/SceneTest/SceneTest.js"/>
|
||||
<file name="../Shared/tests/SchedulerTest/SchedulerTest.js"/>
|
||||
<file name="../Shared/tests/SpriteTest/SpriteTest.js"/>
|
||||
<file name="../Shared/tests/SysTest/SysTest.js"/>
|
||||
<file name="../Shared/tests/TextInputTest/TextInputTest.js"/>
|
||||
<file name="../Shared/tests/TextureCacheTest/TextureCacheTest.js"/>
|
||||
<file name="../Shared/tests/TileMapTest/TileMapTest.js"/>
|
||||
<file name="../Shared/tests/TouchesTest/Ball.js"/>
|
||||
<file name="../Shared/tests/TouchesTest/Paddle.js"/>
|
||||
<file name="../Shared/tests/TouchesTest/TouchesTest.js"/>
|
||||
<file name="../Shared/tests/TransitionsTest/TransitionsTest.js"/>
|
||||
<file name="../Shared/tests/UnitTest/UnitTest.js"/>
|
||||
|
||||
</sources>
|
||||
</jscomp>
|
||||
</target>
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
# create_project.py
|
||||
# Create cross-platform cocos2d-x project
|
||||
# Copyright (c) 2012 cocos2d-x.org
|
||||
# Author: WangZhe
|
||||
|
||||
# define global variables
|
||||
context = {
|
||||
"input" : "/workspace/cocos2d-x/samples/Javascript/Shared/tests",
|
||||
"output" : "/workspace/cocos2d-x/samples/Javascript/TestJavascript/main.js",
|
||||
"cocos2d" : "/workspace/cocos2d-x",
|
||||
}
|
||||
|
||||
# begin
|
||||
import sys
|
||||
import os, os.path
|
||||
|
||||
class FileInfo:
|
||||
def __init__(self, filename, filepath):
|
||||
self.filename = filename
|
||||
self.filepath = filepath
|
||||
|
||||
def getFiles(currentDir):
|
||||
files = {
|
||||
"js" : [],
|
||||
"other" : [],
|
||||
}
|
||||
for root, dirs, file_list in os.walk(currentDir): # Walk directory tree
|
||||
for f in file_list:
|
||||
if f.find(".js") != -1:
|
||||
files["js"].append(FileInfo(f, root))
|
||||
else:
|
||||
files["other"].append(FileInfo(f, root))
|
||||
return files
|
||||
# end of getInfos
|
||||
|
||||
def prepareConfigs():
|
||||
config = {
|
||||
"path_to_compiler": "undefiend",
|
||||
"path_to_excludes": "undefined",
|
||||
"path_to_sources": "undefined",
|
||||
"sources": [],
|
||||
}
|
||||
|
||||
config["path_to_compiler"] = context["cocos2d"] + "/tools/closure-compiler/compiler.jar"
|
||||
config["path_to_excludes"] = context["cocos2d"] + "/scripting/javascript/bindings/obfuscate"
|
||||
config["path_to_sources"] = context["input"]
|
||||
config["path_to_output"] = context["output"]
|
||||
config["js_files"] = ""
|
||||
|
||||
files = getFiles( context["input"] )
|
||||
|
||||
for item in files["js"]:
|
||||
folder = item.filepath.lstrip(config["path_to_sources"])
|
||||
if folder == "":
|
||||
tmp = "<file name=\"" + item.filename + "\"/>" + "\n\t\t\t\t"
|
||||
else:
|
||||
tmp = "<file name=\"" + folder + "/" + item.filename + "\"/>" + "\n\t\t\t\t"
|
||||
|
||||
config["js_files"] += tmp
|
||||
|
||||
return config
|
||||
# end of prepareConfigs
|
||||
|
||||
def generateXmlForCompiler():
|
||||
config = prepareConfigs()
|
||||
|
||||
f1 = open(os.getcwd() + "/config_template.xml", "rb")
|
||||
content = ""
|
||||
for line in f1:
|
||||
if "$PATH_TO_COMPILER" in line:
|
||||
content += line.replace("$PATH_TO_COMPILER", config["path_to_compiler"])
|
||||
elif "$PATH_TO_EXCLUDES" in line:
|
||||
content += line.replace("$PATH_TO_EXCLUDES", config["path_to_excludes"])
|
||||
elif "$PATH_TO_OUTPUT_FILE" in line:
|
||||
content += line.replace("$PATH_TO_OUTPUT_FILE", config["path_to_output"])
|
||||
elif "$PATH_TO_SOURCES" in line:
|
||||
content += line.replace("$PATH_TO_SOURCES", config["path_to_sources"])
|
||||
elif "$JS_FILES" in line:
|
||||
content += line.replace("$JS_FILES", config["js_files"])
|
||||
else:
|
||||
content += line
|
||||
|
||||
f1.close()
|
||||
f2 = open(os.getcwd() + "/obfuscate.xml", "wb")
|
||||
f2.write(content)
|
||||
f2.close()
|
||||
|
||||
# end of dump
|
||||
|
||||
generateXmlForCompiler()
|
|
@ -0,0 +1,125 @@
|
|||
#!/usr/bin/python
|
||||
# create_project.py
|
||||
# Create cross-platform cocos2d-x project
|
||||
# Copyright (c) 2012 cocos2d-x.org
|
||||
# Author: WangZhe
|
||||
|
||||
# define global variables
|
||||
context = {
|
||||
"input" : "undefined",
|
||||
"output" : "undefined",
|
||||
"cocos2d" : "undefined",
|
||||
}
|
||||
|
||||
# begin
|
||||
import sys
|
||||
import os, os.path
|
||||
|
||||
def dumpUsage():
|
||||
print "Usage: generate-config.py -input INPUT_PATH -output OUTPUT_PATH -cocos2d COCOS2D_ROOT_PATH"
|
||||
print "Options:"
|
||||
print " -intput INPUT_PATH The path to javscript files directory"
|
||||
print " -output OUTPUT_PATH The path to the obfuscated javascript file"
|
||||
print " -cocos2d COCOS2D_ROOT_PATH The root path of cocos2d-x, e.g. /workspace/cocos2d-x"
|
||||
print ""
|
||||
|
||||
def checkParams():
|
||||
# generate our internal params
|
||||
context["script_path"] = os.getcwd() + "/"
|
||||
|
||||
if len(sys.argv) < 4:
|
||||
dumpUsage()
|
||||
sys.exit()
|
||||
|
||||
# fine params
|
||||
for i in range(1, len(sys.argv)):
|
||||
if "-input" == sys.argv[i]:
|
||||
context["input"] = sys.argv[i+1]
|
||||
elif "-output" == sys.argv[i]:
|
||||
context["output"] = os.getcwd() + "/" + sys.argv[i+1]
|
||||
elif "-cocos2d" == sys.argv[i]:
|
||||
context["cocos2d"] = sys.argv[i+1]
|
||||
|
||||
# pinrt error log our required paramters are not ready
|
||||
raise_error = False
|
||||
if context["input"] == "undefined":
|
||||
print "Invalid -input parameter"
|
||||
raise_error = True
|
||||
if context["output"] == "undefined":
|
||||
print "Invalid -output parameter"
|
||||
raise_error = True
|
||||
if context["cocos2d"] == "undefined":
|
||||
print "Invalid -cocos2d parameter"
|
||||
raise_error = True
|
||||
if raise_error != False:
|
||||
sys.exit()
|
||||
# end of checkParams
|
||||
|
||||
class FileInfo:
|
||||
def __init__(self, filename, filepath):
|
||||
self.filename = filename
|
||||
self.filepath = filepath
|
||||
|
||||
def getFiles(currentDir):
|
||||
files = {
|
||||
"js" : [],
|
||||
"other" : [],
|
||||
}
|
||||
for root, dirs, file_list in os.walk(currentDir): # Walk directory tree
|
||||
for f in file_list:
|
||||
if f.find(".js") != -1:
|
||||
files["js"].append(FileInfo(f, root))
|
||||
else:
|
||||
files["other"].append(FileInfo(f, root))
|
||||
return files
|
||||
# end of getInfos
|
||||
|
||||
def prepareConfigs():
|
||||
config = {
|
||||
"path_to_compiler": "undefiend",
|
||||
"path_to_excludes": "undefined",
|
||||
"path_to_sources": "undefined",
|
||||
"sources": [],
|
||||
}
|
||||
|
||||
config["path_to_compiler"] = context["cocos2d"] + "/tools/closure-compiler/compiler.jar"
|
||||
config["path_to_excludes"] = context["cocos2d"] + "/scripting/javascript/bindings/obfuscate"
|
||||
config["path_to_sources"] = "./" # don't use context["input"] here
|
||||
config["path_to_output"] = context["output"] + "main.js"
|
||||
config["js_files"] = ""
|
||||
|
||||
files = getFiles( context["input"] )
|
||||
|
||||
for item in files["js"]:
|
||||
config["js_files"] += "<file name=\"" + item.filepath + "/" + item.filename + "\"/>" + "\n\t\t\t\t"
|
||||
|
||||
return config
|
||||
# end of prepareConfigs
|
||||
|
||||
def generateXmlForCompiler():
|
||||
print "preparing configs..."
|
||||
config = prepareConfigs()
|
||||
print "generating obfuscate.xml for google closure compiler"
|
||||
f1 = open(context["cocos2d"] + "tools/closure-compiler/template.xml", "rb")
|
||||
tmp = f1.read()
|
||||
f1.close()
|
||||
from string import Template
|
||||
s = Template(tmp)
|
||||
content = s.substitute( PATH_TO_COMPILER = config["path_to_compiler"],
|
||||
PATH_TO_EXCLUDES = config["path_to_excludes"],
|
||||
PATH_TO_OUTPUT = config["path_to_output"],
|
||||
PATH_TO_SOURCES = config["path_to_sources"],
|
||||
JS_FILES = config["js_files"] )
|
||||
|
||||
f2 = open(context["output"] + "obfuscate.xml", "wb")
|
||||
f2.write(content)
|
||||
f2.close()
|
||||
# end of generateXmlForCompiler
|
||||
|
||||
# main
|
||||
checkParams()
|
||||
generateXmlForCompiler()
|
||||
print "running ant to generate obfuscated main.js"
|
||||
os.popen("ant -buildfile obfuscate.xml")
|
||||
print "done!"
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
<target name="compile">
|
||||
<!--advanced / simple-->
|
||||
<jscomp compilationLevel="advanced" warning="quiet"
|
||||
debug="false" output="$PATH_TO_OUTPUT_FILE">
|
||||
debug="false" output="$PATH_TO_OUTPUT">
|
||||
<externs dir="$PATH_TO_EXCLUDES">
|
||||
<file name="obfuscate_exclude_cocos2d.js"/>
|
||||
<file name="obfuscate_exclude_chipmunk.js"/>
|
Loading…
Reference in New Issue