blob: 4aa450fca7c3a8db98e2e8521fed44f9176fb33c [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
6
7module.exports = function(grunt) {
8 'use strict';
9
10 grunt.initConfig({
11 pkg: grunt.file.readJSON('package.json'),
12 concat: {
13 options: {
14 separator: ';'
15 },
16 dist: {
17 src: ['src/**/*.js'],
18 dest: 'dist/<%= pkg.name %>.js'
19 }
20 },
21 jsdoc : {
22 dist : {
Roger Meier16fcad02014-03-16 21:12:11 +010023 src: ['src/*.js', './README.md'],
Henrique Mendonça095ddb72013-09-20 19:38:03 +020024 options: {
25 destination: 'doc'
26 }
27 }
28 },
29 uglify: {
30 options: {
31 banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
32 },
33 dist: {
34 files: {
35 'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
36 }
37 }
Henrique Mendonça15d90422015-06-25 22:31:41 +100038 },
henriquea2de4102014-02-07 14:12:56 +010039 shell: {
40 InstallThriftJS: {
Philip Frank5066eb42018-03-07 20:49:25 +010041 command: 'mkdir test/build; mkdir test/build/js; mkdir test/build/js/lib; cp src/thrift.js test/build/js/thrift.js'
henriquea2de4102014-02-07 14:12:56 +010042 },
henrique2a7dccc2014-03-07 22:16:51 +010043 InstallThriftNodeJSDep: {
Nobuaki Sukegawa6defea52015-11-14 17:36:29 +090044 command: 'cd ../..; npm install'
henrique2a7dccc2014-03-07 22:16:51 +010045 },
Philip Frank5066eb42018-03-07 20:49:25 +010046 InstallTestLibs: {
47 command: 'cd test; ant download_jslibs'
48 },
henriquea2de4102014-02-07 14:12:56 +010049 ThriftGen: {
Nobuaki Sukegawa4b7dbe32016-05-25 12:09:02 +090050 command: '../../compiler/cpp/thrift -gen js -gen js:node -o test ../../test/ThriftTest.thrift'
henrique2a7dccc2014-03-07 22:16:51 +010051 },
52 ThriftGenJQ: {
Nobuaki Sukegawa4b7dbe32016-05-25 12:09:02 +090053 command: '../../compiler/cpp/thrift -gen js:jquery -gen js:node -o test ../../test/ThriftTest.thrift'
Henrique Mendonça15d90422015-06-25 22:31:41 +100054 },
55 ThriftGenDeepConstructor: {
Nobuaki Sukegawa4b7dbe32016-05-25 12:09:02 +090056 command: '../../compiler/cpp/thrift -gen js -o test ../../test/JsDeepConstructorTest.thrift'
Philip Frank8fdd6102017-12-06 12:38:05 +010057 },
58 ThriftGenES6: {
59 command: '../../compiler/cpp/thrift -gen js -gen js:es6 -o test ../../test/ThriftTest.thrift'
60 },
henriquea2de4102014-02-07 14:12:56 +010061 ThriftTestServer: {
62 options: {
Philip Frank5066eb42018-03-07 20:49:25 +010063 async: true,
64 execOptions: {
65 cwd: "./test",
66 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
67 }
henriquea2de4102014-02-07 14:12:56 +010068 },
Philip Frank5066eb42018-03-07 20:49:25 +010069 command: "node server_http.js",
henrique2a7dccc2014-03-07 22:16:51 +010070 },
71 ThriftTestServer_TLS: {
72 options: {
Philip Frank5066eb42018-03-07 20:49:25 +010073 async: true,
74 execOptions: {
75 cwd: "./test",
76 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
77 }
henrique2a7dccc2014-03-07 22:16:51 +010078 },
Philip Frank5066eb42018-03-07 20:49:25 +010079 command: "node server_https.js",
80 },
Henrique Mendonça095ddb72013-09-20 19:38:03 +020081 },
82 qunit: {
henrique2a7dccc2014-03-07 22:16:51 +010083 ThriftJS: {
Henrique Mendonça095ddb72013-09-20 19:38:03 +020084 options: {
85 urls: [
henriquea2de4102014-02-07 14:12:56 +010086 'http://localhost:8088/test-nojq.html'
Henrique Mendonça095ddb72013-09-20 19:38:03 +020087 ]
88 }
henrique2a7dccc2014-03-07 22:16:51 +010089 },
90 ThriftJSJQ: {
91 options: {
92 urls: [
93 'http://localhost:8088/test.html'
94 ]
95 }
96 },
97 ThriftWS: {
98 options: {
99 urls: [
100 'http://localhost:8088/testws.html'
101 ]
102 }
103 },
104 ThriftJS_TLS: {
105 options: {
106 '--ignore-ssl-errors': true,
107 urls: [
108 'https://localhost:8089/test-nojq.html'
109 ]
110 }
111 },
112 ThriftJSJQ_TLS: {
113 options: {
114 '--ignore-ssl-errors': true,
115 urls: [
116 'https://localhost:8089/test.html'
117 ]
118 }
119 },
120 ThriftWS_TLS: {
121 options: {
122 '--ignore-ssl-errors': true,
123 urls: [
124 'https://localhost:8089/testws.html'
125 ]
126 }
Henrique Mendonça15d90422015-06-25 22:31:41 +1000127 },
128 ThriftDeepConstructor: {
129 options: {
130 urls: [
131 'http://localhost:8088/test-deep-constructor.html'
132 ]
133 }
Philip Frank8fdd6102017-12-06 12:38:05 +0100134 },
135 ThriftWSES6: {
136 options: {
137 urls: [
138 'http://localhost:8088/test-es6.html'
139 ]
140 }
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200141 }
142 },
143 jshint: {
144 files: ['Gruntfile.js', 'src/**/*.js', 'test/*.js'],
145 options: {
146 // options here to override JSHint defaults
147 globals: {
148 jQuery: true,
149 console: true,
150 module: true,
151 document: true
152 }
153 }
154 },
155 });
156
157 grunt.loadNpmTasks('grunt-contrib-uglify');
158 grunt.loadNpmTasks('grunt-contrib-jshint');
159 grunt.loadNpmTasks('grunt-contrib-qunit');
160 grunt.loadNpmTasks('grunt-contrib-concat');
161 grunt.loadNpmTasks('grunt-jsdoc');
Philip Frank5066eb42018-03-07 20:49:25 +0100162 grunt.loadNpmTasks('grunt-shell-spawn');
163
164 grunt.registerTask('wait', 'Wait just one second for server to start', function () {
165 var done = this.async();
166 setTimeout(function() {
167 done(true);
168 }, 1000);
169 });
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200170
Henrique Mendonça15d90422015-06-25 22:31:41 +1000171 grunt.registerTask('test', ['jshint', 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen',
Philip Frank5066eb42018-03-07 20:49:25 +0100172 'shell:InstallTestLibs',
173 'shell:ThriftTestServer', 'shell:ThriftTestServer_TLS',
174 'wait',
Henrique Mendonça15d90422015-06-25 22:31:41 +1000175 'shell:ThriftGenDeepConstructor', 'qunit:ThriftDeepConstructor',
henrique2a7dccc2014-03-07 22:16:51 +0100176 'qunit:ThriftJS', 'qunit:ThriftJS_TLS',
Philip Frank0a84eae2017-12-27 12:54:28 +0100177 'qunit:ThriftWS',
Philip Frank8fdd6102017-12-06 12:38:05 +0100178 'shell:ThriftGenJQ', 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS',
Philip Frank5066eb42018-03-07 20:49:25 +0100179 'shell:ThriftGenES6', 'qunit:ThriftWSES6',
180 'shell:ThriftTestServer:kill', 'shell:ThriftTestServer_TLS:kill',
henrique2a7dccc2014-03-07 22:16:51 +0100181 ]);
Philip Frank55ddf192018-01-02 09:00:36 +0100182 grunt.registerTask('default', ['test', 'concat', 'uglify', 'jsdoc']);
henriquea2de4102014-02-07 14:12:56 +0100183};