port es5 code to es6

This commit is contained in:
Labhansh Agrawal 2019-11-28 19:47:01 +05:30 committed by Benjamin Staneck
parent dbaf81b1dd
commit 58804a2d5b
35 changed files with 257 additions and 283 deletions

View file

@ -1,7 +1,5 @@
'use strict'; import fetch from 'electron-fetch';
import {EventEmitter} from 'events';
const fetch = require('electron-fetch').default;
const {EventEmitter} = require('events');
class AutoUpdater extends EventEmitter { class AutoUpdater extends EventEmitter {
quitAndInstall() { quitAndInstall() {
@ -47,4 +45,4 @@ class AutoUpdater extends EventEmitter {
} }
} }
module.exports = new AutoUpdater(); export default new AutoUpdater();

View file

@ -1,7 +1,7 @@
const {app, Menu} = require('electron'); import {app, Menu} from 'electron';
const {openConfig, getConfig} = require('./config'); import {openConfig, getConfig} from './config';
const {updatePlugins} = require('./plugins'); import {updatePlugins} from './plugins';
const {installCLI} = require('./utils/cli-install'); import {installCLI} from './utils/cli-install';
const commands = { const commands = {
'window:new': () => { 'window:new': () => {
@ -125,7 +125,7 @@ const commands = {
}; };
}); });
exports.execCommand = (command, focusedWindow) => { export const execCommand = (command, focusedWindow) => {
const fn = commands[command]; const fn = commands[command];
if (fn) { if (fn) {
fn(focusedWindow); fn(focusedWindow);

View file

@ -1,16 +1,16 @@
const fs = require('fs'); import fs from 'fs';
const notify = require('./notify'); import notify from './notify';
const {_import, getDefaultConfig} = require('./config/import'); import {_import, getDefaultConfig} from './config/import';
const _openConfig = require('./config/open'); import _openConfig from './config/open';
const win = require('./config/windows'); import win from './config/windows';
const {cfgPath, cfgDir} = require('./config/paths'); import {cfgPath, cfgDir} from './config/paths';
const {getColorMap} = require('./utils/colors'); import {getColorMap} from './utils/colors';
const watchers = []; const watchers = [];
let cfg = {}; let cfg = {};
let _watcher; let _watcher;
const _watch = function() { const _watch = () => {
if (_watcher) { if (_watcher) {
return _watcher; return _watcher;
} }
@ -63,60 +63,60 @@ const _watch = function() {
} }
}; };
exports.subscribe = fn => { export const subscribe = fn => {
watchers.push(fn); watchers.push(fn);
return () => { return () => {
watchers.splice(watchers.indexOf(fn), 1); watchers.splice(watchers.indexOf(fn), 1);
}; };
}; };
exports.getConfigDir = () => { export const getConfigDir = () => {
// expose config directory to load plugin from the right place // expose config directory to load plugin from the right place
return cfgDir; return cfgDir;
}; };
exports.getConfig = () => { export const getConfig = () => {
return cfg.config; return cfg.config;
}; };
exports.openConfig = () => { export const openConfig = () => {
return _openConfig(); return _openConfig();
}; };
exports.getPlugins = () => { export const getPlugins = () => {
return { return {
plugins: cfg.plugins, plugins: cfg.plugins,
localPlugins: cfg.localPlugins localPlugins: cfg.localPlugins
}; };
}; };
exports.getKeymaps = () => { export const getKeymaps = () => {
return cfg.keymaps; return cfg.keymaps;
}; };
exports.setup = () => { export const setup = () => {
cfg = _import(); cfg = _import();
_watch(); _watch();
checkDeprecatedConfig(); checkDeprecatedConfig();
}; };
exports.getWin = win.get; export const getWin = win.get;
exports.winRecord = win.recordState; export const winRecord = win.recordState;
exports.windowDefaults = win.defaults; export const windowDefaults = win.defaults;
const getDeprecatedCSS = function(config) { const getDeprecatedCSS = config => {
const deprecated = []; const deprecated = [];
const deprecatedCSS = ['x-screen', 'x-row', 'cursor-node', '::selection']; const deprecatedCSS = ['x-screen', 'x-row', 'cursor-node', '::selection'];
deprecatedCSS.forEach(css => { deprecatedCSS.forEach(css => {
if ((config.css && config.css.indexOf(css) !== -1) || (config.termCSS && config.termCSS.indexOf(css) !== -1)) { if ((config.css && config.css.includes(css)) || (config.termCSS && config.termCSS.includes(css))) {
deprecated.push(css); deprecated.push(css);
} }
}); });
return deprecated; return deprecated;
}; };
exports.getDeprecatedCSS = getDeprecatedCSS; export {getDeprecatedCSS};
const checkDeprecatedConfig = function() { const checkDeprecatedConfig = () => {
if (!cfg.config) { if (!cfg.config) {
return; return;
} }
@ -128,7 +128,7 @@ const checkDeprecatedConfig = function() {
notify('Configuration warning', `Your configuration uses some deprecated CSS classes (${deprecatedStr})`); notify('Configuration warning', `Your configuration uses some deprecated CSS classes (${deprecatedStr})`);
}; };
exports.fixConfigDefaults = decoratedConfig => { export const fixConfigDefaults = decoratedConfig => {
const defaultConfig = getDefaultConfig().config; const defaultConfig = getDefaultConfig().config;
decoratedConfig.colors = getColorMap(decoratedConfig.colors) || {}; decoratedConfig.colors = getColorMap(decoratedConfig.colors) || {};
// We must have default colors for xterm css. // We must have default colors for xterm css.
@ -136,7 +136,7 @@ exports.fixConfigDefaults = decoratedConfig => {
return decoratedConfig; return decoratedConfig;
}; };
exports.htermConfigTranslate = config => { export const htermConfigTranslate = config => {
const cssReplacements = { const cssReplacements = {
'x-screen x-row([ {.[])': '.xterm-rows > div$1', 'x-screen x-row([ {.[])': '.xterm-rows > div$1',
'.cursor-node([ {.[])': '.terminal-cursor$1', '.cursor-node([ {.[])': '.terminal-cursor$1',

View file

@ -1,16 +1,16 @@
const {moveSync, copySync, existsSync, writeFileSync, readFileSync, lstatSync} = require('fs-extra'); import {moveSync, copySync, existsSync, writeFileSync, readFileSync, lstatSync} from 'fs-extra';
const {sync: mkdirpSync} = require('mkdirp'); import {sync as mkdirpSync} from 'mkdirp';
const {defaultCfg, cfgPath, legacyCfgPath, plugs, defaultPlatformKeyPath} = require('./paths'); import {defaultCfg, cfgPath, legacyCfgPath, plugs, defaultPlatformKeyPath} from './paths';
const {_init, _extractDefault} = require('./init'); import {_init, _extractDefault} from './init';
const notify = require('../notify'); import notify from '../notify';
let defaultConfig; let defaultConfig;
const _write = function(path, data) { const _write = (path, data) => {
// This method will take text formatted as Unix line endings and transform it // This method will take text formatted as Unix line endings and transform it
// to text formatted with DOS line endings. We do this because the default // to text formatted with DOS line endings. We do this because the default
// text editor on Windows (notepad) doesn't Deal with LF files. Still. In 2017. // text editor on Windows (notepad) doesn't Deal with LF files. Still. In 2017.
const crlfify = function(str) { const crlfify = str => {
return str.replace(/\r?\n/g, '\r\n'); return str.replace(/\r?\n/g, '\r\n');
}; };
const format = process.platform === 'win32' ? crlfify(data.toString()) : data; const format = process.platform === 'win32' ? crlfify(data.toString()) : data;
@ -23,7 +23,7 @@ const saveAsBackup = src => {
let attempt = 1; let attempt = 1;
while (attempt < 100) { while (attempt < 100) {
try { try {
const backupPath = src + '.backup' + (attempt === 1 ? '' : attempt); const backupPath = `${src}.backup${attempt === 1 ? '' : attempt}`;
moveSync(src, backupPath); moveSync(src, backupPath);
return backupPath; return backupPath;
} catch (e) { } catch (e) {
@ -81,7 +81,7 @@ const migrateHyper2Config = () => {
); );
}; };
const _importConf = function() { const _importConf = () => {
// init plugin directories if not present // init plugin directories if not present
mkdirpSync(plugs.base); mkdirpSync(plugs.base);
mkdirpSync(plugs.local); mkdirpSync(plugs.local);
@ -120,14 +120,14 @@ const _importConf = function() {
} }
}; };
exports._import = () => { export const _import = () => {
const imported = _importConf(); const imported = _importConf();
defaultConfig = imported.defaultCfg; defaultConfig = imported.defaultCfg;
const result = _init(imported); const result = _init(imported);
return result; return result;
}; };
exports.getDefaultConfig = () => { export const getDefaultConfig = () => {
if (!defaultConfig) { if (!defaultConfig) {
defaultConfig = _extractDefault(_importConf().defaultCfg); defaultConfig = _extractDefault(_importConf().defaultCfg);
} }

View file

@ -1,8 +1,8 @@
const vm = require('vm'); import vm from 'vm';
const notify = require('../notify'); import notify from '../notify';
const mapKeys = require('../utils/map-keys'); import mapKeys from '../utils/map-keys';
const _extract = function(script) { const _extract = script => {
const module = {}; const module = {};
script.runInNewContext({module}); script.runInNewContext({module});
if (!module.exports) { if (!module.exports) {
@ -11,7 +11,7 @@ const _extract = function(script) {
return module.exports; return module.exports;
}; };
const _syntaxValidation = function(cfg) { const _syntaxValidation = cfg => {
try { try {
return new vm.Script(cfg, {filename: '.hyper.js', displayErrors: true}); return new vm.Script(cfg, {filename: '.hyper.js', displayErrors: true});
} catch (err) { } catch (err) {
@ -19,12 +19,12 @@ const _syntaxValidation = function(cfg) {
} }
}; };
const _extractDefault = function(cfg) { const _extractDefault = cfg => {
return _extract(_syntaxValidation(cfg)); return _extract(_syntaxValidation(cfg));
}; };
// init config // init config
const _init = function(cfg) { const _init = cfg => {
const script = _syntaxValidation(cfg.userCfg); const script = _syntaxValidation(cfg.userCfg);
if (script) { if (script) {
const _cfg = _extract(script); const _cfg = _extract(script);
@ -42,7 +42,4 @@ const _init = function(cfg) {
return cfg.defaultCfg; return cfg.defaultCfg;
}; };
module.exports = { export {_init, _extractDefault};
_init,
_extractDefault
};

View file

@ -1,7 +1,6 @@
const {shell} = require('electron'); import {shell} from 'electron';
const {cfgPath} = require('./paths'); import {cfgPath} from './paths';
export default () => Promise.resolve(shell.openItem(cfgPath));
module.exports = () => Promise.resolve(shell.openItem(cfgPath));
// Windows opens .js files with WScript.exe by default // Windows opens .js files with WScript.exe by default
// If the user hasn't set up an editor for .js files, we fallback to notepad. // If the user hasn't set up an editor for .js files, we fallback to notepad.

View file

@ -1,9 +1,9 @@
// This module exports paths, names, and other metadata that is referenced // This module exports paths, names, and other metadata that is referenced
const {homedir} = require('os'); import {homedir} from 'os';
const {app} = require('electron'); import {app} from 'electron';
const {statSync} = require('fs'); import {statSync} from 'fs';
const {resolve, join} = require('path'); import {resolve, join} from 'path';
const isDev = require('electron-is-dev'); import isDev from 'electron-is-dev';
const cfgFile = '.hyper.js'; const cfgFile = '.hyper.js';
const defaultCfgFile = 'config-default.js'; const defaultCfgFile = 'config-default.js';
@ -71,7 +71,7 @@ const defaultPlatformKeyPath = () => {
} }
}; };
module.exports = { export {
cfgDir, cfgDir,
cfgPath, cfgPath,
legacyCfgPath, legacyCfgPath,

View file

@ -1,4 +1,4 @@
const Config = require('electron-store'); import Config from 'electron-store';
const defaults = { const defaults = {
windowPosition: [50, 50], windowPosition: [50, 50],
@ -8,7 +8,7 @@ const defaults = {
// local storage // local storage
const cfg = new Config({defaults}); const cfg = new Config({defaults});
module.exports = { export default {
defaults, defaults,
get() { get() {
const position = cfg.get('windowPosition'); const position = cfg.get('windowPosition');

View file

@ -1,7 +1,7 @@
// Print diagnostic information for a few arguments instead of running Hyper. // Print diagnostic information for a few arguments instead of running Hyper.
if (['--help', '-v', '--version'].includes(process.argv[1])) { if (['--help', '-v', '--version'].includes(process.argv[1])) {
const {version} = require('./package'); const {version} = require('./package');
const configLocation = process.platform === 'win32' ? process.env.userprofile + '\\.hyper.js' : '~/.hyper.js'; const configLocation = process.platform === 'win32' ? `${process.env.userprofile}\\.hyper.js` : '~/.hyper.js';
//eslint-disable-next-line no-console //eslint-disable-next-line no-console
console.log(`Hyper version ${version}`); console.log(`Hyper version ${version}`);
//eslint-disable-next-line no-console //eslint-disable-next-line no-console
@ -45,23 +45,22 @@ if (process.platform === 'win32') {
} }
// Native // Native
const {resolve} = require('path'); import {resolve} from 'path';
// Packages // Packages
const {app, BrowserWindow, Menu} = require('electron'); import {app, BrowserWindow, Menu} from 'electron';
const {gitDescribe} = require('git-describe'); import {gitDescribe} from 'git-describe';
const isDev = require('electron-is-dev'); import isDev from 'electron-is-dev';
import * as config from './config';
const config = require('./config');
// set up config // set up config
config.setup(); config.setup();
const plugins = require('./plugins'); import * as plugins from './plugins';
const {installCLI} = require('./utils/cli-install'); import {installCLI} from './utils/cli-install';
const AppMenu = require('./menus/menu'); import * as AppMenu from './menus/menu';
const Window = require('./ui/window'); import Window from './ui/window';
const windowUtils = require('./utils/window-utils'); import * as windowUtils from './utils/window-utils';
const windowSet = new Set([]); const windowSet = new Set([]);
@ -100,7 +99,7 @@ if (isDev) {
console.log('running in prod mode'); console.log('running in prod mode');
} }
const url = 'file://' + resolve(isDev ? __dirname : app.getAppPath(), 'index.html'); const url = `file://${resolve(isDev ? __dirname : app.getAppPath(), 'index.html')}`;
//eslint-disable-next-line no-console //eslint-disable-next-line no-console
console.log('electron will open', url); console.log('electron will open', url);

View file

@ -1,26 +1,26 @@
// Packages // Packages
const {app, dialog, Menu} = require('electron'); import {app, dialog, Menu} from 'electron';
// Utilities // Utilities
const {getConfig} = require('../config'); import {getConfig} from '../config';
const {icon} = require('../config/paths'); import {icon} from '../config/paths';
const viewMenu = require('./menus/view'); import viewMenu from './menus/view';
const shellMenu = require('./menus/shell'); import shellMenu from './menus/shell';
const editMenu = require('./menus/edit'); import editMenu from './menus/edit';
const pluginsMenu = require('./menus/plugins'); import pluginsMenu from './menus/plugins';
const windowMenu = require('./menus/window'); import windowMenu from './menus/window';
const helpMenu = require('./menus/help'); import helpMenu from './menus/help';
const darwinMenu = require('./menus/darwin'); import darwinMenu from './menus/darwin';
const {getDecoratedKeymaps} = require('../plugins'); import {getDecoratedKeymaps} from '../plugins';
const {execCommand} = require('../commands'); import {execCommand} from '../commands';
const {getRendererTypes} = require('../utils/renderer-utils'); import {getRendererTypes} from '../utils/renderer-utils';
const appName = app.getName(); const appName = app.getName();
const appVersion = app.getVersion(); const appVersion = app.getVersion();
let menu_ = []; let menu_ = [];
exports.createMenu = (createWindow, getLoadedPluginVersions) => { export const createMenu = (createWindow, getLoadedPluginVersions) => {
const config = getConfig(); const config = getConfig();
// We take only first shortcut in array for each command // We take only first shortcut in array for each command
const allCommandKeys = getDecoratedKeymaps(); const allCommandKeys = getDecoratedKeymaps();
@ -69,7 +69,7 @@ exports.createMenu = (createWindow, getLoadedPluginVersions) => {
return menu; return menu;
}; };
exports.buildMenu = template => { export const buildMenu = template => {
menu_ = Menu.buildFromTemplate(template); menu_ = Menu.buildFromTemplate(template);
return menu_; return menu_;
}; };

View file

@ -1,8 +1,8 @@
// This menu label is overrided by OSX to be the appName // This menu label is overrided by OSX to be the appName
// The label is set to appName here so it matches actual behavior // The label is set to appName here so it matches actual behavior
const {app} = require('electron'); import {app} from 'electron';
module.exports = (commandKeys, execCommand, showAbout) => { export default (commandKeys, execCommand, showAbout) => {
return { return {
label: `${app.getName()}`, label: `${app.getName()}`,
submenu: [ submenu: [

View file

@ -1,4 +1,4 @@
module.exports = (commandKeys, execCommand) => { export default (commandKeys, execCommand) => {
const submenu = [ const submenu = [
{ {
label: 'Undo', label: 'Undo',

View file

@ -1,11 +1,10 @@
const {release} = require('os'); import {release} from 'os';
const {app, shell} = require('electron'); import {app, shell} from 'electron';
import {getConfig, getPlugins} from '../../config';
const {getConfig, getPlugins} = require('../../config');
const {arch, env, platform, versions} = process; const {arch, env, platform, versions} = process;
const {version} = require('../../package.json'); import {version} from '../../package.json';
module.exports = (commands, showAbout) => { export default (commands, showAbout) => {
const submenu = [ const submenu = [
{ {
label: `${app.getName()} Website`, label: `${app.getName()} Website`,

View file

@ -1,4 +1,4 @@
module.exports = (commands, execCommand) => { export default (commands, execCommand) => {
return { return {
label: 'Plugins', label: 'Plugins',
submenu: [ submenu: [

View file

@ -1,4 +1,4 @@
module.exports = (commandKeys, execCommand) => { export default (commandKeys, execCommand) => {
const isMac = process.platform === 'darwin'; const isMac = process.platform === 'darwin';
return { return {

View file

@ -1,4 +1,4 @@
module.exports = (commandKeys, execCommand) => { export default (commandKeys, execCommand) => {
return { return {
label: 'View', label: 'View',
submenu: [ submenu: [

View file

@ -1,11 +1,11 @@
module.exports = (commandKeys, execCommand) => { export default (commandKeys, execCommand) => {
// Generating tab:jump array // Generating tab:jump array
const tabJump = []; const tabJump = [];
for (let i = 1; i <= 9; i++) { for (let i = 1; i <= 9; i++) {
// 9 is a special number because it means 'last' // 9 is a special number because it means 'last'
const label = i === 9 ? 'Last' : `${i}`; const label = i === 9 ? 'Last' : `${i}`;
tabJump.push({ tabJump.push({
label: label, label,
accelerator: commandKeys[`tab:jump:${label.toLowerCase()}`] accelerator: commandKeys[`tab:jump:${label.toLowerCase()}`]
}); });
} }

View file

@ -1,11 +1,10 @@
const ms = require('ms'); import ms from 'ms';
const fetch = require('electron-fetch').default; import fetch from 'electron-fetch';
import {version} from './package';
const {version} = require('./package');
const NEWS_URL = 'https://hyper-news.now.sh'; const NEWS_URL = 'https://hyper-news.now.sh';
module.exports = function fetchNotifications(win) { export default function fetchNotifications(win) {
const {rpc} = win; const {rpc} = win;
const retry = err => { const retry = err => {
setTimeout(() => fetchNotifications(win), ms('30m')); setTimeout(() => fetchNotifications(win), ms('30m'));
@ -38,4 +37,4 @@ module.exports = function fetchNotifications(win) {
retry(); retry();
}) })
.catch(retry); .catch(retry);
}; }

View file

@ -1,7 +1,6 @@
const {resolve} = require('path'); import {resolve} from 'path';
import {app, BrowserWindow} from 'electron';
const {app, BrowserWindow} = require('electron'); import isDev from 'electron-is-dev';
const isDev = require('electron-is-dev');
let win; let win;
@ -19,7 +18,7 @@ app.on('ready', () => {
nodeIntegration: true nodeIntegration: true
} }
}); });
const url = 'file://' + resolve(isDev ? __dirname : app.getAppPath(), 'notify.html'); const url = `file://${resolve(isDev ? __dirname : app.getAppPath(), 'notify.html')}`;
win_.loadURL(url); win_.loadURL(url);
win_.webContents.on('dom-ready', () => { win_.webContents.on('dom-ready', () => {
win = win_; win = win_;
@ -44,4 +43,4 @@ function notify(title, body, details = {}) {
} }
} }
module.exports = notify; export default notify;

View file

@ -1,18 +1,16 @@
const {app, dialog} = require('electron'); import {app, dialog} from 'electron';
const {resolve, basename} = require('path'); import {resolve, basename} from 'path';
const {writeFileSync} = require('fs'); import {writeFileSync} from 'fs';
const Config = require('electron-store'); import Config from 'electron-store';
const ms = require('ms'); import ms from 'ms';
import React from 'react';
const React = require('react'); import ReactDom from 'react-dom';
const ReactDom = require('react-dom'); import * as config from './config';
import notify from './notify';
const config = require('./config'); import {availableExtensions} from './plugins/extensions';
const notify = require('./notify'); import {install} from './plugins/install';
const {availableExtensions} = require('./plugins/extensions'); import {plugs} from './config/paths';
const {install} = require('./plugins/install'); import mapKeys from './utils/map-keys';
const {plugs} = require('./config/paths');
const mapKeys = require('./utils/map-keys');
// local storage // local storage
const cache = new Config(); const cache = new Config();
@ -165,9 +163,9 @@ function clearCache() {
} }
} }
exports.updatePlugins = updatePlugins; export {updatePlugins};
exports.getLoadedPluginVersions = () => { export const getLoadedPluginVersions = () => {
return modules.map(mod => ({name: mod._name, version: mod._version})); return modules.map(mod => ({name: mod._name, version: mod._version}));
}; };
@ -239,7 +237,7 @@ function toDependencies(plugins_) {
return obj; return obj;
} }
exports.subscribe = fn => { export const subscribe = fn => {
watchers.push(fn); watchers.push(fn);
return () => { return () => {
watchers.splice(watchers.indexOf(fn), 1); watchers.splice(watchers.indexOf(fn), 1);
@ -258,10 +256,10 @@ function getPaths() {
} }
// expose to renderer // expose to renderer
exports.getPaths = getPaths; export {getPaths};
// get paths from renderer // get paths from renderer
exports.getBasePaths = () => { export const getBasePaths = () => {
return {path, localPath}; return {path, localPath};
}; };
@ -274,7 +272,7 @@ function requirePlugins() {
mod = require(path_); mod = require(path_);
const exposed = mod && Object.keys(mod).some(key => availableExtensions.has(key)); const exposed = mod && Object.keys(mod).some(key => availableExtensions.has(key));
if (!exposed) { if (!exposed) {
notify('Plugin error!', `Plugin "${basename(path_)}" does not expose any ` + 'Hyper extension API methods'); notify('Plugin error!', `${`Plugin "${basename(path_)}" does not expose any `}Hyper extension API methods`);
return; return;
} }
@ -306,7 +304,7 @@ function requirePlugins() {
.filter(v => Boolean(v)); .filter(v => Boolean(v));
} }
exports.onApp = app_ => { export const onApp = app_ => {
modules.forEach(plugin => { modules.forEach(plugin => {
if (plugin.onApp) { if (plugin.onApp) {
try { try {
@ -320,7 +318,7 @@ exports.onApp = app_ => {
}); });
}; };
exports.onWindowClass = win => { export const onWindowClass = win => {
modules.forEach(plugin => { modules.forEach(plugin => {
if (plugin.onWindowClass) { if (plugin.onWindowClass) {
try { try {
@ -334,7 +332,7 @@ exports.onWindowClass = win => {
}); });
}; };
exports.onWindow = win => { export const onWindow = win => {
modules.forEach(plugin => { modules.forEach(plugin => {
if (plugin.onWindow) { if (plugin.onWindow) {
try { try {
@ -380,7 +378,7 @@ function decorateClass(base, key) {
return decorateEntity(base, key, 'function'); return decorateEntity(base, key, 'function');
} }
exports.getDeprecatedConfig = () => { export const getDeprecatedConfig = () => {
const deprecated = {}; const deprecated = {};
const baseConfig = config.getConfig(); const baseConfig = config.getConfig();
modules.forEach(plugin => { modules.forEach(plugin => {
@ -406,15 +404,15 @@ exports.getDeprecatedConfig = () => {
return deprecated; return deprecated;
}; };
exports.decorateMenu = tpl => { export const decorateMenu = tpl => {
return decorateObject(tpl, 'decorateMenu'); return decorateObject(tpl, 'decorateMenu');
}; };
exports.getDecoratedEnv = baseEnv => { export const getDecoratedEnv = baseEnv => {
return decorateObject(baseEnv, 'decorateEnv'); return decorateObject(baseEnv, 'decorateEnv');
}; };
exports.getDecoratedConfig = () => { export const getDecoratedConfig = () => {
const baseConfig = config.getConfig(); const baseConfig = config.getConfig();
const decoratedConfig = decorateObject(baseConfig, 'decorateConfig'); const decoratedConfig = decorateObject(baseConfig, 'decorateConfig');
const fixedConfig = config.fixConfigDefaults(decoratedConfig); const fixedConfig = config.fixConfigDefaults(decoratedConfig);
@ -422,27 +420,27 @@ exports.getDecoratedConfig = () => {
return translatedConfig; return translatedConfig;
}; };
exports.getDecoratedKeymaps = () => { export const getDecoratedKeymaps = () => {
const baseKeymaps = config.getKeymaps(); const baseKeymaps = config.getKeymaps();
// Ensure that all keys are in an array and don't use deprecated key combination` // Ensure that all keys are in an array and don't use deprecated key combination`
const decoratedKeymaps = mapKeys(decorateObject(baseKeymaps, 'decorateKeymaps')); const decoratedKeymaps = mapKeys(decorateObject(baseKeymaps, 'decorateKeymaps'));
return decoratedKeymaps; return decoratedKeymaps;
}; };
exports.getDecoratedBrowserOptions = defaults => { export const getDecoratedBrowserOptions = defaults => {
return decorateObject(defaults, 'decorateBrowserOptions'); return decorateObject(defaults, 'decorateBrowserOptions');
}; };
exports.decorateWindowClass = defaults => { export const decorateWindowClass = defaults => {
return decorateObject(defaults, 'decorateWindowClass'); return decorateObject(defaults, 'decorateWindowClass');
}; };
exports.decorateSessionOptions = defaults => { export const decorateSessionOptions = defaults => {
return decorateObject(defaults, 'decorateSessionOptions'); return decorateObject(defaults, 'decorateSessionOptions');
}; };
exports.decorateSessionClass = Session => { export const decorateSessionClass = Session => {
return decorateClass(Session, 'decorateSessionClass'); return decorateClass(Session, 'decorateSessionClass');
}; };
exports._toDependencies = toDependencies; export {toDependencies as _toDependencies};

View file

@ -1,44 +1,42 @@
module.exports = { export const availableExtensions = new Set([
availableExtensions: new Set([ 'onApp',
'onApp', 'onWindowClass',
'onWindowClass', 'decorateWindowClass',
'decorateWindowClass', 'onWindow',
'onWindow', 'onRendererWindow',
'onRendererWindow', 'onUnload',
'onUnload', 'decorateSessionClass',
'decorateSessionClass', 'decorateSessionOptions',
'decorateSessionOptions', 'middleware',
'middleware', 'reduceUI',
'reduceUI', 'reduceSessions',
'reduceSessions', 'reduceTermGroups',
'reduceTermGroups', 'decorateBrowserOptions',
'decorateBrowserOptions', 'decorateMenu',
'decorateMenu', 'decorateTerm',
'decorateTerm', 'decorateHyper',
'decorateHyper', 'decorateHyperTerm', // for backwards compatibility with hyperterm
'decorateHyperTerm', // for backwards compatibility with hyperterm 'decorateHeader',
'decorateHeader', 'decorateTerms',
'decorateTerms', 'decorateTab',
'decorateTab', 'decorateNotification',
'decorateNotification', 'decorateNotifications',
'decorateNotifications', 'decorateTabs',
'decorateTabs', 'decorateConfig',
'decorateConfig', 'decorateKeymaps',
'decorateKeymaps', 'decorateEnv',
'decorateEnv', 'decorateTermGroup',
'decorateTermGroup', 'decorateSplitPane',
'decorateSplitPane', 'getTermProps',
'getTermProps', 'getTabProps',
'getTabProps', 'getTabsProps',
'getTabsProps', 'getTermGroupProps',
'getTermGroupProps', 'mapHyperTermState',
'mapHyperTermState', 'mapTermsState',
'mapTermsState', 'mapHeaderState',
'mapHeaderState', 'mapNotificationsState',
'mapNotificationsState', 'mapHyperTermDispatch',
'mapHyperTermDispatch', 'mapTermsDispatch',
'mapTermsDispatch', 'mapHeaderDispatch',
'mapHeaderDispatch', 'mapNotificationsDispatch'
'mapNotificationsDispatch' ]);
])
};

View file

@ -1,9 +1,9 @@
const cp = require('child_process'); import cp from 'child_process';
const queue = require('queue'); import queue from 'queue';
const ms = require('ms'); import ms from 'ms';
const {yarn, plugs} = require('../config/paths'); import {yarn, plugs} from '../config/paths';
module.exports = { export default {
install: fn => { install: fn => {
const spawnQueue = queue({concurrency: 1}); const spawnQueue = queue({concurrency: 1});
function yarnFn(args, cb) { function yarnFn(args, cb) {

View file

@ -1,6 +1,6 @@
const {EventEmitter} = require('events'); import {EventEmitter} from 'events';
const {ipcMain} = require('electron'); import {ipcMain} from 'electron';
const uuid = require('uuid'); import uuid from 'uuid';
class Server extends EventEmitter { class Server extends EventEmitter {
constructor(win) { constructor(win) {
@ -53,6 +53,6 @@ class Server extends EventEmitter {
} }
} }
module.exports = win => { export default win => {
return new Server(win); return new Server(win);
}; };

View file

@ -1,11 +1,9 @@
const {EventEmitter} = require('events'); import {EventEmitter} from 'events';
const {StringDecoder} = require('string_decoder'); import {StringDecoder} from 'string_decoder';
import defaultShell from 'default-shell';
const defaultShell = require('default-shell'); import {getDecoratedEnv} from './plugins';
import {productName, version} from './package';
const {getDecoratedEnv} = require('./plugins'); import * as config from './config';
const {productName, version} = require('./package');
const config = require('./config');
const createNodePtyError = () => const createNodePtyError = () =>
new Error( new Error(
@ -74,7 +72,7 @@ class DataBatcher extends EventEmitter {
} }
} }
module.exports = class Session extends EventEmitter { export default class Session extends EventEmitter {
constructor(options) { constructor(options) {
super(); super();
this.pty = null; this.pty = null;
@ -90,7 +88,7 @@ module.exports = class Session extends EventEmitter {
{}, {},
process.env, process.env,
{ {
LANG: osLocale.sync().replace(/-/, '_') + '.UTF-8', LANG: `${osLocale.sync().replace(/-/, '_')}.UTF-8`,
TERM: 'xterm-256color', TERM: 'xterm-256color',
COLORTERM: 'truecolor', COLORTERM: 'truecolor',
TERM_PROGRAM: productName, TERM_PROGRAM: productName,
@ -194,4 +192,4 @@ module.exports = class Session extends EventEmitter {
this.emit('exit'); this.emit('exit');
this.ended = true; this.ended = true;
} }
}; }

View file

@ -1,4 +1,4 @@
const Registry = require('winreg'); import Registry from 'winreg';
const appPath = `"${process.execPath}"`; const appPath = `"${process.execPath}"`;
const regKey = `\\Software\\Classes\\Directory\\background\\shell\\Hyper`; const regKey = `\\Software\\Classes\\Directory\\background\\shell\\Hyper`;
@ -30,7 +30,7 @@ function addValues(hyperKey, commandKey, callback) {
}); });
} }
exports.add = callback => { export const add = callback => {
const hyperKey = new Registry({hive: 'HKCU', key: regKey}); const hyperKey = new Registry({hive: 'HKCU', key: regKey});
const commandKey = new Registry({ const commandKey = new Registry({
hive: 'HKCU', hive: 'HKCU',
@ -78,7 +78,7 @@ exports.add = callback => {
}); });
}; };
exports.remove = callback => { export const remove = callback => {
new Registry({hive: 'HKCU', key: regKey}).destroy(err => { new Registry({hive: 'HKCU', key: regKey}).destroy(err => {
if (err) { if (err) {
//eslint-disable-next-line no-console //eslint-disable-next-line no-console

View file

@ -1,7 +1,7 @@
const editMenu = require('../menus/menus/edit'); import editMenu from '../menus/menus/edit';
const shellMenu = require('../menus/menus/shell'); import shellMenu from '../menus/menus/shell';
const {execCommand} = require('../commands'); import {execCommand} from '../commands';
const {getDecoratedKeymaps} = require('../plugins'); import {getDecoratedKeymaps} from '../plugins';
const separator = {type: 'separator'}; const separator = {type: 'separator'};
const getCommandKeys = keymaps => const getCommandKeys = keymaps =>
@ -19,7 +19,7 @@ const filterCutCopy = (selection, menuItem) => {
return menuItem; return menuItem;
}; };
module.exports = (createWindow, selection) => { export default (createWindow, selection) => {
const commandKeys = getCommandKeys(getDecoratedKeymaps()); const commandKeys = getCommandKeys(getDecoratedKeymaps());
const _shell = shellMenu(commandKeys, execCommand).submenu; const _shell = shellMenu(commandKeys, execCommand).submenu;
const _edit = editMenu(commandKeys, execCommand).submenu.filter(filterCutCopy.bind(null, selection)); const _edit = editMenu(commandKeys, execCommand).submenu.filter(filterCutCopy.bind(null, selection));

View file

@ -1,22 +1,22 @@
const {app, BrowserWindow, shell, Menu} = require('electron'); import {app, BrowserWindow, shell, Menu} from 'electron';
const {isAbsolute} = require('path'); import {isAbsolute} from 'path';
const {parse: parseUrl} = require('url'); import {parse as parseUrl} from 'url';
const uuid = require('uuid'); import uuid from 'uuid';
const fileUriToPath = require('file-uri-to-path'); import fileUriToPath from 'file-uri-to-path';
const isDev = require('electron-is-dev'); import isDev from 'electron-is-dev';
const updater = require('../updater'); import updater from '../updater';
const toElectronBackgroundColor = require('../utils/to-electron-background-color'); import toElectronBackgroundColor from '../utils/to-electron-background-color';
const {icon, cfgDir} = require('../config/paths'); import {icon, cfgDir} from '../config/paths';
const createRPC = require('../rpc'); import createRPC from '../rpc';
const notify = require('../notify'); import notify from '../notify';
const fetchNotifications = require('../notifications'); import fetchNotifications from '../notifications';
const Session = require('../session'); import Session from '../session';
const contextMenuTemplate = require('./contextmenu'); import contextMenuTemplate from './contextmenu';
const {execCommand} = require('../commands'); import {execCommand} from '../commands';
const {setRendererType, unsetRendererType} = require('../utils/renderer-utils'); import {setRendererType, unsetRendererType} from '../utils/renderer-utils';
const {decorateSessionOptions, decorateSessionClass} = require('../plugins'); import {decorateSessionOptions, decorateSessionClass} from '../plugins';
module.exports = class Window { export default class Window {
constructor(options_, cfg, fn) { constructor(options_, cfg, fn) {
const classOpts = Object.assign({uid: uuid.v4()}); const classOpts = Object.assign({uid: uuid.v4()});
app.plugins.decorateWindowClass(classOpts); app.plugins.decorateWindowClass(classOpts);
@ -313,4 +313,4 @@ module.exports = class Window {
return window; return window;
} }
}; }

View file

@ -1,13 +1,13 @@
// Packages // Packages
const electron = require('electron'); import electron from 'electron';
const {app} = electron; const {app} = electron;
const ms = require('ms'); import ms from 'ms';
const retry = require('async-retry'); import retry from 'async-retry';
// Utilities // Utilities
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const {version} = require('./package'); import {version} from './package';
const {getDecoratedConfig} = require('./plugins'); import {getDecoratedConfig} from './plugins';
const {platform} = process; const {platform} = process;
const isLinux = platform === 'linux'; const isLinux = platform === 'linux';
@ -28,7 +28,7 @@ const isCanary = updateChannel => updateChannel === 'canary';
async function init() { async function init() {
autoUpdater.on('error', (err, msg) => { autoUpdater.on('error', (err, msg) => {
//eslint-disable-next-line no-console //eslint-disable-next-line no-console
console.error('Error fetching updates', msg + ' (' + err.stack + ')'); console.error('Error fetching updates', `${msg} (${err.stack})`);
}); });
const config = await retry(async () => { const config = await retry(async () => {
@ -61,7 +61,7 @@ async function init() {
isInit = true; isInit = true;
} }
module.exports = win => { export default win => {
if (!isInit) { if (!isInit) {
init(); init();
} }

View file

@ -1,11 +1,9 @@
const pify = require('pify'); import pify from 'pify';
const fs = require('fs'); import fs from 'fs';
const path = require('path'); import path from 'path';
const Registry = require('winreg'); import Registry from 'winreg';
import notify from '../notify';
const notify = require('../notify'); import {cliScriptPath, cliLinkPath} from '../config/paths';
const {cliScriptPath, cliLinkPath} = require('../config/paths');
const readlink = pify(fs.readlink); const readlink = pify(fs.readlink);
const symlink = pify(fs.symlink); const symlink = pify(fs.symlink);
@ -87,7 +85,7 @@ const logNotify = (withNotification, ...args) => {
withNotification && notify(...args); withNotification && notify(...args);
}; };
exports.installCLI = withNotification => { export const installCLI = withNotification => {
if (process.platform === 'win32') { if (process.platform === 'win32') {
addBinToUserPath() addBinToUserPath()
.then(() => .then(() =>

View file

@ -11,7 +11,7 @@ const generatePrefixedCommand = (command, shortcuts) => {
return result; return result;
}; };
module.exports = config => { export default config => {
return Object.keys(config).reduce((keymap, command) => { return Object.keys(config).reduce((keymap, command) => {
if (!command) { if (!command) {
return; return;

View file

@ -12,8 +12,4 @@ function unsetRendererType(uid) {
delete rendererTypes[uid]; delete rendererTypes[uid];
} }
module.exports = { export {getRendererTypes, setRendererType, unsetRendererType};
getRendererTypes,
setRendererType,
unsetRendererType
};

View file

@ -13,12 +13,8 @@ module.exports = bgColor => {
// http://stackoverflow.com/a/11019879/1202488 // http://stackoverflow.com/a/11019879/1202488
const alphaHex = Math.round(color.alpha() * 255).toString(16); const alphaHex = Math.round(color.alpha() * 255).toString(16);
return ( return `#${alphaHex}${color
'#' + .hex()
alphaHex + .toString()
color .substr(1)}`;
.hex()
.toString()
.substr(1)
);
}; };

View file

@ -115,8 +115,8 @@ export default class SplitPane extends React.PureComponent {
{React.Children.map(children, (child, i) => { {React.Children.map(children, (child, i) => {
const style = { const style = {
// flexBasis doesn't work for the first horizontal pane, height need to be specified // flexBasis doesn't work for the first horizontal pane, height need to be specified
[sizeProperty]: sizes[i] * 100 + '%', [sizeProperty]: `${sizes[i] * 100}%`,
flexBasis: sizes[i] * 100 + '%', flexBasis: `${sizes[i] * 100}%`,
flexGrow: 0 flexGrow: 0
}; };
return [ return [

View file

@ -11,7 +11,7 @@ import terms from '../terms';
import processClipboard from '../utils/paste'; import processClipboard from '../utils/paste';
import SearchBox from './searchBox'; import SearchBox from './searchBox';
const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].indexOf(navigator.platform) >= 0; const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].includes(navigator.platform);
// map old hterm constants to xterm.js // map old hterm constants to xterm.js
const CURSOR_STYLES = { const CURSOR_STYLES = {

View file

@ -1,11 +1,11 @@
// Clear selection range of current selected term view // Clear selection range of current selected term view
// Fix event when terminal text is selected and keyboard action is invoked // Fix event when terminal text is selected and keyboard action is invoked
exports.clear = terminal => { export const clear = terminal => {
terminal.document_.getSelection().removeAllRanges(); terminal.document_.getSelection().removeAllRanges();
}; };
// Use selection extend upon dblclick // Use selection extend upon dblclick
exports.extend = terminal => { export const extend = terminal => {
const sel = terminal.document_.getSelection(); const sel = terminal.document_.getSelection();
// Test if focusNode exist and nodeName is #text // Test if focusNode exist and nodeName is #text
@ -19,7 +19,7 @@ exports.extend = terminal => {
// Fix a bug in ScrollPort selectAll behavior // Fix a bug in ScrollPort selectAll behavior
// Select all rows in the viewport // Select all rows in the viewport
exports.all = terminal => { export const all = terminal => {
const scrollPort = terminal.scrollPort_; const scrollPort = terminal.scrollPort_;
let firstRow; let firstRow;
let lastRow; let lastRow;