blob: 3e4b1c49227c01e55a347d13a81bd3a85d913c3a [file] [log] [blame]
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +03001//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 Martincaef0ed2025-01-15 11:58:39 +01008module.exports = function (grunt) {
9 "use strict";
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030010
11 grunt.initConfig({
Cameron Martincaef0ed2025-01-15 11:58:39 +010012 pkg: grunt.file.readJSON("package.json"),
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030013 concat: {
14 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010015 separator: ";",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030016 },
17 dist: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010018 src: ["src/**/*.js"],
19 dest: "dist/<%= pkg.name %>.js",
20 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030021 },
22 shell: {
23 InstallThriftJS: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010024 command:
25 "mkdir -p test/build/ts/lib; cp ../js/src/thrift.js test/build/ts/thrift.js",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030026 },
27 InstallThriftNodeJSDep: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010028 command: "cd ../..; npm install",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030029 },
30 InstallTestLibs: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010031 command: "cd test; ant download_jslibs",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030032 },
33 ThriftGen: {
34 command: [
Cameron Martincaef0ed2025-01-15 11:58:39 +010035 "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 Cosarf86845e2018-12-05 17:50:18 +030040 },
41 ThriftBrowserifyNodeInt64: {
42 command: [
Cameron Martincaef0ed2025-01-15 11:58:39 +010043 "./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 Cosarf86845e2018-12-05 17:50:18 +030047 },
48 ThriftGenInt64: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010049 command:
50 "../../compiler/cpp/thrift -gen js:ts -o test ../../test/Int64Test.thrift",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030051 },
52 ThriftTestServer: {
53 options: {
54 async: true,
55 execOptions: {
56 cwd: "./test",
Cameron Martincaef0ed2025-01-15 11:58:39 +010057 env: { NODE_PATH: "../../nodejs/lib:../../../node_modules" },
58 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030059 },
60 command: "node server_http.js",
61 },
62 BuildTS: {
63 options: {
64 execOptions: {
65 cwd: "./test",
Cameron Martincaef0ed2025-01-15 11:58:39 +010066 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030067 },
Cameron Martincaef0ed2025-01-15 11:58:39 +010068 command:
69 "../node_modules/typescript/bin/tsc --listFiles --outDir build/ts",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030070 },
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 Martincaef0ed2025-01-15 11:58:39 +010075 ].join(" && "),
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030076 },
77 InstallGeneratedCode: {
78 command: [
79 "mkdir -p test/build/ts",
Cameron Martincaef0ed2025-01-15 11:58:39 +010080 "cp -r test/gen-js test/build/ts",
81 ].join(" && "),
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030082 },
83 },
84 qunit: {
85 ThriftJS: {
86 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010087 urls: ["http://localhost:8089/test.html"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030088 puppeteer: {
89 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +010090 args: ["--no-sandbox"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030091 },
Cameron Martincaef0ed2025-01-15 11:58:39 +010092 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030093 },
94 ThriftJS_Int64: {
95 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010096 urls: ["http://localhost:8089/test-int64.html"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030097 puppeteer: {
98 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +010099 args: ["--no-sandbox"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300100 ignoreHTTPSErrors: true,
101 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100102 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300103 },
104 },
105 jshint: {
106 // The main Thrift library file. not es6 yet :(
107 lib: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100108 src: ["../js/src/**/*.js"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300109 },
110 // The test files use es6
111 test: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100112 src: ["Gruntfile.js", "test/*.js"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300113 options: {
114 esversion: 6,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100115 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300116 },
117 gen_js_code: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100118 src: ["test/gen-js/*.js"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300119 },
120 gen_node_code: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100121 src: ["test/gen-nodejs/*.js"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300122 options: {
123 node: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100124 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300125 },
126 },
127 });
128
Cameron Martincaef0ed2025-01-15 11:58:39 +0100129 grunt.loadNpmTasks("grunt-contrib-jshint");
130 grunt.loadNpmTasks("grunt-contrib-qunit");
131 grunt.loadNpmTasks("grunt-shell-spawn");
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300132
Cameron Martincaef0ed2025-01-15 11:58:39 +0100133 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 Cosarf86845e2018-12-05 17:50:18 +0300143
Cameron Martincaef0ed2025-01-15 11:58:39 +0100144 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 Cosarf86845e2018-12-05 17:50:18 +0300154 ]);
155
Cameron Martincaef0ed2025-01-15 11:58:39 +0100156 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 Cosarf86845e2018-12-05 17:50:18 +0300164 ]);
Cameron Martincaef0ed2025-01-15 11:58:39 +0100165 grunt.registerTask("default", ["test"]);
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300166};