-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwscript.py
More file actions
156 lines (128 loc) · 4.41 KB
/
wscript.py
File metadata and controls
156 lines (128 loc) · 4.41 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
def default(context):
# base = context.Node("./")
build_main(context)
minify(context)
def minify(context):
run_command(
[
'node','./prune.js'
,'./prune.js'
,'-t','./prune.js'
,'-c', 'minify' # "minify" is default command for prune.js
]
, '.'
)
def build_main(context):
base = context.Node("./src/")
# order is important. consumer is on the bottom.
modules = [
['./libs/esprima','esprima']
, ['./libs/argsparser', 'argsparser']
, 'main.parser'
, 'main.asttools'
, 'main.optimizer'
, 'main.generator'
, 'main.toposort'
, 'main.amd'
# these tie all the above together and should almost always be last.
, 'main.commands'
, 'main.processor'
, 'main.runAsMain'
, 'main'
]
body = [
get_escodegen(context)
, get_esmangle(context)
, generate_body(context, base, modules)
]
file_wrapper = context.Node('./src/template_cjs_lite.js').text
context.Node('./prune.js').text = file_wrapper % "\n\n".join(body)
def get_escodegen(context):
base = context.Node("./src/libs/escodegen/")
# order is important. consumer is on the bottom.
modules = [
'./array-set'
, './util'
, './base64'
, './base64-vlq'
, './source-map-generator'
, 'source-map'
, 'escodegen'
]
return generate_body(context, base, modules)
def get_esmangle(context):
base = context.Node("./src/libs/esmangle/")
# order is important. consumer is on the bottom.
modules = [
'estraverse',
'escope',
['./common', '../common'],
['./evaluator', '../evaluator'],
'./pass/hoist-variable-to-arguments',
'./pass/transform-dynamic-to-static-property-access',
'./pass/transform-dynamic-to-static-property-definition',
'./pass/transform-immediate-function-call',
'./pass/transform-logical-association',
'./pass/reordering-function-declarations',
'./pass/remove-unused-label',
'./pass/remove-empty-statement',
'./pass/remove-wasted-blocks',
'./pass/transform-to-compound-assignment',
'./pass/transform-to-sequence-expression',
'./pass/transform-branch-to-expression',
'./pass/transform-typeof-undefined',
'./pass/reduce-sequence-expression',
'./pass/reduce-branch-jump',
'./pass/reduce-multiple-if-statements',
'./pass/dead-code-elimination',
'./pass/remove-side-effect-free-expressions',
'./pass/remove-context-sensitive-expressions',
'./pass/tree-based-constant-folding',
'./pass/drop-variable-definition',
'./pass/remove-unreachable-branch',
'./post/transform-static-to-dynamic-property-access',
'./post/transform-infinity',
'./post/rewrite-boolean',
'./post/rewrite-conditional-expression',
'./annotate-directive',
'esmangle'
]
return generate_body(context, base, modules)
def generate_body(context, base, modules):
module_wrapper = context.Node('./src/template_cjs_module_wrapper.js').text
alias_wrapper = context.Node('./src/template_cjs_module_alias_wrapper.js').text
body = []
for module_name in modules:
# we support aliases for given modules
aliases = []
if type(module_name) == list:
aliases = module_name
module_name = aliases.pop(0)
body.append(
module_wrapper % (
module_name.replace("./", "")
, (base + module_name + '.js').text
, module_name
)
)
print("Appended module '%s'" % module_name)
# this sets up code to create aliases
for alias in aliases:
body.append(
alias_wrapper % (
module_name.replace("./", "")
, alias
, module_name
)
)
print("Appended module alias '%s' for '%s'" % (alias, module_name))
# file_wrapper = context.Node('./src/template_cjs_lite.js').text
# context.Node('./libs/escodegen.js').text = file_wrapper % "\n\n".join(body)
return "\n\n".join(body)
import subprocess
def run_command(command, working_dir):
subprocess.call(
command
, shell=True
, cwd=working_dir
)