blob: 3298d5cf267959a29b3bb99c162e478f3924be18 [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çac0e4a8d2015-06-01 23:23:22 +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'
henriquea2de4102014-02-07 14:12:56 +010051 }
52 },
53 external_daemon: {
54 ThriftTestServer: {
55 options: {
56 startCheck: function(stdout, stderr) {
57 return (/Thrift Server running on port/).test(stdout);
58 },
henrique2a7dccc2014-03-07 22:16:51 +010059 nodeSpawnOptions: {
60 cwd: "test",
61 env: {NODE_PATH: "../../nodejs/lib:../../nodejs/node_modules"}
62 }
henriquea2de4102014-02-07 14:12:56 +010063 },
64 cmd: "node",
65 args: ["server_http.js"]
henrique2a7dccc2014-03-07 22:16:51 +010066 },
67 ThriftTestServer_TLS: {
68 options: {
69 startCheck: function(stdout, stderr) {
70 return (/Thrift Server running on port/).test(stdout);
71 },
72 nodeSpawnOptions: {
73 cwd: "test",
74 env: {NODE_PATH: "../../nodejs/lib:../../nodejs/node_modules"}
75 }
76 },
77 cmd: "node",
78 args: ["server_https.js"]
henriquea2de4102014-02-07 14:12:56 +010079 }
Henrique Mendonça095ddb72013-09-20 19:38:03 +020080 },
81 qunit: {
henrique2a7dccc2014-03-07 22:16:51 +010082 ThriftJS: {
Henrique Mendonça095ddb72013-09-20 19:38:03 +020083 options: {
84 urls: [
henriquea2de4102014-02-07 14:12:56 +010085 'http://localhost:8088/test-nojq.html'
Henrique Mendonça095ddb72013-09-20 19:38:03 +020086 ]
87 }
henrique2a7dccc2014-03-07 22:16:51 +010088 },
89 ThriftJSJQ: {
90 options: {
91 urls: [
92 'http://localhost:8088/test.html'
93 ]
94 }
95 },
96 ThriftWS: {
97 options: {
98 urls: [
99 'http://localhost:8088/testws.html'
100 ]
101 }
102 },
103 ThriftJS_TLS: {
104 options: {
105 '--ignore-ssl-errors': true,
106 urls: [
107 'https://localhost:8089/test-nojq.html'
108 ]
109 }
110 },
111 ThriftJSJQ_TLS: {
112 options: {
113 '--ignore-ssl-errors': true,
114 urls: [
115 'https://localhost:8089/test.html'
116 ]
117 }
118 },
119 ThriftWS_TLS: {
120 options: {
121 '--ignore-ssl-errors': true,
122 urls: [
123 'https://localhost:8089/testws.html'
124 ]
125 }
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200126 }
127 },
128 jshint: {
129 files: ['Gruntfile.js', 'src/**/*.js', 'test/*.js'],
130 options: {
131 // options here to override JSHint defaults
132 globals: {
133 jQuery: true,
134 console: true,
135 module: true,
136 document: true
137 }
138 }
139 },
140 });
141
142 grunt.loadNpmTasks('grunt-contrib-uglify');
143 grunt.loadNpmTasks('grunt-contrib-jshint');
144 grunt.loadNpmTasks('grunt-contrib-qunit');
145 grunt.loadNpmTasks('grunt-contrib-concat');
146 grunt.loadNpmTasks('grunt-jsdoc');
henriquea2de4102014-02-07 14:12:56 +0100147 grunt.loadNpmTasks('grunt-external-daemon');
148 grunt.loadNpmTasks('grunt-shell');
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200149
Henrique Mendonçac0e4a8d2015-06-01 23:23:22 +1000150 grunt.registerTask('test', ['jshint', 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen',
151 'external_daemon:ThriftTestServer', 'external_daemon:ThriftTestServer_TLS',
henrique2a7dccc2014-03-07 22:16:51 +0100152 'qunit:ThriftJS', 'qunit:ThriftJS_TLS',
153 'shell:ThriftGenJQ', 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS'
154 ]);
Henrique Mendonçac0e4a8d2015-06-01 23:23:22 +1000155 grunt.registerTask('default', ['jshint', 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen',
156 'external_daemon:ThriftTestServer', 'external_daemon:ThriftTestServer_TLS',
henrique2a7dccc2014-03-07 22:16:51 +0100157 'qunit:ThriftJS', 'qunit:ThriftJS_TLS',
158 'shell:ThriftGenJQ', 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS',
159 'concat', 'uglify', 'jsdoc'
160 ]);
henriquea2de4102014-02-07 14:12:56 +0100161};