telebit.js/lib/cli-common.js

38 lines
1011 B
JavaScript
Raw Permalink Normal View History

2018-06-11 20:52:01 +00:00
'use strict';
var common = module.exports;
var path = require('path');
var mkdirp = require('mkdirp');
var os = require('os');
var homedir = os.homedir();
2018-06-12 10:36:37 +00:00
var localshare = '.local/share/telebit';
2018-06-11 20:52:01 +00:00
var localconf = '.config/telebit';
common.pipename = function (config) {
var pipename = (config.sock || common.DEFAULT_SOCK_NAME);
if (/^win/i.test(os.platform())) {
pipename = '\\\\?\\pipe' + pipename.replace(/\//, '\\');
}
return pipename;
};
2018-06-12 10:36:37 +00:00
common.DEFAULT_SOCK_NAME = path.join(homedir, localshare, 'var', 'telebit.sock');
2018-06-11 20:52:01 +00:00
try {
2018-06-12 10:36:37 +00:00
mkdirp.sync(path.join(__dirname, '..', 'var', 'log'));
mkdirp.sync(path.join(__dirname, '..', 'var', 'run'));
mkdirp.sync(path.join(__dirname, '..', 'etc'));
} catch(e) {
console.error(e);
}
try {
mkdirp.sync(path.join(homedir, localshare, 'var', 'log'));
mkdirp.sync(path.join(homedir, localshare, 'var', 'run'));
//mkdirp.sync(path.join(homedir, localshare, 'etc'));
2018-06-11 20:52:01 +00:00
mkdirp.sync(path.join(homedir, localconf));
} catch(e) {
console.error(e);
}