“js” to “jsc” for code security .
Firstly , we go to see some documents for jsc security‘s introduct:
You can always find the latest command for converting “js” to “jsc” in the documents under this path “/Users/UserName/cocos2d-x-2.2.2Test/tools/cocos2d-console/console/README.md”.
As the document “README.md” said:
# Will generate bytecode files
wow! it’s scared。
Do not worried! I attend to tell you what happened in this command step by step.
if you do not know how to create a game. please read the tutorial “How to create a”Hello World" C++ project with cocos2d-x2.2.2 or 3.0"
If you are using stable version 3.*
We can find a “.json” format file under this path: “/Users/UserName/cocos2d-x-2.2.2/tools/cocos2d-console/console/bin/compiler_config_sample.json”
And copy it to this path:“/Users/UserName/cocos2d-x-2.2.2/projects/MyGame/Resources”
Under this path:
We can find the “cocos2d.py” script. Here is a tools for convert “js” to “jsc” for code security by python . (you can find many tools in the tools folder).
So if you had already prepared running python environment. you can just perform it like this way:
python cocos2d.py funtionName -argumentName1 (argument) ...
Now you can perform this command like this :
python cocos2d.py jscompile ~~d /Users/UserName/cocos2d-x-2.2.2/projects/MyGame/Resources/~~s /Users/UserName/cocos2d-x-2.2.2/projects/MyGame/Resources/ ~~s /Users/UserName/cocos2d-x-2.2.2/projects/MyGame/Resources/src~~o game.cocos2d.js ~~j /Users/UserName/cocos2d-x-2.2.2Test/projects/MyGame/Resources/compiler_config_sample.json~~c
Then you can remove the all files under the path :“/Users/UserName/cocos2d-x-2.2.2/projects/MyGame/Resources/src”,and run your “Hello world game”. if it performed ok. congratulation! you did a great job for your code security.
h1.Now we can see what happan what happened in below’s command step by step.
In the command “\$ python cocos2d.py jscompile ..”we have 6 arguments.
If you don not want to compress all js files into just a big file. you can input the command like this way:
python cocos2d.py jscompile -d /Users/UserName/cocos2d-x-2.2.2/projects/MyGame/Resources/ -s /Users/UserName/cocos2d-x-2.2.2/projects/MyGame/Resources/ -s /Users/UserName/cocos2d-x-2.2.2/projects/MyGame/Resources/src
Just ignore the ~~j xxx~~o xxx ~~c
h1. In the end:
You can using command
python cocos2d.py jscompile —help
Usage: cocos2d.py jscompile~~s src_dir ~~d dst_dir
~~h, —help show this help message and exit
~~s SRC_DIR_ARR, —src=SRC_DIR_ARR
source directory of js files needed to be compiled,
supports mutiple source directory
~~d DST_DIR, —dst=DST_DIR
destination directory of js bytecode files to be
Whether to use closure compiler to compress all js
files into just a big file
~~o COMPRESSED_FILENAME, —output_compressed_filename=COMPRESSED_FILENAME
Only available when ’~~c’ option was True
~~j COMPILER_CONFIG, —compiler_config=COMPILER_CONFIG
The configuration for closure compiler by using JSON,
please refer to compiler_config_sample.json