|
| 1 | +#!/usr/bin/python |
| 2 | +#create new project by cocos-console |
| 3 | +#build new project and run |
| 4 | + |
| 5 | +import os |
| 6 | +import sys |
| 7 | + |
| 8 | +project_types = ['cpp', 'lua'] |
| 9 | +PROJ_SUFFIX = 'Proj' |
| 10 | +phonePlats = ['mac','ios','android'] |
| 11 | + |
| 12 | +cocos_console_dir = 'tools/cocos2d-console/bin/' |
| 13 | + |
| 14 | +#now cocos2d-console suport different run on Platforms, e.g: only run android on win |
| 15 | +runSupport = { |
| 16 | + 'darwin' : [1, 1, 1], |
| 17 | + 'win' : [0, 0, 1], |
| 18 | + 'linux' : [0, 0, 1] |
| 19 | +} |
| 20 | + |
| 21 | +curPlat = sys.platform |
| 22 | +if curPlat.find('linux') >= 0: |
| 23 | + curPlat = 'linux' |
| 24 | +elif curPlat.find('darwin') >= 0: |
| 25 | + curPlat = 'darwin' |
| 26 | +else: |
| 27 | + curPlat = 'win' |
| 28 | +print 'current platform is:', curPlat |
| 29 | + |
| 30 | +def clean_project(): |
| 31 | + for proj in project_types: |
| 32 | + cmd = 'rm -rf '+proj+PROJ_SUFFIX |
| 33 | + os.system(cmd) |
| 34 | + |
| 35 | +def create_project(): |
| 36 | + print 'will create_project: ' |
| 37 | + idx = 0 |
| 38 | + for proj in project_types: |
| 39 | + print 'proj: ', proj |
| 40 | + cmd = './'+cocos_console_dir+'cocos new -l '+proj+' '+proj+PROJ_SUFFIX |
| 41 | + print proj,'cmd:',cmd |
| 42 | + idx += 1 |
| 43 | + info_create = os.system(cmd) #call cmd on win is diff |
| 44 | + print 'create project',proj,' is:', not info_create |
| 45 | +def build_run(): |
| 46 | + print 'will build and run' |
| 47 | + for proj in project_types: |
| 48 | + idx = 0 |
| 49 | + for phone in phonePlats: |
| 50 | + cmd = './'+cocos_console_dir+'cocos run -p '+phone+' -s '+proj+PROJ_SUFFIX |
| 51 | + print proj,'cmd:',cmd |
| 52 | + if runSupport[curPlat][idx]: |
| 53 | + info_run = os.system(cmd) |
| 54 | + print 'run project', proj, 'is:', not info_run |
| 55 | + idx += 1 |
| 56 | + |
| 57 | +def main(): |
| 58 | + clean_project() |
| 59 | + create_project() |
| 60 | + build_run() |
| 61 | + |
| 62 | +# -------------- main -------------- |
| 63 | +if __name__ == '__main__': |
| 64 | + sys_ret = 0 |
| 65 | + try: |
| 66 | + sys_ret = main() |
| 67 | + except: |
| 68 | + traceback.print_exc() |
| 69 | + sys_ret = 1 |
| 70 | + finally: |
| 71 | + sys.exit(sys_ret) |
| 72 | + |
0 commit comments