summaryrefslogtreecommitdiff
path: root/lib/js/Gruntfile.js
blob: 3298d5cf267959a29b3bb99c162e478f3924be18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//To build dist/thrift.js, dist/thrift.min.js and doc/*
//run grunt at the command line in this directory.
//Prerequisites:
// Node Setup -   nodejs.org
// Grunt Setup -  npm install  //reads the ./package.json and installs project dependencies

module.exports = function(grunt) {
  'use strict';

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    concat: {
      options: {
        separator: ';'
      },
      dist: {
        src: ['src/**/*.js'],
        dest: 'dist/<%= pkg.name %>.js'
      }
    },
    jsdoc : {
        dist : {
            src: ['src/*.js', './README.md'],
            options: {
              destination: 'doc'
            }
        }
    },
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
      },
      dist: {
        files: {
          'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
        }
      }
    },  
    shell: {
      InstallThriftJS: {
        command: 'mkdir test/build; mkdir test/build/js; cp src/thrift.js test/build/js/thrift.js'
      },
      InstallThriftNodeJSDep: {
        command: 'cd ../nodejs; npm install'
      },
      ThriftGen: {
        command: 'thrift -gen js -gen js:node -o test ../../test/ThriftTest.thrift'
      },
      ThriftGenJQ: {
        command: 'thrift -gen js:jquery -gen js:node -o test ../../test/ThriftTest.thrift'
      }
    },
    external_daemon: {
      ThriftTestServer: {
        options: {
          startCheck: function(stdout, stderr) {
            return (/Thrift Server running on port/).test(stdout);
          },
          nodeSpawnOptions: {
                              cwd: "test",
                              env: {NODE_PATH: "../../nodejs/lib:../../nodejs/node_modules"}
                            }
        },
        cmd: "node",
        args: ["server_http.js"]
      },
      ThriftTestServer_TLS: {
        options: {
          startCheck: function(stdout, stderr) {
            return (/Thrift Server running on port/).test(stdout);
          },
          nodeSpawnOptions: {
                              cwd: "test",
                              env: {NODE_PATH: "../../nodejs/lib:../../nodejs/node_modules"}
                            }
        },
        cmd: "node",
        args: ["server_https.js"]
      }
    },
    qunit: {
      ThriftJS: {
        options: {
          urls: [
            'http://localhost:8088/test-nojq.html'
          ]
        }
      },
      ThriftJSJQ: {
        options: {
          urls: [
            'http://localhost:8088/test.html'
          ]
        }
      },
      ThriftWS: {
        options: {
          urls: [
            'http://localhost:8088/testws.html'
          ]
        }
      },
      ThriftJS_TLS: {
        options: {
          '--ignore-ssl-errors': true,
          urls: [
            'https://localhost:8089/test-nojq.html'
          ]
        }
      },
      ThriftJSJQ_TLS: {
        options: {
          '--ignore-ssl-errors': true,
          urls: [
            'https://localhost:8089/test.html'
          ]
        }
      },
      ThriftWS_TLS: {
        options: {
          '--ignore-ssl-errors': true,
          urls: [
            'https://localhost:8089/testws.html'
          ]
        }
      }
    },
    jshint: {
      files: ['Gruntfile.js', 'src/**/*.js', 'test/*.js'],
      options: {
        // options here to override JSHint defaults
        globals: {
          jQuery: true,
          console: true,
          module: true,
          document: true
        }
      }
    },
  });

  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-qunit');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-jsdoc');
  grunt.loadNpmTasks('grunt-external-daemon');
  grunt.loadNpmTasks('grunt-shell');

  grunt.registerTask('test', ['jshint', 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen', 
                              'external_daemon:ThriftTestServer', 'external_daemon:ThriftTestServer_TLS', 
                              'qunit:ThriftJS', 'qunit:ThriftJS_TLS',
                              'shell:ThriftGenJQ', 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS'
                             ]);
  grunt.registerTask('default', ['jshint', 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen', 
                                 'external_daemon:ThriftTestServer', 'external_daemon:ThriftTestServer_TLS', 
                                 'qunit:ThriftJS', 'qunit:ThriftJS_TLS',
                                 'shell:ThriftGenJQ', 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS',
                                 'concat', 'uglify', 'jsdoc'
                                ]);
};