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.

395 lines
8.8 KiB

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