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