Gruntfile.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. module.exports = function( grunt ) {
  2. var fs = require('fs')
  3. grunt.initConfig({
  4. component_build: {
  5. dev: {
  6. output: './dist/',
  7. name: 'seed',
  8. dev: true,
  9. sourceUrls: true,
  10. styles: false,
  11. verbose: true,
  12. standalone: true
  13. },
  14. build: {
  15. output: './dist/',
  16. name: 'seed',
  17. styles: false,
  18. standalone: true
  19. }
  20. },
  21. jshint: {
  22. build: {
  23. src: ['src/**/*.js'],
  24. options: {
  25. jshintrc: "./.jshintrc"
  26. }
  27. }
  28. },
  29. mocha: {
  30. build: {
  31. src: ['test/e2e/*.html'],
  32. options: {
  33. reporter: 'Spec',
  34. run: true
  35. }
  36. }
  37. },
  38. uglify: {
  39. build: {
  40. options: {
  41. compress: true,
  42. mangle: true
  43. },
  44. files: {
  45. 'dist/seed.min.js': 'dist/seed.js'
  46. }
  47. }
  48. },
  49. watch: {
  50. options: {
  51. livereload: true
  52. },
  53. component: {
  54. files: ['src/**/*.js', 'component.json'],
  55. tasks: ['component_build:dev']
  56. }
  57. }
  58. })
  59. grunt.loadNpmTasks( 'grunt-contrib-watch' )
  60. grunt.loadNpmTasks( 'grunt-contrib-jshint' )
  61. grunt.loadNpmTasks( 'grunt-contrib-uglify' )
  62. grunt.loadNpmTasks( 'grunt-component-build' )
  63. grunt.loadNpmTasks( 'grunt-mocha' )
  64. grunt.registerTask( 'test', ['unit', 'mocha'] )
  65. grunt.registerTask( 'default', [
  66. 'jshint',
  67. 'component_build:build',
  68. 'test',
  69. 'uglify'
  70. ])
  71. grunt.registerTask( 'unit', function () {
  72. var done = this.async(),
  73. path = 'test/unit',
  74. Mocha = require('./node_modules/grunt-mocha/node_modules/mocha'),
  75. mocha_instance = new Mocha({
  76. ui: 'bdd',
  77. reporter: 'spec'
  78. })
  79. fs.readdirSync(path).forEach(function (file) {
  80. mocha_instance.addFile(path + '/' + file)
  81. })
  82. mocha_instance.run(function (errCount) {
  83. var withoutErrors = (errCount === 0)
  84. done(withoutErrors)
  85. })
  86. })
  87. grunt.registerTask( 'version', function (version) {
  88. ;['package', 'bower', 'component'].forEach(function (file) {
  89. file = './' + file + '.json'
  90. var json = fs.readFileSync(file, 'utf-8')
  91. json = json.replace(/"version"\s*:\s*"(.+?)"/, '"version": "' + version + '"')
  92. fs.writeFileSync(file, json)
  93. })
  94. })
  95. grunt.registerTask( 'release', function (version) {
  96. grunt.task.run(['default', 'version:' + version])
  97. })
  98. }