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.

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