mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-13 03:35:52 +01:00
43 lines
1.3 KiB
JavaScript
Executable File
43 lines
1.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
var pkg_file = '../package.yaml';
|
|
var fs = require('fs');
|
|
var yaml = require('js-yaml');
|
|
var commander = require('commander');
|
|
var server = require('../lib/index');
|
|
var crypto = require('crypto');
|
|
var pkg = require(pkg_file);
|
|
|
|
commander
|
|
.option('-l, --listen <[host:]port>', 'host:port number to listen on (default: localhost:4873)', '4873')
|
|
.option('-c, --config <config.yaml>', 'use this configuration file (default: ./config.yaml)')
|
|
.version(pkg.version)
|
|
.parse(process.argv);
|
|
|
|
var config;
|
|
if (commander.config) {
|
|
config = yaml.safeLoad(fs.readFileSync(commander.config, 'utf8'));
|
|
} else {
|
|
try {
|
|
config = yaml.safeLoad(fs.readFileSync('./config.yaml', 'utf8'));
|
|
} catch(err) {
|
|
var created_config = require('../lib/config_gen')();
|
|
config = yaml.safeLoad(created_config.yaml);
|
|
console.log('starting with default config, use user: "%s", pass: "%s" to authenticate', created_config.user, created_config.pass);
|
|
fs.writeFileSync('./config.yaml', created_config.yaml);
|
|
}
|
|
}
|
|
|
|
if (!config.user_agent) config.user_agent = 'Sinopia/'+pkg.version;
|
|
|
|
var hostport = commander.listen.split(':');
|
|
if (hostport.length < 2) {
|
|
hostport = [undefined, hostport[0]];
|
|
}
|
|
if (hostport[0] == null) {
|
|
hostport[0] = 'localhost';
|
|
}
|
|
server(config).listen(hostport[1], hostport[0]);
|
|
console.log('Server is listening on http://%s:%s/', hostport[0], hostport[1]);
|
|
|