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.

158 lines
4.1 KiB

  1. 'use strict';
  2. var basename = require('path').basename;
  3. module.exports = function(grunt) {
  4. // Project configuration.
  5. grunt.initConfig({
  6. // Metadata.
  7. pkg: grunt.file.readJSON('package.json'),
  8. banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
  9. '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
  10. '* Copyright (c) <%= grunt.template.today("yyyy") %> Brightcove;' +
  11. ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
  12. // Task configuration.
  13. clean: {
  14. files: ['build', 'dist', 'tmp']
  15. },
  16. concat: {
  17. options: {
  18. banner: '<%= banner %>',
  19. stripBanners: true
  20. },
  21. dist: {
  22. nonull: true,
  23. src: ['src/videojs-hls.js',
  24. 'src/async-queue.js',
  25. 'src/flv-tag.js',
  26. 'src/exp-golomb.js',
  27. 'src/h264-stream.js',
  28. 'src/aac-stream.js',
  29. 'src/segment-parser.js',
  30. 'src/stream.js',
  31. 'src/m3u8/m3u8-parser.js'
  32. ],
  33. dest: 'dist/videojs.hls.js'
  34. }
  35. },
  36. uglify: {
  37. options: {
  38. banner: '<%= banner %>'
  39. },
  40. dist: {
  41. src: '<%= concat.dist.dest %>',
  42. dest: 'dist/videojs.hls.min.js'
  43. }
  44. },
  45. qunit: {
  46. files: ['test/**/*.html', '!test/perf.html']
  47. },
  48. jshint: {
  49. gruntfile: {
  50. options: {
  51. jshintrc: '.jshintrc'
  52. },
  53. src: 'Gruntfile.js'
  54. },
  55. src: {
  56. options: {
  57. jshintrc: 'src/.jshintrc'
  58. },
  59. src: ['src/**/*.js']
  60. },
  61. test: {
  62. options: {
  63. jshintrc: 'test/.jshintrc'
  64. },
  65. src: ['test/**/*.js',
  66. '!test/tsSegment.js',
  67. '!test/fixtures/*.js',
  68. '!test/manifest/**']
  69. }
  70. },
  71. connect: {
  72. dev: {
  73. port: 8000,
  74. base: '.'
  75. }
  76. },
  77. watch: {
  78. gruntfile: {
  79. files: '<%= jshint.gruntfile.src %>',
  80. tasks: ['jshint:gruntfile']
  81. },
  82. src: {
  83. files: '<%= jshint.src.src %>',
  84. tasks: ['jshint:src', 'qunit']
  85. },
  86. test: {
  87. files: '<%= jshint.test.src %>',
  88. tasks: ['jshint:test', 'qunit']
  89. }
  90. }
  91. });
  92. // These plugins provide necessary tasks.
  93. grunt.loadNpmTasks('grunt-contrib-clean');
  94. grunt.loadNpmTasks('grunt-contrib-concat');
  95. grunt.loadNpmTasks('grunt-contrib-uglify');
  96. grunt.loadNpmTasks('grunt-contrib-qunit');
  97. grunt.loadNpmTasks('grunt-contrib-jshint');
  98. grunt.loadNpmTasks('grunt-contrib-watch');
  99. grunt.loadNpmTasks('grunt-contrib-connect');
  100. grunt.registerTask('manifests-to-js', 'Wrap the test fixtures and output' +
  101. ' so they can be loaded in a browser',
  102. function() {
  103. var
  104. jsManifests = 'window.manifests = {\n',
  105. jsExpected = 'window.expected = {\n';
  106. grunt.file.recurse('test/manifest/',
  107. function(abspath, root, sub, filename) {
  108. if ((/\.m3u8$/).test(abspath)) {
  109. // translate this manifest
  110. jsManifests += ' \'' + basename(filename, '.m3u8') + '\': ' +
  111. grunt.file.read(abspath)
  112. .split('\n')
  113. // quote and concatenate
  114. .map(function(line) {
  115. return ' \'' + line + '\\n\' +\n';
  116. }).join('')
  117. // strip leading spaces and the trailing '+'
  118. .slice(4, -3);
  119. jsManifests += ',\n';
  120. }
  121. if ((/\.json$/).test(abspath)) {
  122. // append the JSON
  123. jsExpected += ' "' + basename(filename, '.json') + '": ' +
  124. grunt.file.read(abspath) + ',\n';
  125. }
  126. });
  127. // clean up and close the objects
  128. jsManifests = jsManifests.slice(0, -2);
  129. jsManifests += '\n};\n';
  130. jsExpected = jsExpected.slice(0, -2);
  131. jsExpected += '\n};\n';
  132. // write out the manifests
  133. grunt.file.write('tmp/manifests.js', jsManifests);
  134. grunt.file.write('tmp/expected.js', jsExpected);
  135. });
  136. // Default task.
  137. grunt.registerTask('default',
  138. ['clean',
  139. 'jshint',
  140. 'manifests-to-js',
  141. 'qunit',
  142. 'concat',
  143. 'uglify']);
  144. };