-
Notifications
You must be signed in to change notification settings - Fork 3
/
make-sync-function
executable file
·52 lines (38 loc) · 1.54 KB
/
make-sync-function
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
#!/usr/bin/env node
const commander = require('./lib/commander/index');
const syncFunctionLoader = require('./src/loading/sync-function-loader');
const syncFunctionWriter = require('./src/saving/sync-function-writer');
const errorStatus = 1;
const { version } = require('./package');
// Parse the commandline arguments
commander.arguments('<document_definitions_file> <output_file>')
.version(version, '-v, --version')
.description('A utility for generating sync functions for Couchbase Sync Gateway.')
.option('-j, --json-string', 'enclose the sync function contents in a JSON-compatible string');
commander.on('--help', () => {
// Add some extra information after the main body of the auto-generated usage/help text
console.info(`
For example: ${commander.name()} /path/to/my-doc-definitions.js /path/to/my-new-sync-function.js
See the README for more information.`);
});
commander.parse(process.argv);
if (commander.args.length !== 2) {
commander.outputHelp();
process.exit(errorStatus);
}
const docDefnFilename = commander.args[0];
const outputFilename = commander.args[1];
let syncFuncString;
try {
syncFuncString = syncFunctionLoader.load(docDefnFilename);
} catch (ex) {
process.exit(errorStatus);
}
try {
const formatOptions = { jsonString: commander.jsonString };
syncFunctionWriter.save(outputFilename, syncFuncString, formatOptions);
} catch (ex) {
console.error(`ERROR: Unable to write the sync function to the output file: ${ex}`);
process.exit(errorStatus);
}
console.info(`Sync function written to ${outputFilename}`);