blob: 4421f0cb475d9effdb6deeb75f3923019646ef97 [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: {
Mario Emmenlauer60646962020-04-15 10:26:09 +020042 command: 'cp src/thrift.js test/build/js/thrift.js'
henriquea2de4102014-02-07 14:12:56 +010043 },
henrique2a7dccc2014-03-07 22:16:51 +010044 InstallThriftNodeJSDep: {
Mario Emmenlauer60646962020-04-15 10:26:09 +020045 command: 'cd ../.. && npm install'
henrique2a7dccc2014-03-07 22:16:51 +010046 },
Philip Frank5066eb42018-03-07 20:49:25 +010047 InstallTestLibs: {
Mario Emmenlauer60646962020-04-15 10:26:09 +020048 command: 'cd test && ant download_jslibs'
Philip Frank5066eb42018-03-07 20:49:25 +010049 },
henriquea2de4102014-02-07 14:12:56 +010050 ThriftGen: {
Brian Forbisb5d6ea32018-08-25 23:39:29 -040051 command: [
Mario Emmenlauer60646962020-04-15 10:26:09 +020052 '"../../compiler/cpp/thrift" -gen js --out test/gen-js ../../test/ThriftTest.thrift',
53 '"../../compiler/cpp/thrift" -gen js --out test/gen-js ../../test/JsDeepConstructorTest.thrift',
54 '"../../compiler/cpp/thrift" -gen js:jquery --out test/gen-js-jquery ../../test/ThriftTest.thrift',
55 '"../../compiler/cpp/thrift" -gen js:node --out test/gen-nodejs ../../test/ThriftTest.thrift',
56 '"../../compiler/cpp/thrift" -gen js:es6 --out test/gen-js-es6 ../../test/ThriftTest.thrift',
57 '"../../compiler/cpp/thrift" -gen js:node,es6 --out ./test/gen-nodejs-es6 ../../test/ThriftTest.thrift',
Brian Forbisb5d6ea32018-08-25 23:39:29 -040058 ].join(' && ')
henrique2a7dccc2014-03-07 22:16:51 +010059 },
60 ThriftGenJQ: {
Nobuaki Sukegawa4b7dbe32016-05-25 12:09:02 +090061 command: '../../compiler/cpp/thrift -gen js:jquery -gen js:node -o test ../../test/ThriftTest.thrift'
Henrique Mendonça15d90422015-06-25 22:31:41 +100062 },
63 ThriftGenDeepConstructor: {
Nobuaki Sukegawa4b7dbe32016-05-25 12:09:02 +090064 command: '../../compiler/cpp/thrift -gen js -o test ../../test/JsDeepConstructorTest.thrift'
Philip Frank8fdd6102017-12-06 12:38:05 +010065 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030066 ThriftBrowserifyNodeInt64: {
67 command: [
68 './node_modules/browserify/bin/cmd.js ./node_modules/node-int64/Int64.js -s Int64 -o test/build/js/lib/Int64.js',
69 './node_modules/browserify/bin/cmd.js ../nodejs/lib/thrift/int64_util.js -s Int64Util -o test/build/js/lib/Int64Util.js',
70 './node_modules/browserify/bin/cmd.js ./node_modules/json-int64/index.js -s JSONInt64 -o test/build/js/lib/JSONInt64.js'
71 ].join(' && ')
72 },
73 ThriftGenInt64: {
74 command: '../../compiler/cpp/thrift -gen js -o test ../../test/Int64Test.thrift'
75 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +030076 ThriftGenDoubleConstants: {
77 command: '../../compiler/cpp/thrift -gen js -o test ../../test/DoubleConstantsTest.thrift'
78 },
henriquea2de4102014-02-07 14:12:56 +010079 ThriftTestServer: {
80 options: {
Philip Frank5066eb42018-03-07 20:49:25 +010081 async: true,
82 execOptions: {
83 cwd: "./test",
84 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
85 }
henriquea2de4102014-02-07 14:12:56 +010086 },
Philip Frank5066eb42018-03-07 20:49:25 +010087 command: "node server_http.js",
henrique2a7dccc2014-03-07 22:16:51 +010088 },
Brian Forbisb5d6ea32018-08-25 23:39:29 -040089 ThriftTestServerES6: {
90 options: {
91 async: true,
92 execOptions: {
93 cwd: "./test",
94 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
95 }
96 },
97 command: "node server_http.js --es6",
98 },
henrique2a7dccc2014-03-07 22:16:51 +010099 ThriftTestServer_TLS: {
100 options: {
Philip Frank5066eb42018-03-07 20:49:25 +0100101 async: true,
102 execOptions: {
103 cwd: "./test",
104 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
105 }
henrique2a7dccc2014-03-07 22:16:51 +0100106 },
Philip Frank5066eb42018-03-07 20:49:25 +0100107 command: "node server_https.js",
108 },
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400109 ThriftTestServerES6_TLS: {
110 options: {
111 async: true,
112 execOptions: {
113 cwd: "./test",
114 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
115 }
116 },
117 command: "node server_https.js --es6",
118 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200119 },
120 qunit: {
henrique2a7dccc2014-03-07 22:16:51 +0100121 ThriftJS: {
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200122 options: {
123 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400124 'http://localhost:8089/test-nojq.html'
125 ],
126 puppeteer: {
127 headless: true,
128 args: ['--no-sandbox'],
129 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200130 }
henrique2a7dccc2014-03-07 22:16:51 +0100131 },
132 ThriftJSJQ: {
133 options: {
134 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400135 'http://localhost:8089/test.html'
136 ],
137 puppeteer: {
138 headless: true,
139 args: ['--no-sandbox'],
140 },
henrique2a7dccc2014-03-07 22:16:51 +0100141 }
142 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300143 ThriftJS_DoubleRendering: {
144 options: {
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300145 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400146 'http://localhost:8089/test-double-rendering.html'
147 ],
148 puppeteer: {
149 headless: true,
150 args: ['--no-sandbox'],
151 ignoreHTTPSErrors: true,
152 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300153 }
154 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300155 ThriftJS_Int64: {
156 options: {
157 urls: [
158 'http://localhost:8089/test-int64.html'
159 ],
160 puppeteer: {
161 headless: true,
162 args: ['--no-sandbox'],
163 ignoreHTTPSErrors: true,
164 },
165 }
166 },
henrique2a7dccc2014-03-07 22:16:51 +0100167 ThriftWS: {
168 options: {
169 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400170 'http://localhost:8089/testws.html'
171 ],
172 puppeteer: {
173 headless: true,
174 args: ['--no-sandbox'],
175 },
henrique2a7dccc2014-03-07 22:16:51 +0100176 }
177 },
178 ThriftJS_TLS: {
179 options: {
henrique2a7dccc2014-03-07 22:16:51 +0100180 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400181 'https://localhost:8091/test-nojq.html'
182 ],
183 puppeteer: {
184 headless: true,
185 args: ['--no-sandbox'],
186 ignoreHTTPSErrors: true,
187 },
henrique2a7dccc2014-03-07 22:16:51 +0100188 }
189 },
190 ThriftJSJQ_TLS: {
191 options: {
henrique2a7dccc2014-03-07 22:16:51 +0100192 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400193 'https://localhost:8091/test.html'
194 ],
195 puppeteer: {
196 headless: true,
197 args: ['--no-sandbox'],
198 ignoreHTTPSErrors: true,
199 },
henrique2a7dccc2014-03-07 22:16:51 +0100200 }
201 },
202 ThriftWS_TLS: {
203 options: {
henrique2a7dccc2014-03-07 22:16:51 +0100204 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400205 'https://localhost:8091/testws.html'
206 ],
207 puppeteer: {
208 headless: true,
209 args: ['--no-sandbox'],
210 ignoreHTTPSErrors: true,
211 },
henrique2a7dccc2014-03-07 22:16:51 +0100212 }
Henrique Mendonça15d90422015-06-25 22:31:41 +1000213 },
214 ThriftDeepConstructor: {
215 options: {
216 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400217 'http://localhost:8089/test-deep-constructor.html'
218 ],
219 puppeteer: {
220 headless: true,
221 args: ['--no-sandbox'],
222 },
Henrique Mendonça15d90422015-06-25 22:31:41 +1000223 }
Philip Frank8fdd6102017-12-06 12:38:05 +0100224 },
225 ThriftWSES6: {
226 options: {
227 urls: [
228 'http://localhost:8088/test-es6.html'
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400229 ],
230 puppeteer: {
231 headless: true,
232 args: ['--no-sandbox'],
233 },
Philip Frank8fdd6102017-12-06 12:38:05 +0100234 }
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200235 }
236 },
237 jshint: {
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300238 // The main Thrift library file. not es6 yet :(
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400239 lib: {
240 src: ['src/**/*.js'],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400241 },
242 // The test files use es6
243 test: {
244 src: ['Gruntfile.js', 'test/*.js'],
245 options: {
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400246 esversion: 6,
247 }
248 },
bforbisda1169d2018-10-28 11:27:38 -0400249 gen_js_code: {
250 src: ['test/gen-js/*.js', 'test/gen-js-jquery/*.js'],
251 },
252 gen_es6_code: {
253 src: ['test/gen-js-es6/*.js'],
254 options: {
255 esversion: 6,
256 }
257 },
258 gen_node_code: {
259 src: ['test/gen-nodejs/*.js'],
260 options: {
261 node: true,
262 }
263 },
264 gen_node_es6_code: {
265 src: ['test/gen-nodejs-es6/*.js'],
266 options: {
267 node: true,
268 esversion: 6,
269 }
270 }
271 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200272 });
273
274 grunt.loadNpmTasks('grunt-contrib-uglify');
275 grunt.loadNpmTasks('grunt-contrib-jshint');
276 grunt.loadNpmTasks('grunt-contrib-qunit');
277 grunt.loadNpmTasks('grunt-contrib-concat');
278 grunt.loadNpmTasks('grunt-jsdoc');
Philip Frank5066eb42018-03-07 20:49:25 +0100279 grunt.loadNpmTasks('grunt-shell-spawn');
280
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300281 grunt.registerTask('wait', 'Wait just one second for the server to start', function () {
Philip Frank5066eb42018-03-07 20:49:25 +0100282 var done = this.async();
283 setTimeout(function() {
284 done(true);
285 }, 1000);
286 });
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200287
Mario Emmenlauer60646962020-04-15 10:26:09 +0200288 grunt.registerTask('CreateDirectories', 'Creating required local directories', function () {
289 grunt.file.mkdir('test/build/js/lib');
290 grunt.file.mkdir('test/gen-js');
291 grunt.file.mkdir('test/gen-js-jquery');
292 grunt.file.mkdir('test/gen-nodejs');
293 grunt.file.mkdir('test/gen-js-es6');
294 grunt.file.mkdir('test/gen-nodejs-es6');
295});
296
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400297 grunt.registerTask('installAndGenerate', [
Mario Emmenlauer60646962020-04-15 10:26:09 +0200298 'CreateDirectories',
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300299 'shell:InstallThriftJS',
300 'shell:InstallThriftNodeJSDep',
301 'shell:ThriftGen',
302 'shell:ThriftGenDeepConstructor',
303 'shell:ThriftGenDoubleConstants',
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400304 'shell:InstallTestLibs',
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300305 'shell:ThriftBrowserifyNodeInt64',
306 'shell:ThriftGenInt64'
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400307 ]);
308
309 grunt.registerTask('test', [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400310 'installAndGenerate',
bforbisda1169d2018-10-28 11:27:38 -0400311 'jshint',
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300312 'shell:ThriftTestServer',
313 'shell:ThriftTestServer_TLS',
314 'shell:ThriftTestServerES6',
315 'shell:ThriftTestServerES6_TLS',
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400316 'wait',
317 'qunit:ThriftDeepConstructor',
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300318 'qunit:ThriftJS',
319 'qunit:ThriftJS_TLS',
Ozan Can Altiokcaf7da92019-01-07 14:14:11 +0300320 'qunit:ThriftJS_DoubleRendering',
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400321 'qunit:ThriftWS',
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300322 'qunit:ThriftJSJQ',
323 'qunit:ThriftJSJQ_TLS',
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400324 'qunit:ThriftWSES6',
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300325 'qunit:ThriftJS_Int64',
326 'shell:ThriftTestServer:kill',
327 'shell:ThriftTestServer_TLS:kill',
328 'shell:ThriftTestServerES6:kill',
329 'shell:ThriftTestServerES6_TLS:kill',
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400330 ]);
Philip Frank55ddf192018-01-02 09:00:36 +0100331 grunt.registerTask('default', ['test', 'concat', 'uglify', 'jsdoc']);
henriquea2de4102014-02-07 14:12:56 +0100332};