Gruntfile.js 5.4 KB

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