rob@77: module.exports = function(grunt) { rob@77: rob@77: var exec = require('child_process').exec, rob@77: http = require('http'), rob@77: fs = require('fs'), rob@77: host = 'ajax.googleapis.com', rob@77: jqPath = '/ajax/libs/jquery/1.7.2/jquery.js'; rob@77: rob@77: grunt.registerTask('build', 'builds query module for us in nodje', function() { rob@77: var tmpDir = './tmp', distDir = './lib', rob@77: done = this.async(), wrapper; rob@77: rob@77: rob@77: function buildjQuery(jq) { rob@77: wrapper = fs.readFileSync('./src/wrapper.js', 'utf8'); rob@77: wrapper = wrapper.replace('//JQUERY_SOURCE', jq); rob@77: fs.writeFileSync('./lib/node-jquery.js', wrapper); rob@77: done(); rob@77: } rob@77: rob@77: function writejQuery() { rob@77: var data = '', rob@77: req = http.request({ rob@77: host: host, rob@77: port: 80, rob@77: path: jqPath, rob@77: method: 'GET' rob@77: }, function(res) { rob@77: res.setEncoding('utf8'); rob@77: res.on('data', function(chunk) { rob@77: data += chunk; rob@77: }); rob@77: res.on('end', function() { rob@77: fs.writeFileSync(tmpDir+'/jquery.js', data); rob@77: buildjQuery(data); rob@77: }); rob@77: }); rob@77: req.write('data\n'); rob@77: req.write('data\n'); rob@77: req.end(); rob@77: rob@77: } rob@77: rob@77: function getjQuery() { rob@77: var jq = null; rob@77: try { rob@77: jq = fs.readFileSync(tmpDir+'/jquery.js', 'utf8'); rob@77: buildjQuery(jq); rob@77: } catch (e) { rob@77: writejQuery(); rob@77: } rob@77: } rob@77: rob@77: exec('mkdir '+tmpDir+' && mkdir '+distDir, getjQuery); rob@77: }); rob@77: rob@77: grunt.registerTask('clean', 'removes dist and tmp directories', function() { rob@77: var done = this.async(); rob@77: exec('rm -rf ./tmp && rm -rf ./lib', function() { rob@77: done(); rob@77: }); rob@77: }); rob@77: rob@77: // Project configuration. rob@77: grunt.initConfig({ rob@77: pkg: '', rob@77: test: { rob@77: files: ['test/*.js'] rob@77: }, rob@77: lint: { rob@77: files: ['grunt.js', 'lib/**/*.js', 'test/**/*.js'] rob@77: }, rob@77: watch: { rob@77: files: '', rob@77: tasks: 'default' rob@77: }, rob@77: jshint: { rob@77: options: { rob@77: curly: true, rob@77: eqeqeq: true, rob@77: immed: true, rob@77: latedef: true, rob@77: newcap: true, rob@77: noarg: true, rob@77: sub: true, rob@77: undef: true, rob@77: boss: true, rob@77: eqnull: true, rob@77: node: true rob@77: }, rob@77: globals: { rob@77: exports: true rob@77: } rob@77: } rob@77: }); rob@77: rob@77: // Default task. rob@77: grunt.registerTask('default', 'build test'); rob@77: rob@77: };