forked from Chevrotain/chevrotain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgruntfile.js
230 lines (206 loc) · 7.61 KB
/
gruntfile.js
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
const _ = require("lodash")
const PUBLIC_API_DTS_FILES = [
"lib/src/scan/tokens_public.d.ts",
"lib/src/scan/lexer_public.d.ts",
"lib/src/parse/parser_public.d.ts",
"lib/src/parse/cst/cst_public.d.ts",
"lib/src/parse/errors_public.d.ts",
"lib/src/parse/exceptions_public.d.ts",
"lib/src/parse/grammar/path_public.d.ts",
"lib/src/parse/grammar/gast/gast_public.d.ts",
"lib/src/parse/grammar/gast/gast_visitor.d.ts",
"lib/src/parse/grammar/gast/gast_resolver_public.d.ts",
"lib/src/parse/cache_public.d.ts",
"lib/src/diagrams/render_public.d.ts",
"lib/src/parse/generate/generate_public.d.ts"
]
const karmaConf = process.env.TRAVIS ? "karma_sauce.conf.js" : "karma.conf.js"
const PUBLIC_API_TS_FILES = _.map(PUBLIC_API_DTS_FILES, function(binDefFile) {
return binDefFile.replace("lib/", "").replace(".d", "")
})
// so typedoc can compile "module.exports" in cache_public
PUBLIC_API_TS_FILES.push("./node_modules/@types/node/index.d.ts")
const fourSpaces = " "
const examples_test_command = "yarn test"
const INSTALL_LINK = "yarn install && yarn link chevrotain"
const INSTALL_LINK_TEST = INSTALL_LINK + " && " + examples_test_command
const UNLINK = " && yarn unlink chevrotain"
const banner = "/*! <%= pkg.name %> - v<%= pkg.version %> */"
module.exports = function(grunt) {
const pkg = grunt.file.readJSON("package.json")
//noinspection UnnecessaryLabelJS
grunt.initConfig({
pkg: pkg,
run: {
options: {
failOnError: true
},
yarn_link: {
exec: "yarn link"
},
test_examples_lexer: {
options: {
cwd: process.cwd() + "/examples/lexer/"
},
exec: INSTALL_LINK_TEST + UNLINK
},
test_examples_grammars: {
options: {
cwd: process.cwd() + "/examples/grammars/"
},
exec: INSTALL_LINK_TEST + UNLINK
},
test_examples_parser: {
options: {
cwd: process.cwd() + "/examples/parser/"
},
exec:
INSTALL_LINK +
" && " +
"grunt --gruntfile minification/gruntfile.js" +
" && " +
"cd webpack" +
" && " +
"yarn install" +
" && " +
"yarn link chevrotain" +
" && " +
"cd .." +
" && " +
examples_test_command +
UNLINK
},
test_examples_implementation_languages: {
options: {
cwd: process.cwd() + "/examples/implementation_languages/"
},
exec: INSTALL_LINK + " && yarn test" + UNLINK
},
test_examples_tutorial: {
options: {
cwd: process.cwd() + "/examples/tutorial/"
},
exec: INSTALL_LINK + " && yarn test" + UNLINK
},
test_examples_custom_apis: {
options: {
cwd: process.cwd() + "/examples/custom_apis/"
},
exec: INSTALL_LINK + " && yarn test" + UNLINK
}
},
karma: {
options: {
configFile: karmaConf,
singleRun: true,
client: {
captureConsole: true
}
},
browsers_unit_tests: {
options: {
port: 9980,
files: ["test/test.config.js", "lib/chevrotainSpecs.js"]
}
},
browsers_integration_tests_globals: {
options: {
port: 9982,
files: [
"lib/chevrotain.js",
"test/test.config.js",
"test_integration/**/*spec.js"
]
}
},
browsers_integration_tests_amd: {
options: {
port: 9983,
frameworks: ["requirejs", "mocha", "chai"],
files: [
"lib/chevrotain.js",
"test/test.config.js",
{
pattern: "test_integration/*/*.js",
included: false
},
"test_integration/integration_tests_main.js"
]
}
},
browsers_integration_tests_globals_minified: {
options: {
port: 9984,
files: [
"lib/chevrotain.min.js",
"test/test.config.js",
"test_integration/**/*spec.js"
]
}
},
browsers_integration_tests_amd_minified: {
options: {
port: 9985,
frameworks: ["requirejs", "mocha", "chai"],
files: [
"lib/chevrotain.min.js",
"test/test.config.js",
{
pattern: "test_integration/*/*.js",
included: false
},
"test_integration/integration_tests_main.js"
]
}
}
},
concat: {
release_definitions: {
options: {
// TODO: seems like the HashTable class may need to be included in the public API
banner:
banner +
"\n" +
"export as namespace chevrotain;\n" +
"declare class HashTable<V>{}\n",
process: function processDefinitions(src, filePath) {
const withOutImports = src.replace(
/import.*;(\n|\r\n)/g,
""
)
// TODO: investigate why do Typescript definition files include private members.
const withoutPrivate = withOutImports.replace(
/private.*;(\n|\r\n)/g,
""
)
return withoutPrivate
},
// extra spaces needed to fix indentation.
separator: grunt.util.linefeed + fourSpaces
},
files: {
"lib/chevrotain.d.ts": PUBLIC_API_DTS_FILES
}
}
}
})
require("load-grunt-tasks")(grunt)
const integrationTestsNodeTasks = [
"run:yarn_link",
"run:test_examples_grammars",
"run:test_examples_parser",
"run:test_examples_lexer",
"run:test_examples_implementation_languages",
"run:test_examples_tutorial",
"run:test_examples_custom_apis"
]
const browserTestsTasks = [
"karma:browsers_unit_tests",
"karma:browsers_integration_tests_globals",
"karma:browsers_integration_tests_globals_minified",
"karma:browsers_integration_tests_amd",
"karma:browsers_integration_tests_amd_minified"
]
grunt.registerTask("browsers_tests", browserTestsTasks)
grunt.registerTask("integration_tests", integrationTestsNodeTasks)
}