Gruntfile.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. module.exports = function(grunt) {
  2. grunt.initConfig({
  3. pkg: grunt.file.readJSON('package.json'),
  4. cfg: {
  5. filename: 'easypiechart',
  6. vanillaExportName: 'EasyPieChart'
  7. },
  8. dirs: {
  9. tmp: 'tmp',
  10. src: 'src',
  11. dest: 'dist',
  12. docs: 'docs',
  13. test: 'test',
  14. demo: 'demo'
  15. },
  16. clean: {
  17. all: ['<%= dirs.dest %>/', '<%= dirs.tmp %>/'],
  18. tmp: ['<%= dirs.tmp %>/']
  19. },
  20. concat: {
  21. vanilla: {
  22. src: [
  23. '<%= dirs.src %>/renderer/canvas.js',
  24. '<%= dirs.src %>/<%= cfg.filename %>.js'
  25. ],
  26. dest: '<%= dirs.tmp %>/<%= cfg.filename %>.js'
  27. },
  28. jquery: {
  29. src: [
  30. '<%= dirs.src %>/renderer/canvas.js',
  31. '<%= dirs.src %>/<%= cfg.filename %>.js',
  32. '<%= dirs.src %>/jquery.plugin.js'
  33. ],
  34. dest: '<%= dirs.tmp %>/jquery.<%= cfg.filename %>.js'
  35. },
  36. angular: {
  37. src: [
  38. '<%= dirs.src %>/angular.directive.js',
  39. '<%= dirs.src %>/renderer/canvas.js',
  40. '<%= dirs.src %>/<%= cfg.filename %>.js'
  41. ],
  42. dest: '<%= dirs.tmp %>/angular.<%= cfg.filename %>.js'
  43. }
  44. },
  45. usebanner: {
  46. options: {
  47. position: 'top',
  48. banner: '/**!\n' +
  49. ' * <%= pkg.name %>\n' +
  50. ' * <%= pkg.description %>\n' +
  51. ' *\n' +
  52. ' * @license <%= pkg.license %>\n'+
  53. ' * @author <%= pkg.author.name %> <<%= pkg.author.email %>> (<%= pkg.author.url %>)\n' +
  54. ' * @version <%= pkg.version %>\n' +
  55. ' **/\n'
  56. },
  57. files: {
  58. src: [
  59. '<%= dirs.dest %>/<%= cfg.filename %>.js',
  60. '<%= dirs.dest %>/jquery.<%= cfg.filename %>.js',
  61. '<%= dirs.dest %>/angular.<%= cfg.filename %>.js'
  62. ]
  63. }
  64. },
  65. uglify: {
  66. dist: {
  67. options: {
  68. report: 'gzip',
  69. preserveComments: 'some'
  70. },
  71. files: {
  72. 'dist/<%= cfg.filename %>.min.js': ['dist/<%= cfg.filename %>.js'],
  73. 'dist/jquery.<%= cfg.filename %>.min.js': ['dist/jquery.<%= cfg.filename %>.js'],
  74. 'dist/angular.<%= cfg.filename %>.min.js': ['dist/angular.<%= cfg.filename %>.js']
  75. }
  76. }
  77. },
  78. watch: {
  79. gruntfile: {
  80. files: ['Gruntfile.js']
  81. },
  82. scripts: {
  83. files: '<%= dirs.src %>/**/*.js',
  84. tasks: ['default'],
  85. options: {
  86. debounceDelay: 250
  87. }
  88. },
  89. less: {
  90. files: '<%= dirs.demo %>/*.less',
  91. tasks: ['less'],
  92. options: {
  93. debounceDelay: 250
  94. }
  95. },
  96. readme: {
  97. files: '<%= dirs.docs %>/**/*.md',
  98. tasks: ['readme'],
  99. options: {
  100. debounceDelay: 250
  101. }
  102. }
  103. },
  104. jshint: {
  105. files: [
  106. '<%= dirs.src %>/**/*.js',
  107. '<%= dirs.test %>/**/*.js'
  108. ],
  109. options: {}
  110. },
  111. karma: {
  112. unit: {
  113. configFile: 'karma.conf.coffee'
  114. },
  115. ci: {
  116. configFile: 'karma.conf.coffee',
  117. singleRun: true,
  118. browsers: ['PhantomJS']
  119. }
  120. },
  121. less: {
  122. demo: {
  123. files: {
  124. '<%= dirs.demo %>/style.css': ['<%= dirs.demo %>/style.less']
  125. }
  126. }
  127. },
  128. umd: {
  129. vanilla: {
  130. src: '<%= dirs.tmp %>/<%= cfg.filename %>.js',
  131. dest: '<%= dirs.dest %>/<%= cfg.filename %>.js',
  132. objectToExport: '<%= cfg.vanillaExportName %>',
  133. globalAlias: '<%= cfg.vanillaExportName %>'
  134. },
  135. jquery: {
  136. src: '<%= dirs.tmp %>/jquery.<%= cfg.filename %>.js',
  137. dest: '<%= dirs.dest %>/jquery.<%= cfg.filename %>.js',
  138. deps: {
  139. 'default': ['$'],
  140. amd: ['jquery'],
  141. cjs: ['jquery'],
  142. global: ['jQuery']
  143. }
  144. },
  145. angular: {
  146. src: '<%= dirs.tmp %>/angular.<%= cfg.filename %>.js',
  147. dest: '<%= dirs.dest %>/angular.<%= cfg.filename %>.js',
  148. deps: {
  149. 'default': ['angular'],
  150. amd: ['angular'],
  151. cjs: ['angular'],
  152. global: ['angular']
  153. }
  154. }
  155. }
  156. });
  157. // load all installed grunt tasks
  158. require('load-grunt-tasks')(grunt);
  159. // task defiinitions
  160. grunt.registerTask('default', [
  161. 'clean:all',
  162. 'jshint',
  163. 'concat',
  164. 'umd',
  165. 'usebanner',
  166. 'uglify',
  167. 'clean:tmp',
  168. 'readme'
  169. ]);
  170. grunt.registerTask('test', ['karma:unit']);
  171. grunt.registerTask('all', ['default', 'less']);
  172. };