public static getUserHomePath(): string { let homeDirectory: string = ""; if (os.type() === "Darwin") { homeDirectory = process.env.HOME; } else if (os.type() === "Windows_NT") { homeDirectory = process.env.USERPROFILE; } return homeDirectory; }
function getTerminalCommand() { if (os.type() === 'Windows_NT') { return 'start %s' } else if (os.type() === 'Linux') { return `x-terminal-emulator -e "bash -c \\"%s\\""` } else if (os.type() === 'Darwin') { return `osascript -e 'tell app "Terminal" to do script "%s"'` } else { // not recognised, hope xterm works return `xterm -e "bash -c \\"%s\\""` } }
function getExecutableExtention(): string { if(os.type().match(/^Win/)){ return ".exe"; } return ""; }
return machineId().catch(() => { // In case MachineId fails const hash = crypto.createHash('sha256') const network = os.networkInterfaces() hash.update(os.arch() + os.hostname() + os.platform() + os.type() + network['mac']) return hash.digest('hex') })
function getExecutableExtension(): string { if (os.type().match(/^Win/)) { return '.exe'; } return ''; }
/** * Helper method that sets the environment variable and informs the user they need to restart * in order to enable the Salsa intellisense. */ public static enableSalsa(isRestartRequired: boolean): Q.Promise<boolean> { if (!process.env.VSCODE_TSJS) { let setEnvironmentVariableCommand: string = ""; if (os.type() === "Darwin") { setEnvironmentVariableCommand = "launchctl setenv VSCODE_TSJS 1"; } else if (os.type() === "Windows") { setEnvironmentVariableCommand = "setx VSCODE_TSJS 1"; } return Q({}) .then(() => Q.nfcall(child_process.exec, setEnvironmentVariableCommand)) .then(() => { return true; }); } return Q(isRestartRequired); }
export function handleError (error: Error, options: PrintOptions): any { let cause = (error as any).cause logError(error.message, 'message') while (cause) { logError(cause.message, 'caused by') cause = (cause as any).cause } if (options.verbose && error.stack) { log('') logError(error.stack, 'stack') } log('') logError(process.cwd(), 'cwd') logError(`${os.type()} ${os.release()}`, 'system') logError(process.argv.map(JSON.stringify).join(' '), 'command') logError(process.version, 'node -v') logError(pkg.version, `typings -v`) if ((error as any).code) { logError((error as any).code, 'code') } log('') logError('If you need help, you may report this error at:') logError(` <https://github.com/typings/typings/issues>`) process.exit(1) }
export function handleError (error: BaseError, options: PrintOptions): any { let message = '' let cause = error message += logError(error.message, 'message') while (cause = cause.cause as any) { message += logError(cause.message, 'caused by') } if (options.verbose && error.stack) { message += '\n' message += logError(error.stack, 'stack') } message += '\n' message += logError(process.cwd(), 'cwd') message += logError(`${os.type()} ${os.release()}`, 'system') message += logError(process.argv.map(JSON.stringify).join(' '), 'command') message += logError(process.version, 'node -v') message += logError(pkg.version, `${PROJECT_NAME} -v`) if ((error as any).code) { message += logError((error as any).code, 'code') } message += '\n' message += logError('If you need help, you may report this error at:') message += logError(` <${ISSUES_HOMEPAGE}>`) console.error(message) process.exit(1) }
/** * Download the binary file. * @param binary The binary of interest. * @param outputDir The directory where files are downloaded and stored. * @param opt_proxy The proxy for downloading files. * @param opt_ignoreSSL To ignore SSL. * @param opt_callback Callback method to be executed after the file is downloaded. */ static downloadBinary( binary: Binary, outputDir: string, opt_proxy?: string, opt_ignoreSSL?: boolean, opt_callback?: Function): void { logger.info(binary.name + ': downloading version ' + binary.version()); var url = binary.url(os.type(), os.arch()); if (!url) { logger.error(binary.name + ' v' + binary.version() + ' is not available for your system.'); return; } Downloader.httpGetFile_( url, binary.filename(os.type(), os.arch()), outputDir, opt_proxy, opt_ignoreSSL, (filePath: string) => { if (opt_callback) { opt_callback(binary, outputDir, filePath); } }); }
export function env(): any { let env = Object.assign({}, process.env); if (os.type() == 'Darwin') { env.PATH = `${ROOT}/bin:${env.PATH}`; } else if (os.type() == 'Linux') { if (os.arch() == 'x64') { } else { } } else if (os.type() == 'Windows_NT') { env.Path = `${ROOT}/bin;${env.Path}`; } return env; }