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.

363 lines
8.1 KiB

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