UNPKG

819 BJavaScriptView Raw
1var fs = require('fs-extra');
2
3// The number of files that we need to generate goog.require's for.
4var numFiles = process.argv.length - 1;
5
6/**
7 * Object used a set of found goog.provide's.
8 * @type {Object.<string, boolean>}
9 */
10var requires = {};
11
12process.argv.forEach(function(val, index, array) {
13
14 if (index === 0) {
15 return;
16 }
17
18 fs.readFile(val, function(err, data) {
19 if (err) {
20 return;
21 }
22
23 var re = new RegExp('goog\\.provide\\(\'(.*)\'\\);');
24
25 data.toString().split('\n').forEach(function(line) {
26 var match = line.match(re);
27 if (match) {
28 requires[match[1]] = true;
29 }
30 });
31
32 if (--numFiles === 0) {
33 Object.keys(requires).sort().forEach(function(key) {
34 process.stdout.write('goog.require(\'' + key + '\');\n');
35 });
36 }
37
38 });
39
40});