0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

making storage path relative to config path

This commit is contained in:
Alex Kocharin 2013-09-24 08:15:13 +04:00
parent d4ddf4a3e3
commit c84413517f
2 changed files with 9 additions and 4 deletions

View file

@ -14,21 +14,24 @@ commander
.version(pkg.version) .version(pkg.version)
.parse(process.argv); .parse(process.argv);
var config; var config, config_path;
if (commander.config) { if (commander.config) {
config = yaml.safeLoad(fs.readFileSync(commander.config, 'utf8')); config_path = commander.config;
config = yaml.safeLoad(fs.readFileSync(config_path, 'utf8'));
} else { } else {
config_path = './config.yaml';
try { try {
config = yaml.safeLoad(fs.readFileSync('./config.yaml', 'utf8')); config = yaml.safeLoad(fs.readFileSync(config_path, 'utf8'));
} catch(err) { } catch(err) {
var created_config = require('../lib/config_gen')(); var created_config = require('../lib/config_gen')();
config = yaml.safeLoad(created_config.yaml); 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); 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); fs.writeFileSync(config_path, created_config.yaml);
} }
} }
if (!config.user_agent) config.user_agent = 'Sinopia/'+pkg.version; if (!config.user_agent) config.user_agent = 'Sinopia/'+pkg.version;
if (!config.self_path) config.self_path = config_path;
var hostport = commander.listen.split(':'); var hostport = commander.listen.split(':');
if (hostport.length < 2) { if (hostport.length < 2) {

View file

@ -1,6 +1,7 @@
var fs = require('fs'); var fs = require('fs');
var semver = require('semver'); var semver = require('semver');
var through = require('through'); var through = require('through');
var Path = require('path');
var fs_storage = require('./fs-storage'); var fs_storage = require('./fs-storage');
var UError = require('./error').UserError; var UError = require('./error').UserError;
var utils = require('./utils'); var utils = require('./utils');
@ -9,6 +10,7 @@ var info_file = 'package.json';
function Storage(config) { function Storage(config) {
if (!(this instanceof Storage)) return new Storage(config); if (!(this instanceof Storage)) return new Storage(config);
this.config = config; this.config = config;
var path = Path.resolve(Path.dirname(this.config.self_path), this.config.storage);
this.storage = new fs_storage(this.config.storage); this.storage = new fs_storage(this.config.storage);
return this; return this;
} }