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 | }, |
Ozan Can Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame] | 71 | ThriftGenDoubleConstants: { |
| 72 | command: '../../compiler/cpp/thrift -gen js -o test ../../test/DoubleConstantsTest.thrift' |
| 73 | }, |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 74 | ThriftTestServer: { |
| 75 | options: { |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 76 | async: true, |
| 77 | execOptions: { |
| 78 | cwd: "./test", |
| 79 | env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"} |
| 80 | } |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 81 | }, |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 82 | command: "node server_http.js", |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 83 | }, |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 84 | ThriftTestServerES6: { |
| 85 | options: { |
| 86 | async: true, |
| 87 | execOptions: { |
| 88 | cwd: "./test", |
| 89 | env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"} |
| 90 | } |
| 91 | }, |
| 92 | command: "node server_http.js --es6", |
| 93 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 94 | ThriftTestServer_TLS: { |
| 95 | options: { |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 96 | async: true, |
| 97 | execOptions: { |
| 98 | cwd: "./test", |
| 99 | env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"} |
| 100 | } |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 101 | }, |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 102 | command: "node server_https.js", |
| 103 | }, |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 104 | ThriftTestServerES6_TLS: { |
| 105 | options: { |
| 106 | async: true, |
| 107 | execOptions: { |
| 108 | cwd: "./test", |
| 109 | env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"} |
| 110 | } |
| 111 | }, |
| 112 | command: "node server_https.js --es6", |
| 113 | }, |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 114 | }, |
| 115 | qunit: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 116 | ThriftJS: { |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 117 | options: { |
| 118 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 119 | 'http://localhost:8089/test-nojq.html' |
| 120 | ], |
| 121 | puppeteer: { |
| 122 | headless: true, |
| 123 | args: ['--no-sandbox'], |
| 124 | }, |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 125 | } |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 126 | }, |
| 127 | ThriftJSJQ: { |
| 128 | options: { |
| 129 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 130 | 'http://localhost:8089/test.html' |
| 131 | ], |
| 132 | puppeteer: { |
| 133 | headless: true, |
| 134 | args: ['--no-sandbox'], |
| 135 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 136 | } |
| 137 | }, |
Ozan Can Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame] | 138 | ThriftJS_DoubleRendering: { |
| 139 | options: { |
Ozan Can Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame] | 140 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 141 | 'http://localhost:8089/test-double-rendering.html' |
| 142 | ], |
| 143 | puppeteer: { |
| 144 | headless: true, |
| 145 | args: ['--no-sandbox'], |
| 146 | ignoreHTTPSErrors: true, |
| 147 | }, |
Ozan Can Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame] | 148 | } |
| 149 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 150 | ThriftWS: { |
| 151 | options: { |
| 152 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 153 | 'http://localhost:8089/testws.html' |
| 154 | ], |
| 155 | puppeteer: { |
| 156 | headless: true, |
| 157 | args: ['--no-sandbox'], |
| 158 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 159 | } |
| 160 | }, |
| 161 | ThriftJS_TLS: { |
| 162 | options: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 163 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 164 | 'https://localhost:8091/test-nojq.html' |
| 165 | ], |
| 166 | puppeteer: { |
| 167 | headless: true, |
| 168 | args: ['--no-sandbox'], |
| 169 | ignoreHTTPSErrors: true, |
| 170 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 171 | } |
| 172 | }, |
| 173 | ThriftJSJQ_TLS: { |
| 174 | options: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 175 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 176 | 'https://localhost:8091/test.html' |
| 177 | ], |
| 178 | puppeteer: { |
| 179 | headless: true, |
| 180 | args: ['--no-sandbox'], |
| 181 | ignoreHTTPSErrors: true, |
| 182 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 183 | } |
| 184 | }, |
| 185 | ThriftWS_TLS: { |
| 186 | options: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 187 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 188 | 'https://localhost:8091/testws.html' |
| 189 | ], |
| 190 | puppeteer: { |
| 191 | headless: true, |
| 192 | args: ['--no-sandbox'], |
| 193 | ignoreHTTPSErrors: true, |
| 194 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 195 | } |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 196 | }, |
| 197 | ThriftDeepConstructor: { |
| 198 | options: { |
| 199 | urls: [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 200 | 'http://localhost:8089/test-deep-constructor.html' |
| 201 | ], |
| 202 | puppeteer: { |
| 203 | headless: true, |
| 204 | args: ['--no-sandbox'], |
| 205 | }, |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 206 | } |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 207 | }, |
| 208 | ThriftWSES6: { |
| 209 | options: { |
| 210 | urls: [ |
| 211 | 'http://localhost:8088/test-es6.html' |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 212 | ], |
| 213 | puppeteer: { |
| 214 | headless: true, |
| 215 | args: ['--no-sandbox'], |
| 216 | }, |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 217 | } |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 218 | } |
| 219 | }, |
| 220 | jshint: { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 221 | // The main thrift library file. not es6 yet :( |
| 222 | lib: { |
| 223 | src: ['src/**/*.js'], |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 224 | }, |
| 225 | // The test files use es6 |
| 226 | test: { |
| 227 | src: ['Gruntfile.js', 'test/*.js'], |
| 228 | options: { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 229 | esversion: 6, |
| 230 | } |
| 231 | }, |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 232 | gen_js_code: { |
| 233 | src: ['test/gen-js/*.js', 'test/gen-js-jquery/*.js'], |
| 234 | }, |
| 235 | gen_es6_code: { |
| 236 | src: ['test/gen-js-es6/*.js'], |
| 237 | options: { |
| 238 | esversion: 6, |
| 239 | } |
| 240 | }, |
| 241 | gen_node_code: { |
| 242 | src: ['test/gen-nodejs/*.js'], |
| 243 | options: { |
| 244 | node: true, |
| 245 | } |
| 246 | }, |
| 247 | gen_node_es6_code: { |
| 248 | src: ['test/gen-nodejs-es6/*.js'], |
| 249 | options: { |
| 250 | node: true, |
| 251 | esversion: 6, |
| 252 | } |
| 253 | } |
| 254 | }, |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 255 | }); |
| 256 | |
| 257 | grunt.loadNpmTasks('grunt-contrib-uglify'); |
| 258 | grunt.loadNpmTasks('grunt-contrib-jshint'); |
| 259 | grunt.loadNpmTasks('grunt-contrib-qunit'); |
| 260 | grunt.loadNpmTasks('grunt-contrib-concat'); |
| 261 | grunt.loadNpmTasks('grunt-jsdoc'); |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 262 | grunt.loadNpmTasks('grunt-shell-spawn'); |
| 263 | |
| 264 | grunt.registerTask('wait', 'Wait just one second for server to start', function () { |
| 265 | var done = this.async(); |
| 266 | setTimeout(function() { |
| 267 | done(true); |
| 268 | }, 1000); |
| 269 | }); |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 270 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 271 | grunt.registerTask('installAndGenerate', [ |
| 272 | 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen', |
| 273 | 'shell:ThriftGenDeepConstructor', |
| 274 | 'shell:InstallTestLibs', |
| 275 | ]); |
| 276 | |
| 277 | grunt.registerTask('test', [ |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 278 | 'installAndGenerate', |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 279 | 'jshint', |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame] | 280 | 'shell:ThriftTestServer', 'shell:ThriftTestServer_TLS', |
| 281 | 'shell:ThriftTestServerES6', 'shell:ThriftTestServerES6_TLS', |
| 282 | 'wait', |
| 283 | 'qunit:ThriftDeepConstructor', |
| 284 | 'qunit:ThriftJS', 'qunit:ThriftJS_TLS', |
| 285 | 'qunit:ThriftWS', |
| 286 | 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS', |
| 287 | 'qunit:ThriftWSES6', |
| 288 | 'shell:ThriftTestServer:kill', 'shell:ThriftTestServer_TLS:kill', |
| 289 | 'shell:ThriftTestServerES6:kill', 'shell:ThriftTestServerES6_TLS:kill', |
| 290 | ]); |
Philip Frank | 55ddf19 | 2018-01-02 09:00:36 +0100 | [diff] [blame] | 291 | grunt.registerTask('default', ['test', 'concat', 'uglify', 'jsdoc']); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 292 | }; |