Skip to content

Commit

Permalink
choose bootstrap script
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Mar 23, 2021
1 parent 10dcd75 commit 023c6af
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
60 changes: 37 additions & 23 deletions src/cli/serve/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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),
});
});
Expand Down
7 changes: 4 additions & 3 deletions src/dev/cli_dev_mode/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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, {
Expand All @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/dev/cli_dev_mode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

export { CliDevMode, CliDevModeOptions, SomeCliArgs } from './cli_dev_mode';
export { Log, CliLog, TestLog } from './log';
export { bootstrapDevMode } from './bootstrap';

0 comments on commit 023c6af

Please sign in to comment.