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.

290 lines
7.2 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/flv-tag.js',
  25. 'src/exp-golomb.js',
  26. 'src/h264-stream.js',
  27. 'src/aac-stream.js',
  28. 'src/segment-parser.js',
  29. 'src/stream.js',
  30. 'src/m3u8/m3u8-parser.js',
  31. 'src/xhr.js',
  32. 'src/playlist-loader.js',
  33. 'node_modules/pkcs7/dist/pkcs7.unpad.js',
  34. 'src/decrypter.js'
  35. ],
  36. dest: 'dist/videojs.hls.js'
  37. }
  38. },
  39. uglify: {
  40. options: {
  41. banner: '<%= banner %>'
  42. },
  43. dist: {
  44. src: '<%= concat.dist.dest %>',
  45. dest: 'dist/videojs.hls.min.js'
  46. }
  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. '!test/muxer/**',
  70. '!test/switcher/**']
  71. }
  72. },
  73. connect: {
  74. dev: {
  75. options: {
  76. hostname: '*',
  77. port: 9999,
  78. keepalive: true
  79. }
  80. }
  81. },
  82. open : {
  83. dev : {
  84. path: 'http://127.0.0.1:<%= connect.dev.options.port %>/example.html',
  85. app: 'Google Chrome'
  86. }
  87. },
  88. watch: {
  89. gruntfile: {
  90. files: '<%= jshint.gruntfile.src %>',
  91. tasks: ['jshint:gruntfile']
  92. },
  93. src: {
  94. files: '<%= jshint.src.src %>',
  95. tasks: ['jshint:src', 'test']
  96. },
  97. test: {
  98. files: '<%= jshint.test.src %>',
  99. tasks: ['jshint:test', 'test']
  100. }
  101. },
  102. concurrent: {
  103. dev: {
  104. tasks: ['connect', 'open', 'watch'],
  105. options: {
  106. logConcurrentOutput: true
  107. }
  108. }
  109. },
  110. karma: {
  111. options: {
  112. frameworks: ['qunit']
  113. },
  114. saucelabs: {
  115. configFile: 'test/karma.conf.js',
  116. autoWatch: true
  117. },
  118. dev: {
  119. browsers: ['Chrome', 'Safari', 'Firefox',
  120. 'Opera', 'IE', 'PhantomJS', 'ChromeCanary'],
  121. configFile: 'test/localkarma.conf.js',
  122. autoWatch: true
  123. },
  124. chromecanary: {
  125. options: {
  126. browsers: ['ChromeCanary'],
  127. configFile: 'test/localkarma.conf.js',
  128. autoWatch: true
  129. }
  130. },
  131. phantomjs: {
  132. options: {
  133. browsers: ['PhantomJS'],
  134. configFile: 'test/localkarma.conf.js',
  135. autoWatch: true
  136. }
  137. },
  138. opera: {
  139. options: {
  140. browsers: ['Opera'],
  141. configFile: 'test/localkarma.conf.js',
  142. autoWatch: true
  143. }
  144. },
  145. chrome: {
  146. options: {
  147. browsers: ['Chrome'],
  148. configFile: 'test/localkarma.conf.js',
  149. autoWatch: true
  150. }
  151. },
  152. safari: {
  153. options: {
  154. browsers: ['Safari'],
  155. configFile: 'test/localkarma.conf.js',
  156. autoWatch: true
  157. }
  158. },
  159. firefox: {
  160. options: {
  161. browsers: ['Firefox'],
  162. configFile: 'test/localkarma.conf.js',
  163. autoWatch: true
  164. }
  165. },
  166. ie: {
  167. options: {
  168. browsers: ['IE'],
  169. configFile: 'test/localkarma.conf.js',
  170. autoWatch: true
  171. }
  172. },
  173. ci: {
  174. configFile: 'test/karma.conf.js',
  175. autoWatch: false
  176. }
  177. },
  178. });
  179. // These plugins provide necessary tasks.
  180. grunt.loadNpmTasks('grunt-karma');
  181. grunt.loadNpmTasks('grunt-contrib-clean');
  182. grunt.loadNpmTasks('grunt-contrib-concat');
  183. grunt.loadNpmTasks('grunt-contrib-uglify');
  184. grunt.loadNpmTasks('grunt-contrib-jshint');
  185. grunt.loadNpmTasks('grunt-contrib-watch');
  186. grunt.loadNpmTasks('grunt-contrib-connect');
  187. grunt.loadNpmTasks('grunt-open');
  188. grunt.loadNpmTasks('grunt-concurrent');
  189. grunt.loadNpmTasks('grunt-contrib-watch');
  190. grunt.registerTask('manifests-to-js', 'Wrap the test fixtures and output' +
  191. ' so they can be loaded in a browser',
  192. function() {
  193. var
  194. jsManifests = 'window.manifests = {\n',
  195. jsExpected = 'window.expected = {\n';
  196. grunt.file.recurse('test/manifest/',
  197. function(abspath, root, sub, filename) {
  198. if ((/\.m3u8$/).test(abspath)) {
  199. // translate this manifest
  200. jsManifests += ' \'' + basename(filename, '.m3u8') + '\': ' +
  201. grunt.file.read(abspath)
  202. .split('\n')
  203. // quote and concatenate
  204. .map(function(line) {
  205. return ' \'' + line + '\\n\' +\n';
  206. }).join('')
  207. // strip leading spaces and the trailing '+'
  208. .slice(4, -3);
  209. jsManifests += ',\n';
  210. }
  211. if ((/\.json$/).test(abspath)) {
  212. // append the JSON
  213. jsExpected += ' "' + basename(filename, '.json') + '": ' +
  214. grunt.file.read(abspath) + ',\n';
  215. }
  216. });
  217. // clean up and close the objects
  218. jsManifests = jsManifests.slice(0, -2);
  219. jsManifests += '\n};\n';
  220. jsExpected = jsExpected.slice(0, -2);
  221. jsExpected += '\n};\n';
  222. // write out the manifests
  223. grunt.file.write('tmp/manifests.js', jsManifests);
  224. grunt.file.write('tmp/expected.js', jsExpected);
  225. });
  226. // Launch a Development Environment
  227. grunt.registerTask('dev', 'Launching Dev Environment', 'concurrent:dev');
  228. // Default task.
  229. grunt.registerTask('default',
  230. ['clean',
  231. 'test',
  232. 'concat',
  233. 'uglify']);
  234. // The test task will run `karma:saucelabs` when running in travis,
  235. // otherwise, it'll default to running karma in chrome.
  236. // You can specify which browsers to build with by using grunt-style arguments
  237. // or separating them with a comma:
  238. // grunt test:chrome:firefox # grunt-style
  239. // grunt test:chrome,firefox # comma-separated
  240. grunt.registerTask('test', function() {
  241. var tasks = this.args;
  242. grunt.task.run(['jshint', 'manifests-to-js']);
  243. if (process.env.TRAVIS_PULL_REQUEST) {
  244. grunt.task.run(['karma:phantomjs']);
  245. } else if (process.env.TRAVIS) {
  246. grunt.task.run(['karma:saucelabs']);
  247. } else {
  248. if (tasks.length === 0) {
  249. tasks.push('chrome');
  250. }
  251. if (tasks.length === 1) {
  252. tasks = tasks[0].split(',');
  253. }
  254. tasks = tasks.map(function(el) {
  255. return 'karma:' + el;
  256. });
  257. grunt.task.run(tasks);
  258. }
  259. });
  260. };