diff --git a/src/cli/serve/serve.js b/src/cli/serve/serve.js index 32aa45f686fca..6cc1d591d359c 100644 --- a/src/cli/serve/serve.js +++ b/src/cli/serve/serve.js @@ -15,7 +15,6 @@ import url from 'url'; import { getConfigPath } from '@kbn/utils'; import { IS_KIBANA_DISTRIBUTABLE } from '../../legacy/utils'; import { fromRoot } from '../../core/server/utils'; -import { bootstrap } from '../../core/server'; import { readKeystore } from '../keystore/read_keystore'; function canRequire(path) { @@ -34,6 +33,16 @@ function canRequire(path) { const DEV_MODE_PATH = resolve(__dirname, '../../dev/cli_dev_mode'); const DEV_MODE_SUPPORTED = canRequire(DEV_MODE_PATH); +const getBootstrapScript = () => { + if (DEV_MODE_SUPPORTED && process.env.isDevCliChild !== 'true') { + const { bootstrapDevMode } = require('../../dev/cli_dev_mode'); + return bootstrapDevMode; + } else { + const { bootstrap } = require('../../core/server'); + return bootstrap; + } +}; + const pathCollector = function () { const paths = []; return function (path) { @@ -78,6 +87,7 @@ function applyConfigOverrides(rawConfig, opts, extraCliOptions) { throw new Error(`Can't use --ssl when "${path}" configuration is already defined.`); } } + ensureNotDefined('server.ssl.certificate'); ensureNotDefined('server.ssl.key'); ensureNotDefined('server.ssl.keystore.path'); @@ -209,28 +219,32 @@ export default function (program) { } const unknownOptions = this.getUnknownOptions(); - await bootstrap({ - configs: [].concat(opts.config || []), - cliArgs: { - dev: !!opts.dev, - envName: unknownOptions.env ? unknownOptions.env.name : undefined, - // no longer supported - quiet: !!opts.quiet, - silent: !!opts.silent, - watch: !!opts.watch, - runExamples: !!opts.runExamples, - // We want to run without base path when the `--run-examples` flag is given so that we can use local - // links in other documentation sources, like "View this tutorial [here](http://localhost:5601/app/tutorial/xyz)". - // We can tell users they only have to run with `yarn start --run-examples` to get those - // local links to work. Similar to what we do for "View in Console" links in our - // elastic.co links. - basePath: opts.runExamples ? false : !!opts.basePath, - optimize: !!opts.optimize, - disableOptimizer: !opts.optimizer, - oss: !!opts.oss, - cache: !!opts.cache, - dist: !!opts.dist, - }, + const configs = [].concat(opts.config || []); + const cliArgs = { + dev: !!opts.dev, + envName: unknownOptions.env ? unknownOptions.env.name : undefined, + // no longer supported + quiet: !!opts.quiet, + silent: !!opts.silent, + watch: !!opts.watch, + runExamples: !!opts.runExamples, + // We want to run without base path when the `--run-examples` flag is given so that we can use local + // links in other documentation sources, like "View this tutorial [here](http://localhost:5601/app/tutorial/xyz)". + // We can tell users they only have to run with `yarn start --run-examples` to get those + // local links to work. Similar to what we do for "View in Console" links in our + // elastic.co links. + basePath: opts.runExamples ? false : !!opts.basePath, + optimize: !!opts.optimize, + disableOptimizer: !opts.optimizer, + oss: !!opts.oss, + cache: !!opts.cache, + dist: !!opts.dist, + }; + const bootstrapScript = getBootstrapScript(); + + await bootstrapScript({ + configs, + cliArgs, applyConfigOverrides: (rawConfig) => applyConfigOverrides(rawConfig, opts, unknownOptions), }); }); diff --git a/src/dev/cli_dev_mode/bootstrap.ts b/src/dev/cli_dev_mode/bootstrap.ts index eb7a950cdb94b..86a276c64f1f5 100644 --- a/src/dev/cli_dev_mode/bootstrap.ts +++ b/src/dev/cli_dev_mode/bootstrap.ts @@ -7,7 +7,7 @@ */ import { REPO_ROOT } from '@kbn/utils'; -import { CliArgs, Env } from '@kbn/config'; +import { CliArgs, Env, RawConfigAdapter } from '@kbn/config'; import { CliDevMode } from './cli_dev_mode'; import { CliLog } from './log'; import { convertToLogger } from './log_adapter'; @@ -16,9 +16,10 @@ import { loadConfig } from './config'; interface BootstrapArgs { configs: string[]; cliArgs: CliArgs; + applyConfigOverrides: RawConfigAdapter; } -export async function bootstrapDevMode({ configs, cliArgs }: BootstrapArgs) { +export async function bootstrapDevMode({ configs, cliArgs, applyConfigOverrides }: BootstrapArgs) { const log = new CliLog(!!cliArgs.quiet, !!cliArgs.silent); const env = Env.createDefault(REPO_ROOT, { @@ -29,7 +30,7 @@ export async function bootstrapDevMode({ configs, cliArgs }: BootstrapArgs) { const config = await loadConfig({ env, logger: convertToLogger(log), - rawConfigAdapter: (cfg) => cfg, // TODO: use from cli/serve + rawConfigAdapter: applyConfigOverrides, }); const cliDevMode = new CliDevMode({ diff --git a/src/dev/cli_dev_mode/index.ts b/src/dev/cli_dev_mode/index.ts index 561cc8acf07ae..47bbca045671d 100644 --- a/src/dev/cli_dev_mode/index.ts +++ b/src/dev/cli_dev_mode/index.ts @@ -8,3 +8,4 @@ export { CliDevMode, CliDevModeOptions, SomeCliArgs } from './cli_dev_mode'; export { Log, CliLog, TestLog } from './log'; +export { bootstrapDevMode } from './bootstrap';