blob: 82642438f6857ec830c1420ef5e10fcca76578ce [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: {
41 command: 'mkdir test/build; mkdir test/build/js; cp src/thrift.js test/build/js/thrift.js'
42 },
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 },
henriquea2de4102014-02-07 14:12:56 +010046 ThriftGen: {
Nobuaki Sukegawa4b7dbe32016-05-25 12:09:02 +090047 command: '../../compiler/cpp/thrift -gen js -gen js:node -o test ../../test/ThriftTest.thrift'
henrique2a7dccc2014-03-07 22:16:51 +010048 },
49 ThriftGenJQ: {
Nobuaki Sukegawa4b7dbe32016-05-25 12:09:02 +090050 command: '../../compiler/cpp/thrift -gen js:jquery -gen js:node -o test ../../test/ThriftTest.thrift'
Henrique Mendonça15d90422015-06-25 22:31:41 +100051 },
52 ThriftGenDeepConstructor: {
Nobuaki Sukegawa4b7dbe32016-05-25 12:09:02 +090053 command: '../../compiler/cpp/thrift -gen js -o test ../../test/JsDeepConstructorTest.thrift'
Philip Frank8fdd6102017-12-06 12:38:05 +010054 },
55 ThriftGenES6: {
56 command: '../../compiler/cpp/thrift -gen js -gen js:es6 -o test ../../test/ThriftTest.thrift'
57 },
henriquea2de4102014-02-07 14:12:56 +010058 },
59 external_daemon: {
60 ThriftTestServer: {
61 options: {
62 startCheck: function(stdout, stderr) {
63 return (/Thrift Server running on port/).test(stdout);
64 },
henrique2a7dccc2014-03-07 22:16:51 +010065 nodeSpawnOptions: {
66 cwd: "test",
Nobuaki Sukegawa6defea52015-11-14 17:36:29 +090067 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
henrique2a7dccc2014-03-07 22:16:51 +010068 }
henriquea2de4102014-02-07 14:12:56 +010069 },
70 cmd: "node",
71 args: ["server_http.js"]
henrique2a7dccc2014-03-07 22:16:51 +010072 },
73 ThriftTestServer_TLS: {
74 options: {
75 startCheck: function(stdout, stderr) {
76 return (/Thrift Server running on port/).test(stdout);
77 },
78 nodeSpawnOptions: {
79 cwd: "test",
Nobuaki Sukegawa6defea52015-11-14 17:36:29 +090080 env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
henrique2a7dccc2014-03-07 22:16:51 +010081 }
82 },
83 cmd: "node",
84 args: ["server_https.js"]
henriquea2de4102014-02-07 14:12:56 +010085 }
Henrique Mendonça095ddb72013-09-20 19:38:03 +020086 },
87 qunit: {
henrique2a7dccc2014-03-07 22:16:51 +010088 ThriftJS: {
Henrique Mendonça095ddb72013-09-20 19:38:03 +020089 options: {
90 urls: [
henriquea2de4102014-02-07 14:12:56 +010091 'http://localhost:8088/test-nojq.html'
Henrique Mendonça095ddb72013-09-20 19:38:03 +020092 ]
93 }
henrique2a7dccc2014-03-07 22:16:51 +010094 },
95 ThriftJSJQ: {
96 options: {
97 urls: [
98 'http://localhost:8088/test.html'
99 ]
100 }
101 },
102 ThriftWS: {
103 options: {
104 urls: [
105 'http://localhost:8088/testws.html'
106 ]
107 }
108 },
109 ThriftJS_TLS: {
110 options: {
111 '--ignore-ssl-errors': true,
112 urls: [
113 'https://localhost:8089/test-nojq.html'
114 ]
115 }
116 },
117 ThriftJSJQ_TLS: {
118 options: {
119 '--ignore-ssl-errors': true,
120 urls: [
121 'https://localhost:8089/test.html'
122 ]
123 }
124 },
125 ThriftWS_TLS: {
126 options: {
127 '--ignore-ssl-errors': true,
128 urls: [
129 'https://localhost:8089/testws.html'
130 ]
131 }
Henrique Mendonça15d90422015-06-25 22:31:41 +1000132 },
133 ThriftDeepConstructor: {
134 options: {
135 urls: [
136 'http://localhost:8088/test-deep-constructor.html'
137 ]
138 }
Philip Frank8fdd6102017-12-06 12:38:05 +0100139 },
140 ThriftWSES6: {
141 options: {
142 urls: [
143 'http://localhost:8088/test-es6.html'
144 ]
145 }
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200146 }
147 },
148 jshint: {
149 files: ['Gruntfile.js', 'src/**/*.js', 'test/*.js'],
150 options: {
151 // options here to override JSHint defaults
152 globals: {
153 jQuery: true,
154 console: true,
155 module: true,
156 document: true
157 }
158 }
159 },
160 });
161
162 grunt.loadNpmTasks('grunt-contrib-uglify');
163 grunt.loadNpmTasks('grunt-contrib-jshint');
164 grunt.loadNpmTasks('grunt-contrib-qunit');
165 grunt.loadNpmTasks('grunt-contrib-concat');
166 grunt.loadNpmTasks('grunt-jsdoc');
henriquea2de4102014-02-07 14:12:56 +0100167 grunt.loadNpmTasks('grunt-external-daemon');
168 grunt.loadNpmTasks('grunt-shell');
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200169
Henrique Mendonça15d90422015-06-25 22:31:41 +1000170 grunt.registerTask('test', ['jshint', 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen',
171 'external_daemon:ThriftTestServer', 'external_daemon:ThriftTestServer_TLS',
172 'shell:ThriftGenDeepConstructor', 'qunit:ThriftDeepConstructor',
henrique2a7dccc2014-03-07 22:16:51 +0100173 'qunit:ThriftJS', 'qunit:ThriftJS_TLS',
Philip Frank0a84eae2017-12-27 12:54:28 +0100174 'qunit:ThriftWS',
Philip Frank8fdd6102017-12-06 12:38:05 +0100175 'shell:ThriftGenJQ', 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS',
176 'shell:ThriftGenES6', 'qunit:ThriftWSES6'
henrique2a7dccc2014-03-07 22:16:51 +0100177 ]);
Philip Frank55ddf192018-01-02 09:00:36 +0100178 grunt.registerTask('default', ['test', 'concat', 'uglify', 'jsdoc']);
henriquea2de4102014-02-07 14:12:56 +0100179};