You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

360 lines
8.0 KiB

  1. module.exports = function(grunt) {
  2. var
  3. defaultTasks = [
  4. // watch less folder
  5. 'watch'
  6. ],
  7. watchTasks = [
  8. // compiles less
  9. 'less:buildCSS',
  10. // copies assets and js over to build dir
  11. 'copy:toBuild',
  12. // copies files over to docs
  13. 'copy:buildToDocs',
  14. // copies examples over to docs
  15. 'copy:examplesToDocs'
  16. ],
  17. buildTasks = [
  18. // clean build directory
  19. 'clean:build',
  20. // compiles less
  21. 'less:buildCSS',
  22. // copies assets and js over to build dir
  23. 'copy:toBuild',
  24. // creates minified css of each file
  25. 'cssmin:minifyCSS',
  26. // creates custom license in header
  27. 'cssmin:addBanner',
  28. // creates minified js of each file
  29. 'uglify:minifyJS',
  30. // creates release js of all together
  31. 'uglify:buildReleaseJS',
  32. // creates minified css of each file
  33. 'cssmin:minifyCSS',
  34. // creates custom license in header
  35. 'cssmin:addBanner',
  36. // creates release zip
  37. 'compress:everything',
  38. // cleans docs folder
  39. 'clean:docs',
  40. // copies spec files over to docs
  41. 'copy:specToDocs',
  42. // copies examples over to docs
  43. 'copy:examplesToDocs',
  44. // copies files over to docs
  45. 'copy:buildToDocs'
  46. ],
  47. config
  48. ;
  49. config = {
  50. package : grunt.file.readJSON('package.json'),
  51. /*******************************
  52. Watch
  53. *******************************/
  54. // watches for changes in a source folder
  55. watch: {
  56. scripts: {
  57. files: [
  58. '../examples/**/*',
  59. '../src/**/*.less',
  60. '../src/**/*.js'
  61. ],
  62. tasks : watchTasks
  63. }
  64. },
  65. /*******************************
  66. Build
  67. *******************************/
  68. clean: {
  69. build : {
  70. cwd: '../build',
  71. src: '*'
  72. },
  73. docs : {
  74. cwd: 'src/files/build/',
  75. src: '*'
  76. }
  77. },
  78. less: {
  79. options: {
  80. compress : false,
  81. optimization : 2
  82. },
  83. buildCSS: {
  84. options : {
  85. paths : ['../build']
  86. },
  87. expand : true,
  88. cwd : '../src',
  89. src : [
  90. '**/*.less'
  91. ],
  92. dest : '../build/uncompressed/',
  93. // this allows multiple dot names to be preserved
  94. rename: function(folder, filename) {
  95. return folder + filename.substring(0, filename.lastIndexOf('.') ) + '.css';
  96. }
  97. }
  98. },
  99. copy: {
  100. toBuild: {
  101. files: [
  102. // exact copy for less
  103. {
  104. expand : true,
  105. cwd : '../src/',
  106. src : [
  107. '**/*'
  108. ],
  109. dest : '../build/less'
  110. },
  111. // copy everything but less files for uncompressed release
  112. {
  113. expand : true,
  114. cwd : '../src/',
  115. src : [
  116. '**/*.js',
  117. 'images/*',
  118. 'fonts/*'
  119. ],
  120. dest : '../build/uncompressed'
  121. },
  122. // copy everything but less for minified release
  123. {
  124. expand : true,
  125. cwd : '../src/',
  126. src : [
  127. '**/*.js',
  128. 'images/*',
  129. 'fonts/*'
  130. ],
  131. dest : '../build/minified'
  132. },
  133. // copy assets only for packaged version
  134. {
  135. expand : true,
  136. cwd : '../src/',
  137. src : [
  138. 'images/*',
  139. 'fonts/*'
  140. ],
  141. dest : '../build/packaged'
  142. }
  143. ]
  144. },
  145. // make library available in docs
  146. buildToDocs: {
  147. files: [
  148. {
  149. expand : true,
  150. cwd : '../build/',
  151. src : [
  152. '**'
  153. ],
  154. dest : 'src/files/build/'
  155. }
  156. ]
  157. },
  158. // copy spec files to docs
  159. specToDocs: {
  160. files: [
  161. {
  162. expand : true,
  163. cwd : '../spec',
  164. src : [
  165. '**'
  166. ],
  167. dest : 'src/files/spec/'
  168. }
  169. ]
  170. },
  171. // copy spec files to docs
  172. examplesToDocs: {
  173. files: [
  174. {
  175. expand : true,
  176. cwd : '../examples',
  177. src : [
  178. '**'
  179. ],
  180. dest : 'src/files/examples/'
  181. }
  182. ]
  183. }
  184. },
  185. // generate documented source code
  186. docco: {
  187. generate: {
  188. expand : true,
  189. cwd : '../spec',
  190. src : [
  191. '**/*.commented.js'
  192. ],
  193. options: {
  194. css: '',
  195. output: 'src/files/generated/'
  196. }
  197. }
  198. },
  199. compress: {
  200. // copies entire build to release zip
  201. everything: {
  202. options: {
  203. archive: '../build/semantic.zip'
  204. },
  205. files: [
  206. {
  207. expand : true,
  208. cwd : '../build/',
  209. src : [
  210. '**'
  211. ]
  212. }
  213. ]
  214. }
  215. },
  216. cssmin: {
  217. // copy minified css to minified release
  218. minifyCSS: {
  219. expand : true,
  220. cwd : '../build/uncompressed',
  221. src : [
  222. '**/*.css'
  223. ],
  224. dest : '../build/minified',
  225. ext : '.min.css'
  226. },
  227. // add comment banner to css release
  228. addBanner: {
  229. options : {
  230. banner : '' +
  231. '/*\n' +
  232. '* # <%= package.semantic.name %>\n' +
  233. '* Version: <%= package.semantic.version %>\n' +
  234. '* http://github.com/jlukic/semantic-ui\n' +
  235. '*\n' +
  236. '*\n' +
  237. '* Copyright <%= grunt.template.today("yyyy") %> Contributors\n' +
  238. '* Released under the MIT license\n' +
  239. '* http://opensource.org/licenses/MIT\n' +
  240. '*\n' +
  241. '* Released: <%= grunt.template.today("mm/dd/yyyy") %>\n' +
  242. '*/\n'
  243. },
  244. files: {
  245. '../build/packaged/css/semantic.min.css': [
  246. '../build/uncompressed/**/*.css'
  247. ]
  248. }
  249. }
  250. },
  251. uglify: {
  252. minifyJS: {
  253. expand : true,
  254. cwd : '../build/uncompressed',
  255. src : [
  256. '**/*.js'
  257. ],
  258. dest : '../build/minified',
  259. ext : '.min.js',
  260. banner : '' +
  261. '/*' +
  262. '* # <%= package.semantic.name %>\n' +
  263. '* Version: <%= package.semantic.version %>\n' +
  264. '* http://github.com/jlukic/semantic-ui\n' +
  265. '*\n' +
  266. '*\n' +
  267. '* Copyright <%= grunt.template.today("yyyy") %> Contributors\n' +
  268. '* Released under the MIT license\n' +
  269. '* http://opensource.org/licenses/MIT\n' +
  270. '*\n' +
  271. '* Release Date: <%= grunt.template.today("mm/dd/yyyy") %>\n' +
  272. '*/\n'
  273. },
  274. buildReleaseJS: {
  275. options: {
  276. mangle : true,
  277. compress : true,
  278. banner : '' +
  279. '/*' +
  280. '* # <%= package.semantic.name %>\n' +
  281. '* Version: <%= package.semantic.version %>\n' +
  282. '* http://github.com/jlukic/semantic-ui\n' +
  283. '*\n' +
  284. '*\n' +
  285. '* Copyright <%= grunt.template.today("yyyy") %> Contributors\n' +
  286. '* Released under the MIT license\n' +
  287. '* http://opensource.org/licenses/MIT\n' +
  288. '*\n' +
  289. '* Release Date: <%= grunt.template.today("mm/dd/yyyy") %>\n' +
  290. '*/\n'
  291. },
  292. files: {
  293. '../build/packaged/javascript/semantic.min.js': [
  294. '../build/uncompressed/**/*.js'
  295. ]
  296. }
  297. }
  298. }
  299. };
  300. grunt.loadNpmTasks('grunt-contrib-clean');
  301. grunt.loadNpmTasks('grunt-contrib-compress');
  302. grunt.loadNpmTasks('grunt-contrib-copy');
  303. grunt.loadNpmTasks('grunt-contrib-cssmin');
  304. grunt.loadNpmTasks('grunt-contrib-less');
  305. grunt.loadNpmTasks('grunt-contrib-uglify');
  306. grunt.loadNpmTasks('grunt-contrib-watch');
  307. grunt.loadNpmTasks('grunt-docco');
  308. grunt.initConfig(config);
  309. grunt.registerTask('default', defaultTasks);
  310. grunt.registerTask('build', buildTasks);
  311. };