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.

638 lines
14 KiB

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