diff --git a/app/auto-updater-linux.js b/app/auto-updater-linux.js index 1257c206..d3b73dd1 100644 --- a/app/auto-updater-linux.js +++ b/app/auto-updater-linux.js @@ -1,7 +1,5 @@ -'use strict'; - -const fetch = require('electron-fetch').default; -const {EventEmitter} = require('events'); +import fetch from 'electron-fetch'; +import {EventEmitter} from 'events'; class AutoUpdater extends EventEmitter { quitAndInstall() { @@ -47,4 +45,4 @@ class AutoUpdater extends EventEmitter { } } -module.exports = new AutoUpdater(); +export default new AutoUpdater(); diff --git a/app/commands.js b/app/commands.js index 2cba5bca..a5e5acb6 100644 --- a/app/commands.js +++ b/app/commands.js @@ -1,7 +1,7 @@ -const {app, Menu} = require('electron'); -const {openConfig, getConfig} = require('./config'); -const {updatePlugins} = require('./plugins'); -const {installCLI} = require('./utils/cli-install'); +import {app, Menu} from 'electron'; +import {openConfig, getConfig} from './config'; +import {updatePlugins} from './plugins'; +import {installCLI} from './utils/cli-install'; const commands = { 'window:new': () => { @@ -125,7 +125,7 @@ const commands = { }; }); -exports.execCommand = (command, focusedWindow) => { +export const execCommand = (command, focusedWindow) => { const fn = commands[command]; if (fn) { fn(focusedWindow); diff --git a/app/config.js b/app/config.js index 6c2a80a3..1f2ce686 100644 --- a/app/config.js +++ b/app/config.js @@ -1,16 +1,16 @@ -const fs = require('fs'); -const notify = require('./notify'); -const {_import, getDefaultConfig} = require('./config/import'); -const _openConfig = require('./config/open'); -const win = require('./config/windows'); -const {cfgPath, cfgDir} = require('./config/paths'); -const {getColorMap} = require('./utils/colors'); +import fs from 'fs'; +import notify from './notify'; +import {_import, getDefaultConfig} from './config/import'; +import _openConfig from './config/open'; +import win from './config/windows'; +import {cfgPath, cfgDir} from './config/paths'; +import {getColorMap} from './utils/colors'; const watchers = []; let cfg = {}; let _watcher; -const _watch = function() { +const _watch = () => { if (_watcher) { return _watcher; } @@ -63,60 +63,60 @@ const _watch = function() { } }; -exports.subscribe = fn => { +export const subscribe = fn => { watchers.push(fn); return () => { watchers.splice(watchers.indexOf(fn), 1); }; }; -exports.getConfigDir = () => { +export const getConfigDir = () => { // expose config directory to load plugin from the right place return cfgDir; }; -exports.getConfig = () => { +export const getConfig = () => { return cfg.config; }; -exports.openConfig = () => { +export const openConfig = () => { return _openConfig(); }; -exports.getPlugins = () => { +export const getPlugins = () => { return { plugins: cfg.plugins, localPlugins: cfg.localPlugins }; }; -exports.getKeymaps = () => { +export const getKeymaps = () => { return cfg.keymaps; }; -exports.setup = () => { +export const setup = () => { cfg = _import(); _watch(); checkDeprecatedConfig(); }; -exports.getWin = win.get; -exports.winRecord = win.recordState; -exports.windowDefaults = win.defaults; +export const getWin = win.get; +export const winRecord = win.recordState; +export const windowDefaults = win.defaults; -const getDeprecatedCSS = function(config) { +const getDeprecatedCSS = config => { const deprecated = []; const deprecatedCSS = ['x-screen', 'x-row', 'cursor-node', '::selection']; 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); } }); return deprecated; }; -exports.getDeprecatedCSS = getDeprecatedCSS; +export {getDeprecatedCSS}; -const checkDeprecatedConfig = function() { +const checkDeprecatedConfig = () => { if (!cfg.config) { return; } @@ -128,7 +128,7 @@ const checkDeprecatedConfig = function() { notify('Configuration warning', `Your configuration uses some deprecated CSS classes (${deprecatedStr})`); }; -exports.fixConfigDefaults = decoratedConfig => { +export const fixConfigDefaults = decoratedConfig => { const defaultConfig = getDefaultConfig().config; decoratedConfig.colors = getColorMap(decoratedConfig.colors) || {}; // We must have default colors for xterm css. @@ -136,7 +136,7 @@ exports.fixConfigDefaults = decoratedConfig => { return decoratedConfig; }; -exports.htermConfigTranslate = config => { +export const htermConfigTranslate = config => { const cssReplacements = { 'x-screen x-row([ {.[])': '.xterm-rows > div$1', '.cursor-node([ {.[])': '.terminal-cursor$1', diff --git a/app/config/import.js b/app/config/import.js index 678dc3d6..0fd65668 100644 --- a/app/config/import.js +++ b/app/config/import.js @@ -1,16 +1,16 @@ -const {moveSync, copySync, existsSync, writeFileSync, readFileSync, lstatSync} = require('fs-extra'); -const {sync: mkdirpSync} = require('mkdirp'); -const {defaultCfg, cfgPath, legacyCfgPath, plugs, defaultPlatformKeyPath} = require('./paths'); -const {_init, _extractDefault} = require('./init'); -const notify = require('../notify'); +import {moveSync, copySync, existsSync, writeFileSync, readFileSync, lstatSync} from 'fs-extra'; +import {sync as mkdirpSync} from 'mkdirp'; +import {defaultCfg, cfgPath, legacyCfgPath, plugs, defaultPlatformKeyPath} from './paths'; +import {_init, _extractDefault} from './init'; +import notify from '../notify'; let defaultConfig; -const _write = function(path, data) { +const _write = (path, data) => { // 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 // 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'); }; const format = process.platform === 'win32' ? crlfify(data.toString()) : data; @@ -23,7 +23,7 @@ const saveAsBackup = src => { let attempt = 1; while (attempt < 100) { try { - const backupPath = src + '.backup' + (attempt === 1 ? '' : attempt); + const backupPath = `${src}.backup${attempt === 1 ? '' : attempt}`; moveSync(src, backupPath); return backupPath; } catch (e) { @@ -81,7 +81,7 @@ const migrateHyper2Config = () => { ); }; -const _importConf = function() { +const _importConf = () => { // init plugin directories if not present mkdirpSync(plugs.base); mkdirpSync(plugs.local); @@ -120,14 +120,14 @@ const _importConf = function() { } }; -exports._import = () => { +export const _import = () => { const imported = _importConf(); defaultConfig = imported.defaultCfg; const result = _init(imported); return result; }; -exports.getDefaultConfig = () => { +export const getDefaultConfig = () => { if (!defaultConfig) { defaultConfig = _extractDefault(_importConf().defaultCfg); } diff --git a/app/config/init.js b/app/config/init.js index 80373b92..c84d1f93 100644 --- a/app/config/init.js +++ b/app/config/init.js @@ -1,8 +1,8 @@ -const vm = require('vm'); -const notify = require('../notify'); -const mapKeys = require('../utils/map-keys'); +import vm from 'vm'; +import notify from '../notify'; +import mapKeys from '../utils/map-keys'; -const _extract = function(script) { +const _extract = script => { const module = {}; script.runInNewContext({module}); if (!module.exports) { @@ -11,7 +11,7 @@ const _extract = function(script) { return module.exports; }; -const _syntaxValidation = function(cfg) { +const _syntaxValidation = cfg => { try { return new vm.Script(cfg, {filename: '.hyper.js', displayErrors: true}); } catch (err) { @@ -19,12 +19,12 @@ const _syntaxValidation = function(cfg) { } }; -const _extractDefault = function(cfg) { +const _extractDefault = cfg => { return _extract(_syntaxValidation(cfg)); }; // init config -const _init = function(cfg) { +const _init = cfg => { const script = _syntaxValidation(cfg.userCfg); if (script) { const _cfg = _extract(script); @@ -42,7 +42,4 @@ const _init = function(cfg) { return cfg.defaultCfg; }; -module.exports = { - _init, - _extractDefault -}; +export {_init, _extractDefault}; diff --git a/app/config/open.js b/app/config/open.js index 1e15a58f..4352cabe 100644 --- a/app/config/open.js +++ b/app/config/open.js @@ -1,7 +1,6 @@ -const {shell} = require('electron'); -const {cfgPath} = require('./paths'); - -module.exports = () => Promise.resolve(shell.openItem(cfgPath)); +import {shell} from 'electron'; +import {cfgPath} from './paths'; +export default () => Promise.resolve(shell.openItem(cfgPath)); // 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. diff --git a/app/config/paths.js b/app/config/paths.js index 4364691c..2d59d913 100644 --- a/app/config/paths.js +++ b/app/config/paths.js @@ -1,9 +1,9 @@ // This module exports paths, names, and other metadata that is referenced -const {homedir} = require('os'); -const {app} = require('electron'); -const {statSync} = require('fs'); -const {resolve, join} = require('path'); -const isDev = require('electron-is-dev'); +import {homedir} from 'os'; +import {app} from 'electron'; +import {statSync} from 'fs'; +import {resolve, join} from 'path'; +import isDev from 'electron-is-dev'; const cfgFile = '.hyper.js'; const defaultCfgFile = 'config-default.js'; @@ -71,7 +71,7 @@ const defaultPlatformKeyPath = () => { } }; -module.exports = { +export { cfgDir, cfgPath, legacyCfgPath, diff --git a/app/config/windows.js b/app/config/windows.js index c56c683e..2706c500 100644 --- a/app/config/windows.js +++ b/app/config/windows.js @@ -1,4 +1,4 @@ -const Config = require('electron-store'); +import Config from 'electron-store'; const defaults = { windowPosition: [50, 50], @@ -8,7 +8,7 @@ const defaults = { // local storage const cfg = new Config({defaults}); -module.exports = { +export default { defaults, get() { const position = cfg.get('windowPosition'); diff --git a/app/index.js b/app/index.js index 666af8c7..49474b4e 100644 --- a/app/index.js +++ b/app/index.js @@ -1,7 +1,7 @@ // Print diagnostic information for a few arguments instead of running Hyper. if (['--help', '-v', '--version'].includes(process.argv[1])) { 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 console.log(`Hyper version ${version}`); //eslint-disable-next-line no-console @@ -45,23 +45,22 @@ if (process.platform === 'win32') { } // Native -const {resolve} = require('path'); +import {resolve} from 'path'; // Packages -const {app, BrowserWindow, Menu} = require('electron'); -const {gitDescribe} = require('git-describe'); -const isDev = require('electron-is-dev'); - -const config = require('./config'); +import {app, BrowserWindow, Menu} from 'electron'; +import {gitDescribe} from 'git-describe'; +import isDev from 'electron-is-dev'; +import * as config from './config'; // set up config config.setup(); -const plugins = require('./plugins'); -const {installCLI} = require('./utils/cli-install'); -const AppMenu = require('./menus/menu'); -const Window = require('./ui/window'); -const windowUtils = require('./utils/window-utils'); +import * as plugins from './plugins'; +import {installCLI} from './utils/cli-install'; +import * as AppMenu from './menus/menu'; +import Window from './ui/window'; +import * as windowUtils from './utils/window-utils'; const windowSet = new Set([]); @@ -100,7 +99,7 @@ if (isDev) { 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 console.log('electron will open', url); diff --git a/app/menus/menu.js b/app/menus/menu.js index d1ba6065..5eb7b820 100644 --- a/app/menus/menu.js +++ b/app/menus/menu.js @@ -1,26 +1,26 @@ // Packages -const {app, dialog, Menu} = require('electron'); +import {app, dialog, Menu} from 'electron'; // Utilities -const {getConfig} = require('../config'); -const {icon} = require('../config/paths'); -const viewMenu = require('./menus/view'); -const shellMenu = require('./menus/shell'); -const editMenu = require('./menus/edit'); -const pluginsMenu = require('./menus/plugins'); -const windowMenu = require('./menus/window'); -const helpMenu = require('./menus/help'); -const darwinMenu = require('./menus/darwin'); -const {getDecoratedKeymaps} = require('../plugins'); -const {execCommand} = require('../commands'); -const {getRendererTypes} = require('../utils/renderer-utils'); +import {getConfig} from '../config'; +import {icon} from '../config/paths'; +import viewMenu from './menus/view'; +import shellMenu from './menus/shell'; +import editMenu from './menus/edit'; +import pluginsMenu from './menus/plugins'; +import windowMenu from './menus/window'; +import helpMenu from './menus/help'; +import darwinMenu from './menus/darwin'; +import {getDecoratedKeymaps} from '../plugins'; +import {execCommand} from '../commands'; +import {getRendererTypes} from '../utils/renderer-utils'; const appName = app.getName(); const appVersion = app.getVersion(); let menu_ = []; -exports.createMenu = (createWindow, getLoadedPluginVersions) => { +export const createMenu = (createWindow, getLoadedPluginVersions) => { const config = getConfig(); // We take only first shortcut in array for each command const allCommandKeys = getDecoratedKeymaps(); @@ -69,7 +69,7 @@ exports.createMenu = (createWindow, getLoadedPluginVersions) => { return menu; }; -exports.buildMenu = template => { +export const buildMenu = template => { menu_ = Menu.buildFromTemplate(template); return menu_; }; diff --git a/app/menus/menus/darwin.js b/app/menus/menus/darwin.js index 5badbd8a..9e50b771 100644 --- a/app/menus/menus/darwin.js +++ b/app/menus/menus/darwin.js @@ -1,8 +1,8 @@ // This menu label is overrided by OSX to be the appName // 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 { label: `${app.getName()}`, submenu: [ diff --git a/app/menus/menus/edit.js b/app/menus/menus/edit.js index 0c017447..67aba6e6 100644 --- a/app/menus/menus/edit.js +++ b/app/menus/menus/edit.js @@ -1,4 +1,4 @@ -module.exports = (commandKeys, execCommand) => { +export default (commandKeys, execCommand) => { const submenu = [ { label: 'Undo', diff --git a/app/menus/menus/help.js b/app/menus/menus/help.js index 6f920c8c..c9ac4985 100644 --- a/app/menus/menus/help.js +++ b/app/menus/menus/help.js @@ -1,11 +1,10 @@ -const {release} = require('os'); -const {app, shell} = require('electron'); - -const {getConfig, getPlugins} = require('../../config'); +import {release} from 'os'; +import {app, shell} from 'electron'; +import {getConfig, getPlugins} from '../../config'; 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 = [ { label: `${app.getName()} Website`, diff --git a/app/menus/menus/plugins.js b/app/menus/menus/plugins.js index e252b2d2..2ca8702e 100644 --- a/app/menus/menus/plugins.js +++ b/app/menus/menus/plugins.js @@ -1,4 +1,4 @@ -module.exports = (commands, execCommand) => { +export default (commands, execCommand) => { return { label: 'Plugins', submenu: [ diff --git a/app/menus/menus/shell.js b/app/menus/menus/shell.js index c02af006..958f53f2 100644 --- a/app/menus/menus/shell.js +++ b/app/menus/menus/shell.js @@ -1,4 +1,4 @@ -module.exports = (commandKeys, execCommand) => { +export default (commandKeys, execCommand) => { const isMac = process.platform === 'darwin'; return { diff --git a/app/menus/menus/view.js b/app/menus/menus/view.js index 04d6df61..ff89e445 100644 --- a/app/menus/menus/view.js +++ b/app/menus/menus/view.js @@ -1,4 +1,4 @@ -module.exports = (commandKeys, execCommand) => { +export default (commandKeys, execCommand) => { return { label: 'View', submenu: [ diff --git a/app/menus/menus/window.js b/app/menus/menus/window.js index eefa97dc..4f9fb4cd 100644 --- a/app/menus/menus/window.js +++ b/app/menus/menus/window.js @@ -1,11 +1,11 @@ -module.exports = (commandKeys, execCommand) => { +export default (commandKeys, execCommand) => { // Generating tab:jump array const tabJump = []; for (let i = 1; i <= 9; i++) { // 9 is a special number because it means 'last' const label = i === 9 ? 'Last' : `${i}`; tabJump.push({ - label: label, + label, accelerator: commandKeys[`tab:jump:${label.toLowerCase()}`] }); } diff --git a/app/notifications.js b/app/notifications.js index c4efb4b6..0167489b 100644 --- a/app/notifications.js +++ b/app/notifications.js @@ -1,11 +1,10 @@ -const ms = require('ms'); -const fetch = require('electron-fetch').default; - -const {version} = require('./package'); +import ms from 'ms'; +import fetch from 'electron-fetch'; +import {version} from './package'; const NEWS_URL = 'https://hyper-news.now.sh'; -module.exports = function fetchNotifications(win) { +export default function fetchNotifications(win) { const {rpc} = win; const retry = err => { setTimeout(() => fetchNotifications(win), ms('30m')); @@ -38,4 +37,4 @@ module.exports = function fetchNotifications(win) { retry(); }) .catch(retry); -}; +} diff --git a/app/notify.js b/app/notify.js index 3383aa09..b003397f 100644 --- a/app/notify.js +++ b/app/notify.js @@ -1,7 +1,6 @@ -const {resolve} = require('path'); - -const {app, BrowserWindow} = require('electron'); -const isDev = require('electron-is-dev'); +import {resolve} from 'path'; +import {app, BrowserWindow} from 'electron'; +import isDev from 'electron-is-dev'; let win; @@ -19,7 +18,7 @@ app.on('ready', () => { 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_.webContents.on('dom-ready', () => { win = win_; @@ -44,4 +43,4 @@ function notify(title, body, details = {}) { } } -module.exports = notify; +export default notify; diff --git a/app/plugins.js b/app/plugins.js index cb2bcc72..98277929 100644 --- a/app/plugins.js +++ b/app/plugins.js @@ -1,18 +1,16 @@ -const {app, dialog} = require('electron'); -const {resolve, basename} = require('path'); -const {writeFileSync} = require('fs'); -const Config = require('electron-store'); -const ms = require('ms'); - -const React = require('react'); -const ReactDom = require('react-dom'); - -const config = require('./config'); -const notify = require('./notify'); -const {availableExtensions} = require('./plugins/extensions'); -const {install} = require('./plugins/install'); -const {plugs} = require('./config/paths'); -const mapKeys = require('./utils/map-keys'); +import {app, dialog} from 'electron'; +import {resolve, basename} from 'path'; +import {writeFileSync} from 'fs'; +import Config from 'electron-store'; +import ms from 'ms'; +import React from 'react'; +import ReactDom from 'react-dom'; +import * as config from './config'; +import notify from './notify'; +import {availableExtensions} from './plugins/extensions'; +import {install} from './plugins/install'; +import {plugs} from './config/paths'; +import mapKeys from './utils/map-keys'; // local storage 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})); }; @@ -239,7 +237,7 @@ function toDependencies(plugins_) { return obj; } -exports.subscribe = fn => { +export const subscribe = fn => { watchers.push(fn); return () => { watchers.splice(watchers.indexOf(fn), 1); @@ -258,10 +256,10 @@ function getPaths() { } // expose to renderer -exports.getPaths = getPaths; +export {getPaths}; // get paths from renderer -exports.getBasePaths = () => { +export const getBasePaths = () => { return {path, localPath}; }; @@ -274,7 +272,7 @@ function requirePlugins() { mod = require(path_); const exposed = mod && Object.keys(mod).some(key => availableExtensions.has(key)); 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; } @@ -306,7 +304,7 @@ function requirePlugins() { .filter(v => Boolean(v)); } -exports.onApp = app_ => { +export const onApp = app_ => { modules.forEach(plugin => { if (plugin.onApp) { try { @@ -320,7 +318,7 @@ exports.onApp = app_ => { }); }; -exports.onWindowClass = win => { +export const onWindowClass = win => { modules.forEach(plugin => { if (plugin.onWindowClass) { try { @@ -334,7 +332,7 @@ exports.onWindowClass = win => { }); }; -exports.onWindow = win => { +export const onWindow = win => { modules.forEach(plugin => { if (plugin.onWindow) { try { @@ -380,7 +378,7 @@ function decorateClass(base, key) { return decorateEntity(base, key, 'function'); } -exports.getDeprecatedConfig = () => { +export const getDeprecatedConfig = () => { const deprecated = {}; const baseConfig = config.getConfig(); modules.forEach(plugin => { @@ -406,15 +404,15 @@ exports.getDeprecatedConfig = () => { return deprecated; }; -exports.decorateMenu = tpl => { +export const decorateMenu = tpl => { return decorateObject(tpl, 'decorateMenu'); }; -exports.getDecoratedEnv = baseEnv => { +export const getDecoratedEnv = baseEnv => { return decorateObject(baseEnv, 'decorateEnv'); }; -exports.getDecoratedConfig = () => { +export const getDecoratedConfig = () => { const baseConfig = config.getConfig(); const decoratedConfig = decorateObject(baseConfig, 'decorateConfig'); const fixedConfig = config.fixConfigDefaults(decoratedConfig); @@ -422,27 +420,27 @@ exports.getDecoratedConfig = () => { return translatedConfig; }; -exports.getDecoratedKeymaps = () => { +export const getDecoratedKeymaps = () => { const baseKeymaps = config.getKeymaps(); // Ensure that all keys are in an array and don't use deprecated key combination` const decoratedKeymaps = mapKeys(decorateObject(baseKeymaps, 'decorateKeymaps')); return decoratedKeymaps; }; -exports.getDecoratedBrowserOptions = defaults => { +export const getDecoratedBrowserOptions = defaults => { return decorateObject(defaults, 'decorateBrowserOptions'); }; -exports.decorateWindowClass = defaults => { +export const decorateWindowClass = defaults => { return decorateObject(defaults, 'decorateWindowClass'); }; -exports.decorateSessionOptions = defaults => { +export const decorateSessionOptions = defaults => { return decorateObject(defaults, 'decorateSessionOptions'); }; -exports.decorateSessionClass = Session => { +export const decorateSessionClass = Session => { return decorateClass(Session, 'decorateSessionClass'); }; -exports._toDependencies = toDependencies; +export {toDependencies as _toDependencies}; diff --git a/app/plugins/extensions.js b/app/plugins/extensions.js index 1c124565..5fd3cdfe 100644 --- a/app/plugins/extensions.js +++ b/app/plugins/extensions.js @@ -1,44 +1,42 @@ -module.exports = { - availableExtensions: new Set([ - 'onApp', - 'onWindowClass', - 'decorateWindowClass', - 'onWindow', - 'onRendererWindow', - 'onUnload', - 'decorateSessionClass', - 'decorateSessionOptions', - 'middleware', - 'reduceUI', - 'reduceSessions', - 'reduceTermGroups', - 'decorateBrowserOptions', - 'decorateMenu', - 'decorateTerm', - 'decorateHyper', - 'decorateHyperTerm', // for backwards compatibility with hyperterm - 'decorateHeader', - 'decorateTerms', - 'decorateTab', - 'decorateNotification', - 'decorateNotifications', - 'decorateTabs', - 'decorateConfig', - 'decorateKeymaps', - 'decorateEnv', - 'decorateTermGroup', - 'decorateSplitPane', - 'getTermProps', - 'getTabProps', - 'getTabsProps', - 'getTermGroupProps', - 'mapHyperTermState', - 'mapTermsState', - 'mapHeaderState', - 'mapNotificationsState', - 'mapHyperTermDispatch', - 'mapTermsDispatch', - 'mapHeaderDispatch', - 'mapNotificationsDispatch' - ]) -}; +export const availableExtensions = new Set([ + 'onApp', + 'onWindowClass', + 'decorateWindowClass', + 'onWindow', + 'onRendererWindow', + 'onUnload', + 'decorateSessionClass', + 'decorateSessionOptions', + 'middleware', + 'reduceUI', + 'reduceSessions', + 'reduceTermGroups', + 'decorateBrowserOptions', + 'decorateMenu', + 'decorateTerm', + 'decorateHyper', + 'decorateHyperTerm', // for backwards compatibility with hyperterm + 'decorateHeader', + 'decorateTerms', + 'decorateTab', + 'decorateNotification', + 'decorateNotifications', + 'decorateTabs', + 'decorateConfig', + 'decorateKeymaps', + 'decorateEnv', + 'decorateTermGroup', + 'decorateSplitPane', + 'getTermProps', + 'getTabProps', + 'getTabsProps', + 'getTermGroupProps', + 'mapHyperTermState', + 'mapTermsState', + 'mapHeaderState', + 'mapNotificationsState', + 'mapHyperTermDispatch', + 'mapTermsDispatch', + 'mapHeaderDispatch', + 'mapNotificationsDispatch' +]); diff --git a/app/plugins/install.js b/app/plugins/install.js index 145365b9..78e7d587 100644 --- a/app/plugins/install.js +++ b/app/plugins/install.js @@ -1,9 +1,9 @@ -const cp = require('child_process'); -const queue = require('queue'); -const ms = require('ms'); -const {yarn, plugs} = require('../config/paths'); +import cp from 'child_process'; +import queue from 'queue'; +import ms from 'ms'; +import {yarn, plugs} from '../config/paths'; -module.exports = { +export default { install: fn => { const spawnQueue = queue({concurrency: 1}); function yarnFn(args, cb) { diff --git a/app/rpc.js b/app/rpc.js index e07b9eaf..e964d141 100644 --- a/app/rpc.js +++ b/app/rpc.js @@ -1,6 +1,6 @@ -const {EventEmitter} = require('events'); -const {ipcMain} = require('electron'); -const uuid = require('uuid'); +import {EventEmitter} from 'events'; +import {ipcMain} from 'electron'; +import uuid from 'uuid'; class Server extends EventEmitter { constructor(win) { @@ -53,6 +53,6 @@ class Server extends EventEmitter { } } -module.exports = win => { +export default win => { return new Server(win); }; diff --git a/app/session.js b/app/session.js index fac3b928..8397c8c8 100644 --- a/app/session.js +++ b/app/session.js @@ -1,11 +1,9 @@ -const {EventEmitter} = require('events'); -const {StringDecoder} = require('string_decoder'); - -const defaultShell = require('default-shell'); - -const {getDecoratedEnv} = require('./plugins'); -const {productName, version} = require('./package'); -const config = require('./config'); +import {EventEmitter} from 'events'; +import {StringDecoder} from 'string_decoder'; +import defaultShell from 'default-shell'; +import {getDecoratedEnv} from './plugins'; +import {productName, version} from './package'; +import * as config from './config'; const createNodePtyError = () => new Error( @@ -74,7 +72,7 @@ class DataBatcher extends EventEmitter { } } -module.exports = class Session extends EventEmitter { +export default class Session extends EventEmitter { constructor(options) { super(); this.pty = null; @@ -90,7 +88,7 @@ module.exports = class Session extends EventEmitter { {}, process.env, { - LANG: osLocale.sync().replace(/-/, '_') + '.UTF-8', + LANG: `${osLocale.sync().replace(/-/, '_')}.UTF-8`, TERM: 'xterm-256color', COLORTERM: 'truecolor', TERM_PROGRAM: productName, @@ -194,4 +192,4 @@ module.exports = class Session extends EventEmitter { this.emit('exit'); this.ended = true; } -}; +} diff --git a/app/system-context-menu.js b/app/system-context-menu.js index 4d2eb08e..06b1b6e7 100644 --- a/app/system-context-menu.js +++ b/app/system-context-menu.js @@ -1,4 +1,4 @@ -const Registry = require('winreg'); +import Registry from 'winreg'; const appPath = `"${process.execPath}"`; 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 commandKey = new Registry({ hive: 'HKCU', @@ -78,7 +78,7 @@ exports.add = callback => { }); }; -exports.remove = callback => { +export const remove = callback => { new Registry({hive: 'HKCU', key: regKey}).destroy(err => { if (err) { //eslint-disable-next-line no-console diff --git a/app/ui/contextmenu.js b/app/ui/contextmenu.js index 6817d949..481e130f 100644 --- a/app/ui/contextmenu.js +++ b/app/ui/contextmenu.js @@ -1,7 +1,7 @@ -const editMenu = require('../menus/menus/edit'); -const shellMenu = require('../menus/menus/shell'); -const {execCommand} = require('../commands'); -const {getDecoratedKeymaps} = require('../plugins'); +import editMenu from '../menus/menus/edit'; +import shellMenu from '../menus/menus/shell'; +import {execCommand} from '../commands'; +import {getDecoratedKeymaps} from '../plugins'; const separator = {type: 'separator'}; const getCommandKeys = keymaps => @@ -19,7 +19,7 @@ const filterCutCopy = (selection, menuItem) => { return menuItem; }; -module.exports = (createWindow, selection) => { +export default (createWindow, selection) => { const commandKeys = getCommandKeys(getDecoratedKeymaps()); const _shell = shellMenu(commandKeys, execCommand).submenu; const _edit = editMenu(commandKeys, execCommand).submenu.filter(filterCutCopy.bind(null, selection)); diff --git a/app/ui/window.js b/app/ui/window.js index 96815e62..9f830f67 100644 --- a/app/ui/window.js +++ b/app/ui/window.js @@ -1,22 +1,22 @@ -const {app, BrowserWindow, shell, Menu} = require('electron'); -const {isAbsolute} = require('path'); -const {parse: parseUrl} = require('url'); -const uuid = require('uuid'); -const fileUriToPath = require('file-uri-to-path'); -const isDev = require('electron-is-dev'); -const updater = require('../updater'); -const toElectronBackgroundColor = require('../utils/to-electron-background-color'); -const {icon, cfgDir} = require('../config/paths'); -const createRPC = require('../rpc'); -const notify = require('../notify'); -const fetchNotifications = require('../notifications'); -const Session = require('../session'); -const contextMenuTemplate = require('./contextmenu'); -const {execCommand} = require('../commands'); -const {setRendererType, unsetRendererType} = require('../utils/renderer-utils'); -const {decorateSessionOptions, decorateSessionClass} = require('../plugins'); +import {app, BrowserWindow, shell, Menu} from 'electron'; +import {isAbsolute} from 'path'; +import {parse as parseUrl} from 'url'; +import uuid from 'uuid'; +import fileUriToPath from 'file-uri-to-path'; +import isDev from 'electron-is-dev'; +import updater from '../updater'; +import toElectronBackgroundColor from '../utils/to-electron-background-color'; +import {icon, cfgDir} from '../config/paths'; +import createRPC from '../rpc'; +import notify from '../notify'; +import fetchNotifications from '../notifications'; +import Session from '../session'; +import contextMenuTemplate from './contextmenu'; +import {execCommand} from '../commands'; +import {setRendererType, unsetRendererType} from '../utils/renderer-utils'; +import {decorateSessionOptions, decorateSessionClass} from '../plugins'; -module.exports = class Window { +export default class Window { constructor(options_, cfg, fn) { const classOpts = Object.assign({uid: uuid.v4()}); app.plugins.decorateWindowClass(classOpts); @@ -313,4 +313,4 @@ module.exports = class Window { return window; } -}; +} diff --git a/app/updater.js b/app/updater.js index 27382eef..c7766529 100644 --- a/app/updater.js +++ b/app/updater.js @@ -1,13 +1,13 @@ // Packages -const electron = require('electron'); +import electron from 'electron'; const {app} = electron; -const ms = require('ms'); -const retry = require('async-retry'); +import ms from 'ms'; +import retry from 'async-retry'; // Utilities // eslint-disable-next-line no-unused-vars -const {version} = require('./package'); -const {getDecoratedConfig} = require('./plugins'); +import {version} from './package'; +import {getDecoratedConfig} from './plugins'; const {platform} = process; const isLinux = platform === 'linux'; @@ -28,7 +28,7 @@ const isCanary = updateChannel => updateChannel === 'canary'; async function init() { autoUpdater.on('error', (err, msg) => { //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 () => { @@ -61,7 +61,7 @@ async function init() { isInit = true; } -module.exports = win => { +export default win => { if (!isInit) { init(); } diff --git a/app/utils/cli-install.js b/app/utils/cli-install.js index 606022cf..f0da9f54 100644 --- a/app/utils/cli-install.js +++ b/app/utils/cli-install.js @@ -1,11 +1,9 @@ -const pify = require('pify'); -const fs = require('fs'); -const path = require('path'); -const Registry = require('winreg'); - -const notify = require('../notify'); - -const {cliScriptPath, cliLinkPath} = require('../config/paths'); +import pify from 'pify'; +import fs from 'fs'; +import path from 'path'; +import Registry from 'winreg'; +import notify from '../notify'; +import {cliScriptPath, cliLinkPath} from '../config/paths'; const readlink = pify(fs.readlink); const symlink = pify(fs.symlink); @@ -87,7 +85,7 @@ const logNotify = (withNotification, ...args) => { withNotification && notify(...args); }; -exports.installCLI = withNotification => { +export const installCLI = withNotification => { if (process.platform === 'win32') { addBinToUserPath() .then(() => diff --git a/app/utils/map-keys.js b/app/utils/map-keys.js index c5f99fb5..aac64ceb 100644 --- a/app/utils/map-keys.js +++ b/app/utils/map-keys.js @@ -11,7 +11,7 @@ const generatePrefixedCommand = (command, shortcuts) => { return result; }; -module.exports = config => { +export default config => { return Object.keys(config).reduce((keymap, command) => { if (!command) { return; diff --git a/app/utils/renderer-utils.js b/app/utils/renderer-utils.js index 7385b484..7ea6b643 100644 --- a/app/utils/renderer-utils.js +++ b/app/utils/renderer-utils.js @@ -12,8 +12,4 @@ function unsetRendererType(uid) { delete rendererTypes[uid]; } -module.exports = { - getRendererTypes, - setRendererType, - unsetRendererType -}; +export {getRendererTypes, setRendererType, unsetRendererType}; diff --git a/app/utils/to-electron-background-color.js b/app/utils/to-electron-background-color.js index 053abbae..6612bf68 100644 --- a/app/utils/to-electron-background-color.js +++ b/app/utils/to-electron-background-color.js @@ -13,12 +13,8 @@ module.exports = bgColor => { // http://stackoverflow.com/a/11019879/1202488 const alphaHex = Math.round(color.alpha() * 255).toString(16); - return ( - '#' + - alphaHex + - color - .hex() - .toString() - .substr(1) - ); + return `#${alphaHex}${color + .hex() + .toString() + .substr(1)}`; }; diff --git a/lib/components/split-pane.js b/lib/components/split-pane.js index ff555f5c..e3d8fa0d 100644 --- a/lib/components/split-pane.js +++ b/lib/components/split-pane.js @@ -115,8 +115,8 @@ export default class SplitPane extends React.PureComponent { {React.Children.map(children, (child, i) => { const style = { // flexBasis doesn't work for the first horizontal pane, height need to be specified - [sizeProperty]: sizes[i] * 100 + '%', - flexBasis: sizes[i] * 100 + '%', + [sizeProperty]: `${sizes[i] * 100}%`, + flexBasis: `${sizes[i] * 100}%`, flexGrow: 0 }; return [ diff --git a/lib/components/term.js b/lib/components/term.js index 43a7c068..252811ac 100644 --- a/lib/components/term.js +++ b/lib/components/term.js @@ -11,7 +11,7 @@ import terms from '../terms'; import processClipboard from '../utils/paste'; 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 const CURSOR_STYLES = { diff --git a/lib/utils/selection.js b/lib/utils/selection.js index 35c5a560..13c001e2 100644 --- a/lib/utils/selection.js +++ b/lib/utils/selection.js @@ -1,11 +1,11 @@ // Clear selection range of current selected term view // Fix event when terminal text is selected and keyboard action is invoked -exports.clear = terminal => { +export const clear = terminal => { terminal.document_.getSelection().removeAllRanges(); }; // Use selection extend upon dblclick -exports.extend = terminal => { +export const extend = terminal => { const sel = terminal.document_.getSelection(); // Test if focusNode exist and nodeName is #text @@ -19,7 +19,7 @@ exports.extend = terminal => { // Fix a bug in ScrollPort selectAll behavior // Select all rows in the viewport -exports.all = terminal => { +export const all = terminal => { const scrollPort = terminal.scrollPort_; let firstRow; let lastRow;