watch.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. newPath = filepath.replace(/^public/, 'public_gen');
  24. grunt.log.writeln('Copying to ' + newPath);
  25. grunt.file.copy(filepath, newPath);
  26. // copy ts file also used by source maps
  27. //changes changed file source to that of the changed file
  28. var option = 'typescript.build.src';
  29. var result = filepath;
  30. grunt.config(option, result);
  31. grunt.task.run('typescript:build');
  32. grunt.task.run('tslint');
  33. }
  34. });
  35. return {
  36. copy_to_gen: {
  37. files: ['<%= srcDir %>/**/*'],
  38. tasks: [],
  39. options: {
  40. spawn: false
  41. }
  42. },
  43. };
  44. };