-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
116 lines (93 loc) · 3.06 KB
/
index.js
File metadata and controls
116 lines (93 loc) · 3.06 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
'use strict';
var events = require('events');
var configuration = require('./modules/configuration.js');
var web = require('./modules/web-router.js');
var Parser = require('./modules/parser.js');
var logger = require('./modules/logger.js');
var ArgumentParser = require('argparse').ArgumentParser;
var eventEmitter;
var parser;
var version = '0.6.0';
/* port number */
var serverPort = 8000;
var configurationPath = '';
/**
* the main entry point of the program
*/
function main() {
params();
configuration.readConfig(configurationPath);
eventEmitter = new events.EventEmitter();
startProcess();
}
/* parse args and manage help */
function params() {
var parser = new ArgumentParser({
version: version,
addHelp:true,
description: 'Dependency watcher parses files defined in configuration file and build relationship. A web server is started where you can connect to watch dependencies. More information available at https://github.com/restimel/dependencyWatcher/blob/master/README.md'
});
parser.addArgument(['-p', '--port'], {
help: 'Set the port of webserver (by default, it uses port 8000)',
defaultValue: 8000,
dest: 'port',
type: 'int',
metavar: '<port>'
});
parser.addArgument('--verbose', {
help: 'Display also all logs in standard output',
defaultValue: false,
action: 'storeTrue',
dest: 'verbose',
});
parser.addArgument('--logLevel', {
help: 'Set the level of log (should be a number between 0 and 5)',
defaultValue: undefined,
dest: 'logLevel',
type: 'int',
metavar: '<L>'
});
parser.addArgument('configuration', {
help: 'Define the path of the configuration file (by default, it reads configuration.json)',
nargs: '?',
defaultValue: './configuration.json',
metavar: '<configuration_file>'
});
var args = parser.parseArgs();
if (args.logLevel !== null) {
configuration._logLevel = args.logLevel;
}
changePort(args.port);
configuration.verbose = args.verbose;
configurationPath = args.configuration;
}
function changePort(port) {
var portNb = Number(port);
if (isNaN(portNb) || portNb > 65535 || portNb < 0 || portNb%1 !== 0) {
logger.error('Port number "' + port +'" is invalid. Please enter a valid port number.');
process.exit(1);
}
serverPort = portNb;
}
function startProcess() {
parser = new Parser(eventEmitter);
web.server(eventEmitter, serverPort, {
key: configuration.security.key,
cert: configuration.security.cert,
});
eventEmitter.addListener('parseFiles', parseFiles);
}
function parseFiles(confIndex, callback) {
logger.trace('parseFiles');
if (typeof callback === 'function') {
eventEmitter.once('parsed:parser', callback);
}
if (configuration.configuration[confIndex]) {
logger.debug('change currentConf');
configuration.currentConf = confIndex;
}
parser.parse();
}
/* run script */
main();