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.

625 lines
14 KiB

11 years ago
11 years ago
11 years ago
Merge branch 'css' of github.com:jlukic/Semantic-UI into css Conflicts: Gruntfile.js build/less/elements/button.less build/less/modules/rating.js build/minified/elements/button.min.css build/minified/modules/rating.js build/minified/modules/rating.min.css build/minified/modules/rating.min.js build/packaged/css/semantic.css.REMOVED.git-id build/packaged/css/semantic.min.css.REMOVED.git-id build/packaged/javascript/semantic.js.REMOVED.git-id build/packaged/javascript/semantic.min.js.REMOVED.git-id build/uncompressed/elements/button.css build/uncompressed/modules/rating.js node/src/files/build/less/elements/button.less node/src/files/build/less/modules/rating.js node/src/files/build/less/modules/rating.less node/src/files/build/minified/elements/button.min.css node/src/files/build/minified/modules/rating.js node/src/files/build/minified/modules/rating.min.css node/src/files/build/minified/modules/rating.min.js node/src/files/build/packaged/css/semantic.css.REMOVED.git-id node/src/files/build/packaged/css/semantic.min.css.REMOVED.git-id node/src/files/build/packaged/javascript/semantic.js.REMOVED.git-id node/src/files/build/packaged/javascript/semantic.min.js.REMOVED.git-id node/src/files/build/semantic.zip.REMOVED.git-id node/src/files/build/uncompressed/elements/button.css node/src/files/build/uncompressed/modules/rating.css node/src/files/build/uncompressed/modules/rating.js rtl/less/elements/button.less rtl/less/modules/rating.js rtl/minified/elements/button.min.css rtl/minified/modules/rating.js rtl/minified/modules/rating.min.css rtl/minified/modules/rating.min.js rtl/packaged/css/semantic.css.REMOVED.git-id rtl/packaged/css/semantic.min.css.REMOVED.git-id rtl/packaged/javascript/semantic.js.REMOVED.git-id rtl/packaged/javascript/semantic.min.js.REMOVED.git-id rtl/uncompressed/elements/button.css rtl/uncompressed/modules/rating.js src/elements/button.less
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/**/*.variables',
  137. 'src/**/*.js'
  138. ],
  139. tasks : watchTasks
  140. }
  141. },
  142. /*******************************
  143. Test
  144. *******************************/
  145. clear: {
  146. terminal: {
  147. }
  148. },
  149. karma: {
  150. watch: {
  151. configFile : 'karma.conf.js',
  152. background : true
  153. },
  154. travis: {
  155. configFile : 'karma.conf.js',
  156. singleRun : true
  157. }
  158. },
  159. /*******************************
  160. Build
  161. *******************************/
  162. autoprefixer: {
  163. options: {
  164. browsers: [
  165. 'last 2 version',
  166. '> 1%',
  167. 'opera 12.1',
  168. 'safari 6',
  169. 'ie 9',
  170. 'bb 10',
  171. 'android 4'
  172. ]
  173. },
  174. prefixBuild: {
  175. src : 'build/**/*.css'
  176. },
  177. prefixDocs: {
  178. src : 'docs/build/**/*.css'
  179. }
  180. },
  181. clean: {
  182. options: {
  183. force: true
  184. },
  185. build : [
  186. 'build/less',
  187. 'build/minified',
  188. 'build/packaged',
  189. 'build/uncompressed'
  190. ],
  191. release : [
  192. 'docs/build',
  193. 'docs',
  194. 'rtl'
  195. ]
  196. },
  197. docco: {
  198. generate: {
  199. options: {
  200. css : 'spec/assets/docco.css',
  201. output : 'spec/docs/'
  202. },
  203. files: [
  204. {
  205. expand : true,
  206. cwd : 'spec/',
  207. src : [
  208. '**.commented.js'
  209. ]
  210. }
  211. ]
  212. }
  213. },
  214. cssjanus: {
  215. rtl: {
  216. expand : true,
  217. cwd : 'build/',
  218. src : [
  219. '**/*.less',
  220. '**/*.css',
  221. ],
  222. dest : 'rtl'
  223. },
  224. },
  225. less: {
  226. options: {
  227. paths : ['src'],
  228. compress : false,
  229. optimization : 2
  230. },
  231. // optimized for watch, src is built on watch task using callbacks
  232. buildDocsCSS: {
  233. src : 'src',
  234. dest : 'docs/build/uncompressed/',
  235. rename : preserveFileExtensions
  236. },
  237. buildTestCSS: {
  238. expand : true,
  239. cwd : 'src',
  240. src : [
  241. '**/*.less'
  242. ],
  243. dest : 'docs/build/uncompressed/',
  244. rename: preserveFileExtensions
  245. },
  246. buildCSS: {
  247. expand : true,
  248. cwd : 'src',
  249. src : [
  250. '**/*.less'
  251. ],
  252. dest : 'build/uncompressed/',
  253. rename: preserveFileExtensions
  254. }
  255. },
  256. copy: {
  257. srcToDocs: {
  258. files: [
  259. // exact copy for less
  260. {
  261. expand : true,
  262. cwd : 'src/**/*.less',
  263. src : [
  264. '**/*'
  265. ],
  266. dest : 'docs/build/less'
  267. },
  268. // copy everything but less files for uncompressed release
  269. {
  270. expand : true,
  271. cwd : 'src/',
  272. src : [
  273. '**/*.js',
  274. 'images/*',
  275. 'fonts/*'
  276. ],
  277. dest : 'docs/build/uncompressed'
  278. },
  279. // copy assets only for minified version
  280. {
  281. expand : true,
  282. cwd : 'src/',
  283. src : [
  284. 'images/*',
  285. 'fonts/*'
  286. ],
  287. dest : 'docs/build/minified'
  288. },
  289. // copy assets only for packaged version
  290. {
  291. expand : true,
  292. cwd : 'src/',
  293. src : [
  294. 'images/*',
  295. 'fonts/*'
  296. ],
  297. dest : 'docs/build/packaged'
  298. }
  299. ]
  300. },
  301. srcToBuild: {
  302. files: [
  303. // exact copy for less
  304. {
  305. expand : true,
  306. cwd : 'src/',
  307. src : [
  308. '**/*'
  309. ],
  310. dest : 'build/less'
  311. },
  312. // copy everything but less files for uncompressed release
  313. {
  314. expand : true,
  315. cwd : 'src/',
  316. src : [
  317. '**/*.js',
  318. 'images/*',
  319. 'fonts/*'
  320. ],
  321. dest : 'build/uncompressed'
  322. },
  323. // copy assets only for minified version
  324. {
  325. expand : true,
  326. cwd : 'src/',
  327. src : [
  328. 'images/*',
  329. 'fonts/*'
  330. ],
  331. dest : 'build/minified'
  332. },
  333. // copy assets only for packaged version
  334. {
  335. expand : true,
  336. cwd : 'src/',
  337. src : [
  338. 'images/*',
  339. 'fonts/*'
  340. ],
  341. dest : 'build/packaged'
  342. }
  343. ]
  344. },
  345. // create new rtl assets
  346. buildToRTL: {
  347. files: [
  348. {
  349. expand : true,
  350. cwd : 'build/',
  351. src : [
  352. '**'
  353. ],
  354. dest : 'rtl'
  355. }
  356. ]
  357. },
  358. // make library available in docs
  359. buildToDocs: {
  360. files: [
  361. {
  362. expand : true,
  363. cwd : 'build/',
  364. src : [
  365. '**'
  366. ],
  367. dest : 'docs/build/'
  368. }
  369. ]
  370. },
  371. // copy spec files to docs
  372. specToDocs: {
  373. files: [
  374. {
  375. expand : true,
  376. cwd : 'spec',
  377. src : [
  378. '**'
  379. ],
  380. dest : 'docs/spec/'
  381. }
  382. ]
  383. },
  384. // copy spec files to docs
  385. examplesToDocs: {
  386. files: [
  387. {
  388. expand : true,
  389. cwd : 'build/examples',
  390. src : [
  391. '**'
  392. ],
  393. dest : 'docs/build/examples/'
  394. }
  395. ]
  396. }
  397. },
  398. compress: {
  399. options: {
  400. archive: 'docs/build/semantic.zip'
  401. },
  402. everything: {
  403. files: [
  404. {
  405. expand : true,
  406. cwd : 'build/',
  407. src : [
  408. '**'
  409. ]
  410. }
  411. ]
  412. }
  413. },
  414. concat: {
  415. options: {
  416. },
  417. createCSSPackage: {
  418. src: ['build/uncompressed/**/*.css'],
  419. dest: 'build/packaged/css/semantic.css'
  420. },
  421. createJSPackage: {
  422. src: ['build/uncompressed/**/*.js'],
  423. dest: 'build/packaged/javascript/semantic.js'
  424. },
  425. createDocsCSSPackage: {
  426. src: ['docs/build/uncompressed/**/*.css'],
  427. dest: 'docs/build/packaged/css/semantic.css'
  428. },
  429. createDocsJSPackage: {
  430. src: ['docs/build/uncompressed/**/*.js'],
  431. dest: 'docs/build/packaged/javascript/semantic.js'
  432. },
  433. },
  434. cssmin: {
  435. options : {
  436. keepSpecialComments: 0,
  437. report: 'min',
  438. banner : '' +
  439. '/*\n' +
  440. '* # <%= package.title %>\n' +
  441. '* Version: <%= package.version %>\n' +
  442. '* http://github.com/jlukic/semantic-ui\n' +
  443. '*\n' +
  444. '*\n' +
  445. '* Copyright <%= grunt.template.today("yyyy") %> Contributors\n' +
  446. '* Released under the MIT license\n' +
  447. '* http://opensource.org/licenses/MIT\n' +
  448. '*\n' +
  449. '* Released: <%= grunt.template.today("mm/dd/yyyy") %>\n' +
  450. '*/\n'
  451. },
  452. // copy minified css to minified release
  453. minifyCSS: {
  454. expand : true,
  455. cwd : 'build/uncompressed',
  456. src : [
  457. '**/*.css'
  458. ],
  459. dest : 'build/minified/',
  460. rename: preserveMinFileExtensions
  461. },
  462. // add comment banner to css release
  463. createMinCSSPackage: {
  464. files: {
  465. 'build/packaged/css/semantic.min.css': [
  466. 'build/uncompressed/**/*.css'
  467. ]
  468. }
  469. }
  470. },
  471. uglify: {
  472. minifyJS: {
  473. expand : true,
  474. cwd : 'build/uncompressed',
  475. src : [
  476. '**/*.js'
  477. ],
  478. dest : 'build/minified',
  479. ext : '.min.js',
  480. banner : '' +
  481. '/*' +
  482. '* # <%= package.title %>\n' +
  483. '* Version: <%= package.version %>\n' +
  484. '* http://github.com/jlukic/semantic-ui\n' +
  485. '*\n' +
  486. '*\n' +
  487. '* Copyright <%= grunt.template.today("yyyy") %> Contributors\n' +
  488. '* Released under the MIT license\n' +
  489. '* http://opensource.org/licenses/MIT\n' +
  490. '*\n' +
  491. '* Release Date: <%= grunt.template.today("mm/dd/yyyy") %>\n' +
  492. '*/\n'
  493. },
  494. createMinJSPackage: {
  495. options: {
  496. mangle : true,
  497. compress : true,
  498. banner : '' +
  499. '/*' +
  500. '* # <%= package.title %>\n' +
  501. '* Version: <%= package.version %>\n' +
  502. '* http://github.com/jlukic/semantic-ui\n' +
  503. '*\n' +
  504. '*\n' +
  505. '* Copyright <%= grunt.template.today("yyyy") %> Contributors\n' +
  506. '* Released under the MIT license\n' +
  507. '* http://opensource.org/licenses/MIT\n' +
  508. '*\n' +
  509. '* Release Date: <%= grunt.template.today("mm/dd/yyyy") %>\n' +
  510. '*/\n'
  511. },
  512. files: {
  513. 'build/packaged/javascript/semantic.min.js': [
  514. 'build/uncompressed/**/*.js'
  515. ]
  516. }
  517. }
  518. }
  519. };
  520. grunt.loadNpmTasks('grunt-contrib-clean');
  521. grunt.loadNpmTasks('grunt-contrib-compress');
  522. grunt.loadNpmTasks('grunt-contrib-concat');
  523. grunt.loadNpmTasks('grunt-contrib-copy');
  524. grunt.loadNpmTasks('grunt-contrib-cssmin');
  525. grunt.loadNpmTasks('grunt-contrib-less');
  526. grunt.loadNpmTasks('grunt-contrib-uglify');
  527. grunt.loadNpmTasks('grunt-contrib-watch');
  528. grunt.loadNpmTasks('grunt-autoprefixer');
  529. grunt.loadNpmTasks('grunt-docco-multi');
  530. grunt.loadNpmTasks('grunt-cssjanus');
  531. grunt.loadNpmTasks('grunt-clear');
  532. grunt.loadNpmTasks('grunt-karma');
  533. grunt.initConfig(config);
  534. grunt.registerTask('default', defaultTasks);
  535. grunt.registerTask('test', testTasks);
  536. grunt.registerTask('release', releaseTasks);
  537. grunt.registerTask('rtl', rtlTasks);
  538. grunt.registerTask('docs', docTasks);
  539. grunt.registerTask('build', buildTasks);
  540. // compiles only changed less files <https://npmjs.org/package/grunt-contrib-watch>
  541. grunt.event.on('watch', setWatchFiles);
  542. };