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.

501 lines
11 KiB

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