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 (/(\.scss)$/.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. grunt.config('typescript.build.src', filepath);
  29. grunt.config('tslint.source.files.src', filepath);
  30. grunt.task.run('typescript:build');
  31. grunt.task.run('tslint');
  32. }
  33. });
  34. return {
  35. copy_to_gen: {
  36. files: ['<%= srcDir %>/**/*'],
  37. tasks: [],
  38. options: {
  39. spawn: false
  40. }
  41. },
  42. };
  43. };