Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const os = require('os');
const fs = require('fs');
const path = require('path');
const WeChatBot = require('../../wechat');
const reload = require('require-reload')(require);
// init weChatBot
let options = {
basePath: path.join(os.userInfo().homedir, 'Desktop')
}
let weChatBot = new WeChatBot(options);
// hot-reload bot.js
let Bot = reload('./bot');
let bot = new Bot(weChatBot);
let reloading = false;
fs.watch('./bot.js', () => {
if(reloading)
return;
reloading = true;
setTimeout(() => {
try {
Bot = reload('./bot');
bot = new Bot(weChatBot);
console.log('bot reloaded');
private getArgs(network?: Network) {
const args = {
cwd: network ? network.path : __dirname,
env: {
...process.env,
...(remote && remote.process ? remote.process.env : {}),
},
};
if (isLinux()) {
const { uid, gid } = os.userInfo();
debug(`env: uid=${uid} gid=${gid}`);
args.env = {
...args.env,
// add user/group id's to env so that file permissions on the
// docker volumes are set correctly. containers cannot write
// to disk on linux if permissions aren't set correctly
USERID: uid,
GROUPID: gid,
};
}
return args;
}
executeCommand(command, cwd) {
let timeoutTimer;
command = command.filter(x => x.length);
// sudo mode is requested in plugin config
if (hb.useSudo) {
command.unshift('sudo', '-E', '-n');
}
hb.log(`Running Command: ${command.join(' ')}`);
this.wssBroadcast(color.cyan(`USER: ${os.userInfo().username}\n\r`));
this.wssBroadcast(color.cyan(`DIR: ${cwd}\n\r`));
this.wssBroadcast(color.cyan(`CMD: ${command.join(' ')}\n\r\n\r`));
return new Bluebird((resolve, reject) => {
const term = pty.spawn(command.shift(), command, {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: cwd,
env: process.env
});
// send stdout data from the process to all clients
term.on('data', (data) => {
this.wssBroadcast(data);
});
public static timestampFilePath(): string {
// Get the home directory from the OS, first. Fallback to $HOME.
const homedir = os.userInfo().homedir || os.homedir();
if (!homedir || !homedir.trim()) {
throw new Error('Cannot determine home directory');
}
// Using the same path from account-cache.ts
return path.join(homedir, '.cdk', 'cache', 'repo-version-ttl');
}
function addSecretToCredentialStore(ssoAppName, secret) {
try {
switch (process.platform) {
case "win32":
console.log(`Adding application secret for ${ssoAppName} to Windows Credential Store`);
const addSecretToWindowsStoreCommand = `powershell -ExecutionPolicy Bypass -File "${defaults.addSecretCommandPath}" "${ssoAppName}" "${os.userInfo().username}" "${secret}"`;
childProcess.execSync(addSecretToWindowsStoreCommand, { stdio: "pipe" });
break;
case "darwin":
console.log(`Adding application secret for ${ssoAppName} to Mac OS Keychain`);
const addSecretToMacStoreCommand = `sudo security add-generic-password -a ${os.userInfo().username} -s "${ssoAppName}" -w "${secret}"`;
childProcess.execSync(addSecretToMacStoreCommand, { stdio: "pipe" });
break;
default:
throw new Error(`Platform not supported: ${process.platform}`);
}
} catch (err) {
throw new Error(`Unable to add secret for ${ssoAppName} to Windows Credential Store. \n${err}`);
}
}
function isDictionariesFolderOwnedByUser() {
const stat = statSync(SPELLING_DICTIONARIES_PATH);
const mUserInfo = userInfo();
return isObject(stat) && isObject(mUserInfo) && 'uid' in stat && 'uid' in mUserInfo && stat.uid === mUserInfo.uid;
}
if (typeof name !== 'string') {
throw new Error('"name" must be a string got: ' + typeof name);
}
if (typeof notifierName !== 'string') {
throw new Error('"notifierName" must be a string got: ' + typeof notifierName);
}
Logger[name] = Logger._loggers[name] = notifierName;
return Logger;
}
}
Logger._loggers = {};
Logger.DefaultOptions = {
user: os.userInfo ? os.userInfo().username : 'browser',
ignore: null,
preNotify: null,
level: Severity.DEBUG,
channel: path.basename(__filename),
formatter: Formatter.get('detailed'),
enabled: true,
color: false,
};
module.exports = Logger;
function getUsername() {
return os.userInfo().username
}
export function getUsername(): string {
return os.userInfo().username;
}