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.

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