2016-10-18 06:41:04 +03:00
|
|
|
/**
|
|
|
|
* This module is inspired by https://github.com/sindresorhus/username/blob/master/index.js .
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var execa = require('execa');
|
|
|
|
var os = require('os');
|
2016-10-27 09:49:40 +03:00
|
|
|
var utils = require('./utils.js');
|
2016-10-18 06:41:04 +03:00
|
|
|
|
|
|
|
function getEnvVar() {
|
|
|
|
var env = process.env;
|
|
|
|
return env.LOGNAME ||
|
|
|
|
env.USER ||
|
|
|
|
env.LNAME ||
|
|
|
|
env.USERNAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanWinCmd(x) {
|
|
|
|
return x.replace(/^.*\\/, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUsername () {
|
|
|
|
var envVar = getEnvVar();
|
|
|
|
|
|
|
|
if (envVar) {
|
|
|
|
return envVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (process.platform === 'darwin' || process.platform === 'linux') {
|
|
|
|
return execa.sync('id', ['-un']).stdout;
|
|
|
|
} else if (process.platform === 'win32') {
|
|
|
|
return cleanWinCmd(execa.sync('whoami').stdout);
|
|
|
|
}
|
2016-10-19 06:24:52 +03:00
|
|
|
} catch (err) { } // eslint-disable-line
|
|
|
|
}
|
2016-10-18 06:41:04 +03:00
|
|
|
|
|
|
|
module.exports = function () {
|
2016-10-27 09:49:40 +03:00
|
|
|
return utils.getSha256Hash(os.hostname() + getUsername());
|
2016-10-18 06:41:04 +03:00
|
|
|
};
|