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.

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