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.

722 lines
16 KiB

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