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: { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 42 | command: 'mkdir -p test/build/js/lib; 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: { |
Nobuaki Sukegawa | 6defea5 | 2015-11-14 17:36:29 +0900 | [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: { |
| 48 | command: 'cd test; ant download_jslibs' |
| 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: [ |
| 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(' && ') |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 64 | }, |
| 65 | ThriftGenJQ: { |
Nobuaki Sukegawa | 4b7dbe3 | 2016-05-25 12:09:02 +0900 | [diff] [blame] | 66 | 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] | 67 | }, |
| 68 | ThriftGenDeepConstructor: { |
Nobuaki Sukegawa | 4b7dbe3 | 2016-05-25 12:09:02 +0900 | [diff] [blame] | 69 | command: '../../compiler/cpp/thrift -gen js -o test ../../test/JsDeepConstructorTest.thrift' |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 70 | }, |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 71 | 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 Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame] | 81 | ThriftGenDoubleConstants: { |
| 82 | command: '../../compiler/cpp/thrift -gen js -o test ../../test/DoubleConstantsTest.thrift' |
| 83 | }, |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 84 | ThriftTestServer: { |
| 85 | options: { |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 86 | async: true, |
| 87 | execOptions: { |
| 88 | cwd: "./test", |
| 89 | env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"} |
| 90 | } |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 91 | }, |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 92 | command: "node server_http.js", |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 93 | }, |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 94 | 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 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 104 | ThriftTestServer_TLS: { |
| 105 | options: { |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 106 | async: true, |
| 107 | execOptions: { |
| 108 | cwd: "./test", |
| 109 | env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"} |
| 110 | } |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 111 | }, |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 112 | command: "node server_https.js", |
| 113 | }, |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 114 | 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ça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 124 | }, |
| 125 | qunit: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 126 | ThriftJS: { |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 127 | options: { |
| 128 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 129 | 'http://localhost:8089/test-nojq.html' |
| 130 | ], |
| 131 | puppeteer: { |
| 132 | headless: true, |
| 133 | args: ['--no-sandbox'], |
| 134 | }, |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 135 | } |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 136 | }, |
| 137 | ThriftJSJQ: { |
| 138 | options: { |
| 139 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 140 | 'http://localhost:8089/test.html' |
| 141 | ], |
| 142 | puppeteer: { |
| 143 | headless: true, |
| 144 | args: ['--no-sandbox'], |
| 145 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 146 | } |
| 147 | }, |
Ozan Can Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame] | 148 | ThriftJS_DoubleRendering: { |
| 149 | options: { |
Ozan Can Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame] | 150 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 151 | 'http://localhost:8089/test-double-rendering.html' |
| 152 | ], |
| 153 | puppeteer: { |
| 154 | headless: true, |
| 155 | args: ['--no-sandbox'], |
| 156 | ignoreHTTPSErrors: true, |
| 157 | }, |
Ozan Can Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame] | 158 | } |
| 159 | }, |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 160 | 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 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 172 | ThriftWS: { |
| 173 | options: { |
| 174 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 175 | 'http://localhost:8089/testws.html' |
| 176 | ], |
| 177 | puppeteer: { |
| 178 | headless: true, |
| 179 | args: ['--no-sandbox'], |
| 180 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 181 | } |
| 182 | }, |
| 183 | ThriftJS_TLS: { |
| 184 | options: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 185 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 186 | 'https://localhost:8091/test-nojq.html' |
| 187 | ], |
| 188 | puppeteer: { |
| 189 | headless: true, |
| 190 | args: ['--no-sandbox'], |
| 191 | ignoreHTTPSErrors: true, |
| 192 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 193 | } |
| 194 | }, |
| 195 | ThriftJSJQ_TLS: { |
| 196 | options: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 197 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 198 | 'https://localhost:8091/test.html' |
| 199 | ], |
| 200 | puppeteer: { |
| 201 | headless: true, |
| 202 | args: ['--no-sandbox'], |
| 203 | ignoreHTTPSErrors: true, |
| 204 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 205 | } |
| 206 | }, |
| 207 | ThriftWS_TLS: { |
| 208 | options: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 209 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 210 | 'https://localhost:8091/testws.html' |
| 211 | ], |
| 212 | puppeteer: { |
| 213 | headless: true, |
| 214 | args: ['--no-sandbox'], |
| 215 | ignoreHTTPSErrors: true, |
| 216 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 217 | } |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 218 | }, |
| 219 | ThriftDeepConstructor: { |
| 220 | options: { |
| 221 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 222 | 'http://localhost:8089/test-deep-constructor.html' |
| 223 | ], |
| 224 | puppeteer: { |
| 225 | headless: true, |
| 226 | args: ['--no-sandbox'], |
| 227 | }, |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 228 | } |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 229 | }, |
| 230 | ThriftWSES6: { |
| 231 | options: { |
| 232 | urls: [ |
| 233 | 'http://localhost:8088/test-es6.html' |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 234 | ], |
| 235 | puppeteer: { |
| 236 | headless: true, |
| 237 | args: ['--no-sandbox'], |
| 238 | }, |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 239 | } |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 240 | } |
| 241 | }, |
| 242 | jshint: { |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 243 | // The main Thrift library file. not es6 yet :( |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 244 | lib: { |
| 245 | src: ['src/**/*.js'], |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 246 | }, |
| 247 | // The test files use es6 |
| 248 | test: { |
| 249 | src: ['Gruntfile.js', 'test/*.js'], |
| 250 | options: { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 251 | esversion: 6, |
| 252 | } |
| 253 | }, |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 254 | 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ça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 277 | }); |
| 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 Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 284 | grunt.loadNpmTasks('grunt-shell-spawn'); |
| 285 | |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 286 | 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] | 287 | var done = this.async(); |
| 288 | setTimeout(function() { |
| 289 | done(true); |
| 290 | }, 1000); |
| 291 | }); |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 292 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 293 | grunt.registerTask('installAndGenerate', [ |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 294 | 'shell:InstallThriftJS', |
| 295 | 'shell:InstallThriftNodeJSDep', |
| 296 | 'shell:ThriftGen', |
| 297 | 'shell:ThriftGenDeepConstructor', |
| 298 | 'shell:ThriftGenDoubleConstants', |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 299 | 'shell:InstallTestLibs', |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 300 | 'shell:ThriftBrowserifyNodeInt64', |
| 301 | 'shell:ThriftGenInt64' |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 302 | ]); |
| 303 | |
| 304 | grunt.registerTask('test', [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 305 | 'installAndGenerate', |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 306 | 'jshint', |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 307 | 'shell:ThriftTestServer', |
| 308 | 'shell:ThriftTestServer_TLS', |
| 309 | 'shell:ThriftTestServerES6', |
| 310 | 'shell:ThriftTestServerES6_TLS', |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 311 | 'wait', |
| 312 | 'qunit:ThriftDeepConstructor', |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 313 | 'qunit:ThriftJS', |
| 314 | 'qunit:ThriftJS_TLS', |
Ozan Can Altiok | caf7da9 | 2019-01-07 14:14:11 +0300 | [diff] [blame] | 315 | 'qunit:ThriftJS_DoubleRendering', |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 316 | 'qunit:ThriftWS', |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 317 | 'qunit:ThriftJSJQ', |
| 318 | 'qunit:ThriftJSJQ_TLS', |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 319 | 'qunit:ThriftWSES6', |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 320 | 'qunit:ThriftJS_Int64', |
| 321 | 'shell:ThriftTestServer:kill', |
| 322 | 'shell:ThriftTestServer_TLS:kill', |
| 323 | 'shell:ThriftTestServerES6:kill', |
| 324 | 'shell:ThriftTestServerES6_TLS:kill', |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 325 | ]); |
Philip Frank | 55ddf19 | 2018-01-02 09:00:36 +0100 | [diff] [blame] | 326 | grunt.registerTask('default', ['test', 'concat', 'uglify', 'jsdoc']); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 327 | }; |