diff --git a/src/ui/UiApp.js b/src/ui/UiApp.js index 4e6fcaa36ef80..8967b528228d6 100644 --- a/src/ui/UiApp.js +++ b/src/ui/UiApp.js @@ -1,6 +1,6 @@ -var _ = require('lodash'); +const _ = require('lodash'); var { join } = require('path'); -var autoload = require('./autoload'); +const autoload = require('./autoload'); class UiApp { constructor(uiExports, spec) { diff --git a/src/ui/UiAppCollection.js b/src/ui/UiAppCollection.js index e4eda77fb0ede..79456e57773d2 100644 --- a/src/ui/UiAppCollection.js +++ b/src/ui/UiAppCollection.js @@ -1,8 +1,8 @@ -let _ = require('lodash'); -let UiApp = require('./UiApp'); -let Collection = require('requirefrom')('src')('utils/Collection'); +const _ = require('lodash'); +const UiApp = require('./UiApp'); +const Collection = require('requirefrom')('src')('utils/Collection'); -let byIdCache = Symbol('byId'); +const byIdCache = Symbol('byId'); module.exports = class UiAppCollection extends Collection { @@ -25,7 +25,7 @@ module.exports = class UiAppCollection extends Collection { return this.hidden.new(spec); } - let app = new UiApp(this.uiExports, spec); + const app = new UiApp(this.uiExports, spec); if (_.includes(this.claimedIds, app.id)) { throw new Error('Unable to create two apps with the id ' + app.id + '.'); diff --git a/src/ui/UiBundle.js b/src/ui/UiBundle.js index b610c24b7b4d0..0a37e38e03cf1 100644 --- a/src/ui/UiBundle.js +++ b/src/ui/UiBundle.js @@ -1,10 +1,10 @@ let { join } = require('path'); let { promisify } = require('bluebird'); -let read = promisify(require('fs').readFile); -let write = promisify(require('fs').writeFile); -let unlink = promisify(require('fs').unlink); -let stat = promisify(require('fs').stat); +const read = promisify(require('fs').readFile); +const write = promisify(require('fs').writeFile); +const unlink = promisify(require('fs').unlink); +const stat = promisify(require('fs').stat); module.exports = class UiBundle { constructor(opts) { @@ -15,7 +15,7 @@ module.exports = class UiBundle { this.template = opts.template; this.env = opts.env; - let pathBase = join(this.env.workingDir, this.id); + const pathBase = join(this.env.workingDir, this.id); this.entryPath = `${pathBase}.entry.js`; this.outputPath = `${pathBase}.bundle.js`; @@ -30,7 +30,7 @@ module.exports = class UiBundle { async readEntryFile() { try { - let content = await read(this.entryPath); + const content = await read(this.entryPath); return content.toString('utf8'); } catch (e) { diff --git a/src/ui/UiBundleCollection.js b/src/ui/UiBundleCollection.js index 328c03dad1568..e2083f0f7444b 100644 --- a/src/ui/UiBundleCollection.js +++ b/src/ui/UiBundleCollection.js @@ -2,14 +2,14 @@ let { pull, transform, pluck } = require('lodash'); let { join } = require('path'); let { resolve, promisify } = require('bluebird'); let { makeRe } = require('minimatch'); -let rimraf = promisify(require('rimraf')); -let mkdirp = promisify(require('mkdirp')); -let unlink = promisify(require('fs').unlink); -let readdir = promisify(require('fs').readdir); -let readSync = require('fs').readFileSync; +const rimraf = promisify(require('rimraf')); +const mkdirp = promisify(require('mkdirp')); +const unlink = promisify(require('fs').unlink); +const readdir = promisify(require('fs').readdir); +const readSync = require('fs').readFileSync; -let UiBundle = require('./UiBundle'); -let appEntryTemplate = require('./appEntryTemplate'); +const UiBundle = require('./UiBundle'); +const appEntryTemplate = require('./appEntryTemplate'); class UiBundleCollection { constructor(bundlerEnv, filter) { @@ -48,9 +48,9 @@ class UiBundleCollection { case 1: return `bundle for ${this.each[0].id}`; default: - var ids = this.getIds(); - var last = ids.pop(); - var commas = ids.join(', '); + const ids = this.getIds(); + const last = ids.pop(); + const commas = ids.join(', '); return `bundles for ${commas} and ${last}`; } } @@ -63,8 +63,8 @@ class UiBundleCollection { await this.ensureDir(); for (let bundle of this.each) { - let existing = await bundle.readEntryFile(); - let expected = bundle.renderContent(); + const existing = await bundle.readEntryFile(); + const expected = bundle.renderContent(); if (existing !== expected) { await bundle.writeEntryFile(); @@ -74,10 +74,10 @@ class UiBundleCollection { } async getInvalidBundles() { - let invalids = new UiBundleCollection(this.env); + const invalids = new UiBundleCollection(this.env); for (let bundle of this.each) { - let exists = await bundle.checkForExistingOutput(); + const exists = await bundle.checkForExistingOutput(); if (!exists) { invalids.add(bundle); } diff --git a/src/ui/UiBundlerEnv.js b/src/ui/UiBundlerEnv.js index 74a2195d152c5..d01e8cdcd4eb4 100644 --- a/src/ui/UiBundlerEnv.js +++ b/src/ui/UiBundlerEnv.js @@ -1,12 +1,12 @@ let { includes, flow, escapeRegExp } = require('lodash'); let { isString, isArray, isPlainObject, get } = require('lodash'); let { keys } = require('lodash'); -let fromRoot = require('../utils/fromRoot'); +const fromRoot = require('../utils/fromRoot'); -let asRegExp = flow( +const asRegExp = flow( escapeRegExp, function (path) { - let last = path.slice(-1); + const last = path.slice(-1); if (last === '/' || last === '\\') { // match a directory explicitly return path + '.*'; @@ -18,7 +18,7 @@ let asRegExp = flow( RegExp ); -let arr = v => [].concat(v || []); +const arr = v => [].concat(v || []); module.exports = class UiBundlerEnv { constructor(workingDir) { @@ -58,7 +58,7 @@ module.exports = class UiBundlerEnv { } consumePlugin(plugin) { - let tag = `${plugin.id}@${plugin.version}`; + const tag = `${plugin.id}@${plugin.version}`; if (includes(this.pluginInfo, tag)) return; if (plugin.publicDir) { @@ -141,7 +141,7 @@ module.exports = class UiBundlerEnv { this.aliases[id] = path; - let loader = []; + const loader = []; if (imports) { loader.push(`imports?${imports}`); } @@ -153,10 +153,10 @@ module.exports = class UiBundlerEnv { } claim(id, pluginId) { - let owner = pluginId ? `Plugin ${pluginId}` : 'Kibana Server'; + const owner = pluginId ? `Plugin ${pluginId}` : 'Kibana Server'; // TODO(spalger): we could do a lot more to detect colliding module defs - var existingOwner = this.aliasOwners[id] || this.aliasOwners[`${id}$`]; + const existingOwner = this.aliasOwners[id] || this.aliasOwners[`${id}$`]; if (existingOwner) { throw new TypeError(`${owner} attempted to override export "${id}" from ${existingOwner}`); diff --git a/src/ui/UiExports.js b/src/ui/UiExports.js index 4daf11f87801d..cd0fd4f73b8c2 100644 --- a/src/ui/UiExports.js +++ b/src/ui/UiExports.js @@ -1,7 +1,7 @@ -var _ = require('lodash'); -var minimatch = require('minimatch'); +const _ = require('lodash'); +const minimatch = require('minimatch'); -var UiAppCollection = require('./UiAppCollection'); +const UiAppCollection = require('./UiAppCollection'); class UiExports { constructor({ urlBasePath }) { @@ -16,10 +16,10 @@ class UiExports { consumePlugin(plugin) { plugin.apps = new UiAppCollection(this); - var types = _.keys(plugin.uiExportsSpecs); + const types = _.keys(plugin.uiExportsSpecs); if (!types) return false; - var unkown = _.reject(types, this.exportConsumer, this); + const unkown = _.reject(types, this.exportConsumer, this); if (unkown.length) { throw new Error('unknown export types ' + unkown.join(', ') + ' in plugin ' + plugin.id); } @@ -40,7 +40,7 @@ class UiExports { exportConsumer(type) { for (let consumer of this.consumers) { if (!consumer.exportConsumer) continue; - let fn = consumer.exportConsumer(type); + const fn = consumer.exportConsumer(type); if (fn) return fn; } @@ -49,7 +49,7 @@ class UiExports { case 'apps': return (plugin, specs) => { for (let spec of [].concat(specs || [])) { - let app = this.apps.new(_.defaults({}, spec, { + const app = this.apps.new(_.defaults({}, spec, { id: plugin.id, urlBasePath: this.urlBasePath })); @@ -80,9 +80,9 @@ class UiExports { } find(patterns) { - var aliases = this.aliases; - var names = _.keys(aliases); - var matcher = _.partialRight(minimatch.filter, { matchBase: true }); + const aliases = this.aliases; + const names = _.keys(aliases); + const matcher = _.partialRight(minimatch.filter, { matchBase: true }); return _.chain(patterns) .map(function (pattern) { diff --git a/src/ui/appEntryTemplate.js b/src/ui/appEntryTemplate.js index 714de7ba07fce..99a04121005bb 100644 --- a/src/ui/appEntryTemplate.js +++ b/src/ui/appEntryTemplate.js @@ -1,10 +1,10 @@ module.exports = function ({env, bundle}) { - let pluginSlug = env.pluginInfo.sort() + const pluginSlug = env.pluginInfo.sort() .map(p => ' * - ' + p) .join('\n'); - let requires = bundle.modules + const requires = bundle.modules .map(m => `require('${m}');`) .join('\n'); diff --git a/src/ui/autoload.js b/src/ui/autoload.js index 79ee476fd67b1..82bf7a18dc86a 100644 --- a/src/ui/autoload.js +++ b/src/ui/autoload.js @@ -1,30 +1,30 @@ -var _ = require('lodash'); -var resolve = require('path').resolve; -var basename = require('path').basename; -var readdir = require('fs').readdirSync; +const _ = require('lodash'); +const resolve = require('path').resolve; +const basename = require('path').basename; +const readdir = require('fs').readdirSync; -var utils = require('requirefrom')('src/utils'); -var fromRoot = utils('fromRoot'); +const utils = require('requirefrom')('src/utils'); +const fromRoot = utils('fromRoot'); function scan(type) { - var dir = fromRoot('src/ui/public', type); + const dir = fromRoot('src/ui/public', type); return _.chain(readdir(dir)) .reject(function (name) { return name[0] === '.' || name[0] === '_'; }) .map(function (filename) { - var path = resolve(dir, filename); - var name = basename(filename, '.js'); + const path = resolve(dir, filename); + const name = basename(filename, '.js'); return `ui/${type}/${name}`; }) .value(); } function findStyles() { - var base = ['ui/styles/theme.less', 'ui/styles/base.less']; - var exclude = ['ui/styles/mixins.less', 'ui/styles/variables.less']; - var found = scan('styles', true); + const base = ['ui/styles/theme.less', 'ui/styles/base.less']; + const exclude = ['ui/styles/mixins.less', 'ui/styles/variables.less']; + const found = scan('styles', true); return _.difference(_.union(base, found), exclude); } diff --git a/src/ui/index.js b/src/ui/index.js index a376e229a5d20..ebefd439077ab 100644 --- a/src/ui/index.js +++ b/src/ui/index.js @@ -1,22 +1,22 @@ module.exports = async (kbnServer, server, config) => { let { defaults } = require('lodash'); - let Boom = require('boom'); - let formatUrl = require('url').format; + const Boom = require('boom'); + const formatUrl = require('url').format; let { resolve } = require('path'); - let readFile = require('fs').readFileSync; + const readFile = require('fs').readFileSync; - let fromRoot = require('../utils/fromRoot'); - let UiExports = require('./UiExports'); - let UiBundle = require('./UiBundle'); - let UiBundleCollection = require('./UiBundleCollection'); - let UiBundlerEnv = require('./UiBundlerEnv'); - let loadingGif = readFile(fromRoot('src/ui/public/loading.gif'), { encoding: 'base64'}); + const fromRoot = require('../utils/fromRoot'); + const UiExports = require('./UiExports'); + const UiBundle = require('./UiBundle'); + const UiBundleCollection = require('./UiBundleCollection'); + const UiBundlerEnv = require('./UiBundlerEnv'); + const loadingGif = readFile(fromRoot('src/ui/public/loading.gif'), { encoding: 'base64'}); - let uiExports = kbnServer.uiExports = new UiExports({ + const uiExports = kbnServer.uiExports = new UiExports({ urlBasePath: config.get('server.basePath') }); - let bundlerEnv = new UiBundlerEnv(config.get('optimize.bundleDir')); + const bundlerEnv = new UiBundlerEnv(config.get('optimize.bundleDir')); bundlerEnv.addContext('env', config.get('env.name')); bundlerEnv.addContext('urlBasePath', config.get('server.basePath')); bundlerEnv.addContext('sourceMaps', config.get('optimize.sourceMaps')); @@ -28,14 +28,14 @@ module.exports = async (kbnServer, server, config) => { uiExports.consumePlugin(plugin); } - let bundles = kbnServer.bundles = new UiBundleCollection(bundlerEnv, config.get('optimize.bundleFilter')); + const bundles = kbnServer.bundles = new UiBundleCollection(bundlerEnv, config.get('optimize.bundleFilter')); for (let app of uiExports.getAllApps()) { bundles.addApp(app); } for (let gen of uiExports.getBundleProviders()) { - let bundle = await gen(UiBundle, bundlerEnv, uiExports.getAllApps()); + const bundle = await gen(UiBundle, bundlerEnv, uiExports.getAllApps()); if (bundle) bundles.add(bundle); } @@ -47,8 +47,8 @@ module.exports = async (kbnServer, server, config) => { path: '/app/{id}', method: 'GET', handler: function (req, reply) { - let id = req.params.id; - let app = uiExports.apps.byId[id]; + const id = req.params.id; + const app = uiExports.apps.byId[id]; if (!app) return reply(Boom.notFound('Unknown app ' + id)); if (kbnServer.status.isGreen()) {