blob: bd36d0f2635b5153159fff6c86b83d500f05710f [file] [log] [blame]
Jens Geyer72a714e2025-08-26 22:12:07 +02001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030020//To build dist/thrift.js, dist/thrift.min.js and doc/*
21//run grunt at the command line in this directory.
22//Prerequisites:
23// Node Setup - nodejs.org
24// Grunt Setup - npm install //reads the ./package.json and installs project dependencies
25// Run grunt - npx grunt // uses project-local installed version of grunt (from package.json)
26
Cameron Martincaef0ed2025-01-15 11:58:39 +010027module.exports = function (grunt) {
28 "use strict";
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030029
30 grunt.initConfig({
Cameron Martincaef0ed2025-01-15 11:58:39 +010031 pkg: grunt.file.readJSON("package.json"),
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030032 concat: {
33 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010034 separator: ";",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030035 },
36 dist: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010037 src: ["src/**/*.js"],
38 dest: "dist/<%= pkg.name %>.js",
39 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030040 },
41 shell: {
42 InstallThriftJS: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010043 command:
44 "mkdir -p test/build/ts/lib; cp ../js/src/thrift.js test/build/ts/thrift.js",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030045 },
46 InstallThriftNodeJSDep: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010047 command: "cd ../..; npm install",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030048 },
49 InstallTestLibs: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010050 command: "cd test; ant download_jslibs",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030051 },
52 ThriftGen: {
53 command: [
Cameron Martincaef0ed2025-01-15 11:58:39 +010054 "mkdir -p test/gen-js",
55 "../../compiler/cpp/thrift -gen js:ts --out test/gen-js ../../test/v0.16/ThriftTest.thrift",
56 "mkdir -p test/gen-nodejs",
57 "../../compiler/cpp/thrift -gen js:node,ts --out test/gen-nodejs ../../test/v0.16/ThriftTest.thrift",
58 ].join(" && "),
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030059 },
60 ThriftBrowserifyNodeInt64: {
61 command: [
Cameron Martincaef0ed2025-01-15 11:58:39 +010062 "./node_modules/browserify/bin/cmd.js ./node_modules/node-int64/Int64.js -s Int64 -o test/build/js/lib/Int64.js",
63 "./node_modules/browserify/bin/cmd.js ../nodejs/lib/thrift/int64_util.js -s Int64Util -o test/build/js/lib/Int64Util.js",
64 "./node_modules/browserify/bin/cmd.js ./node_modules/json-int64/index.js -s JSONInt64 -o test/build/js/lib/JSONInt64.js",
65 ].join(" && "),
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030066 },
67 ThriftGenInt64: {
Cameron Martincaef0ed2025-01-15 11:58:39 +010068 command:
69 "../../compiler/cpp/thrift -gen js:ts -o test ../../test/Int64Test.thrift",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030070 },
71 ThriftTestServer: {
72 options: {
73 async: true,
74 execOptions: {
75 cwd: "./test",
Cameron Martincaef0ed2025-01-15 11:58:39 +010076 env: { NODE_PATH: "../../nodejs/lib:../../../node_modules" },
77 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030078 },
79 command: "node server_http.js",
80 },
81 BuildTS: {
82 options: {
83 execOptions: {
84 cwd: "./test",
Cameron Martincaef0ed2025-01-15 11:58:39 +010085 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030086 },
Cameron Martincaef0ed2025-01-15 11:58:39 +010087 command:
88 "../node_modules/typescript/bin/tsc --listFiles --outDir build/ts",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030089 },
90 BrowserifyCompiledTS: {
91 command: [
92 "./node_modules/browserify/bin/cmd.js test/build/ts/test.js -o test/build/ts/lib/test.js --standalone test",
93 "./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 +010094 ].join(" && "),
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030095 },
96 InstallGeneratedCode: {
97 command: [
98 "mkdir -p test/build/ts",
Cameron Martincaef0ed2025-01-15 11:58:39 +010099 "cp -r test/gen-js test/build/ts",
100 ].join(" && "),
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300101 },
102 },
103 qunit: {
104 ThriftJS: {
105 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100106 urls: ["http://localhost:8089/test.html"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300107 puppeteer: {
108 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100109 args: ["--no-sandbox"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300110 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100111 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300112 },
113 ThriftJS_Int64: {
114 options: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100115 urls: ["http://localhost:8089/test-int64.html"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300116 puppeteer: {
117 headless: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100118 args: ["--no-sandbox"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300119 ignoreHTTPSErrors: true,
120 },
Cameron Martincaef0ed2025-01-15 11:58:39 +0100121 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300122 },
123 },
124 jshint: {
125 // The main Thrift library file. not es6 yet :(
126 lib: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100127 src: ["../js/src/**/*.js"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300128 },
129 // The test files use es6
130 test: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100131 src: ["Gruntfile.js", "test/*.js"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300132 options: {
133 esversion: 6,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100134 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300135 },
136 gen_js_code: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100137 src: ["test/gen-js/*.js"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300138 },
139 gen_node_code: {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100140 src: ["test/gen-nodejs/*.js"],
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300141 options: {
142 node: true,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100143 },
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300144 },
145 },
146 });
147
Cameron Martincaef0ed2025-01-15 11:58:39 +0100148 grunt.loadNpmTasks("grunt-contrib-jshint");
149 grunt.loadNpmTasks("grunt-contrib-qunit");
150 grunt.loadNpmTasks("grunt-shell-spawn");
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300151
Cameron Martincaef0ed2025-01-15 11:58:39 +0100152 grunt.registerTask(
153 "wait",
154 "Wait just one second for the server to start",
155 function () {
156 var done = this.async();
157 setTimeout(function () {
158 done(true);
159 }, 1000);
160 },
161 );
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300162
Cameron Martincaef0ed2025-01-15 11:58:39 +0100163 grunt.registerTask("installAndGenerate", [
164 "shell:InstallThriftJS",
165 "shell:InstallThriftNodeJSDep",
166 "shell:ThriftGen",
167 "shell:ThriftBrowserifyNodeInt64",
168 "shell:ThriftGenInt64",
169 "shell:InstallTestLibs",
170 "shell:BuildTS",
171 "shell:InstallGeneratedCode",
172 "shell:BrowserifyCompiledTS",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300173 ]);
174
Cameron Martincaef0ed2025-01-15 11:58:39 +0100175 grunt.registerTask("test", [
176 "installAndGenerate",
177 "jshint",
178 "shell:ThriftTestServer",
179 "wait",
180 "qunit:ThriftJS",
181 "qunit:ThriftJS_Int64",
182 "shell:ThriftTestServer:kill",
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300183 ]);
Cameron Martincaef0ed2025-01-15 11:58:39 +0100184 grunt.registerTask("default", ["test"]);
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300185};