2013-05-22 08:48:04 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2013-05-31 08:26:11 +02:00
|
|
|
var fs = require('fs');
|
|
|
|
var yaml = require('js-yaml');
|
2013-05-22 08:48:04 +02:00
|
|
|
var commander = require('commander');
|
2013-05-31 08:26:11 +02:00
|
|
|
var pkg = yaml.safeLoad(fs.readFileSync('../package.yaml', 'utf8'));
|
|
|
|
var server = require('../lib/index');
|
2013-06-08 03:16:28 +02:00
|
|
|
var crypto = require('crypto');
|
2013-05-22 08:48:04 +02:00
|
|
|
|
|
|
|
commander
|
2013-05-31 08:26:11 +02:00
|
|
|
.option('-l, --listen <[host:]port>', 'host:port number to listen on (default: localhost:4873)', '4873')
|
2013-05-22 08:48:04 +02:00
|
|
|
.option('-s, --storage <path>', 'path to package cache (default: "~/.npmrepod")')
|
|
|
|
// todo: need something to do with invalid https certificate, but we just can't use http by default
|
|
|
|
.option('-u, --uplink <url>', 'parent registry (default: "https://registry.npmjs.org/")')
|
2013-05-31 08:26:11 +02:00
|
|
|
.option('-c, --config <file.yaml>', 'use this configuration file')
|
|
|
|
.version(pkg.version)
|
2013-05-22 08:48:04 +02:00
|
|
|
.parse(process.argv);
|
|
|
|
|
2013-06-08 03:16:28 +02:00
|
|
|
if (commander.config) {
|
|
|
|
var config = yaml.safeLoad(fs.readFileSync(commander.config, 'utf8'));
|
|
|
|
} else {
|
|
|
|
var pass = crypto.randomBytes(8).toString('base64').replace(/[=+\/]/g, '');
|
|
|
|
var config = {
|
|
|
|
users: {
|
|
|
|
admin: {
|
|
|
|
password: crypto.createHash('sha1').update(pass).digest('hex')
|
|
|
|
},
|
|
|
|
},
|
|
|
|
uplinks: {
|
|
|
|
npmjs: {
|
|
|
|
url: 'https://registry.npmjs.org/'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
packages: {
|
|
|
|
'/.*/': {
|
|
|
|
publish: ['admin'],
|
|
|
|
access: ['all'],
|
|
|
|
proxy: ['npmjs'],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log('starting with default config, use user: "admin", pass: "%s" to authenticate', pass);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!config.user_agent) config.user_agent = 'Sinopia/'+pkg.version;
|
|
|
|
|
2013-05-31 08:26:11 +02:00
|
|
|
var hostport = commander.listen.split(':');
|
|
|
|
if (hostport.length < 2) {
|
|
|
|
hostport = [undefined, hostport[0]];
|
2013-05-22 08:48:04 +02:00
|
|
|
}
|
2013-06-08 03:16:28 +02:00
|
|
|
server(config).listen(hostport[1], hostport[0]);
|
2013-05-31 08:26:11 +02:00
|
|
|
console.log('Server is listening on http://%s:%s/', hostport[0] || 'localhost', hostport[1]);
|
2013-05-22 08:48:04 +02:00
|
|
|
|