Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 1 | //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 Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 6 | // Run grunt - npx grunt // uses project-local installed version of grunt (from package.json) |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 7 | |
| 8 | module.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 Meier | 16fcad0 | 2014-03-16 21:12:11 +0100 | [diff] [blame] | 24 | src: ['src/*.js', './README.md'], |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 25 | 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ça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 39 | }, |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 40 | shell: { |
| 41 | InstallThriftJS: { |
Mario Emmenlauer | 6064696 | 2020-04-15 10:26:09 +0200 | [diff] [blame] | 42 | command: 'cp src/thrift.js test/build/js/thrift.js' |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 43 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 44 | InstallThriftNodeJSDep: { |
Mario Emmenlauer | 6064696 | 2020-04-15 10:26:09 +0200 | [diff] [blame] | 45 | command: 'cd ../.. && npm install' |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 46 | }, |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 47 | InstallTestLibs: { |
Mario Emmenlauer | 6064696 | 2020-04-15 10:26:09 +0200 | [diff] [blame] | 48 | command: 'cd test && ant download_jslibs' |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 49 | }, |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 50 | ThriftGen: { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 51 | command: [ |
Mario Emmenlauer | 6064696 | 2020-04-15 10:26:09 +0200 | [diff] [blame] | 52 | '"../../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 Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 58 | ].join(' && ') |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 59 | }, |
| 60 | ThriftGenJQ: { |
Nobuaki Sukegawa | 4b7dbe3 | 2016-05-25 12:09:02 +0900 | [diff] [blame] | 61 | command: '../../compiler/cpp/thrift -gen js:jquery -gen js:node -o test ../../test/ThriftTest.thrift' |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 62 | }, |
| 63 | ThriftGenDeepConstructor: { |
Nobuaki Sukegawa | 4b7dbe3 | 2016-05-25 12:09:02 +0900 | [diff] [blame] | 64 | command: '../../compiler/cpp/thrift -gen js -o test ../../test/JsDeepConstructorTest.thrift' |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 65 | }, |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 66 | 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 Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame] | 76 | ThriftGenDoubleConstants: { |
| 77 | command: '../../compiler/cpp/thrift -gen js -o test ../../test/DoubleConstantsTest.thrift' |
| 78 | }, |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 79 | ThriftTestServer: { |
| 80 | options: { |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 81 | async: true, |
| 82 | execOptions: { |
| 83 | cwd: "./test", |
| 84 | env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"} |
| 85 | } |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 86 | }, |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 87 | command: "node server_http.js", |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 88 | }, |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 89 | 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 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 99 | ThriftTestServer_TLS: { |
| 100 | options: { |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 101 | async: true, |
| 102 | execOptions: { |
| 103 | cwd: "./test", |
| 104 | env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"} |
| 105 | } |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 106 | }, |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 107 | command: "node server_https.js", |
| 108 | }, |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 109 | 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ça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 119 | }, |
| 120 | qunit: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 121 | ThriftJS: { |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 122 | options: { |
| 123 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 124 | 'http://localhost:8089/test-nojq.html' |
| 125 | ], |
| 126 | puppeteer: { |
| 127 | headless: true, |
| 128 | args: ['--no-sandbox'], |
| 129 | }, |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 130 | } |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 131 | }, |
| 132 | ThriftJSJQ: { |
| 133 | options: { |
| 134 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 135 | 'http://localhost:8089/test.html' |
| 136 | ], |
| 137 | puppeteer: { |
| 138 | headless: true, |
| 139 | args: ['--no-sandbox'], |
| 140 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 141 | } |
| 142 | }, |
Ozan Can Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame] | 143 | ThriftJS_DoubleRendering: { |
| 144 | options: { |
Ozan Can Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame] | 145 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 146 | 'http://localhost:8089/test-double-rendering.html' |
| 147 | ], |
| 148 | puppeteer: { |
| 149 | headless: true, |
| 150 | args: ['--no-sandbox'], |
| 151 | ignoreHTTPSErrors: true, |
| 152 | }, |
Ozan Can Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame] | 153 | } |
| 154 | }, |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 155 | 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 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 167 | ThriftWS: { |
| 168 | options: { |
| 169 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 170 | 'http://localhost:8089/testws.html' |
| 171 | ], |
| 172 | puppeteer: { |
| 173 | headless: true, |
| 174 | args: ['--no-sandbox'], |
| 175 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 176 | } |
| 177 | }, |
| 178 | ThriftJS_TLS: { |
| 179 | options: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 180 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 181 | 'https://localhost:8091/test-nojq.html' |
| 182 | ], |
| 183 | puppeteer: { |
| 184 | headless: true, |
| 185 | args: ['--no-sandbox'], |
| 186 | ignoreHTTPSErrors: true, |
| 187 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 188 | } |
| 189 | }, |
| 190 | ThriftJSJQ_TLS: { |
| 191 | options: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 192 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 193 | 'https://localhost:8091/test.html' |
| 194 | ], |
| 195 | puppeteer: { |
| 196 | headless: true, |
| 197 | args: ['--no-sandbox'], |
| 198 | ignoreHTTPSErrors: true, |
| 199 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 200 | } |
| 201 | }, |
| 202 | ThriftWS_TLS: { |
| 203 | options: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 204 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 205 | 'https://localhost:8091/testws.html' |
| 206 | ], |
| 207 | puppeteer: { |
| 208 | headless: true, |
| 209 | args: ['--no-sandbox'], |
| 210 | ignoreHTTPSErrors: true, |
| 211 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 212 | } |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 213 | }, |
| 214 | ThriftDeepConstructor: { |
| 215 | options: { |
| 216 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 217 | 'http://localhost:8089/test-deep-constructor.html' |
| 218 | ], |
| 219 | puppeteer: { |
| 220 | headless: true, |
| 221 | args: ['--no-sandbox'], |
| 222 | }, |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 223 | } |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 224 | }, |
| 225 | ThriftWSES6: { |
| 226 | options: { |
| 227 | urls: [ |
| 228 | 'http://localhost:8088/test-es6.html' |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 229 | ], |
| 230 | puppeteer: { |
| 231 | headless: true, |
| 232 | args: ['--no-sandbox'], |
| 233 | }, |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 234 | } |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 235 | } |
| 236 | }, |
| 237 | jshint: { |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 238 | // The main Thrift library file. not es6 yet :( |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 239 | lib: { |
| 240 | src: ['src/**/*.js'], |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 241 | }, |
| 242 | // The test files use es6 |
| 243 | test: { |
| 244 | src: ['Gruntfile.js', 'test/*.js'], |
| 245 | options: { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 246 | esversion: 6, |
| 247 | } |
| 248 | }, |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 249 | 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ça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 272 | }); |
| 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 Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 279 | grunt.loadNpmTasks('grunt-shell-spawn'); |
| 280 | |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 281 | grunt.registerTask('wait', 'Wait just one second for the server to start', function () { |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 282 | var done = this.async(); |
| 283 | setTimeout(function() { |
| 284 | done(true); |
| 285 | }, 1000); |
| 286 | }); |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 287 | |
Mario Emmenlauer | 6064696 | 2020-04-15 10:26:09 +0200 | [diff] [blame] | 288 | 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 Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 297 | grunt.registerTask('installAndGenerate', [ |
Mario Emmenlauer | 6064696 | 2020-04-15 10:26:09 +0200 | [diff] [blame] | 298 | 'CreateDirectories', |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 299 | 'shell:InstallThriftJS', |
| 300 | 'shell:InstallThriftNodeJSDep', |
| 301 | 'shell:ThriftGen', |
| 302 | 'shell:ThriftGenDeepConstructor', |
| 303 | 'shell:ThriftGenDoubleConstants', |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 304 | 'shell:InstallTestLibs', |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 305 | 'shell:ThriftBrowserifyNodeInt64', |
| 306 | 'shell:ThriftGenInt64' |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 307 | ]); |
| 308 | |
| 309 | grunt.registerTask('test', [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 310 | 'installAndGenerate', |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 311 | 'jshint', |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 312 | 'shell:ThriftTestServer', |
| 313 | 'shell:ThriftTestServer_TLS', |
| 314 | 'shell:ThriftTestServerES6', |
| 315 | 'shell:ThriftTestServerES6_TLS', |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 316 | 'wait', |
| 317 | 'qunit:ThriftDeepConstructor', |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 318 | 'qunit:ThriftJS', |
| 319 | 'qunit:ThriftJS_TLS', |
Ozan Can Altiok | caf7da9 | 2019-01-07 14:14:11 +0300 | [diff] [blame] | 320 | 'qunit:ThriftJS_DoubleRendering', |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 321 | 'qunit:ThriftWS', |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 322 | 'qunit:ThriftJSJQ', |
| 323 | 'qunit:ThriftJSJQ_TLS', |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 324 | 'qunit:ThriftWSES6', |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 325 | 'qunit:ThriftJS_Int64', |
| 326 | 'shell:ThriftTestServer:kill', |
| 327 | 'shell:ThriftTestServer_TLS:kill', |
| 328 | 'shell:ThriftTestServerES6:kill', |
| 329 | 'shell:ThriftTestServerES6_TLS:kill', |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 330 | ]); |
Philip Frank | 55ddf19 | 2018-01-02 09:00:36 +0100 | [diff] [blame] | 331 | grunt.registerTask('default', ['test', 'concat', 'uglify', 'jsdoc']); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 332 | }; |