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.

656 lines
15 KiB

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