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.

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