Gruntfile.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*-----------------------------------------------------
  2. * livereload Default Setting
  3. *-----------------------------------------------------*/
  4. 'use strict';
  5. var path = require('path');
  6. /*-----------------------------------------------------
  7. * Module Setting
  8. *-----------------------------------------------------*/
  9. module.exports = function(grunt) {
  10. // These plugins provide necessary tasks.
  11. /* [Build plugin & task ] ------------------------------------*/
  12. grunt.loadNpmTasks('grunt-contrib-clean');
  13. grunt.loadNpmTasks('grunt-contrib-concat');
  14. grunt.loadNpmTasks('grunt-contrib-uglify');
  15. grunt.loadNpmTasks('grunt-contrib-copy');
  16. grunt.loadNpmTasks('grunt-text-replace');
  17. grunt.loadNpmTasks('grunt-contrib-watch');
  18. grunt.loadNpmTasks('grunt-contrib-less');
  19. grunt.loadNpmTasks('grunt-postcss');
  20. grunt.loadNpmTasks('grunt-autoprefixer');
  21. var banner = '/*!\n' +
  22. ' * ====================================================\n' +
  23. ' * <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
  24. '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
  25. '<%= pkg.homepage ? " * " + pkg.homepage + "\\n" : "" %>' +
  26. ' * GitHub: <%= pkg.repository.url %> \n' +
  27. ' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
  28. ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>\n' +
  29. ' * ====================================================\n' +
  30. ' */\n\n';
  31. var packs = ['index', 'edit', 'share', 'm-share'];
  32. var sources = require('./import.js');
  33. var srcPath = 'src/';
  34. var distPath = 'dist/';
  35. var distPages = ['index', 'edit', 'viewshare', 'm-share'].map(function(name) {
  36. return distPath + name + '.html';
  37. });
  38. var concatConfigs = {};
  39. packs.forEach(function(pack) {
  40. concatConfigs[pack] = {
  41. options: {
  42. banner: banner + '(function(window) {\n\n',
  43. footer: '\n\n})(window)',
  44. sourceMap: true,
  45. sourceMapStyle: 'link'
  46. },
  47. src: sources.filter(function(source) {
  48. return source.pack == '*' || source.pack.split('|').indexOf(pack) !== -1;
  49. }).map(function(source) {
  50. return source.path;
  51. }),
  52. dest: distPath + 'kityminder.' + pack + '.js'
  53. };
  54. });
  55. // Project configuration.
  56. grunt.initConfig({
  57. // Metadata.
  58. pkg: grunt.file.readJSON('package.json'),
  59. clean: ['dist', 'native-support/upload/', 'native-support/src/tmp/'],
  60. concat: concatConfigs,
  61. uglify: {
  62. minimize: {
  63. options: {
  64. banner: banner,
  65. sourceMap: true
  66. },
  67. files: (function() {
  68. var files = {};
  69. packs.forEach(function(pack) {
  70. files[distPath + 'kityminder.' + pack + '.min.js'] = distPath + 'kityminder.' + pack + '.js';
  71. });
  72. return files;
  73. })()
  74. }
  75. },
  76. copy: {
  77. dir: {
  78. files: [{
  79. src: [
  80. 'ui/theme/**/css/*.css',
  81. 'ui/theme/**/css/*.css.map',
  82. 'ui/theme/**/images/*',
  83. 'lang/**/*',
  84. 'static/**/*',
  85. 'native-support/**/*',
  86. 'lib/ZeroClipboard.swf',
  87. 'lib/inflate.js',
  88. 'lib/source-map.min.js',
  89. 'index.html',
  90. 'edit.html',
  91. 'viewshare.html',
  92. 'm-share.html',
  93. 'download.php'
  94. ],
  95. dest: distPath
  96. }]
  97. },
  98. km_config: {
  99. expand: true,
  100. src: 'kityminder.config.js',
  101. dest: distPath
  102. },
  103. mise: {
  104. files: [{
  105. src: ['LICENSE', 'favicon.ico', 'README.md', 'CHANGELOG.md'],
  106. dest: distPath
  107. }]
  108. }
  109. },
  110. replace: {
  111. online: {
  112. src: distPages,
  113. overwrite: true,
  114. replacements: [{
  115. from: /import\.js\?pack=([\w-]+)\"/,
  116. to: 'kityminder.$1.min.js"'
  117. }]
  118. },
  119. pageNoCache: {
  120. src: distPages,
  121. overwrite: true,
  122. replacements: [{
  123. from: /(src|href)=\"(.+?)\.(js|css)\"/ig,
  124. to: '$1="$2.$3?_=' + (+new Date()) + '"'
  125. }]
  126. },
  127. imageNoCache: {
  128. src: 'dist/ui/theme/default/css/default.all.css',
  129. overwrite: true,
  130. replacements: [{
  131. from: /\.png/ig,
  132. to: '.png?_=' + (+new Date())
  133. }]
  134. }
  135. },
  136. watch: {
  137. less: {
  138. files: ['ui/theme/**/*.less'],
  139. tasks: ['less:compile', 'autoprefixer']
  140. }
  141. },
  142. less: {
  143. compile: {
  144. files: {
  145. 'ui/theme/default/css/default.all.temp.css': [
  146. 'ui/theme/default/css/import.less'
  147. ]
  148. },
  149. options: {
  150. sourceMap: true,
  151. sourceMapFilename: 'ui/theme/default/css/default.all.temp.css.map',
  152. sourceMapBasepath: 'ui/theme/default/css/'
  153. }
  154. }
  155. },
  156. autoprefixer: {
  157. all: {
  158. options: {
  159. map: true
  160. },
  161. src: 'ui/theme/default/css/default.all.temp.css',
  162. dest: 'ui/theme/default/css/default.all.css'
  163. }
  164. }
  165. });
  166. // Build task(s).
  167. grunt.registerTask('default', ['clean', 'concat', 'uglify', 'less', 'autoprefixer', 'copy', 'replace']);
  168. grunt.registerTask('dev', ['less', 'autoprefixer', 'watch']);
  169. };