blob: 4d092a4ec275ddf9d52d2532b3acc07b4c8bfd01 [file] [log] [blame]
Jens Geyer72a714e2025-08-26 22:12:07 +02001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
Henrique Mendonça095ddb72013-09-20 19:38:03 +020020//To build dist/thrift.js, dist/thrift.min.js and doc/*
21//run grunt at the command line in this directory.
22//Prerequisites:
23// Node Setup - nodejs.org
24// Grunt Setup - npm install //reads the ./package.json and installs project dependencies
Brian Forbisb5d6ea32018-08-25 23:39:29 -040025// Run grunt - npx grunt // uses project-local installed version of grunt (from package.json)
Henrique Mendonça095ddb72013-09-20 19:38:03 +020026
Cameron Martincaef0ed2025-01-15 11:58:39 +010027module.exports = function (grunt) {
28 "use strict";
Henrique Mendonça095ddb72013-09-20 19:38:03 +020029
30 grunt.initConfig({
Cameron Martincaef0ed2025-01-15 11:58:39 +010031 pkg: grunt.file.readJSON("package.json"),
Henrique Mendonça095ddb72013-09-20 19:38:03 +020032 concat: {
33 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010034 separator: ";",
Henrique Mendonça095ddb72013-09-20 19:38:03 +020035 },
36 dist: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010037 src: ["src/**/*.js"],
38 dest: "dist/<%= pkg.name %>.js",
39 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +020040 },
Cameron Martincaef0ed2025-01-15 11:58:39 +010041 jsdoc: {
42 dist: {
43 src: ["src/*.js", "./README.md"],
44 options: {
45 destination: "doc",
46 },
47 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +020048 },
49 uglify: {
50 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010051 banner:
52 '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n',
Henrique Mendonça095ddb72013-09-20 19:38:03 +020053 },
54 dist: {
55 files: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010056 "dist/<%= pkg.name %>.min.js": ["<%= concat.dist.dest %>"],
57 },
58 },
Henrique Mendonça15d90422015-06-25 22:31:41 +100059 },
henriquea2de4102014-02-07 14:12:56 +010060 shell: {
61 InstallThriftJS: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010062 command: "cp src/thrift.js test/build/js/thrift.js",
henriquea2de4102014-02-07 14:12:56 +010063 },
henrique2a7dccc2014-03-07 22:16:51 +010064 InstallThriftNodeJSDep: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010065 command: "cd ../.. && npm install",
henrique2a7dccc2014-03-07 22:16:51 +010066 },
Philip Frank5066eb42018-03-07 20:49:25 +010067 InstallTestLibs: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010068 command: "cd test && ant download_jslibs",
Philip Frank5066eb42018-03-07 20:49:25 +010069 },
henriquea2de4102014-02-07 14:12:56 +010070 ThriftGen: {
Brian Forbisb5d6ea32018-08-25 23:39:29 -040071 command: [
Jens Geyerf066d842022-06-13 23:37:25 +020072 '"../../compiler/cpp/thrift" -gen js --out test/gen-js ../../test/v0.16/ThriftTest.thrift',
Mario Emmenlauer60646962020-04-15 10:26:09 +020073 '"../../compiler/cpp/thrift" -gen js --out test/gen-js ../../test/JsDeepConstructorTest.thrift',
Jens Geyerf066d842022-06-13 23:37:25 +020074 '"../../compiler/cpp/thrift" -gen js:jquery --out test/gen-js-jquery ../../test/v0.16/ThriftTest.thrift',
75 '"../../compiler/cpp/thrift" -gen js:node --out test/gen-nodejs ../../test/v0.16/ThriftTest.thrift',
76 '"../../compiler/cpp/thrift" -gen js:es6 --out test/gen-js-es6 ../../test/v0.16/ThriftTest.thrift',
77 '"../../compiler/cpp/thrift" -gen js:node,es6 --out ./test/gen-nodejs-es6 ../../test/v0.16/ThriftTest.thrift',
Cameron Martincaef0ed2025-01-15 11:58:39 +010078 ].join(" && "),
henrique2a7dccc2014-03-07 22:16:51 +010079 },
80 ThriftGenJQ: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010081 command:
82 "../../compiler/cpp/thrift -gen js:jquery -gen js:node -o test ../../test/v0.16/ThriftTest.thrift",
Henrique Mendonça15d90422015-06-25 22:31:41 +100083 },
84 ThriftGenDeepConstructor: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010085 command:
86 "../../compiler/cpp/thrift -gen js -o test ../../test/JsDeepConstructorTest.thrift",
Philip Frank8fdd6102017-12-06 12:38:05 +010087 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030088 ThriftBrowserifyNodeInt64: {
89 command: [
Cameron Martincaef0ed2025-01-15 11:58:39 +010090 "./node_modules/browserify/bin/cmd.js ./node_modules/node-int64/Int64.js -s Int64 -o test/build/js/lib/Int64.js",
91 "./node_modules/browserify/bin/cmd.js ../nodejs/lib/thrift/int64_util.js -s Int64Util -o test/build/js/lib/Int64Util.js",
92 "./node_modules/browserify/bin/cmd.js ./node_modules/json-int64/index.js -s JSONInt64 -o test/build/js/lib/JSONInt64.js",
93 ].join(" && "),
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030094 },
95 ThriftGenInt64: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010096 command:
97 "../../compiler/cpp/thrift -gen js -o test ../../test/Int64Test.thrift",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030098 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +030099 ThriftGenDoubleConstants: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100100 command:
101 "../../compiler/cpp/thrift -gen js -o test ../../test/DoubleConstantsTest.thrift",
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300102 },
henriquea2de4102014-02-07 14:12:56 +0100103 ThriftTestServer: {
104 options: {
Philip Frank5066eb42018-03-07 20:49:25 +0100105 async: true,
106 execOptions: {
107 cwd: "./test",
Cameron Martincaef0ed2025-01-15 11:58:39 +0100108 env: { NODE_PATH: "../../nodejs/lib:../../../node_modules" },
109 },
henriquea2de4102014-02-07 14:12:56 +0100110 },
Philip Frank5066eb42018-03-07 20:49:25 +0100111 command: "node server_http.js",
henrique2a7dccc2014-03-07 22:16:51 +0100112 },
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400113 ThriftTestServerES6: {
114 options: {
115 async: true,
116 execOptions: {
117 cwd: "./test",
Cameron Martincaef0ed2025-01-15 11:58:39 +0100118 env: { NODE_PATH: "../../nodejs/lib:../../../node_modules" },
119 },
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400120 },
121 command: "node server_http.js --es6",
122 },
henrique2a7dccc2014-03-07 22:16:51 +0100123 ThriftTestServer_TLS: {
124 options: {
Philip Frank5066eb42018-03-07 20:49:25 +0100125 async: true,
126 execOptions: {
127 cwd: "./test",
Cameron Martincaef0ed2025-01-15 11:58:39 +0100128 env: { NODE_PATH: "../../nodejs/lib:../../../node_modules" },
129 },
henrique2a7dccc2014-03-07 22:16:51 +0100130 },
Philip Frank5066eb42018-03-07 20:49:25 +0100131 command: "node server_https.js",
132 },
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400133 ThriftTestServerES6_TLS: {
134 options: {
135 async: true,
136 execOptions: {
137 cwd: "./test",
Cameron Martincaef0ed2025-01-15 11:58:39 +0100138 env: { NODE_PATH: "../../nodejs/lib:../../../node_modules" },
139 },
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400140 },
141 command: "node server_https.js --es6",
142 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200143 },
144 qunit: {
henrique2a7dccc2014-03-07 22:16:51 +0100145 ThriftJS: {
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200146 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100147 urls: ["http://localhost:8089/test-nojq.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400148 puppeteer: {
149 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100150 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400151 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100152 },
henrique2a7dccc2014-03-07 22:16:51 +0100153 },
154 ThriftJSJQ: {
155 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100156 urls: ["http://localhost:8089/test.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400157 puppeteer: {
158 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100159 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400160 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100161 },
henrique2a7dccc2014-03-07 22:16:51 +0100162 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300163 ThriftJS_DoubleRendering: {
164 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100165 urls: ["http://localhost:8089/test-double-rendering.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400166 puppeteer: {
167 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100168 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400169 ignoreHTTPSErrors: true,
170 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100171 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300172 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300173 ThriftJS_Int64: {
174 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100175 urls: ["http://localhost:8089/test-int64.html"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300176 puppeteer: {
177 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100178 args: ["--no-sandbox"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300179 ignoreHTTPSErrors: true,
180 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100181 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300182 },
henrique2a7dccc2014-03-07 22:16:51 +0100183 ThriftWS: {
184 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100185 urls: ["http://localhost:8089/testws.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400186 puppeteer: {
187 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100188 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400189 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100190 },
henrique2a7dccc2014-03-07 22:16:51 +0100191 },
192 ThriftJS_TLS: {
193 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100194 urls: ["https://localhost:8091/test-nojq.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400195 puppeteer: {
196 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100197 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400198 ignoreHTTPSErrors: true,
199 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100200 },
henrique2a7dccc2014-03-07 22:16:51 +0100201 },
202 ThriftJSJQ_TLS: {
203 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100204 urls: ["https://localhost:8091/test.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400205 puppeteer: {
206 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100207 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400208 ignoreHTTPSErrors: true,
209 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100210 },
henrique2a7dccc2014-03-07 22:16:51 +0100211 },
212 ThriftWS_TLS: {
213 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100214 urls: ["https://localhost:8091/testws.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400215 puppeteer: {
216 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100217 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400218 ignoreHTTPSErrors: true,
219 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100220 },
Henrique Mendonça15d90422015-06-25 22:31:41 +1000221 },
222 ThriftDeepConstructor: {
223 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100224 urls: ["http://localhost:8089/test-deep-constructor.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400225 puppeteer: {
226 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100227 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400228 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100229 },
Philip Frank8fdd6102017-12-06 12:38:05 +0100230 },
231 ThriftWSES6: {
232 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100233 urls: ["http://localhost:8088/test-es6.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400234 puppeteer: {
235 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100236 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400237 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100238 },
239 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200240 },
241 jshint: {
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300242 // The main Thrift library file. not es6 yet :(
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400243 lib: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100244 src: ["src/**/*.js"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400245 },
246 // The test files use es6
247 test: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100248 src: ["Gruntfile.js", "test/*.js"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400249 options: {
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400250 esversion: 6,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100251 },
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400252 },
bforbisda1169d2018-10-28 11:27:38 -0400253 gen_js_code: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100254 src: ["test/gen-js/*.js", "test/gen-js-jquery/*.js"],
bforbisda1169d2018-10-28 11:27:38 -0400255 },
256 gen_es6_code: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100257 src: ["test/gen-js-es6/*.js"],
bforbisda1169d2018-10-28 11:27:38 -0400258 options: {
259 esversion: 6,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100260 },
bforbisda1169d2018-10-28 11:27:38 -0400261 },
262 gen_node_code: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100263 src: ["test/gen-nodejs/*.js"],
bforbisda1169d2018-10-28 11:27:38 -0400264 options: {
265 node: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100266 },
bforbisda1169d2018-10-28 11:27:38 -0400267 },
268 gen_node_es6_code: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100269 src: ["test/gen-nodejs-es6/*.js"],
bforbisda1169d2018-10-28 11:27:38 -0400270 options: {
271 node: true,
272 esversion: 6,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100273 },
274 },
bforbisda1169d2018-10-28 11:27:38 -0400275 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200276 });
277
Cameron Martincaef0ed2025-01-15 11:58:39 +0100278 grunt.loadNpmTasks("grunt-contrib-uglify");
279 grunt.loadNpmTasks("grunt-contrib-jshint");
280 grunt.loadNpmTasks("grunt-contrib-qunit");
281 grunt.loadNpmTasks("grunt-contrib-concat");
282 grunt.loadNpmTasks("grunt-jsdoc");
283 grunt.loadNpmTasks("grunt-shell-spawn");
Philip Frank5066eb42018-03-07 20:49:25 +0100284
Cameron Martincaef0ed2025-01-15 11:58:39 +0100285 grunt.registerTask(
286 "wait",
287 "Wait just one second for the server to start",
288 function () {
289 var done = this.async();
290 setTimeout(function () {
291 done(true);
292 }, 1000);
293 },
294 );
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200295
Cameron Martincaef0ed2025-01-15 11:58:39 +0100296 grunt.registerTask(
297 "CreateDirectories",
298 "Creating required local directories",
299 function () {
300 grunt.file.mkdir("test/build/js/lib");
301 grunt.file.mkdir("test/gen-js");
302 grunt.file.mkdir("test/gen-js-jquery");
303 grunt.file.mkdir("test/gen-nodejs");
304 grunt.file.mkdir("test/gen-js-es6");
305 grunt.file.mkdir("test/gen-nodejs-es6");
306 },
307 );
Mario Emmenlauer60646962020-04-15 10:26:09 +0200308
Cameron Martincaef0ed2025-01-15 11:58:39 +0100309 grunt.registerTask("installAndGenerate", [
310 "CreateDirectories",
311 "shell:InstallThriftJS",
312 "shell:InstallThriftNodeJSDep",
313 "shell:ThriftGen",
314 "shell:ThriftGenDeepConstructor",
315 "shell:ThriftGenDoubleConstants",
316 "shell:InstallTestLibs",
317 "shell:ThriftBrowserifyNodeInt64",
318 "shell:ThriftGenInt64",
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400319 ]);
320
Cameron Martincaef0ed2025-01-15 11:58:39 +0100321 grunt.registerTask("test", [
322 "installAndGenerate",
323 "jshint",
324 "shell:ThriftTestServer",
325 "shell:ThriftTestServer_TLS",
326 "shell:ThriftTestServerES6",
327 "shell:ThriftTestServerES6_TLS",
328 "wait",
329 "qunit:ThriftDeepConstructor",
330 "qunit:ThriftJS",
331 "qunit:ThriftJS_TLS",
332 "qunit:ThriftJS_DoubleRendering",
333 "qunit:ThriftWS",
334 "qunit:ThriftJSJQ",
335 "qunit:ThriftJSJQ_TLS",
336 "qunit:ThriftWSES6",
337 "qunit:ThriftJS_Int64",
338 "shell:ThriftTestServer:kill",
339 "shell:ThriftTestServer_TLS:kill",
340 "shell:ThriftTestServerES6:kill",
341 "shell:ThriftTestServerES6_TLS:kill",
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400342 ]);
Cameron Martincaef0ed2025-01-15 11:58:39 +0100343 grunt.registerTask("default", ["test", "concat", "uglify", "jsdoc"]);
henriquea2de4102014-02-07 14:12:56 +0100344};