update-webvtt.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env node
  2. var gift = require('gift'),
  3. fs = require('fs'),
  4. argv = require('optimist')
  5. .usage('Update vtt.jsm with the latest from a vtt.js directory.\nUsage:' +
  6. ' $0 -d [dir]')
  7. .demand('d')
  8. .options('d', {
  9. alias: 'dir',
  10. describe: 'Path to WebVTT directory.'
  11. })
  12. .options('r', {
  13. alias: 'rev',
  14. describe: 'Revision to update to.',
  15. default: 'master'
  16. })
  17. .options('w', {
  18. alias: 'write',
  19. describe: 'Path to file to write to.',
  20. default: "./vtt.jsm"
  21. })
  22. .argv;
  23. var repo = gift(argv.d);
  24. repo.status(function(err, status) {
  25. if (!status.clean) {
  26. console.log("The repository's working directory is not clean. Aborting.");
  27. process.exit(1);
  28. }
  29. repo.checkout(argv.r, function() {
  30. repo.commits(argv.r, 1, function(err, commits) {
  31. var vttjs = fs.readFileSync(argv.d + "/lib/vtt.js", 'utf8');
  32. // Remove settings for VIM and Emacs.
  33. vttjs = vttjs.replace(/\/\* -\*-.*-\*- \*\/\n/, '');
  34. vttjs = vttjs.replace(/\/\* vim:.* \*\/\n/, '');
  35. // Concatenate header and vttjs code.
  36. vttjs =
  37. '/* This Source Code Form is subject to the terms of the Mozilla Public\n' +
  38. ' * License, v. 2.0. If a copy of the MPL was not distributed with this\n' +
  39. ' * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n\n' +
  40. 'this.EXPORTED_SYMBOLS = ["WebVTT"];\n\n' +
  41. '/**\n' +
  42. ' * Code below is vtt.js the JS WebVTT implementation.\n' +
  43. ' * Current source code can be found at http://github.com/mozilla/vtt.js\n' +
  44. ' *\n' +
  45. ' * Code taken from commit ' + commits[0].id + '\n' +
  46. ' */\n' +
  47. vttjs;
  48. fs.writeFileSync(argv.w, vttjs);
  49. });
  50. });
  51. });