Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. module.exports = function(grunt) {
  2. grunt.loadNpmTasks('grunt-contrib-watch');
  3. grunt.loadNpmTasks('grunt-contrib-clean');
  4. grunt.loadNpmTasks('grunt-contrib-copy');
  5. grunt.loadNpmTasks('grunt-nodemon');
  6. grunt.loadNpmTasks('grunt-concurrent');
  7. grunt.loadNpmTasks('grunt-html2js');
  8.  
  9. var userConfig = require('./build.config.js');
  10.  
  11. var taskConfig = {
  12. pkg: grunt.file.readJSON('package.json'),
  13.  
  14. nodemon: {
  15. dev: {
  16. script: 'server/server.js',
  17. options: {
  18. watchedFolders: ['server']
  19. }
  20. }
  21. },
  22. concurrent: {
  23. dev: {
  24. tasks: ['nodemon', 'watch'],
  25. options: {
  26. logConcurrentOutput: true
  27. }
  28. }
  29. },
  30. clean: [
  31. '<%= build_dir %>'
  32. ],
  33.  
  34. index: {
  35. build: {
  36. dir: '<%= build_dir %>',
  37. src: [
  38. '<%= vendor_files.js %>',
  39. '<%= build_dir %>/src/**/*.js'
  40. ]
  41. }
  42. },
  43. html2js: {
  44. app: {
  45. options: {
  46. base: 'src/app'
  47. },
  48. src: [ '<%= app_files.atpl %>' ],
  49. dest: '<%= build_dir %>/templates-app.js'
  50. }
  51. },
  52.  
  53. copy: {
  54. appjs: {
  55. files: [
  56. {
  57. src: ['<%= app_files.js %>'],
  58. dest: '<%= build_dir %>/',
  59. cwd: '.',
  60. expand: true
  61. }
  62. ]
  63. },
  64. },
  65. watch: {
  66. jssrc: {
  67. files: [
  68. '<%= app_files.js %>'
  69. ],
  70. tasks: ['copy', 'index']
  71. },
  72. html: {
  73. files: [ '<%= app_files.html %>'],
  74. tasks: ['index:build']
  75. },
  76. gruntfile: {
  77. files: 'Gruntfile.js',
  78. tasks: [],
  79. options: {
  80. livereload: false
  81. }
  82. } }
  83. };
  84.  
  85. grunt.initConfig(grunt.util._.extend(taskConfig, userConfig));
  86.  
  87. // Setup default grunt tasks generally
  88. grunt.registerTask('default', ['build', 'concurrent']);
  89.  
  90. // Setup grunt tasks to handle all the copying and building
  91. grunt.registerTask('build', [
  92. 'clean', 'copy', 'index', 'html2js'
  93. ]);
  94.  
  95.  
  96. function filterForJS(files) {
  97. return files.filter(function (file) {
  98. return file.match(/\.js$/);
  99. });
  100. }
  101. grunt.registerMultiTask('index', 'Process index.html template', function() {
  102. var dirRE = new RegExp('^(' + grunt.config('build_dir') + ')\/', 'g');
  103. var jsFiles = filterForJS(this.filesSrc).map(function (file) {
  104. return file.replace(dirRE, '');
  105. });
  106.  
  107. grunt.file.copy('src/index.html', this.data.dir + '/index.html', {
  108. process: function(contents, path) {
  109. return grunt.template.process(contents, {
  110. data: {
  111. scripts: jsFiles
  112. }
  113. });
  114. }
  115. });
  116. });
  117. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement