-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.py
133 lines (99 loc) · 4.43 KB
/
builder.py
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import os
import subprocess as sp
import sys
import argparse
DEFAULT_BUILDER_PORT = '7900'
DEFAULT_BUILD_DIRECTORY = 'build/'
BUILDER_PROJECT_NAME = 'leojs'
BUILDER_COMPILER_COMMAND = 'tsc'
BUILDER_DTS_GENERATOR_COMMAND = 'dts-generator'
BUILDER_INDEX_FILES = [ 'index.html', 'playground.html' ]
BUILDER_RESOURCES_FOLDER = 'res' # assets
BUILDER_EXTJS_FOLDER = 'extjs' # extra js libraries
# Add here the extra files you want to copy to the build dir
BUILDER_EXTRA_FILES_LIST = [ 'playgroundEntryPoint.js',
'playground.css',
'playgroundNavbar.js' ]
MODE_BUILD_ONLY = 'build'
MODE_BUILD_AND_RUN = 'all'
MODE_RUN_ONLY = 'run'
class RBuilder :
def __init__( self ) :
self.m_parser = argparse.ArgumentParser( description = 'Builder config properties' )
self.m_parser.add_argument( 'builderMode', help = '(build)|run|all', default = 'build' )
self.m_parser.add_argument( '--port', help = 'port to run the app', default = DEFAULT_BUILDER_PORT )
self.m_parser.add_argument( '--buildDir', help = 'output build directory', default = DEFAULT_BUILD_DIRECTORY )
self.m_buildMode = MODE_BUILD_ONLY
self.m_buildDir = DEFAULT_BUILD_DIRECTORY
self.m_port = DEFAULT_BUILDER_PORT
def execute( self ) :
_args = self.m_parser.parse_args()
self.m_buildMode = _args.builderMode
self.m_buildDir = _args.buildDir
self.m_port = _args.port
if self.m_buildMode == MODE_BUILD_ONLY :
self._clean()
self._build()
self._postCopy()
elif self.m_buildMode == MODE_RUN_ONLY :
self._run()
elif self.m_buildMode == MODE_BUILD_AND_RUN :
self._clean()
self._build()
self._postCopy()
self._run()
else :
print 'Wrong build mode: ', self.m_buildMode
print 'Valid modes: build|run|all'
def _build( self ) :
print( 'STARTED BUILDING ...' )
print( 'building js' )
# Build to js
_errorCode = sp.call( [BUILDER_COMPILER_COMMAND, '--outDir', self.m_buildDir] )
if ( _errorCode != 0 ) :
print 'Error while compiling typescript files'
sys.exit( 0 )
print( 'ok!' )
print( 'bundling d.ts declarations' )
# Build bundled d.ts
try :
sp.call( [BUILDER_DTS_GENERATOR_COMMAND,
'--name', BUILDER_PROJECT_NAME,
'--project', './',
'--out', self.m_buildDir + BUILDER_PROJECT_NAME + '.d.ts'] )
except :
print( 'Mmmm, it seems you dont have dts-generator for d.ts generation' )
print( 'No worries, d.ts is generated and used only in the playground, for completions' )
print( 'ok!' )
print( 'DONE BUILDING' )
def _clean( self ) :
print( 'CLEANING ...' )
if os.path.exists( self.m_buildDir ) :
sp.call( ['rm', '-r', self.m_buildDir] )
print( 'DONE' )
def _postCopy( self ) :
# copy index files
for _indxFileName in BUILDER_INDEX_FILES :
sp.call( ['cp', _indxFileName, self.m_buildDir] )
# copy extra .js files
for _extraJsFile in BUILDER_EXTRA_FILES_LIST :
sp.call( ['cp', _extraJsFile, self.m_buildDir ] )
# copy extjs folder
sp.call( ['cp', '-r', BUILDER_EXTJS_FOLDER, self.m_buildDir] )
# copy resources folder
sp.call( ['cp', '-r', BUILDER_RESOURCES_FOLDER, self.m_buildDir] )
# copy playground resources
sp.call( ['cp', '-r', 'snippets/', self.m_buildDir] )
# Copy resources from cat1js
sp.call( ['cp', '-r', 'ext/cat1js/res/imgs', self.m_buildDir + BUILDER_RESOURCES_FOLDER] )
sp.call( ['cp', '-r', 'ext/cat1js/res/models', self.m_buildDir + BUILDER_RESOURCES_FOLDER] )
sp.call( ['cp', '-r', 'ext/cat1js/res/shaders', self.m_buildDir + BUILDER_RESOURCES_FOLDER] )
sp.call( ['cp', '-r', 'ext/cat1js/res/text', self.m_buildDir + BUILDER_RESOURCES_FOLDER] )
# Copy monaco editor minified from cat1js
sp.call( ['cp', '-r', 'ext/cat1js/extjs/monaco-editor', self.m_buildDir + BUILDER_EXTJS_FOLDER] )
def _run( self ) :
# run using simplehttpserver
sp.call( ['python2', '-m', 'SimpleHTTPServer', self.m_port] )
if __name__ == '__main__' :
_builder = RBuilder()
_builder.execute()