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.

542 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. '../src/**/*.js'
  93. ],
  94. tasks : ['karma:test:run']
  95. },
  96. src: {
  97. files: [
  98. '../build/examples/**/*',
  99. '../src/**/*.less',
  100. '../src/**/*.js'
  101. ],
  102. tasks : watchTasks
  103. }
  104. },
  105. /*******************************
  106. Test
  107. *******************************/
  108. karma: {
  109. test: {
  110. configFile : 'test/karma.conf.js',
  111. background : true,
  112. reporters: 'dots'
  113. },
  114. travis: {
  115. configFile : 'test/karma.conf.js',
  116. singleRun : true
  117. }
  118. },
  119. /*******************************
  120. Build
  121. *******************************/
  122. clean: {
  123. options: {
  124. force: true
  125. },
  126. build : [
  127. '../build/less',
  128. '../build/minified',
  129. '../build/packaged',
  130. '../build/uncompressed'
  131. ],
  132. release : [
  133. '../docs/build',
  134. '../docs',
  135. '../rtl'
  136. ]
  137. },
  138. docco: {
  139. generate: {
  140. options: {
  141. css : '../spec/assets/docco.css',
  142. output : '../spec/docs/'
  143. },
  144. files: [
  145. {
  146. expand : true,
  147. cwd : '../spec/',
  148. src : [
  149. '**.commented.js'
  150. ]
  151. }
  152. ]
  153. }
  154. },
  155. cssjanus: {
  156. rtl: {
  157. expand : true,
  158. cwd : '../build/',
  159. src : [
  160. '**/*.less',
  161. '**/*.css',
  162. ],
  163. dest : '../rtl'
  164. },
  165. },
  166. less: {
  167. options: {
  168. paths : ['../src'],
  169. compress : false,
  170. optimization : 2
  171. },
  172. // optimized for watch, src is built on watch task using callbacks
  173. buildDocsCSS: {
  174. src : '../src',
  175. dest : '../docs/build/uncompressed/',
  176. rename : preserveFileExtensions
  177. },
  178. buildTestCSS: {
  179. expand : true,
  180. cwd : '../src',
  181. src : [
  182. '**/*.less'
  183. ],
  184. dest : '../docs/build/uncompressed/',
  185. rename: preserveFileExtensions
  186. },
  187. buildCSS: {
  188. expand : true,
  189. cwd : '../src',
  190. src : [
  191. '**/*.less'
  192. ],
  193. dest : '../build/uncompressed/',
  194. rename: preserveFileExtensions
  195. }
  196. },
  197. copy: {
  198. srcToDocs: {
  199. files: [
  200. // exact copy for less
  201. {
  202. expand : true,
  203. cwd : '../src/**/*.less',
  204. src : [
  205. '**/*'
  206. ],
  207. dest : '../docs/build/less'
  208. },
  209. // copy everything but less files for uncompressed release
  210. {
  211. expand : true,
  212. cwd : '../src/',
  213. src : [
  214. '**/*.js',
  215. 'images/*',
  216. 'fonts/*'
  217. ],
  218. dest : '../docs/build/uncompressed'
  219. },
  220. // copy everything but less for minified release
  221. {
  222. expand : true,
  223. cwd : '../src/',
  224. src : [
  225. '**/*.js',
  226. 'images/*',
  227. 'fonts/*'
  228. ],
  229. dest : '../docs/build/minified'
  230. },
  231. // copy assets only for packaged version
  232. {
  233. expand : true,
  234. cwd : '../src/',
  235. src : [
  236. 'images/*',
  237. 'fonts/*'
  238. ],
  239. dest : '../docs/build/packaged'
  240. }
  241. ]
  242. },
  243. srcToBuild: {
  244. files: [
  245. // exact copy for less
  246. {
  247. expand : true,
  248. cwd : '../src/',
  249. src : [
  250. '**/*'
  251. ],
  252. dest : '../build/less'
  253. },
  254. // copy everything but less files for uncompressed release
  255. {
  256. expand : true,
  257. cwd : '../src/',
  258. src : [
  259. '**/*.js',
  260. 'images/*',
  261. 'fonts/*'
  262. ],
  263. dest : '../build/uncompressed'
  264. },
  265. // copy everything but less for minified release
  266. {
  267. expand : true,
  268. cwd : '../src/',
  269. src : [
  270. '**/*.js',
  271. 'images/*',
  272. 'fonts/*'
  273. ],
  274. dest : '../build/minified'
  275. },
  276. // copy assets only for packaged version
  277. {
  278. expand : true,
  279. cwd : '../src/',
  280. src : [
  281. 'images/*',
  282. 'fonts/*'
  283. ],
  284. dest : '../build/packaged'
  285. }
  286. ]
  287. },
  288. // create new rtl assets
  289. buildToRTL: {
  290. files: [
  291. {
  292. expand : true,
  293. cwd : '../build/',
  294. src : [
  295. '**'
  296. ],
  297. dest : '../rtl'
  298. }
  299. ]
  300. },
  301. // make library available in docs
  302. buildToDocs: {
  303. files: [
  304. {
  305. expand : true,
  306. cwd : '../build/',
  307. src : [
  308. '**'
  309. ],
  310. dest : '../docs/build/'
  311. }
  312. ]
  313. },
  314. // copy spec files to docs
  315. specToDocs: {
  316. files: [
  317. {
  318. expand : true,
  319. cwd : '../spec',
  320. src : [
  321. '**'
  322. ],
  323. dest : '../docs/spec/'
  324. }
  325. ]
  326. },
  327. // copy spec files to docs
  328. examplesToDocs: {
  329. files: [
  330. {
  331. expand : true,
  332. cwd : '../build/examples',
  333. src : [
  334. '**'
  335. ],
  336. dest : '../docs/examples/'
  337. }
  338. ]
  339. }
  340. },
  341. compress: {
  342. options: {
  343. archive: '../docs/build/semantic.zip'
  344. },
  345. everything: {
  346. files: [
  347. {
  348. expand : true,
  349. cwd : '../build/',
  350. src : [
  351. '**'
  352. ]
  353. }
  354. ]
  355. }
  356. },
  357. concat: {
  358. options: {
  359. },
  360. concatenateCSS: {
  361. src: ["../build/uncompressed/**/*.css"],
  362. dest: "../build/packaged/css/semantic.css"
  363. },
  364. concatenateJS: {
  365. src: ["../build/uncompressed/**/*.js"],
  366. dest: "../build/packaged/javascript/semantic.js"
  367. },
  368. },
  369. cssmin: {
  370. // copy minified css to minified release
  371. minifyCSS: {
  372. expand : true,
  373. cwd : '../build/uncompressed',
  374. src : [
  375. '**/*.css'
  376. ],
  377. dest : '../build/minified',
  378. ext : '.min.css'
  379. },
  380. // add comment banner to css release
  381. addBanner: {
  382. options : {
  383. banner : '' +
  384. '/*\n' +
  385. '* # <%= package.semantic.name %>\n' +
  386. '* Version: <%= package.semantic.version %>\n' +
  387. '* http://github.com/jlukic/semantic-ui\n' +
  388. '*\n' +
  389. '*\n' +
  390. '* Copyright <%= grunt.template.today("yyyy") %> Contributors\n' +
  391. '* Released under the MIT license\n' +
  392. '* http://opensource.org/licenses/MIT\n' +
  393. '*\n' +
  394. '* Released: <%= grunt.template.today("mm/dd/yyyy") %>\n' +
  395. '*/\n'
  396. },
  397. files: {
  398. '../build/packaged/css/semantic.min.css': [
  399. '../build/uncompressed/**/*.css'
  400. ]
  401. }
  402. }
  403. },
  404. uglify: {
  405. minifyJS: {
  406. expand : true,
  407. cwd : '../build/uncompressed',
  408. src : [
  409. '**/*.js'
  410. ],
  411. dest : '../build/minified',
  412. ext : '.min.js',
  413. banner : '' +
  414. '/*' +
  415. '* # <%= package.semantic.name %>\n' +
  416. '* Version: <%= package.semantic.version %>\n' +
  417. '* http://github.com/jlukic/semantic-ui\n' +
  418. '*\n' +
  419. '*\n' +
  420. '* Copyright <%= grunt.template.today("yyyy") %> Contributors\n' +
  421. '* Released under the MIT license\n' +
  422. '* http://opensource.org/licenses/MIT\n' +
  423. '*\n' +
  424. '* Release Date: <%= grunt.template.today("mm/dd/yyyy") %>\n' +
  425. '*/\n'
  426. },
  427. buildReleaseJS: {
  428. options: {
  429. mangle : true,
  430. compress : true,
  431. banner : '' +
  432. '/*' +
  433. '* # <%= package.semantic.name %>\n' +
  434. '* Version: <%= package.semantic.version %>\n' +
  435. '* http://github.com/jlukic/semantic-ui\n' +
  436. '*\n' +
  437. '*\n' +
  438. '* Copyright <%= grunt.template.today("yyyy") %> Contributors\n' +
  439. '* Released under the MIT license\n' +
  440. '* http://opensource.org/licenses/MIT\n' +
  441. '*\n' +
  442. '* Release Date: <%= grunt.template.today("mm/dd/yyyy") %>\n' +
  443. '*/\n'
  444. },
  445. files: {
  446. '../build/packaged/javascript/semantic.min.js': [
  447. '../build/uncompressed/**/*.js'
  448. ]
  449. }
  450. }
  451. }
  452. };
  453. grunt.loadNpmTasks('grunt-contrib-clean');
  454. grunt.loadNpmTasks('grunt-contrib-compress');
  455. grunt.loadNpmTasks('grunt-contrib-concat');
  456. grunt.loadNpmTasks('grunt-contrib-copy');
  457. grunt.loadNpmTasks('grunt-contrib-cssmin');
  458. grunt.loadNpmTasks('grunt-contrib-less');
  459. grunt.loadNpmTasks('grunt-contrib-uglify');
  460. grunt.loadNpmTasks('grunt-contrib-watch');
  461. grunt.loadNpmTasks('grunt-docco-multi');
  462. grunt.loadNpmTasks('grunt-cssjanus');
  463. grunt.loadNpmTasks('grunt-karma');
  464. grunt.initConfig(config);
  465. grunt.registerTask('default', defaultTasks);
  466. grunt.registerTask('build', buildTasks);
  467. grunt.registerTask('test', testTasks);
  468. // compiles only changed less files <https://npmjs.org/package/grunt-contrib-watch>
  469. grunt.event.on('watch', setWatchFiles);
  470. };