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 |
| 6 | |
| 7 | module.exports = function(grunt) { |
| 8 | 'use strict'; |
| 9 | |
| 10 | grunt.initConfig({ |
| 11 | pkg: grunt.file.readJSON('package.json'), |
| 12 | concat: { |
| 13 | options: { |
| 14 | separator: ';' |
| 15 | }, |
| 16 | dist: { |
| 17 | src: ['src/**/*.js'], |
| 18 | dest: 'dist/<%= pkg.name %>.js' |
| 19 | } |
| 20 | }, |
| 21 | jsdoc : { |
| 22 | dist : { |
Roger Meier | 16fcad0 | 2014-03-16 21:12:11 +0100 | [diff] [blame] | 23 | src: ['src/*.js', './README.md'], |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 24 | options: { |
| 25 | destination: 'doc' |
| 26 | } |
| 27 | } |
| 28 | }, |
| 29 | uglify: { |
| 30 | options: { |
| 31 | banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n' |
| 32 | }, |
| 33 | dist: { |
| 34 | files: { |
| 35 | 'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>'] |
| 36 | } |
| 37 | } |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 38 | }, |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 39 | shell: { |
| 40 | InstallThriftJS: { |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 41 | command: 'mkdir test/build; mkdir test/build/js; mkdir test/build/js/lib; cp src/thrift.js test/build/js/thrift.js' |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 42 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 43 | InstallThriftNodeJSDep: { |
Nobuaki Sukegawa | 6defea5 | 2015-11-14 17:36:29 +0900 | [diff] [blame] | 44 | command: 'cd ../..; npm install' |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 45 | }, |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 46 | InstallTestLibs: { |
| 47 | command: 'cd test; ant download_jslibs' |
| 48 | }, |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 49 | ThriftGen: { |
Nobuaki Sukegawa | 4b7dbe3 | 2016-05-25 12:09:02 +0900 | [diff] [blame] | 50 | command: '../../compiler/cpp/thrift -gen js -gen js:node -o test ../../test/ThriftTest.thrift' |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 51 | }, |
| 52 | ThriftGenJQ: { |
Nobuaki Sukegawa | 4b7dbe3 | 2016-05-25 12:09:02 +0900 | [diff] [blame] | 53 | 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] | 54 | }, |
| 55 | ThriftGenDeepConstructor: { |
Nobuaki Sukegawa | 4b7dbe3 | 2016-05-25 12:09:02 +0900 | [diff] [blame] | 56 | command: '../../compiler/cpp/thrift -gen js -o test ../../test/JsDeepConstructorTest.thrift' |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 57 | }, |
Ozan Can Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame^] | 58 | ThriftGenDoubleConstants: { |
| 59 | command: '../../compiler/cpp/thrift -gen js -o test ../../test/DoubleConstantsTest.thrift' |
| 60 | }, |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 61 | ThriftGenES6: { |
| 62 | command: '../../compiler/cpp/thrift -gen js -gen js:es6 -o test ../../test/ThriftTest.thrift' |
| 63 | }, |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 64 | ThriftTestServer: { |
| 65 | options: { |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 66 | async: true, |
| 67 | execOptions: { |
| 68 | cwd: "./test", |
| 69 | env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"} |
| 70 | } |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 71 | }, |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 72 | command: "node server_http.js", |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 73 | }, |
| 74 | ThriftTestServer_TLS: { |
| 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 | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 81 | }, |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 82 | command: "node server_https.js", |
| 83 | }, |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 84 | }, |
| 85 | qunit: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 86 | ThriftJS: { |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 87 | options: { |
| 88 | urls: [ |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 89 | 'http://localhost:8088/test-nojq.html' |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 90 | ] |
| 91 | } |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 92 | }, |
| 93 | ThriftJSJQ: { |
| 94 | options: { |
| 95 | urls: [ |
| 96 | 'http://localhost:8088/test.html' |
| 97 | ] |
| 98 | } |
| 99 | }, |
Ozan Can Altiok | e46419b | 2018-03-20 15:02:28 +0300 | [diff] [blame^] | 100 | ThriftJS_DoubleRendering: { |
| 101 | options: { |
| 102 | '--ignore-ssl-errors': true, |
| 103 | urls: [ |
| 104 | 'http://localhost:8088/test-double-rendering.html' |
| 105 | ] |
| 106 | } |
| 107 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 108 | ThriftWS: { |
| 109 | options: { |
| 110 | urls: [ |
| 111 | 'http://localhost:8088/testws.html' |
| 112 | ] |
| 113 | } |
| 114 | }, |
| 115 | ThriftJS_TLS: { |
| 116 | options: { |
| 117 | '--ignore-ssl-errors': true, |
| 118 | urls: [ |
| 119 | 'https://localhost:8089/test-nojq.html' |
| 120 | ] |
| 121 | } |
| 122 | }, |
| 123 | ThriftJSJQ_TLS: { |
| 124 | options: { |
| 125 | '--ignore-ssl-errors': true, |
| 126 | urls: [ |
| 127 | 'https://localhost:8089/test.html' |
| 128 | ] |
| 129 | } |
| 130 | }, |
| 131 | ThriftWS_TLS: { |
| 132 | options: { |
| 133 | '--ignore-ssl-errors': true, |
| 134 | urls: [ |
| 135 | 'https://localhost:8089/testws.html' |
| 136 | ] |
| 137 | } |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 138 | }, |
| 139 | ThriftDeepConstructor: { |
| 140 | options: { |
| 141 | urls: [ |
| 142 | 'http://localhost:8088/test-deep-constructor.html' |
| 143 | ] |
| 144 | } |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 145 | }, |
| 146 | ThriftWSES6: { |
| 147 | options: { |
| 148 | urls: [ |
| 149 | 'http://localhost:8088/test-es6.html' |
| 150 | ] |
| 151 | } |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 152 | } |
| 153 | }, |
| 154 | jshint: { |
| 155 | files: ['Gruntfile.js', 'src/**/*.js', 'test/*.js'], |
| 156 | options: { |
| 157 | // options here to override JSHint defaults |
| 158 | globals: { |
| 159 | jQuery: true, |
| 160 | console: true, |
| 161 | module: true, |
| 162 | document: true |
| 163 | } |
| 164 | } |
| 165 | }, |
| 166 | }); |
| 167 | |
| 168 | grunt.loadNpmTasks('grunt-contrib-uglify'); |
| 169 | grunt.loadNpmTasks('grunt-contrib-jshint'); |
| 170 | grunt.loadNpmTasks('grunt-contrib-qunit'); |
| 171 | grunt.loadNpmTasks('grunt-contrib-concat'); |
| 172 | grunt.loadNpmTasks('grunt-jsdoc'); |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 173 | grunt.loadNpmTasks('grunt-shell-spawn'); |
| 174 | |
| 175 | grunt.registerTask('wait', 'Wait just one second for server to start', function () { |
| 176 | var done = this.async(); |
| 177 | setTimeout(function() { |
| 178 | done(true); |
| 179 | }, 1000); |
| 180 | }); |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 181 | |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 182 | grunt.registerTask('test', ['jshint', 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen', |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 183 | 'shell:InstallTestLibs', |
| 184 | 'shell:ThriftTestServer', 'shell:ThriftTestServer_TLS', |
| 185 | 'wait', |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 186 | 'shell:ThriftGenDeepConstructor', 'qunit:ThriftDeepConstructor', |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 187 | 'qunit:ThriftJS', 'qunit:ThriftJS_TLS', |
Philip Frank | 0a84eae | 2017-12-27 12:54:28 +0100 | [diff] [blame] | 188 | 'qunit:ThriftWS', |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 189 | 'shell:ThriftGenJQ', 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS', |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 190 | 'shell:ThriftGenES6', 'qunit:ThriftWSES6', |
| 191 | 'shell:ThriftTestServer:kill', 'shell:ThriftTestServer_TLS:kill', |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 192 | ]); |
Philip Frank | 55ddf19 | 2018-01-02 09:00:36 +0100 | [diff] [blame] | 193 | grunt.registerTask('default', ['test', 'concat', 'uglify', 'jsdoc']); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 194 | }; |