-
Notifications
You must be signed in to change notification settings - Fork 16
/
joinSchema.js
executable file
·67 lines (53 loc) · 1.39 KB
/
joinSchema.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
"use strict";
var Getopt = require('node-getopt');
var schemaUtils = require('./lib/schemaUtils.js');
var getopt = new Getopt([
['h', 'help', 'display this help'],
['q', 'quiet', 'silence most messages'],
]).bindHelp();
getopt.setHelp(
'Usage: joinSchema.js src_dir dst.json [OPTIONS]\n' +
' Read a directory of JSON schema, and save them in a single file\n\n' +
'OPTIONS:\n' +
'[[OPTIONS]]'
);
// global var, stores stuff about the running instance
var cfg = {
// from parseArgs()
//quiet: false,
//srcDir: 'path/to/source/directory/of/schema',
//dstFile: 'path/to/destination/json/file',
};
function init() {
parseArgs();
}
function printHelp() {
getopt.showHelp();
}
function parseArgs() {
// Chop ['node', 'this_file.js'] -- also works when run as ./this_file.js
var rest = process.argv.slice(2);
var opt = getopt.parse(rest);
rest = opt.argv;
if (rest.length !== 2) {
printHelp();
process.exit(1);
}
cfg.srcDir = rest[0];
cfg.dstFile = rest[1];
schemaUtils.VERBOSE = !opt.options.quiet;
}
function work() {
schemaUtils.loadSchemaDir(cfg.srcDir, function(err, data) {
if (err) throw err;
schemaUtils.writeSchema(data, cfg.dstFile, function (err) {
if (err) throw err;
})
});
}
function main() {
init();
work();
}
main();