2018-07-11 10:19:35 +02:00
|
|
|
/*
|
|
|
|
* Licensed to Elasticsearch B.V. under one or more contributor
|
|
|
|
* license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright
|
|
|
|
* ownership. Elasticsearch B.V. licenses this file to you under
|
|
|
|
* the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
|
2020-09-16 09:17:05 +02:00
|
|
|
import { resolve, join } from 'path';
|
|
|
|
import loadJsonFile from 'load-json-file';
|
2020-10-16 11:55:46 +02:00
|
|
|
import { getPluginSearchPaths } from './plugins';
|
2019-10-15 14:19:11 +02:00
|
|
|
import { PackageInfo, EnvironmentMode } from './types';
|
2018-07-11 10:19:35 +02:00
|
|
|
|
2018-12-04 20:57:14 +01:00
|
|
|
/** @internal */
|
2018-07-11 10:19:35 +02:00
|
|
|
export interface EnvOptions {
|
2018-08-23 22:31:32 +02:00
|
|
|
configs: string[];
|
2018-09-06 17:39:04 +02:00
|
|
|
cliArgs: CliArgs;
|
2018-08-23 22:31:32 +02:00
|
|
|
isDevClusterMaster: boolean;
|
2018-07-11 10:19:35 +02:00
|
|
|
}
|
|
|
|
|
2018-12-04 20:57:14 +01:00
|
|
|
/** @internal */
|
2018-09-06 17:39:04 +02:00
|
|
|
export interface CliArgs {
|
|
|
|
dev: boolean;
|
|
|
|
envName?: string;
|
|
|
|
quiet: boolean;
|
|
|
|
silent: boolean;
|
|
|
|
watch: boolean;
|
|
|
|
repl: boolean;
|
|
|
|
basePath: boolean;
|
2018-11-08 15:12:01 +01:00
|
|
|
open: boolean;
|
2019-06-24 17:07:07 +02:00
|
|
|
oss: boolean;
|
2020-08-13 18:08:44 +02:00
|
|
|
/** @deprecated use disableOptimizer to know if the @kbn/optimizer is disabled in development */
|
|
|
|
optimize?: boolean;
|
2020-01-06 09:24:15 +01:00
|
|
|
runExamples: boolean;
|
2020-08-13 18:08:44 +02:00
|
|
|
disableOptimizer: boolean;
|
|
|
|
cache: boolean;
|
|
|
|
dist: boolean;
|
2018-09-06 17:39:04 +02:00
|
|
|
}
|
|
|
|
|
2020-09-16 09:17:05 +02:00
|
|
|
/** @internal */
|
|
|
|
export interface RawPackageInfo {
|
|
|
|
branch: string;
|
|
|
|
version: string;
|
|
|
|
build: {
|
|
|
|
distributable?: boolean;
|
|
|
|
number: number;
|
|
|
|
sha: string;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-07-11 10:19:35 +02:00
|
|
|
export class Env {
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2020-09-16 09:17:05 +02:00
|
|
|
public static createDefault(repoRoot: string, options: EnvOptions, pkg?: RawPackageInfo): Env {
|
|
|
|
if (!pkg) {
|
|
|
|
pkg = loadJsonFile.sync(join(repoRoot, 'package.json')) as RawPackageInfo;
|
|
|
|
}
|
|
|
|
return new Env(repoRoot, pkg, options);
|
2018-07-11 10:19:35 +02:00
|
|
|
}
|
|
|
|
|
2018-12-04 20:57:14 +01:00
|
|
|
/** @internal */
|
2018-07-11 10:19:35 +02:00
|
|
|
public readonly configDir: string;
|
2018-12-04 20:57:14 +01:00
|
|
|
/** @internal */
|
2018-07-11 10:19:35 +02:00
|
|
|
public readonly binDir: string;
|
2018-12-04 20:57:14 +01:00
|
|
|
/** @internal */
|
2018-07-11 10:19:35 +02:00
|
|
|
public readonly logDir: string;
|
2018-12-04 20:57:14 +01:00
|
|
|
/** @internal */
|
2019-07-10 21:26:23 +02:00
|
|
|
public readonly pluginSearchPaths: readonly string[];
|
2018-07-11 10:19:35 +02:00
|
|
|
|
|
|
|
/**
|
2018-08-23 22:31:32 +02:00
|
|
|
* Information about Kibana package (version, build number etc.).
|
2018-07-11 10:19:35 +02:00
|
|
|
*/
|
2018-08-23 22:31:32 +02:00
|
|
|
public readonly packageInfo: Readonly<PackageInfo>;
|
2018-07-11 10:19:35 +02:00
|
|
|
|
2018-08-23 22:31:32 +02:00
|
|
|
/**
|
|
|
|
* Mode Kibana currently run in (development or production).
|
|
|
|
*/
|
|
|
|
public readonly mode: Readonly<EnvironmentMode>;
|
2018-07-11 10:19:35 +02:00
|
|
|
|
|
|
|
/**
|
2018-08-23 22:31:32 +02:00
|
|
|
* Arguments provided through command line.
|
2018-12-04 20:57:14 +01:00
|
|
|
* @internal
|
2018-07-11 10:19:35 +02:00
|
|
|
*/
|
2018-09-06 17:39:04 +02:00
|
|
|
public readonly cliArgs: Readonly<CliArgs>;
|
2018-07-11 10:19:35 +02:00
|
|
|
|
|
|
|
/**
|
2018-08-23 22:31:32 +02:00
|
|
|
* Paths to the configuration files.
|
2018-12-04 20:57:14 +01:00
|
|
|
* @internal
|
2018-07-11 10:19:35 +02:00
|
|
|
*/
|
2019-07-10 21:26:23 +02:00
|
|
|
public readonly configs: readonly string[];
|
2018-08-23 22:31:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates that this Kibana instance is run as development Node Cluster master.
|
2018-12-04 20:57:14 +01:00
|
|
|
* @internal
|
2018-08-23 22:31:32 +02:00
|
|
|
*/
|
|
|
|
public readonly isDevClusterMaster: boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2020-09-16 09:17:05 +02:00
|
|
|
constructor(public readonly homeDir: string, pkg: RawPackageInfo, options: EnvOptions) {
|
2018-08-23 22:31:32 +02:00
|
|
|
this.configDir = resolve(this.homeDir, 'config');
|
|
|
|
this.binDir = resolve(this.homeDir, 'bin');
|
|
|
|
this.logDir = resolve(this.homeDir, 'log');
|
|
|
|
|
2020-10-16 11:55:46 +02:00
|
|
|
this.pluginSearchPaths = getPluginSearchPaths({
|
|
|
|
rootDir: this.homeDir,
|
|
|
|
oss: options.cliArgs.oss,
|
|
|
|
examples: options.cliArgs.runExamples,
|
|
|
|
});
|
2018-12-04 20:57:14 +01:00
|
|
|
|
2018-08-23 22:31:32 +02:00
|
|
|
this.cliArgs = Object.freeze(options.cliArgs);
|
|
|
|
this.configs = Object.freeze(options.configs);
|
|
|
|
this.isDevClusterMaster = options.isDevClusterMaster;
|
|
|
|
|
2018-09-06 17:39:04 +02:00
|
|
|
const isDevMode = this.cliArgs.dev || this.cliArgs.envName === 'development';
|
2018-08-23 22:31:32 +02:00
|
|
|
this.mode = Object.freeze<EnvironmentMode>({
|
2018-09-06 17:39:04 +02:00
|
|
|
dev: isDevMode,
|
|
|
|
name: isDevMode ? 'development' : 'production',
|
|
|
|
prod: !isDevMode,
|
2018-08-23 22:31:32 +02:00
|
|
|
});
|
|
|
|
|
2019-07-05 13:47:03 +02:00
|
|
|
const isKibanaDistributable = Boolean(pkg.build && pkg.build.distributable === true);
|
2018-08-23 22:31:32 +02:00
|
|
|
this.packageInfo = Object.freeze({
|
|
|
|
branch: pkg.branch,
|
|
|
|
buildNum: isKibanaDistributable ? pkg.build.number : Number.MAX_SAFE_INTEGER,
|
|
|
|
buildSha: isKibanaDistributable ? pkg.build.sha : 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
|
|
|
|
version: pkg.version,
|
2019-07-05 13:47:03 +02:00
|
|
|
dist: isKibanaDistributable,
|
2018-08-23 22:31:32 +02:00
|
|
|
});
|
2018-07-11 10:19:35 +02:00
|
|
|
}
|
|
|
|
}
|