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.

549 lines
12 KiB

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