watch.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. module.exports = function(config, grunt) {
  2. 'use strict';
  3. grunt.event.on('watch', function(action, filepath) {
  4. var newPath;
  5. grunt.log.writeln('File Changed: ' + filepath);
  6. if (/(\.html)|(\.json)$/.test(filepath)) {
  7. newPath = filepath.replace(/^public/, 'public_gen');
  8. grunt.log.writeln('Copying to ' + newPath);
  9. grunt.file.copy(filepath, newPath);
  10. }
  11. if (/(\.js)$/.test(filepath)) {
  12. newPath = filepath.replace(/^public/, 'public_gen');
  13. grunt.log.writeln('Copying to ' + newPath);
  14. grunt.file.copy(filepath, newPath);
  15. grunt.task.run('jshint');
  16. grunt.task.run('jscs');
  17. }
  18. if (/(\.less)$/.test(filepath)) {
  19. grunt.task.run('clean:css');
  20. grunt.task.run('css');
  21. }
  22. if (/(\.ts)$/.test(filepath)) {
  23. //changes changed file source to that of the changed file
  24. var option = 'typescript.build.src';
  25. var result = filepath;
  26. grunt.config(option, result);
  27. grunt.task.run('typescript:build');
  28. grunt.task.run('tslint');
  29. // copy ts file also used by source maps
  30. newPath = filepath.replace(/^public/, 'public_gen');
  31. grunt.file.copy(filepath, newPath);
  32. }
  33. });
  34. return {
  35. copy_to_gen: {
  36. files: ['<%= srcDir %>/**/*'],
  37. tasks: [],
  38. options: {
  39. spawn: false
  40. }
  41. },
  42. };
  43. };