blob: 089ef8f6610108ca641f6ebd7530b8abafb8baaa [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
Cameron Martincaef0ed2025-01-15 11:58:39 +01008module.exports = function (grunt) {
9 "use strict";
Henrique Mendonça095ddb72013-09-20 19:38:03 +020010
11 grunt.initConfig({
Cameron Martincaef0ed2025-01-15 11:58:39 +010012 pkg: grunt.file.readJSON("package.json"),
Henrique Mendonça095ddb72013-09-20 19:38:03 +020013 concat: {
14 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010015 separator: ";",
Henrique Mendonça095ddb72013-09-20 19:38:03 +020016 },
17 dist: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010018 src: ["src/**/*.js"],
19 dest: "dist/<%= pkg.name %>.js",
20 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +020021 },
Cameron Martincaef0ed2025-01-15 11:58:39 +010022 jsdoc: {
23 dist: {
24 src: ["src/*.js", "./README.md"],
25 options: {
26 destination: "doc",
27 },
28 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +020029 },
30 uglify: {
31 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010032 banner:
33 '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n',
Henrique Mendonça095ddb72013-09-20 19:38:03 +020034 },
35 dist: {
36 files: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010037 "dist/<%= pkg.name %>.min.js": ["<%= concat.dist.dest %>"],
38 },
39 },
Henrique Mendonça15d90422015-06-25 22:31:41 +100040 },
henriquea2de4102014-02-07 14:12:56 +010041 shell: {
42 InstallThriftJS: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010043 command: "cp src/thrift.js test/build/js/thrift.js",
henriquea2de4102014-02-07 14:12:56 +010044 },
henrique2a7dccc2014-03-07 22:16:51 +010045 InstallThriftNodeJSDep: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010046 command: "cd ../.. && npm install",
henrique2a7dccc2014-03-07 22:16:51 +010047 },
Philip Frank5066eb42018-03-07 20:49:25 +010048 InstallTestLibs: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010049 command: "cd test && ant download_jslibs",
Philip Frank5066eb42018-03-07 20:49:25 +010050 },
henriquea2de4102014-02-07 14:12:56 +010051 ThriftGen: {
Brian Forbisb5d6ea32018-08-25 23:39:29 -040052 command: [
Jens Geyerf066d842022-06-13 23:37:25 +020053 '"../../compiler/cpp/thrift" -gen js --out test/gen-js ../../test/v0.16/ThriftTest.thrift',
Mario Emmenlauer60646962020-04-15 10:26:09 +020054 '"../../compiler/cpp/thrift" -gen js --out test/gen-js ../../test/JsDeepConstructorTest.thrift',
Jens Geyerf066d842022-06-13 23:37:25 +020055 '"../../compiler/cpp/thrift" -gen js:jquery --out test/gen-js-jquery ../../test/v0.16/ThriftTest.thrift',
56 '"../../compiler/cpp/thrift" -gen js:node --out test/gen-nodejs ../../test/v0.16/ThriftTest.thrift',
57 '"../../compiler/cpp/thrift" -gen js:es6 --out test/gen-js-es6 ../../test/v0.16/ThriftTest.thrift',
58 '"../../compiler/cpp/thrift" -gen js:node,es6 --out ./test/gen-nodejs-es6 ../../test/v0.16/ThriftTest.thrift',
Cameron Martincaef0ed2025-01-15 11:58:39 +010059 ].join(" && "),
henrique2a7dccc2014-03-07 22:16:51 +010060 },
61 ThriftGenJQ: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010062 command:
63 "../../compiler/cpp/thrift -gen js:jquery -gen js:node -o test ../../test/v0.16/ThriftTest.thrift",
Henrique Mendonça15d90422015-06-25 22:31:41 +100064 },
65 ThriftGenDeepConstructor: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010066 command:
67 "../../compiler/cpp/thrift -gen js -o test ../../test/JsDeepConstructorTest.thrift",
Philip Frank8fdd6102017-12-06 12:38:05 +010068 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030069 ThriftBrowserifyNodeInt64: {
70 command: [
Cameron Martincaef0ed2025-01-15 11:58:39 +010071 "./node_modules/browserify/bin/cmd.js ./node_modules/node-int64/Int64.js -s Int64 -o test/build/js/lib/Int64.js",
72 "./node_modules/browserify/bin/cmd.js ../nodejs/lib/thrift/int64_util.js -s Int64Util -o test/build/js/lib/Int64Util.js",
73 "./node_modules/browserify/bin/cmd.js ./node_modules/json-int64/index.js -s JSONInt64 -o test/build/js/lib/JSONInt64.js",
74 ].join(" && "),
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030075 },
76 ThriftGenInt64: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010077 command:
78 "../../compiler/cpp/thrift -gen js -o test ../../test/Int64Test.thrift",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030079 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +030080 ThriftGenDoubleConstants: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010081 command:
82 "../../compiler/cpp/thrift -gen js -o test ../../test/DoubleConstantsTest.thrift",
Ozan Can Altioke46419b2018-03-20 15:02:28 +030083 },
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",
Cameron Martincaef0ed2025-01-15 11:58:39 +010089 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",
Cameron Martincaef0ed2025-01-15 11:58:39 +010099 env: { NODE_PATH: "../../nodejs/lib:../../../node_modules" },
100 },
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400101 },
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",
Cameron Martincaef0ed2025-01-15 11:58:39 +0100109 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",
Cameron Martincaef0ed2025-01-15 11:58:39 +0100119 env: { NODE_PATH: "../../nodejs/lib:../../../node_modules" },
120 },
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400121 },
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: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100128 urls: ["http://localhost:8089/test-nojq.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400129 puppeteer: {
130 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100131 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400132 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100133 },
henrique2a7dccc2014-03-07 22:16:51 +0100134 },
135 ThriftJSJQ: {
136 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100137 urls: ["http://localhost:8089/test.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400138 puppeteer: {
139 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100140 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400141 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100142 },
henrique2a7dccc2014-03-07 22:16:51 +0100143 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300144 ThriftJS_DoubleRendering: {
145 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100146 urls: ["http://localhost:8089/test-double-rendering.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400147 puppeteer: {
148 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100149 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400150 ignoreHTTPSErrors: true,
151 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100152 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300153 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300154 ThriftJS_Int64: {
155 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100156 urls: ["http://localhost:8089/test-int64.html"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300157 puppeteer: {
158 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100159 args: ["--no-sandbox"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300160 ignoreHTTPSErrors: true,
161 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100162 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300163 },
henrique2a7dccc2014-03-07 22:16:51 +0100164 ThriftWS: {
165 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100166 urls: ["http://localhost:8089/testws.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400167 puppeteer: {
168 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100169 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400170 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100171 },
henrique2a7dccc2014-03-07 22:16:51 +0100172 },
173 ThriftJS_TLS: {
174 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100175 urls: ["https://localhost:8091/test-nojq.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400176 puppeteer: {
177 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100178 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400179 ignoreHTTPSErrors: true,
180 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100181 },
henrique2a7dccc2014-03-07 22:16:51 +0100182 },
183 ThriftJSJQ_TLS: {
184 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100185 urls: ["https://localhost:8091/test.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 ignoreHTTPSErrors: true,
190 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100191 },
henrique2a7dccc2014-03-07 22:16:51 +0100192 },
193 ThriftWS_TLS: {
194 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100195 urls: ["https://localhost:8091/testws.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400196 puppeteer: {
197 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100198 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400199 ignoreHTTPSErrors: true,
200 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100201 },
Henrique Mendonça15d90422015-06-25 22:31:41 +1000202 },
203 ThriftDeepConstructor: {
204 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100205 urls: ["http://localhost:8089/test-deep-constructor.html"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400206 puppeteer: {
207 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100208 args: ["--no-sandbox"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400209 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100210 },
Philip Frank8fdd6102017-12-06 12:38:05 +0100211 },
212 ThriftWSES6: {
213 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100214 urls: ["http://localhost:8088/test-es6.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 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100219 },
220 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200221 },
222 jshint: {
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300223 // The main Thrift library file. not es6 yet :(
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400224 lib: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100225 src: ["src/**/*.js"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400226 },
227 // The test files use es6
228 test: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100229 src: ["Gruntfile.js", "test/*.js"],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400230 options: {
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400231 esversion: 6,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100232 },
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400233 },
bforbisda1169d2018-10-28 11:27:38 -0400234 gen_js_code: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100235 src: ["test/gen-js/*.js", "test/gen-js-jquery/*.js"],
bforbisda1169d2018-10-28 11:27:38 -0400236 },
237 gen_es6_code: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100238 src: ["test/gen-js-es6/*.js"],
bforbisda1169d2018-10-28 11:27:38 -0400239 options: {
240 esversion: 6,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100241 },
bforbisda1169d2018-10-28 11:27:38 -0400242 },
243 gen_node_code: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100244 src: ["test/gen-nodejs/*.js"],
bforbisda1169d2018-10-28 11:27:38 -0400245 options: {
246 node: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100247 },
bforbisda1169d2018-10-28 11:27:38 -0400248 },
249 gen_node_es6_code: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100250 src: ["test/gen-nodejs-es6/*.js"],
bforbisda1169d2018-10-28 11:27:38 -0400251 options: {
252 node: true,
253 esversion: 6,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100254 },
255 },
bforbisda1169d2018-10-28 11:27:38 -0400256 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200257 });
258
Cameron Martincaef0ed2025-01-15 11:58:39 +0100259 grunt.loadNpmTasks("grunt-contrib-uglify");
260 grunt.loadNpmTasks("grunt-contrib-jshint");
261 grunt.loadNpmTasks("grunt-contrib-qunit");
262 grunt.loadNpmTasks("grunt-contrib-concat");
263 grunt.loadNpmTasks("grunt-jsdoc");
264 grunt.loadNpmTasks("grunt-shell-spawn");
Philip Frank5066eb42018-03-07 20:49:25 +0100265
Cameron Martincaef0ed2025-01-15 11:58:39 +0100266 grunt.registerTask(
267 "wait",
268 "Wait just one second for the server to start",
269 function () {
270 var done = this.async();
271 setTimeout(function () {
272 done(true);
273 }, 1000);
274 },
275 );
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200276
Cameron Martincaef0ed2025-01-15 11:58:39 +0100277 grunt.registerTask(
278 "CreateDirectories",
279 "Creating required local directories",
280 function () {
281 grunt.file.mkdir("test/build/js/lib");
282 grunt.file.mkdir("test/gen-js");
283 grunt.file.mkdir("test/gen-js-jquery");
284 grunt.file.mkdir("test/gen-nodejs");
285 grunt.file.mkdir("test/gen-js-es6");
286 grunt.file.mkdir("test/gen-nodejs-es6");
287 },
288 );
Mario Emmenlauer60646962020-04-15 10:26:09 +0200289
Cameron Martincaef0ed2025-01-15 11:58:39 +0100290 grunt.registerTask("installAndGenerate", [
291 "CreateDirectories",
292 "shell:InstallThriftJS",
293 "shell:InstallThriftNodeJSDep",
294 "shell:ThriftGen",
295 "shell:ThriftGenDeepConstructor",
296 "shell:ThriftGenDoubleConstants",
297 "shell:InstallTestLibs",
298 "shell:ThriftBrowserifyNodeInt64",
299 "shell:ThriftGenInt64",
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400300 ]);
301
Cameron Martincaef0ed2025-01-15 11:58:39 +0100302 grunt.registerTask("test", [
303 "installAndGenerate",
304 "jshint",
305 "shell:ThriftTestServer",
306 "shell:ThriftTestServer_TLS",
307 "shell:ThriftTestServerES6",
308 "shell:ThriftTestServerES6_TLS",
309 "wait",
310 "qunit:ThriftDeepConstructor",
311 "qunit:ThriftJS",
312 "qunit:ThriftJS_TLS",
313 "qunit:ThriftJS_DoubleRendering",
314 "qunit:ThriftWS",
315 "qunit:ThriftJSJQ",
316 "qunit:ThriftJSJQ_TLS",
317 "qunit:ThriftWSES6",
318 "qunit:ThriftJS_Int64",
319 "shell:ThriftTestServer:kill",
320 "shell:ThriftTestServer_TLS:kill",
321 "shell:ThriftTestServerES6:kill",
322 "shell:ThriftTestServerES6_TLS:kill",
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400323 ]);
Cameron Martincaef0ed2025-01-15 11:58:39 +0100324 grunt.registerTask("default", ["test", "concat", "uglify", "jsdoc"]);
henriquea2de4102014-02-07 14:12:56 +0100325};