gruntfile.js 7.2 KB

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