tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

update-webvtt.js (1802B)


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