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.

624 lines
14 KiB

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