-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsplitSchema.js
executable file
·66 lines (54 loc) · 1.39 KB
/
splitSchema.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
#!/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: splitSchema.js src.json dst_dir [OPTIONS]\n' +
' Take a JSON schema, and save its parts as separate files\n\n' +
'OPTIONS:\n' +
'[[OPTIONS]]'
);
// global var, stores stuff about the running instance
var cfg = {
// from parseArgs()
//quiet: false,
//srcFile: 'path/to/json/file',
//dstDir: 'path/to/destination/directory',
};
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.srcFile = rest[0];
cfg.dstDir = rest[1];
schemaUtils.VERBOSE = !opt.options.quiet;
}
function work() {
schemaUtils.splitSchemaFile(cfg.srcFile, cfg.dstDir, function(err) {
if (!err) return;
if (err.code === 'ENOENT') {
err.message = "File '" + err.path + "' does not exist";
}
throw err;
});
}
function main() {
init();
work();
}
main();