blob: bb7691a0a0253ced166f36590eb9265c15fc5ba9 [file] [log] [blame]
Henrique Mendonça095ddb72013-09-20 19:38:03 +02001//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
Brian Forbisb5d6ea32018-08-25 23:39:29 -04006// Run grunt - npx grunt // uses project-local installed version of grunt (from package.json)
Henrique Mendonça095ddb72013-09-20 19:38:03 +02007
8module.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 jsdoc : {
23 dist : {
Roger Meier16fcad02014-03-16 21:12:11 +010024 src: ['src/*.js', './README.md'],
Henrique Mendonça095ddb72013-09-20 19:38:03 +020025 options: {
26 destination: 'doc'
27 }
28 }
29 },
30 uglify: {
31 options: {
32 banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
33 },
34 dist: {
35 files: {
36 'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
37 }
38 }
Henrique Mendonça15d90422015-06-25 22:31:41 +100039 },
henriquea2de4102014-02-07 14:12:56 +010040 shell: {
41 InstallThriftJS: {
Brian Forbisb5d6ea32018-08-25 23:39:29 -040042 command: 'mkdir -p test/build/js/lib; cp src/thrift.js test/build/js/thrift.js'
henriquea2de4102014-02-07 14:12:56 +010043 },
henrique2a7dccc2014-03-07 22:16:51 +010044 InstallThriftNodeJSDep: {
Nobuaki Sukegawa6defea52015-11-14 17:36:29 +090045 command: 'cd ../..; npm install'
henrique2a7dccc2014-03-07 22:16:51 +010046 },
Philip Frank5066eb42018-03-07 20:49:25 +010047 InstallTestLibs: {
48 command: 'cd test; ant download_jslibs'
49 },
henriquea2de4102014-02-07 14:12:56 +010050 ThriftGen: {
Brian Forbisb5d6ea32018-08-25 23:39:29 -040051 command: [
52 'mkdir -p test/gen-js',
53 '../../compiler/cpp/thrift -gen js --out test/gen-js ../../test/ThriftTest.thrift',
54 '../../compiler/cpp/thrift -gen js --out test/gen-js ../../test/JsDeepConstructorTest.thrift',
55 'mkdir -p test/gen-js-jquery',
56 '../../compiler/cpp/thrift -gen js:jquery --out test/gen-js-jquery ../../test/ThriftTest.thrift',
57 'mkdir -p test/gen-nodejs',
58 '../../compiler/cpp/thrift -gen js:node --out test/gen-nodejs ../../test/ThriftTest.thrift',
59 'mkdir -p test/gen-js-es6',
60 '../../compiler/cpp/thrift -gen js:es6 --out test/gen-js-es6 ../../test/ThriftTest.thrift',
61 'mkdir -p test/gen-nodejs-es6',
62 '../../compiler/cpp/thrift -gen js:node,es6 --out ./test/gen-nodejs-es6 ../../test/ThriftTest.thrift',
63 ].join(' && ')
henrique2a7dccc2014-03-07 22:16:51 +010064 },
65 ThriftGenJQ: {
Nobuaki Sukegawa4b7dbe32016-05-25 12:09:02 +090066 command: '../../compiler/cpp/thrift -gen js:jquery -gen js:node -o test ../../test/ThriftTest.thrift'
Henrique Mendonça15d90422015-06-25 22:31:41 +100067 },
68 ThriftGenDeepConstructor: {
Nobuaki Sukegawa4b7dbe32016-05-25 12:09:02 +090069 command: '../../compiler/cpp/thrift -gen js -o test ../../test/JsDeepConstructorTest.thrift'
Philip Frank8fdd6102017-12-06 12:38:05 +010070 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +030071 ThriftGenDoubleConstants: {
72 command: '../../compiler/cpp/thrift -gen js -o test ../../test/DoubleConstantsTest.thrift'
73 },
henriquea2de4102014-02-07 14:12:56 +010074 ThriftTestServer: {
75 options: {
Philip Frank5066eb42018-03-07 20:49:25 +010076 async: true,
77 execOptions: {
78 cwd: "./test",
79 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
80 }
henriquea2de4102014-02-07 14:12:56 +010081 },
Philip Frank5066eb42018-03-07 20:49:25 +010082 command: "node server_http.js",
henrique2a7dccc2014-03-07 22:16:51 +010083 },
Brian Forbisb5d6ea32018-08-25 23:39:29 -040084 ThriftTestServerES6: {
85 options: {
86 async: true,
87 execOptions: {
88 cwd: "./test",
89 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
90 }
91 },
92 command: "node server_http.js --es6",
93 },
henrique2a7dccc2014-03-07 22:16:51 +010094 ThriftTestServer_TLS: {
95 options: {
Philip Frank5066eb42018-03-07 20:49:25 +010096 async: true,
97 execOptions: {
98 cwd: "./test",
99 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
100 }
henrique2a7dccc2014-03-07 22:16:51 +0100101 },
Philip Frank5066eb42018-03-07 20:49:25 +0100102 command: "node server_https.js",
103 },
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400104 ThriftTestServerES6_TLS: {
105 options: {
106 async: true,
107 execOptions: {
108 cwd: "./test",
109 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
110 }
111 },
112 command: "node server_https.js --es6",
113 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200114 },
115 qunit: {
henrique2a7dccc2014-03-07 22:16:51 +0100116 ThriftJS: {
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200117 options: {
118 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400119 'http://localhost:8089/test-nojq.html'
120 ],
121 puppeteer: {
122 headless: true,
123 args: ['--no-sandbox'],
124 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200125 }
henrique2a7dccc2014-03-07 22:16:51 +0100126 },
127 ThriftJSJQ: {
128 options: {
129 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400130 'http://localhost:8089/test.html'
131 ],
132 puppeteer: {
133 headless: true,
134 args: ['--no-sandbox'],
135 },
henrique2a7dccc2014-03-07 22:16:51 +0100136 }
137 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300138 ThriftJS_DoubleRendering: {
139 options: {
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300140 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400141 'http://localhost:8089/test-double-rendering.html'
142 ],
143 puppeteer: {
144 headless: true,
145 args: ['--no-sandbox'],
146 ignoreHTTPSErrors: true,
147 },
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300148 }
149 },
henrique2a7dccc2014-03-07 22:16:51 +0100150 ThriftWS: {
151 options: {
152 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400153 'http://localhost:8089/testws.html'
154 ],
155 puppeteer: {
156 headless: true,
157 args: ['--no-sandbox'],
158 },
henrique2a7dccc2014-03-07 22:16:51 +0100159 }
160 },
161 ThriftJS_TLS: {
162 options: {
henrique2a7dccc2014-03-07 22:16:51 +0100163 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400164 'https://localhost:8091/test-nojq.html'
165 ],
166 puppeteer: {
167 headless: true,
168 args: ['--no-sandbox'],
169 ignoreHTTPSErrors: true,
170 },
henrique2a7dccc2014-03-07 22:16:51 +0100171 }
172 },
173 ThriftJSJQ_TLS: {
174 options: {
henrique2a7dccc2014-03-07 22:16:51 +0100175 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400176 'https://localhost:8091/test.html'
177 ],
178 puppeteer: {
179 headless: true,
180 args: ['--no-sandbox'],
181 ignoreHTTPSErrors: true,
182 },
henrique2a7dccc2014-03-07 22:16:51 +0100183 }
184 },
185 ThriftWS_TLS: {
186 options: {
henrique2a7dccc2014-03-07 22:16:51 +0100187 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400188 'https://localhost:8091/testws.html'
189 ],
190 puppeteer: {
191 headless: true,
192 args: ['--no-sandbox'],
193 ignoreHTTPSErrors: true,
194 },
henrique2a7dccc2014-03-07 22:16:51 +0100195 }
Henrique Mendonça15d90422015-06-25 22:31:41 +1000196 },
197 ThriftDeepConstructor: {
198 options: {
199 urls: [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400200 'http://localhost:8089/test-deep-constructor.html'
201 ],
202 puppeteer: {
203 headless: true,
204 args: ['--no-sandbox'],
205 },
Henrique Mendonça15d90422015-06-25 22:31:41 +1000206 }
Philip Frank8fdd6102017-12-06 12:38:05 +0100207 },
208 ThriftWSES6: {
209 options: {
210 urls: [
211 'http://localhost:8088/test-es6.html'
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400212 ],
213 puppeteer: {
214 headless: true,
215 args: ['--no-sandbox'],
216 },
Philip Frank8fdd6102017-12-06 12:38:05 +0100217 }
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200218 }
219 },
220 jshint: {
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400221 // The main thrift library file. not es6 yet :(
222 lib: {
223 src: ['src/**/*.js'],
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400224 },
225 // The test files use es6
226 test: {
227 src: ['Gruntfile.js', 'test/*.js'],
228 options: {
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400229 esversion: 6,
230 }
231 },
bforbisda1169d2018-10-28 11:27:38 -0400232 gen_js_code: {
233 src: ['test/gen-js/*.js', 'test/gen-js-jquery/*.js'],
234 },
235 gen_es6_code: {
236 src: ['test/gen-js-es6/*.js'],
237 options: {
238 esversion: 6,
239 }
240 },
241 gen_node_code: {
242 src: ['test/gen-nodejs/*.js'],
243 options: {
244 node: true,
245 }
246 },
247 gen_node_es6_code: {
248 src: ['test/gen-nodejs-es6/*.js'],
249 options: {
250 node: true,
251 esversion: 6,
252 }
253 }
254 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200255 });
256
257 grunt.loadNpmTasks('grunt-contrib-uglify');
258 grunt.loadNpmTasks('grunt-contrib-jshint');
259 grunt.loadNpmTasks('grunt-contrib-qunit');
260 grunt.loadNpmTasks('grunt-contrib-concat');
261 grunt.loadNpmTasks('grunt-jsdoc');
Philip Frank5066eb42018-03-07 20:49:25 +0100262 grunt.loadNpmTasks('grunt-shell-spawn');
263
264 grunt.registerTask('wait', 'Wait just one second for server to start', function () {
265 var done = this.async();
266 setTimeout(function() {
267 done(true);
268 }, 1000);
269 });
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200270
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400271 grunt.registerTask('installAndGenerate', [
272 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen',
273 'shell:ThriftGenDeepConstructor',
274 'shell:InstallTestLibs',
275 ]);
276
277 grunt.registerTask('test', [
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400278 'installAndGenerate',
bforbisda1169d2018-10-28 11:27:38 -0400279 'jshint',
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400280 'shell:ThriftTestServer', 'shell:ThriftTestServer_TLS',
281 'shell:ThriftTestServerES6', 'shell:ThriftTestServerES6_TLS',
282 'wait',
283 'qunit:ThriftDeepConstructor',
284 'qunit:ThriftJS', 'qunit:ThriftJS_TLS',
285 'qunit:ThriftWS',
286 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS',
287 'qunit:ThriftWSES6',
288 'shell:ThriftTestServer:kill', 'shell:ThriftTestServer_TLS:kill',
289 'shell:ThriftTestServerES6:kill', 'shell:ThriftTestServerES6_TLS:kill',
290 ]);
Philip Frank55ddf192018-01-02 09:00:36 +0100291 grunt.registerTask('default', ['test', 'concat', 'uglify', 'jsdoc']);
henriquea2de4102014-02-07 14:12:56 +0100292};