diff --git a/app/config/import.js b/app/config/import.js index 3f18678c..4032a2da 100644 --- a/app/config/import.js +++ b/app/config/import.js @@ -1,5 +1,6 @@ const {writeFileSync, readFileSync} = require('fs'); -const {defaultCfg, cfgPath} = require('./paths'); +const {sync: mkdirpSync} = require('mkdirp'); +const {defaultCfg, cfgPath, plugs} = require('./paths'); const _init = require('./init'); const _keymaps = require('./keymaps'); @@ -15,6 +16,10 @@ const _write = function (path, data) { }; const _importConf = function () { + // init plugin directories if not present + mkdirpSync(plugs.base); + mkdirpSync(plugs.local); + try { const _defaultCfg = readFileSync(defaultCfg, 'utf8'); try { diff --git a/app/config/paths.js b/app/config/paths.js index 60cf52d2..596ecca1 100644 --- a/app/config/paths.js +++ b/app/config/paths.js @@ -15,6 +15,14 @@ const devDir = resolve(__dirname, '../..'); const devCfg = join(devDir, cfgFile); const defaultCfg = resolve(__dirname, defaultCfgFile); +const plugins = resolve(cfgDir, '.hyper_plugins'); +const plugs = { + base: plugins, + local: resolve(plugins, 'local'), + cache: resolve(plugins, 'cache') +}; +const yarn = resolve(__dirname, '../../bin/yarn-standalone.js'); + const icon = resolve(__dirname, '../static/icon.png'); const keymapPath = resolve(__dirname, '../keymaps'); @@ -44,5 +52,5 @@ if (isDev) { } module.exports = { - cfgDir, cfgPath, cfgFile, defaultCfg, icon, defaultPlatformKeyPath + cfgDir, cfgPath, cfgFile, defaultCfg, icon, defaultPlatformKeyPath, plugs, yarn }; diff --git a/app/plugins.js b/app/plugins.js index 9c3b8a2d..10d57cc5 100644 --- a/app/plugins.js +++ b/app/plugins.js @@ -1,45 +1,21 @@ const {app, dialog} = require('electron'); const {resolve, basename} = require('path'); const {writeFileSync} = require('fs'); -const cp = require('child_process'); -const {sync: mkdirpSync} = require('mkdirp'); const Config = require('electron-config'); const ms = require('ms'); -const queue = require('queue'); - -const spawnQueue = queue({concurrency: 1}); const config = require('./config'); const notify = require('./notify'); const _keys = require('./config/keymaps'); +const {availableExtensions} = require('./plugins/extensions'); +const {install} = require('./plugins/install'); +const {plugs} = require('./config/paths'); // local storage const cache = new Config(); -// modules path -const path = resolve(config.getConfigDir(), '.hyper_plugins'); -const localPath = resolve(path, 'local'); -const cachePath = resolve(path, 'cache'); -const availableExtensions = new Set([ - 'onApp', 'onWindow', 'onRendererWindow', 'onUnload', 'middleware', - 'reduceUI', 'reduceSessions', 'reduceTermGroups', - 'decorateMenu', 'decorateTerm', 'decorateHyper', - 'decorateHyperTerm', // for backwards compatibility with hyperterm - 'decorateHeader', 'decorateTerms', 'decorateTab', - 'decorateNotification', 'decorateNotifications', - 'decorateTabs', 'decorateConfig', 'decorateEnv', - 'decorateTermGroup', 'decorateSplitPane', 'getTermProps', - 'getTabProps', 'getTabsProps', 'getTermGroupProps', - 'mapHyperTermState', 'mapTermsState', - 'mapHeaderState', 'mapNotificationsState', - 'mapHyperTermDispatch', 'mapTermsDispatch', - 'mapHeaderDispatch', 'mapNotificationsDispatch', - 'extendKeymaps' -]); - -// init plugin directories if not present -mkdirpSync(path); -mkdirpSync(localPath); +const path = plugs.base; +const localPath = plugs.local; // caches let plugins = config.getPlugins(); @@ -222,47 +198,6 @@ function toDependencies(plugins) { return obj; } -function install(fn) { - function yarn(args, cb) { - const yarnPath = resolve(__dirname, '..', 'bin', 'yarn-standalone.js'); - const env = { - NODE_ENV: 'production', - ELECTRON_RUN_AS_NODE: 'true' - }; - - spawnQueue.push(end => { - const cmd = [process.execPath, yarnPath].concat(args).join(' '); - console.log('Launching yarn:', cmd); - - cp.exec(cmd, { - cwd: path, - env, - shell: true, - timeout: ms('5m'), - stdio: ['ignore', 'ignore', 'inherit'] - }, err => { - if (err) { - cb(err); - } else { - cb(null); - } - - end(); - spawnQueue.start(); - }); - }); - - spawnQueue.start(); - } - - yarn(['install', '--no-emoji', '--no-lockfile', '--cache-folder', cachePath], err => { - if (err) { - return fn(err); - } - fn(null); - }); -} - exports.subscribe = function (fn) { watchers.push(fn); return () => { diff --git a/app/plugins/extensions.js b/app/plugins/extensions.js new file mode 100644 index 00000000..7cbefb04 --- /dev/null +++ b/app/plugins/extensions.js @@ -0,0 +1,18 @@ +module.exports = { + availableExtensions: new Set([ + 'onApp', 'onWindow', 'onRendererWindow', 'onUnload', 'middleware', + 'reduceUI', 'reduceSessions', 'reduceTermGroups', + 'decorateMenu', 'decorateTerm', 'decorateHyper', + 'decorateHyperTerm', // for backwards compatibility with hyperterm + 'decorateHeader', 'decorateTerms', 'decorateTab', + 'decorateNotification', 'decorateNotifications', + 'decorateTabs', 'decorateConfig', 'decorateEnv', + 'decorateTermGroup', 'decorateSplitPane', 'getTermProps', + 'getTabProps', 'getTabsProps', 'getTermGroupProps', + 'mapHyperTermState', 'mapTermsState', + 'mapHeaderState', 'mapNotificationsState', + 'mapHyperTermDispatch', 'mapTermsDispatch', + 'mapHeaderDispatch', 'mapNotificationsDispatch', + 'extendKeymaps' + ]) +}; diff --git a/app/plugins/install.js b/app/plugins/install.js new file mode 100644 index 00000000..da322fbb --- /dev/null +++ b/app/plugins/install.js @@ -0,0 +1,46 @@ +const cp = require('child_process'); +const queue = require('queue'); +const ms = require('ms'); +const {yarn, plugs} = require('../config/paths'); + +module.exports = { + install: fn => { + const spawnQueue = queue({concurrency: 1}); + function yarnFn(args, cb) { + const env = { + NODE_ENV: 'production', + ELECTRON_RUN_AS_NODE: 'true' + }; + spawnQueue.push(end => { + const cmd = [process.execPath, yarn].concat(args).join(' '); + console.log('Launching yarn:', cmd); + + cp.exec(cmd, { + cwd: plugs.base, + env, + shell: true, + timeout: ms('5m'), + stdio: ['ignore', 'ignore', 'inherit'] + }, err => { + if (err) { + cb(err); + } else { + cb(null); + } + + end(); + spawnQueue.start(); + }); + }); + + spawnQueue.start(); + } + + yarnFn(['install', '--no-emoji', '--no-lockfile', '--cache-folder', plugs.cache], err => { + if (err) { + return fn(err); + } + fn(null); + }); + } +};