blob: 87b826fb159fe6b7564a1103ac1cd58f16e675a5 [file] [log] [blame]
Henrique Mendonça095ddb72013-09-20 19:38:03 +02001//To build dist/thrift.js, dist/thrift.min.js and doc/*
2//run grunt at the command line in this directory.
3//Prerequisites:
4// Node Setup - nodejs.org
5// Grunt Setup - npm install //reads the ./package.json and installs project dependencies
Brian Forbisb5d6ea32018-08-25 23:39:29 -04006// Run grunt - npx grunt // uses project-local installed version of grunt (from package.json)
Henrique Mendonça095ddb72013-09-20 19:38:03 +02007
8module.exports = function(grunt) {
9 'use strict';
10
11 grunt.initConfig({
12 pkg: grunt.file.readJSON('package.json'),
13 concat: {
14 options: {
15 separator: ';'
16 },
17 dist: {
18 src: ['src/**/*.js'],
19 dest: 'dist/<%= pkg.name %>.js'
20 }
21 },
22 jsdoc : {
23 dist : {
Roger Meier16fcad02014-03-16 21:12:11 +010024 src: ['src/*.js', './README.md'],
Henrique Mendonça095ddb72013-09-20 19:38:03 +020025 options: {
26 destination: 'doc'
27 }
28 }
29 },
30 uglify: {
31 options: {
32 banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
33 },
34 dist: {
35 files: {
36 'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
37 }
38 }
Henrique Mendonça15d90422015-06-25 22:31:41 +100039 },
henriquea2de4102014-02-07 14:12:56 +010040 shell: {
41 InstallThriftJS: {
Brian Forbisb5d6ea32018-08-25 23:39:29 -040042 command: 'mkdir -p test/build/js/lib; cp src/thrift.js test/build/js/thrift.js'
henriquea2de4102014-02-07 14:12:56 +010043 },
henrique2a7dccc2014-03-07 22:16:51 +010044 InstallThriftNodeJSDep: {
Nobuaki Sukegawa6defea52015-11-14 17:36:29 +090045 command: 'cd ../..; npm install'
henrique2a7dccc2014-03-07 22:16:51 +010046 },
Philip Frank5066eb42018-03-07 20:49:25 +010047 InstallTestLibs: {
48 command: 'cd test; ant download_jslibs'
49 },
henriquea2de4102014-02-07 14:12:56 +010050 ThriftGen: {
Brian Forbisb5d6ea32018-08-25 23:39:29 -040051 command: [
52 'mkdir -p test/gen-js',
53 '../../compiler/cpp/thrift -gen js --out test/gen-js ../../test/ThriftTest.thrift',
54 '../../compiler/cpp/thrift -gen js --out test/gen-js ../../test/JsDeepConstructorTest.thrift',
55 'mkdir -p test/gen-js-jquery',
56 '../../compiler/cpp/thrift -gen js:jquery --out test/gen-js-jquery ../../test/ThriftTest.thrift',
57 'mkdir -p test/gen-nodejs',
58 '../../compiler/cpp/thrift -gen js:node --out test/gen-nodejs ../../test/ThriftTest.thrift',
59 'mkdir -p test/gen-js-es6',
60 '../../compiler/cpp/thrift -gen js:es6 --out test/gen-js-es6 ../../test/ThriftTest.thrift',
61 'mkdir -p test/gen-nodejs-es6',
62 '../../compiler/cpp/thrift -gen js:node,es6 --out ./test/gen-nodejs-es6 ../../test/ThriftTest.thrift',
63 ].join(' && ')
henrique2a7dccc2014-03-07 22:16:51 +010064 },
65 ThriftGenJQ: {
Nobuaki Sukegawa4b7dbe32016-05-25 12:09:02 +090066 command: '../../compiler/cpp/thrift -gen js:jquery -gen js:node -o test ../../test/ThriftTest.thrift'
Henrique Mendonça15d90422015-06-25 22:31:41 +100067 },
68 ThriftGenDeepConstructor: {
Nobuaki Sukegawa4b7dbe32016-05-25 12:09:02 +090069 command: '../../compiler/cpp/thrift -gen js -o test ../../test/JsDeepConstructorTest.thrift'
Philip Frank8fdd6102017-12-06 12:38:05 +010070 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030071 ThriftBrowserifyNodeInt64: {
72 command: [
73 './node_modules/browserify/bin/cmd.js ./node_modules/node-int64/Int64.js -s Int64 -o test/build/js/lib/Int64.js',
74 './node_modules/browserify/bin/cmd.js ../nodejs/lib/thrift/int64_util.js -s Int64Util -o test/build/js/lib/Int64Util.js',
75 './node_modules/browserify/bin/cmd.js ./node_modules/json-int64/index.js -s JSONInt64 -o test/build/js/lib/JSONInt64.js'
76 ].join(' && ')
77 },
78 ThriftGenInt64: {
79 command: '../../compiler/cpp/thrift -gen js -o test ../../test/Int64Test.thrift'
80 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +030081 ThriftGenDoubleConstants: {
82 command: '../../compiler/cpp/thrift -gen js -o test ../../test/DoubleConstantsTest.thrift'
83 },
henriquea2de4102014-02-07 14:12:56 +010084 ThriftTestServer: {
85 options: {
Philip Frank5066eb42018-03-07 20:49:25 +010086 async: true,
87 execOptions: {
88 cwd: "./test",
89 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
90 }
henriquea2de4102014-02-07 14:12:56 +010091 },
Philip Frank5066eb42018-03-07 20:49:25 +010092 command: "node server_http.js",
henrique2a7dccc2014-03-07 22:16:51 +010093 },
Brian Forbisb5d6ea32018-08-25 23:39:29 -040094 ThriftTestServerES6: {
95 options: {
96 async: true,
97 execOptions: {
98 cwd: "./test",
99 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
100 }
101 },
102 command: "node server_http.js --es6",
103 },
henrique2a7dccc2014-03-07 22:16:51 +0100104 ThriftTestServer_TLS: {
105 options: {
Philip Frank5066eb42018-03-07 20:49:25 +0100106 async: true,
107 execOptions: {
108 cwd: "./test",
109 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
110 }
henrique2a7dccc2014-03-07 22:16:51 +0100111 },
Philip Frank5066eb42018-03-07 20:49:25 +0100112 command: "node server_https.js",
113 },
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400114 ThriftTestServerES6_TLS: {
115 options: {
116 async: true,
117 execOptions: {
118 cwd: "./test",
119 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
120 }
121 },
122 command: "node server_https.js --es6",
123 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200124 },
125 qunit: {
henrique2a7dccc2014-03-07 22:16:51 +0100126 ThriftJS: {
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200127 options: {
128 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400129 'http://localhost:8089/test-nojq.html'
130 ],
131 puppeteer: {
132 headless: true,
133 args: ['--no-sandbox'],
134 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200135 }
henrique2a7dccc2014-03-07 22:16:51 +0100136 },
137 ThriftJSJQ: {
138 options: {
139 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400140 'http://localhost:8089/test.html'
141 ],
142 puppeteer: {
143 headless: true,
144 args: ['--no-sandbox'],
145 },
henrique2a7dccc2014-03-07 22:16:51 +0100146 }
147 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300148 ThriftJS_DoubleRendering: {
149 options: {
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300150 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400151 'http://localhost:8089/test-double-rendering.html'
152 ],
153 puppeteer: {
154 headless: true,
155 args: ['--no-sandbox'],
156 ignoreHTTPSErrors: true,
157 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300158 }
159 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300160 ThriftJS_Int64: {
161 options: {
162 urls: [
163 'http://localhost:8089/test-int64.html'
164 ],
165 puppeteer: {
166 headless: true,
167 args: ['--no-sandbox'],
168 ignoreHTTPSErrors: true,
169 },
170 }
171 },
henrique2a7dccc2014-03-07 22:16:51 +0100172 ThriftWS: {
173 options: {
174 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400175 'http://localhost:8089/testws.html'
176 ],
177 puppeteer: {
178 headless: true,
179 args: ['--no-sandbox'],
180 },
henrique2a7dccc2014-03-07 22:16:51 +0100181 }
182 },
183 ThriftJS_TLS: {
184 options: {
henrique2a7dccc2014-03-07 22:16:51 +0100185 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400186 'https://localhost:8091/test-nojq.html'
187 ],
188 puppeteer: {
189 headless: true,
190 args: ['--no-sandbox'],
191 ignoreHTTPSErrors: true,
192 },
henrique2a7dccc2014-03-07 22:16:51 +0100193 }
194 },
195 ThriftJSJQ_TLS: {
196 options: {
henrique2a7dccc2014-03-07 22:16:51 +0100197 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400198 'https://localhost:8091/test.html'
199 ],
200 puppeteer: {
201 headless: true,
202 args: ['--no-sandbox'],
203 ignoreHTTPSErrors: true,
204 },
henrique2a7dccc2014-03-07 22:16:51 +0100205 }
206 },
207 ThriftWS_TLS: {
208 options: {
henrique2a7dccc2014-03-07 22:16:51 +0100209 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400210 'https://localhost:8091/testws.html'
211 ],
212 puppeteer: {
213 headless: true,
214 args: ['--no-sandbox'],
215 ignoreHTTPSErrors: true,
216 },
henrique2a7dccc2014-03-07 22:16:51 +0100217 }
Henrique Mendonça15d90422015-06-25 22:31:41 +1000218 },
219 ThriftDeepConstructor: {
220 options: {
221 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400222 'http://localhost:8089/test-deep-constructor.html'
223 ],
224 puppeteer: {
225 headless: true,
226 args: ['--no-sandbox'],
227 },
Henrique Mendonça15d90422015-06-25 22:31:41 +1000228 }
Philip Frank8fdd6102017-12-06 12:38:05 +0100229 },
230 ThriftWSES6: {
231 options: {
232 urls: [
233 'http://localhost:8088/test-es6.html'
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400234 ],
235 puppeteer: {
236 headless: true,
237 args: ['--no-sandbox'],
238 },
Philip Frank8fdd6102017-12-06 12:38:05 +0100239 }
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200240 }
241 },
242 jshint: {
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300243 // The main Thrift library file. not es6 yet :(
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400244 lib: {
245 src: ['src/**/*.js'],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400246 },
247 // The test files use es6
248 test: {
249 src: ['Gruntfile.js', 'test/*.js'],
250 options: {
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400251 esversion: 6,
252 }
253 },
bforbisda1169d2018-10-28 11:27:38 -0400254 gen_js_code: {
255 src: ['test/gen-js/*.js', 'test/gen-js-jquery/*.js'],
256 },
257 gen_es6_code: {
258 src: ['test/gen-js-es6/*.js'],
259 options: {
260 esversion: 6,
261 }
262 },
263 gen_node_code: {
264 src: ['test/gen-nodejs/*.js'],
265 options: {
266 node: true,
267 }
268 },
269 gen_node_es6_code: {
270 src: ['test/gen-nodejs-es6/*.js'],
271 options: {
272 node: true,
273 esversion: 6,
274 }
275 }
276 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200277 });
278
279 grunt.loadNpmTasks('grunt-contrib-uglify');
280 grunt.loadNpmTasks('grunt-contrib-jshint');
281 grunt.loadNpmTasks('grunt-contrib-qunit');
282 grunt.loadNpmTasks('grunt-contrib-concat');
283 grunt.loadNpmTasks('grunt-jsdoc');
Philip Frank5066eb42018-03-07 20:49:25 +0100284 grunt.loadNpmTasks('grunt-shell-spawn');
285
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300286 grunt.registerTask('wait', 'Wait just one second for the server to start', function () {
Philip Frank5066eb42018-03-07 20:49:25 +0100287 var done = this.async();
288 setTimeout(function() {
289 done(true);
290 }, 1000);
291 });
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200292
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400293 grunt.registerTask('installAndGenerate', [
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300294 'shell:InstallThriftJS',
295 'shell:InstallThriftNodeJSDep',
296 'shell:ThriftGen',
297 'shell:ThriftGenDeepConstructor',
298 'shell:ThriftGenDoubleConstants',
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400299 'shell:InstallTestLibs',
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300300 'shell:ThriftBrowserifyNodeInt64',
301 'shell:ThriftGenInt64'
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400302 ]);
303
304 grunt.registerTask('test', [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400305 'installAndGenerate',
bforbisda1169d2018-10-28 11:27:38 -0400306 'jshint',
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300307 'shell:ThriftTestServer',
308 'shell:ThriftTestServer_TLS',
309 'shell:ThriftTestServerES6',
310 'shell:ThriftTestServerES6_TLS',
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400311 'wait',
312 'qunit:ThriftDeepConstructor',
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300313 'qunit:ThriftJS',
314 'qunit:ThriftJS_TLS',
Ozan Can Altiokcaf7da92019-01-07 14:14:11 +0300315 'qunit:ThriftJS_DoubleRendering',
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400316 'qunit:ThriftWS',
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300317 'qunit:ThriftJSJQ',
318 'qunit:ThriftJSJQ_TLS',
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400319 'qunit:ThriftWSES6',
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300320 'qunit:ThriftJS_Int64',
321 'shell:ThriftTestServer:kill',
322 'shell:ThriftTestServer_TLS:kill',
323 'shell:ThriftTestServerES6:kill',
324 'shell:ThriftTestServerES6_TLS:kill',
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400325 ]);
Philip Frank55ddf192018-01-02 09:00:36 +0100326 grunt.registerTask('default', ['test', 'concat', 'uglify', 'jsdoc']);
henriquea2de4102014-02-07 14:12:56 +0100327};