forked from finos/git-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·53 lines (44 loc) · 1.39 KB
/
index.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
#!/usr/bin/env node
/* eslint-disable max-len */
const argv = require('yargs/yargs')(process.argv.slice(2))
.usage('Usage: $0 [options]')
.options({
validate: {
description:
'Check the proxy.config.json file in the current working directory for validation errors.',
required: false,
alias: 'v',
},
config: {
description: 'Path to custom git-proxy configuration file.',
default: 'proxy.config.json',
required: false,
alias: 'c',
},
}).argv;
require('./src/config/file').configFile = argv.c ? argv.c : undefined;
if (argv.v) {
const fs = require('fs');
const path = require('path');
const validate = require('jsonschema').validate;
const configFile = require('./src/config/file').configFile;
if (!fs.existsSync(configFile)) {
console.error(
`Config file ${configFile} doesn't exist, nothing to validate! Did you forget -c/--config?`,
);
process.exit(1);
}
const config = JSON.parse(fs.readFileSync(configFile));
const schema = JSON.parse(
fs.readFileSync(path.join(__dirname, 'config.schema.json')),
);
validate(config, schema, { required: true, throwError: true });
console.log(`${configFile} is valid`);
process.exit(0);
}
const proxy = require('./src/proxy');
const service = require('./src/service');
proxy.start();
service.start();
module.exports.proxy = proxy;
module.exports.service = service;