close #8 template ~ as os.homedir

This commit is contained in:
AJ ONeal 2015-12-19 11:59:50 -08:00
parent 77f54981c5
commit 1e2f559c2e
1 changed files with 7 additions and 1 deletions

View File

@ -1,12 +1,14 @@
'use strict';
var fs = require('fs');
var path = require('path');
var PromiseA = require('bluebird');
var homeRe = new RegExp("^~(\\/|\\\|\\" + path.sep + ")");
var re = /^[a-zA-Z0-9\.\-]+$/;
var punycode = require('punycode');
mudole.exports.isValidDomain = function (domain) {
module.exports.isValidDomain = function (domain) {
if (re.test(domain)) {
return domain;
}
@ -21,9 +23,11 @@ mudole.exports.isValidDomain = function (domain) {
};
module.exports.tplConfigDir = function merge(configDir, defaults) {
var homedir = require('homedir')();
Object.keys(defaults).forEach(function (key) {
if ('string' === typeof defaults[key]) {
defaults[key] = defaults[key].replace(':config', configDir).replace(':conf', configDir);
defaults[key] = defaults[key].replace(homeRe, homedir + path.sep);
}
});
};
@ -42,9 +46,11 @@ module.exports.merge = function merge(defaults, args) {
};
module.exports.tplHostname = function merge(hostname, copy) {
var homedir = require('homedir')();
Object.keys(copy).forEach(function (key) {
if ('string' === typeof copy[key]) {
copy[key] = copy[key].replace(':hostname', hostname).replace(':host', hostname);
copy[key] = copy[key].replace(homeRe, homedir + path.sep);
}
});