Gruntfile.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. module.exports = function(grunt) {
  2. grunt.initConfig({
  3. jshint: {
  4. all: [
  5. 'Gruntfile.js',
  6. 'tasks/*.js',
  7. '<%= nodeunit.tests %>',
  8. ],
  9. options: {
  10. jshintrc: '.jshintrc',
  11. },
  12. },
  13. replace: {
  14. example: {
  15. src: ['test/text_files/example.txt'],
  16. dest: 'test/modified/',
  17. replacements: [{
  18. from: 'Hello',
  19. to: 'Good bye'
  20. }, {
  21. from: /(f|F)(o{2,100})/g,
  22. to: 'M$2'
  23. }, {
  24. from: /"localhost"/,
  25. to: function (matchedWord, index, fullText, regexMatches) {
  26. return '"www.mysite.com"';
  27. }
  28. }, {
  29. from: '<p>Version:</p>',
  30. to: '<p>Version: <%= grunt.template.date("18 Feb 2013", "yyyy-mm-dd") %></p>'
  31. }, {
  32. from: /[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{2,4}/g,
  33. to: function() {
  34. return "<%= grunt.template.date('18 Feb 2013', 'dd/mm/yyyy') %>";
  35. }
  36. }]
  37. },
  38. overwrite: {
  39. src: ['test/modified/example.txt'],
  40. overwrite: true,
  41. replacements: [{
  42. from: 'World',
  43. to: 'PLANET'
  44. }]
  45. },
  46. disable_template_processing: {
  47. src: ['test/text_files/template-example.txt'],
  48. dest: 'test/modified/',
  49. options: {
  50. processTemplates: false
  51. },
  52. replacements: [{
  53. from: /url\(.*\)/g,
  54. to: function () {
  55. return "url(<% some unprocessed text %>)";
  56. }
  57. }]
  58. }
  59. },
  60. nodeunit: {
  61. errors: ['test/text-replace-error-tests.js'],
  62. tests: ['test/text-replace-unit-tests.js'],
  63. replace: ['test/text-replace-functional-tests.js'],
  64. },
  65. });
  66. grunt.loadTasks('tasks');
  67. grunt.loadNpmTasks('grunt-contrib-jshint');
  68. grunt.loadNpmTasks('grunt-contrib-nodeunit');
  69. grunt.registerTask('default', ['jshint', 'test']);
  70. /*
  71. A note on testing (ie. running: grunt test):
  72. There are two kinds of tests:
  73. - Tests that don't result in a warning
  74. - Test that do result in a warning (grunt.warn())
  75. I haven't been able to find a convenient way of testing for grunt.warn()
  76. events without enabling '--force' when running grunt. For this reason I've
  77. set up the 'test' task to just run the main tests, and only if --force is on
  78. to run the error-throwing tests.
  79. */
  80. grunt.registerTask('test', function () {
  81. var isForceOn = grunt.option('force') || false;
  82. var taskList = ['nodeunit:tests'];
  83. if (isForceOn) {
  84. taskList.push('nodeunit:errors');
  85. }
  86. taskList.push('replace');
  87. taskList.push('nodeunit:replace');
  88. grunt.task.run(taskList);
  89. });
  90. };