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 | }, |
| 58 | ThriftGenES6: { |
| 59 | command: '../../compiler/cpp/thrift -gen js -gen js:es6 -o test ../../test/ThriftTest.thrift' |
| 60 | }, |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 61 | ThriftTestServer: { |
| 62 | options: { |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 63 | async: true, |
| 64 | execOptions: { |
| 65 | cwd: "./test", |
| 66 | env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"} |
| 67 | } |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 68 | }, |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 69 | command: "node server_http.js", |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 70 | }, |
| 71 | ThriftTestServer_TLS: { |
| 72 | options: { |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 73 | async: true, |
| 74 | execOptions: { |
| 75 | cwd: "./test", |
| 76 | env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"} |
| 77 | } |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 78 | }, |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 79 | command: "node server_https.js", |
| 80 | }, |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 81 | }, |
| 82 | qunit: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 83 | ThriftJS: { |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 84 | options: { |
| 85 | urls: [ |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 86 | 'http://localhost:8088/test-nojq.html' |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 87 | ] |
| 88 | } |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 89 | }, |
| 90 | ThriftJSJQ: { |
| 91 | options: { |
| 92 | urls: [ |
| 93 | 'http://localhost:8088/test.html' |
| 94 | ] |
| 95 | } |
| 96 | }, |
| 97 | ThriftWS: { |
| 98 | options: { |
| 99 | urls: [ |
| 100 | 'http://localhost:8088/testws.html' |
| 101 | ] |
| 102 | } |
| 103 | }, |
| 104 | ThriftJS_TLS: { |
| 105 | options: { |
| 106 | '--ignore-ssl-errors': true, |
| 107 | urls: [ |
| 108 | 'https://localhost:8089/test-nojq.html' |
| 109 | ] |
| 110 | } |
| 111 | }, |
| 112 | ThriftJSJQ_TLS: { |
| 113 | options: { |
| 114 | '--ignore-ssl-errors': true, |
| 115 | urls: [ |
| 116 | 'https://localhost:8089/test.html' |
| 117 | ] |
| 118 | } |
| 119 | }, |
| 120 | ThriftWS_TLS: { |
| 121 | options: { |
| 122 | '--ignore-ssl-errors': true, |
| 123 | urls: [ |
| 124 | 'https://localhost:8089/testws.html' |
| 125 | ] |
| 126 | } |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 127 | }, |
| 128 | ThriftDeepConstructor: { |
| 129 | options: { |
| 130 | urls: [ |
| 131 | 'http://localhost:8088/test-deep-constructor.html' |
| 132 | ] |
| 133 | } |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 134 | }, |
| 135 | ThriftWSES6: { |
| 136 | options: { |
| 137 | urls: [ |
| 138 | 'http://localhost:8088/test-es6.html' |
| 139 | ] |
| 140 | } |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 141 | } |
| 142 | }, |
| 143 | jshint: { |
| 144 | files: ['Gruntfile.js', 'src/**/*.js', 'test/*.js'], |
| 145 | options: { |
| 146 | // options here to override JSHint defaults |
| 147 | globals: { |
| 148 | jQuery: true, |
| 149 | console: true, |
| 150 | module: true, |
| 151 | document: true |
| 152 | } |
| 153 | } |
| 154 | }, |
| 155 | }); |
| 156 | |
| 157 | grunt.loadNpmTasks('grunt-contrib-uglify'); |
| 158 | grunt.loadNpmTasks('grunt-contrib-jshint'); |
| 159 | grunt.loadNpmTasks('grunt-contrib-qunit'); |
| 160 | grunt.loadNpmTasks('grunt-contrib-concat'); |
| 161 | grunt.loadNpmTasks('grunt-jsdoc'); |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 162 | grunt.loadNpmTasks('grunt-shell-spawn'); |
| 163 | |
| 164 | grunt.registerTask('wait', 'Wait just one second for server to start', function () { |
| 165 | var done = this.async(); |
| 166 | setTimeout(function() { |
| 167 | done(true); |
| 168 | }, 1000); |
| 169 | }); |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 170 | |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 171 | grunt.registerTask('test', ['jshint', 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen', |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 172 | 'shell:InstallTestLibs', |
| 173 | 'shell:ThriftTestServer', 'shell:ThriftTestServer_TLS', |
| 174 | 'wait', |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 175 | 'shell:ThriftGenDeepConstructor', 'qunit:ThriftDeepConstructor', |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 176 | 'qunit:ThriftJS', 'qunit:ThriftJS_TLS', |
Philip Frank | 0a84eae | 2017-12-27 12:54:28 +0100 | [diff] [blame] | 177 | 'qunit:ThriftWS', |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 178 | 'shell:ThriftGenJQ', 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS', |
Philip Frank | 5066eb4 | 2018-03-07 20:49:25 +0100 | [diff] [blame] | 179 | 'shell:ThriftGenES6', 'qunit:ThriftWSES6', |
| 180 | 'shell:ThriftTestServer:kill', 'shell:ThriftTestServer_TLS:kill', |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 181 | ]); |
Philip Frank | 55ddf19 | 2018-01-02 09:00:36 +0100 | [diff] [blame] | 182 | grunt.registerTask('default', ['test', 'concat', 'uglify', 'jsdoc']); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 183 | }; |