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.

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