blob: 32c88346b3d0d70c632e26548e4dad4affef9fa8 [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: {
44 command: 'cd ../nodejs; npm install'
45 },
henriquea2de4102014-02-07 14:12:56 +010046 ThriftGen: {
47 command: 'thrift -gen js -gen js:node -o test ../../test/ThriftTest.thrift'
henrique2a7dccc2014-03-07 22:16:51 +010048 },
49 ThriftGenJQ: {
50 command: 'thrift -gen js:jquery -gen js:node -o test ../../test/ThriftTest.thrift'
Henrique Mendonça15d90422015-06-25 22:31:41 +100051 },
52 ThriftGenDeepConstructor: {
53 command: 'thrift -gen js -o test ../../test/JsDeepConstructorTest.thrift'
henriquea2de4102014-02-07 14:12:56 +010054 }
55 },
56 external_daemon: {
57 ThriftTestServer: {
58 options: {
59 startCheck: function(stdout, stderr) {
60 return (/Thrift Server running on port/).test(stdout);
61 },
henrique2a7dccc2014-03-07 22:16:51 +010062 nodeSpawnOptions: {
63 cwd: "test",
64 env: {NODE_PATH: "../../nodejs/lib:../../nodejs/node_modules"}
65 }
henriquea2de4102014-02-07 14:12:56 +010066 },
67 cmd: "node",
68 args: ["server_http.js"]
henrique2a7dccc2014-03-07 22:16:51 +010069 },
70 ThriftTestServer_TLS: {
71 options: {
72 startCheck: function(stdout, stderr) {
73 return (/Thrift Server running on port/).test(stdout);
74 },
75 nodeSpawnOptions: {
76 cwd: "test",
77 env: {NODE_PATH: "../../nodejs/lib:../../nodejs/node_modules"}
78 }
79 },
80 cmd: "node",
81 args: ["server_https.js"]
henriquea2de4102014-02-07 14:12:56 +010082 }
Henrique Mendonça095ddb72013-09-20 19:38:03 +020083 },
84 qunit: {
henrique2a7dccc2014-03-07 22:16:51 +010085 ThriftJS: {
Henrique Mendonça095ddb72013-09-20 19:38:03 +020086 options: {
87 urls: [
henriquea2de4102014-02-07 14:12:56 +010088 'http://localhost:8088/test-nojq.html'
Henrique Mendonça095ddb72013-09-20 19:38:03 +020089 ]
90 }
henrique2a7dccc2014-03-07 22:16:51 +010091 },
92 ThriftJSJQ: {
93 options: {
94 urls: [
95 'http://localhost:8088/test.html'
96 ]
97 }
98 },
99 ThriftWS: {
100 options: {
101 urls: [
102 'http://localhost:8088/testws.html'
103 ]
104 }
105 },
106 ThriftJS_TLS: {
107 options: {
108 '--ignore-ssl-errors': true,
109 urls: [
110 'https://localhost:8089/test-nojq.html'
111 ]
112 }
113 },
114 ThriftJSJQ_TLS: {
115 options: {
116 '--ignore-ssl-errors': true,
117 urls: [
118 'https://localhost:8089/test.html'
119 ]
120 }
121 },
122 ThriftWS_TLS: {
123 options: {
124 '--ignore-ssl-errors': true,
125 urls: [
126 'https://localhost:8089/testws.html'
127 ]
128 }
Henrique Mendonça15d90422015-06-25 22:31:41 +1000129 },
130 ThriftDeepConstructor: {
131 options: {
132 urls: [
133 'http://localhost:8088/test-deep-constructor.html'
134 ]
135 }
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200136 }
137 },
138 jshint: {
139 files: ['Gruntfile.js', 'src/**/*.js', 'test/*.js'],
140 options: {
141 // options here to override JSHint defaults
142 globals: {
143 jQuery: true,
144 console: true,
145 module: true,
146 document: true
147 }
148 }
149 },
150 });
151
152 grunt.loadNpmTasks('grunt-contrib-uglify');
153 grunt.loadNpmTasks('grunt-contrib-jshint');
154 grunt.loadNpmTasks('grunt-contrib-qunit');
155 grunt.loadNpmTasks('grunt-contrib-concat');
156 grunt.loadNpmTasks('grunt-jsdoc');
henriquea2de4102014-02-07 14:12:56 +0100157 grunt.loadNpmTasks('grunt-external-daemon');
158 grunt.loadNpmTasks('grunt-shell');
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200159
Henrique Mendonça15d90422015-06-25 22:31:41 +1000160 grunt.registerTask('test', ['jshint', 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen',
161 'external_daemon:ThriftTestServer', 'external_daemon:ThriftTestServer_TLS',
162 'shell:ThriftGenDeepConstructor', 'qunit:ThriftDeepConstructor',
henrique2a7dccc2014-03-07 22:16:51 +0100163 'qunit:ThriftJS', 'qunit:ThriftJS_TLS',
164 'shell:ThriftGenJQ', 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS'
165 ]);
Henrique Mendonça15d90422015-06-25 22:31:41 +1000166 grunt.registerTask('default', ['jshint', 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen',
167 'external_daemon:ThriftTestServer', 'external_daemon:ThriftTestServer_TLS',
henrique2a7dccc2014-03-07 22:16:51 +0100168 'qunit:ThriftJS', 'qunit:ThriftJS_TLS',
169 'shell:ThriftGenJQ', 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS',
170 'concat', 'uglify', 'jsdoc'
171 ]);
henriquea2de4102014-02-07 14:12:56 +0100172};