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