gruntfile.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*global module:false, require:false, __dirname:false*/
  2. module.exports = function(grunt) {
  3. // Project configuration.
  4. grunt.initConfig({
  5. pkg: grunt.file.readJSON('package.json'),
  6. concat: {
  7. dist: {
  8. src: ['src/<%= pkg.name %>.js', 'src/<%= pkg.name %>.*.js'],
  9. dest: 'dist/<%= pkg.name %>.js'
  10. }
  11. },
  12. copy: {
  13. libs : {
  14. files : [
  15. { expand: true, cwd : 'libs/', src: ['*'], dest: 'dist/libs/' }
  16. ]
  17. },
  18. docs : {
  19. files : [
  20. { expand: true, cwd : 'dist/', src: ['**/*'], dest: 'docs/assets/dist/' }
  21. ]
  22. }
  23. },
  24. uglify: {
  25. options: {
  26. banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> - (<%= _.pluck(pkg.licenses, "type").join(", ") %>) */\n',
  27. preserveComments: false,
  28. //sourceMap: "dist/jstree.min.map",
  29. //sourceMappingURL: "jstree.min.map",
  30. report: "min",
  31. beautify: {
  32. ascii_only: true
  33. },
  34. compress: {
  35. hoist_funs: false,
  36. loops: false,
  37. unused: false
  38. }
  39. },
  40. dist: {
  41. src: ['<%= concat.dist.dest %>'],
  42. dest: 'dist/<%= pkg.name %>.min.js'
  43. }
  44. },
  45. qunit: {
  46. files: ['test/**/*.html']
  47. },
  48. jshint: {
  49. options: {
  50. 'curly' : true,
  51. 'eqeqeq' : true,
  52. 'latedef' : true,
  53. 'newcap' : true,
  54. 'noarg' : true,
  55. 'sub' : true,
  56. 'undef' : true,
  57. 'boss' : true,
  58. 'eqnull' : true,
  59. 'browser' : true,
  60. 'trailing' : true,
  61. 'globals' : {
  62. 'console' : true,
  63. 'jQuery' : true,
  64. 'browser' : true,
  65. 'XSLTProcessor' : true,
  66. 'ActiveXObject' : true
  67. }
  68. },
  69. beforeconcat: ['src/<%= pkg.name %>.js', 'src/<%= pkg.name %>.*.js'],
  70. afterconcat: ['dist/<%= pkg.name %>.js']
  71. },
  72. dox: {
  73. files: {
  74. src: ['src/*.js'],
  75. dest: 'docs'
  76. }
  77. },
  78. amd : {
  79. files: {
  80. src: ['dist/jstree.js'],
  81. dest: 'dist/jstree.js'
  82. }
  83. },
  84. less: {
  85. production: {
  86. options : {
  87. cleancss : true,
  88. compress : true
  89. },
  90. files: {
  91. "dist/themes/default/style.min.css" : "src/themes/default/style.less"
  92. }
  93. },
  94. development: {
  95. files: {
  96. "src/themes/default/style.css" : "src/themes/default/style.less",
  97. "dist/themes/default/style.css" : "src/themes/default/style.less"
  98. }
  99. }
  100. },
  101. watch: {
  102. js : {
  103. files: ['src/**/*.js'],
  104. tasks: ['js'],
  105. options : {
  106. atBegin : true
  107. }
  108. },
  109. css : {
  110. files: ['src/**/*.less','src/**/*.png','src/**/*.gif'],
  111. tasks: ['css'],
  112. options : {
  113. atBegin : true
  114. }
  115. },
  116. },
  117. imagemin: {
  118. dynamic: {
  119. options: { // Target options
  120. optimizationLevel: 7,
  121. pngquant : true
  122. },
  123. files: [{
  124. expand: true, // Enable dynamic expansion
  125. cwd: 'src/themes/default/', // Src matches are relative to this path
  126. src: ['**/*.{png,jpg,gif}'], // Actual patterns to match
  127. dest: 'dist/themes/default/' // Destination path prefix
  128. }]
  129. }
  130. }
  131. });
  132. grunt.loadNpmTasks('grunt-contrib-jshint');
  133. grunt.loadNpmTasks('grunt-contrib-concat');
  134. grunt.loadNpmTasks('grunt-contrib-copy');
  135. grunt.loadNpmTasks('grunt-contrib-uglify');
  136. grunt.loadNpmTasks('grunt-contrib-less');
  137. grunt.loadNpmTasks('grunt-contrib-qunit');
  138. grunt.loadNpmTasks('grunt-contrib-watch');
  139. grunt.loadNpmTasks('grunt-contrib-imagemin');
  140. grunt.registerMultiTask('amd', 'Clean up AMD', function () {
  141. var s, d;
  142. this.files.forEach(function (f) {
  143. s = f.src;
  144. d = f.dest;
  145. });
  146. grunt.file.copy(s, d, {
  147. process: function (contents) {
  148. contents = contents.replace(/\s*if\(\$\.jstree\.plugins\.[a-z]+\)\s*\{\s*return;\s*\}/ig, '');
  149. contents = contents.replace(/\/\*globals[^\/]+\//ig, '');
  150. //contents = contents.replace(/\(function \(factory[\s\S]*?undefined/mig, '(function ($, undefined');
  151. //contents = contents.replace(/\}\)\);/g, '}(jQuery));');
  152. contents = contents.replace(/\(function \(factory[\s\S]*?undefined[^\n]+/mig, '');
  153. contents = contents.replace(/\}\)\);/g, '');
  154. contents = contents.replace(/\s*("|')use strict("|');/g, '');
  155. return grunt.file.read('src/intro.js') + contents + grunt.file.read('src/outro.js');
  156. }
  157. });
  158. });
  159. grunt.registerMultiTask('dox', 'Generate dox output ', function() {
  160. var exec = require('child_process').exec,
  161. path = require('path'),
  162. done = this.async(),
  163. doxPath = path.resolve(__dirname),
  164. formatter = [doxPath, 'node_modules', '.bin', 'dox'].join(path.sep);
  165. exec(formatter + ' < "dist/jstree.js" > "docs/jstree.json"', {maxBuffer: 5000*1024}, function(error, stout, sterr){
  166. if (error) {
  167. grunt.log.error(formatter);
  168. grunt.log.error("WARN: "+ error);
  169. }
  170. if (!error) {
  171. grunt.log.writeln('dist/jstree.js doxxed.');
  172. done();
  173. }
  174. });
  175. });
  176. // Default task.
  177. grunt.registerTask('default', ['jshint:beforeconcat','concat','amd','jshint:afterconcat','copy:libs','uglify','less','imagemin','copy:docs','qunit','dox']);
  178. grunt.registerTask('js', ['concat','amd','uglify']);
  179. grunt.registerTask('css', ['copy','less']);
  180. };