watch.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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)$/.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. }
  30. });
  31. return {
  32. copy_to_gen: {
  33. files: ['<%= srcDir %>/**/*'],
  34. tasks: [],
  35. options: {
  36. spawn: false
  37. }
  38. },
  39. };
  40. };