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.

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