Gruntfile.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* global require, module */
  2. var path = require('path');
  3. module.exports = function(grunt) {
  4. 'use strict';
  5. // Load grunt tasks automatically
  6. require('load-grunt-tasks')(grunt);
  7. grunt.loadNpmTasks('grunt-browser-sync');
  8. grunt.loadNpmTasks('grunt-contrib-watch');
  9. var pkg = grunt.file.readJSON('package.json');
  10. var appConfig = {
  11. app: require('./bower.json').appPath || 'app',
  12. dist: 'dist'
  13. };
  14. var banner = '/*!\n' +
  15. ' * ====================================================\n' +
  16. ' * <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
  17. '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
  18. '<%= pkg.homepage ? " * " + pkg.homepage + "\\n" : "" %>' +
  19. ' * GitHub: <%= pkg.repository.url %> \n' +
  20. ' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
  21. ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>\n' +
  22. ' * ====================================================\n' +
  23. ' */\n\n';
  24. var expose = '\nuse(\'expose-editor\');\n';
  25. // Project configuration.
  26. grunt.initConfig({
  27. // Metadata.
  28. pkg: pkg,
  29. yeoman: appConfig,
  30. clean: {
  31. last: [
  32. '.tmp',
  33. 'dist/*.js',
  34. 'dist/*.css',
  35. 'dist/*.css.map'
  36. ],
  37. clstmp: ['.tmp']
  38. },
  39. // resolve dependence
  40. dependence: {
  41. options: {
  42. base: 'src',
  43. entrance: 'expose-editor'
  44. },
  45. merge: {
  46. files: [{
  47. src: [
  48. 'src/**/*.js'
  49. ],
  50. dest: '.tmp/scripts/kityminder.editor.logic.js'
  51. }]
  52. }
  53. },
  54. // browser sync for dev
  55. browserSync: {
  56. bsFiles: {
  57. dist: 'dist/css/*.css',
  58. src: 'src/**'
  59. },
  60. options: {
  61. server: {
  62. baseDir: './',
  63. index: 'index.html',
  64. watchTask: true
  65. }
  66. }
  67. },
  68. // concat
  69. concat: {
  70. closure: {
  71. options: {
  72. banner: banner + '(function () {\n',
  73. footer: expose + '})();'
  74. },
  75. files: {
  76. 'dist/kityminder.editor.js': [
  77. '.tmp/scripts/kityminder.editor.logic.js',
  78. '.tmp/scripts/kityminder.app.annotated.js',
  79. '.tmp/scripts/templates.annotated.js',
  80. '.tmp/scripts/service/*.js',
  81. '.tmp/scripts/filter/*.js',
  82. '.tmp/scripts/dialog/**/*.js',
  83. '.tmp/scripts/directive/**/*.js'
  84. ]
  85. }
  86. }
  87. },
  88. uglify: {
  89. options: {
  90. banner: banner
  91. },
  92. minimize: {
  93. files: [{
  94. src: 'dist/kityminder.editor.js',
  95. dest: 'dist/kityminder.editor.min.js'
  96. }]
  97. }
  98. },
  99. less: {
  100. compile: {
  101. options: {
  102. sourceMap: true,
  103. sourceMapURL: 'kityminder.editor.css.map',
  104. sourceMapFilename: 'dist/kityminder.editor.css.map'
  105. },
  106. files: [{
  107. dest: 'dist/kityminder.editor.css',
  108. src: 'less/editor.less'
  109. }]
  110. }
  111. },
  112. cssmin: {
  113. dist: {
  114. files: {
  115. 'dist/kityminder.editor.min.css': 'dist/kityminder.editor.css'
  116. }
  117. }
  118. },
  119. ngtemplates: {
  120. kityminderEditor: {
  121. src: ['ui/directive/**/*.html', 'ui/dialog/**/*.html'],
  122. dest: 'ui/templates.js',
  123. options: {
  124. htmlmin: {
  125. collapseBooleanAttributes: true,
  126. collapseWhitespace: true,
  127. removeComments: true
  128. }
  129. }
  130. }
  131. },
  132. // Automatically inject Bower components into the app
  133. wiredep: {
  134. dev: {
  135. src: ['index.html'],
  136. devDependencies: true
  137. },
  138. dist: {
  139. src: ['dist/index.html']
  140. }
  141. },
  142. // Copies remaining files to places other tasks can use
  143. copy: {
  144. dist: {
  145. files: [{
  146. expand: true,
  147. cwd: 'ui',
  148. src: 'images/*',
  149. dest: 'dist'
  150. }]
  151. }
  152. },
  153. // ng-annotate tries to make the code safe for minification automatically
  154. // by using the Angular long form for dependency injection.
  155. ngAnnotate: {
  156. dist: {
  157. files: [{
  158. expand: true,
  159. cwd: 'ui/',
  160. src: '**/*.js',
  161. ext: '.annotated.js',
  162. extDot: 'last',
  163. dest: '.tmp/scripts/'
  164. }]
  165. }
  166. }
  167. });
  168. // Build task(s).
  169. grunt.registerTask('build', ['clean:last',
  170. //'wiredep:dist',
  171. 'ngtemplates', 'dependence', 'ngAnnotate', 'concat', 'uglify', 'less', 'cssmin', 'copy', 'clean:clstmp']);
  172. grunt.registerTask('dev', ['clean:last',
  173. //'wiredep:dev',
  174. 'ngtemplates', 'dependence', 'ngAnnotate', 'concat', 'uglify', 'less', 'cssmin', 'copy', 'clean:clstmp', 'browserSync', 'watch']);
  175. };