Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [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 | // Run grunt - npx grunt // uses project-local installed version of grunt (from package.json) |
| 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 | shell: { |
| 23 | InstallThriftJS: { |
| 24 | command: 'mkdir -p test/build/ts/lib; cp ../js/src/thrift.js test/build/ts/thrift.js' |
| 25 | }, |
| 26 | InstallThriftNodeJSDep: { |
| 27 | command: 'cd ../..; npm install' |
| 28 | }, |
| 29 | InstallTestLibs: { |
| 30 | command: 'cd test; ant download_jslibs' |
| 31 | }, |
| 32 | ThriftGen: { |
| 33 | command: [ |
| 34 | 'mkdir -p test/gen-js', |
Jens Geyer | f066d84 | 2022-06-13 23:37:25 +0200 | [diff] [blame] | 35 | '../../compiler/cpp/thrift -gen js:ts --out test/gen-js ../../test/v0.16/ThriftTest.thrift', |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 36 | 'mkdir -p test/gen-nodejs', |
Jens Geyer | f066d84 | 2022-06-13 23:37:25 +0200 | [diff] [blame] | 37 | '../../compiler/cpp/thrift -gen js:node,ts --out test/gen-nodejs ../../test/v0.16/ThriftTest.thrift', |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 38 | ].join(' && ') |
| 39 | }, |
| 40 | ThriftBrowserifyNodeInt64: { |
| 41 | command: [ |
| 42 | './node_modules/browserify/bin/cmd.js ./node_modules/node-int64/Int64.js -s Int64 -o test/build/js/lib/Int64.js', |
| 43 | './node_modules/browserify/bin/cmd.js ../nodejs/lib/thrift/int64_util.js -s Int64Util -o test/build/js/lib/Int64Util.js', |
| 44 | './node_modules/browserify/bin/cmd.js ./node_modules/json-int64/index.js -s JSONInt64 -o test/build/js/lib/JSONInt64.js' |
| 45 | ].join(' && ') |
| 46 | }, |
| 47 | ThriftGenInt64: { |
| 48 | command: '../../compiler/cpp/thrift -gen js:ts -o test ../../test/Int64Test.thrift' |
| 49 | }, |
| 50 | ThriftTestServer: { |
| 51 | options: { |
| 52 | async: true, |
| 53 | execOptions: { |
| 54 | cwd: "./test", |
| 55 | env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"} |
| 56 | } |
| 57 | }, |
| 58 | command: "node server_http.js", |
| 59 | }, |
| 60 | BuildTS: { |
| 61 | options: { |
| 62 | execOptions: { |
| 63 | cwd: "./test", |
| 64 | } |
| 65 | }, |
| 66 | command : "../node_modules/typescript/bin/tsc --listFiles --outDir build/ts" |
| 67 | }, |
| 68 | BrowserifyCompiledTS: { |
| 69 | command: [ |
| 70 | "./node_modules/browserify/bin/cmd.js test/build/ts/test.js -o test/build/ts/lib/test.js --standalone test", |
| 71 | "./node_modules/browserify/bin/cmd.js test/build/ts/test-int64.js -o test/build/ts/lib/test-int64.js --standalone testInt64", |
| 72 | ].join(" && ") |
| 73 | }, |
| 74 | InstallGeneratedCode: { |
| 75 | command: [ |
| 76 | "mkdir -p test/build/ts", |
| 77 | "cp -r test/gen-js test/build/ts" |
| 78 | ].join(" && ") |
| 79 | }, |
| 80 | }, |
| 81 | qunit: { |
| 82 | ThriftJS: { |
| 83 | options: { |
| 84 | urls: [ |
| 85 | 'http://localhost:8089/test.html' |
| 86 | ], |
| 87 | puppeteer: { |
| 88 | headless: true, |
| 89 | args: ['--no-sandbox'], |
| 90 | }, |
| 91 | } |
| 92 | }, |
| 93 | ThriftJS_Int64: { |
| 94 | options: { |
| 95 | urls: [ |
| 96 | 'http://localhost:8089/test-int64.html' |
| 97 | ], |
| 98 | puppeteer: { |
| 99 | headless: true, |
| 100 | args: ['--no-sandbox'], |
| 101 | ignoreHTTPSErrors: true, |
| 102 | }, |
| 103 | } |
| 104 | }, |
| 105 | }, |
| 106 | jshint: { |
| 107 | // The main Thrift library file. not es6 yet :( |
| 108 | lib: { |
| 109 | src: ['../js/src/**/*.js'], |
| 110 | }, |
| 111 | // The test files use es6 |
| 112 | test: { |
| 113 | src: ['Gruntfile.js', 'test/*.js'], |
| 114 | options: { |
| 115 | esversion: 6, |
| 116 | } |
| 117 | }, |
| 118 | gen_js_code: { |
| 119 | src: ['test/gen-js/*.js'], |
| 120 | }, |
| 121 | gen_node_code: { |
| 122 | src: ['test/gen-nodejs/*.js'], |
| 123 | options: { |
| 124 | node: true, |
| 125 | } |
| 126 | }, |
| 127 | }, |
| 128 | }); |
| 129 | |
| 130 | grunt.loadNpmTasks('grunt-contrib-jshint'); |
| 131 | grunt.loadNpmTasks('grunt-contrib-qunit'); |
| 132 | grunt.loadNpmTasks('grunt-shell-spawn'); |
| 133 | |
| 134 | grunt.registerTask('wait', 'Wait just one second for the server to start', function () { |
| 135 | var done = this.async(); |
| 136 | setTimeout(function() { |
| 137 | done(true); |
| 138 | }, 1000); |
| 139 | }); |
| 140 | |
| 141 | grunt.registerTask('installAndGenerate', [ |
| 142 | 'shell:InstallThriftJS', |
| 143 | 'shell:InstallThriftNodeJSDep', |
| 144 | 'shell:ThriftGen', |
| 145 | 'shell:ThriftBrowserifyNodeInt64', |
| 146 | 'shell:ThriftGenInt64', |
| 147 | 'shell:InstallTestLibs', |
| 148 | 'shell:BuildTS', |
| 149 | 'shell:InstallGeneratedCode', |
| 150 | 'shell:BrowserifyCompiledTS', |
| 151 | ]); |
| 152 | |
| 153 | grunt.registerTask('test', [ |
| 154 | 'installAndGenerate', |
| 155 | 'jshint', |
| 156 | 'shell:ThriftTestServer', |
| 157 | 'wait', |
| 158 | 'qunit:ThriftJS', |
| 159 | 'qunit:ThriftJS_Int64', |
| 160 | 'shell:ThriftTestServer:kill', |
| 161 | ]); |
| 162 | grunt.registerTask('default', ['test']); |
| 163 | }; |