Gruntfile.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. module.exports = function(grunt) {
  2. var cfg = require('./package.json');
  3. grunt.initConfig({
  4. jst: {
  5. compile: {
  6. options: {
  7. templateSettings: {
  8. evaluate : /\{\[([\s\S]+?)\]\}/g,
  9. interpolate : /\{\{([\s\S]+?)\}\}/g
  10. },
  11. processName: function (filepath) {
  12. // E.g. src/templates/trimmed_chat.html
  13. return filepath.match(/src\/templates\/([a-z_]+)\.html/)[1];
  14. }
  15. },
  16. files: {
  17. "builds/templates.js": ["src/templates/*.html"]
  18. },
  19. }
  20. },
  21. jshint: {
  22. options: {
  23. trailing: true
  24. },
  25. target: {
  26. src : [
  27. 'converse.js',
  28. 'mock.js',
  29. 'main.js',
  30. 'tests_main.js',
  31. 'spec/*.js'
  32. ]
  33. }
  34. },
  35. cssmin: {
  36. options: {
  37. banner: "/*"+
  38. "* Converse.js (Web-based XMPP instant messaging client) \n"+
  39. "* http://conversejs.org \n"+
  40. "* Copyright (c) 2012, Jan-Carel Brand <jc@opkode.com> \n"+
  41. "* Dual licensed under the MIT and GPL Licenses \n"+
  42. "*/"
  43. },
  44. minify: {
  45. dest: 'css/converse.min.css',
  46. src: ['css/converse.css']
  47. }
  48. }
  49. });
  50. grunt.loadNpmTasks('grunt-contrib-cssmin');
  51. grunt.loadNpmTasks('grunt-contrib-jshint');
  52. grunt.loadNpmTasks('grunt-contrib-jst');
  53. grunt.loadNpmTasks('grunt-contrib-requirejs');
  54. grunt.registerTask('test', 'Run Tests', function () {
  55. var done = this.async();
  56. var child_process = require('child_process');
  57. var exec = child_process.exec;
  58. exec('./node_modules/.bin/phantomjs '+
  59. 'node_modules/jasmine-reporters/test/phantomjs-testrunner.js '+
  60. __dirname+'/tests.html',
  61. function (err, stdout, stderr) {
  62. if (err) {
  63. grunt.log.write('Tests failed with error code '+err.code);
  64. grunt.log.write(stderr);
  65. }
  66. grunt.log.write(stdout);
  67. done();
  68. });
  69. });
  70. grunt.registerTask('fetch', 'Set up the development environment', function () {
  71. var done = this.async();
  72. var child_process = require('child_process');
  73. var exec = child_process.exec;
  74. exec('./node_modules/.bin/bower update',
  75. function (err, stdout, stderr) {
  76. if (err) {
  77. grunt.log.write('build failed with error code '+err.code);
  78. grunt.log.write(stderr);
  79. }
  80. grunt.log.write(stdout);
  81. done();
  82. });
  83. });
  84. grunt.registerTask('jsmin', 'Create a new release', function () {
  85. var done = this.async();
  86. var child_process = require('child_process');
  87. var exec = child_process.exec;
  88. var callback = function (err, stdout, stderr) {
  89. if (err) {
  90. grunt.log.write('build failed with error code '+err.code);
  91. grunt.log.write(stderr);
  92. }
  93. grunt.log.write(stdout);
  94. done();
  95. };
  96. exec('./node_modules/requirejs/bin/r.js -o src/build.js && ' +
  97. './node_modules/requirejs/bin/r.js -o src/build.js optimize=none out=builds/converse.js && ' +
  98. './node_modules/requirejs/bin/r.js -o src/build-no-jquery.js &&' +
  99. './node_modules/requirejs/bin/r.js -o src/build-no-jquery.js optimize=none out=builds/converse.nojquery.js && ' +
  100. './node_modules/requirejs/bin/r.js -o src/build-no-locales-no-otr.js && ' +
  101. './node_modules/requirejs/bin/r.js -o src/build-no-locales-no-otr.js optimize=none out=builds/converse-no-locales-no-otr.js && ' +
  102. './node_modules/requirejs/bin/r.js -o src/build-no-otr.js &&' +
  103. './node_modules/requirejs/bin/r.js -o src/build-no-otr.js optimize=none out=builds/converse-no-otr.js && ' +
  104. './node_modules/requirejs/bin/r.js -o src/build-website-no-otr.js &&' +
  105. './node_modules/requirejs/bin/r.js -o src/build-website.js', callback);
  106. // XXX: It might be possible to not have separate build config files. For example:
  107. // 'r.js -o src/build.js paths.converse-dependencies=src/deps-no-otr paths.locales=locale/nolocales out=builds/converse-no-locales-no-otr.min.js'
  108. });
  109. grunt.registerTask('minify', 'Create a new minified builds', ['cssmin', 'jsmin']);
  110. grunt.registerTask('check', 'Perform all checks (e.g. before releasing)', function () {
  111. grunt.task.run('jshint', 'test');
  112. });
  113. };