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: { |
| 41 | command: 'mkdir test/build; mkdir test/build/js; cp src/thrift.js test/build/js/thrift.js' |
| 42 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 43 | InstallThriftNodeJSDep: { |
| 44 | command: 'cd ../nodejs; npm install' |
| 45 | }, |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 46 | ThriftGen: { |
| 47 | command: 'thrift -gen js -gen js:node -o test ../../test/ThriftTest.thrift' |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 48 | }, |
| 49 | ThriftGenJQ: { |
| 50 | command: '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] | 51 | }, |
| 52 | ThriftGenDeepConstructor: { |
| 53 | command: 'thrift -gen js -o test ../../test/JsDeepConstructorTest.thrift' |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 54 | } |
| 55 | }, |
| 56 | external_daemon: { |
| 57 | ThriftTestServer: { |
| 58 | options: { |
| 59 | startCheck: function(stdout, stderr) { |
| 60 | return (/Thrift Server running on port/).test(stdout); |
| 61 | }, |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 62 | nodeSpawnOptions: { |
| 63 | cwd: "test", |
| 64 | env: {NODE_PATH: "../../nodejs/lib:../../nodejs/node_modules"} |
| 65 | } |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 66 | }, |
| 67 | cmd: "node", |
| 68 | args: ["server_http.js"] |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 69 | }, |
| 70 | ThriftTestServer_TLS: { |
| 71 | options: { |
| 72 | startCheck: function(stdout, stderr) { |
| 73 | return (/Thrift Server running on port/).test(stdout); |
| 74 | }, |
| 75 | nodeSpawnOptions: { |
| 76 | cwd: "test", |
| 77 | env: {NODE_PATH: "../../nodejs/lib:../../nodejs/node_modules"} |
| 78 | } |
| 79 | }, |
| 80 | cmd: "node", |
| 81 | args: ["server_https.js"] |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 82 | } |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 83 | }, |
| 84 | qunit: { |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 85 | ThriftJS: { |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 86 | options: { |
| 87 | urls: [ |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 88 | 'http://localhost:8088/test-nojq.html' |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 89 | ] |
| 90 | } |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 91 | }, |
| 92 | ThriftJSJQ: { |
| 93 | options: { |
| 94 | urls: [ |
| 95 | 'http://localhost:8088/test.html' |
| 96 | ] |
| 97 | } |
| 98 | }, |
| 99 | ThriftWS: { |
| 100 | options: { |
| 101 | urls: [ |
| 102 | 'http://localhost:8088/testws.html' |
| 103 | ] |
| 104 | } |
| 105 | }, |
| 106 | ThriftJS_TLS: { |
| 107 | options: { |
| 108 | '--ignore-ssl-errors': true, |
| 109 | urls: [ |
| 110 | 'https://localhost:8089/test-nojq.html' |
| 111 | ] |
| 112 | } |
| 113 | }, |
| 114 | ThriftJSJQ_TLS: { |
| 115 | options: { |
| 116 | '--ignore-ssl-errors': true, |
| 117 | urls: [ |
| 118 | 'https://localhost:8089/test.html' |
| 119 | ] |
| 120 | } |
| 121 | }, |
| 122 | ThriftWS_TLS: { |
| 123 | options: { |
| 124 | '--ignore-ssl-errors': true, |
| 125 | urls: [ |
| 126 | 'https://localhost:8089/testws.html' |
| 127 | ] |
| 128 | } |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 129 | }, |
| 130 | ThriftDeepConstructor: { |
| 131 | options: { |
| 132 | urls: [ |
| 133 | 'http://localhost:8088/test-deep-constructor.html' |
| 134 | ] |
| 135 | } |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 136 | } |
| 137 | }, |
| 138 | jshint: { |
| 139 | files: ['Gruntfile.js', 'src/**/*.js', 'test/*.js'], |
| 140 | options: { |
| 141 | // options here to override JSHint defaults |
| 142 | globals: { |
| 143 | jQuery: true, |
| 144 | console: true, |
| 145 | module: true, |
| 146 | document: true |
| 147 | } |
| 148 | } |
| 149 | }, |
| 150 | }); |
| 151 | |
| 152 | grunt.loadNpmTasks('grunt-contrib-uglify'); |
| 153 | grunt.loadNpmTasks('grunt-contrib-jshint'); |
| 154 | grunt.loadNpmTasks('grunt-contrib-qunit'); |
| 155 | grunt.loadNpmTasks('grunt-contrib-concat'); |
| 156 | grunt.loadNpmTasks('grunt-jsdoc'); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 157 | grunt.loadNpmTasks('grunt-external-daemon'); |
| 158 | grunt.loadNpmTasks('grunt-shell'); |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 159 | |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 160 | grunt.registerTask('test', ['jshint', 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen', |
| 161 | 'external_daemon:ThriftTestServer', 'external_daemon:ThriftTestServer_TLS', |
| 162 | 'shell:ThriftGenDeepConstructor', 'qunit:ThriftDeepConstructor', |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 163 | 'qunit:ThriftJS', 'qunit:ThriftJS_TLS', |
| 164 | 'shell:ThriftGenJQ', 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS' |
| 165 | ]); |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 166 | grunt.registerTask('default', ['jshint', 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen', |
| 167 | 'external_daemon:ThriftTestServer', 'external_daemon:ThriftTestServer_TLS', |
henrique | 2a7dccc | 2014-03-07 22:16:51 +0100 | [diff] [blame] | 168 | 'qunit:ThriftJS', 'qunit:ThriftJS_TLS', |
| 169 | 'shell:ThriftGenJQ', 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS', |
| 170 | 'concat', 'uglify', 'jsdoc' |
| 171 | ]); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 172 | }; |