Innovenergy_trunk/frontend/node_modules/testcafe/lib/configuration/configuration-base.js

227 lines
32 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const debug_1 = __importDefault(require("debug"));
const json5_1 = __importDefault(require("json5"));
const lodash_1 = require("lodash");
const promisified_functions_1 = require("../utils/promisified-functions");
const option_1 = __importDefault(require("./option"));
const option_source_1 = __importDefault(require("./option-source"));
const resolve_path_relatively_cwd_1 = __importDefault(require("../utils/resolve-path-relatively-cwd"));
const render_template_1 = __importDefault(require("../utils/render-template"));
const warning_message_1 = __importDefault(require("../notifications/warning-message"));
const log_1 = __importDefault(require("../cli/log"));
const formats_1 = require("./formats");
const DEBUG_LOGGER = (0, debug_1.default)('testcafe:configuration');
class Configuration {
constructor(configurationFilesNames) {
var _a;
this._options = {};
this._defaultPaths = this._resolveFilePaths(configurationFilesNames);
this._filePath = (_a = this._defaultPaths) === null || _a === void 0 ? void 0 : _a[0];
this._overriddenOptions = [];
}
static _fromObj(obj) {
const result = Object.create(null);
Object.entries(obj).forEach(([key, value]) => {
result[key] = new option_1.default(key, value);
});
return result;
}
static _showConsoleWarning(message) {
log_1.default.write(message);
}
static _showWarningForError(error, warningTemplate, ...args) {
const message = (0, render_template_1.default)(warningTemplate, ...args);
Configuration._showConsoleWarning(message);
DEBUG_LOGGER(message);
DEBUG_LOGGER(error);
}
static _resolveFilePath(path) {
if (!path)
return null;
return (0, path_1.isAbsolute)(path) ? path : (0, resolve_path_relatively_cwd_1.default)(path);
}
_resolveFilePaths(filesNames) {
if (!filesNames)
return void 0;
return (0, lodash_1.castArray)(filesNames).reduce((result, name) => {
const resolveFilePath = Configuration._resolveFilePath(name);
if (resolveFilePath)
result.push(resolveFilePath);
return result;
}, []);
}
async init() {
this._overriddenOptions = [];
}
mergeOptions(options) {
Object.entries(options).map(([key, value]) => {
const option = this._ensureOption(key, value, option_source_1.default.Input);
if (value === void 0)
return;
this._setOptionValue(option, value);
});
}
mergeDeep(option, source) {
(0, lodash_1.mergeWith)(option.value, source, (targetValue, sourceValue, property) => {
this._addOverriddenOptionIfNecessary(targetValue, sourceValue, option.source, `${option.name}.${property}`);
return sourceValue !== void 0 ? sourceValue : targetValue;
});
}
getOption(key) {
if (!key)
return void 0;
const option = this._options[key];
if (!option)
return void 0;
return option.value;
}
getOptions(predicate) {
const result = Object.create(null);
let includeInResult = true;
Object.entries(this._options).forEach(([name, option]) => {
includeInResult = predicate ? predicate(name, option) : true;
if (includeInResult)
result[name] = option.value;
});
return result;
}
clone(nonClonedOptions) {
const configuration = (0, lodash_1.cloneDeep)(this);
if (nonClonedOptions) {
(0, lodash_1.castArray)(nonClonedOptions).forEach(key => {
if (configuration._options[key])
configuration._options[key].value = this._options[key].value;
});
}
return configuration;
}
get filePath() {
return this._filePath;
}
get defaultPaths() {
return this._defaultPaths;
}
async _load() {
var _a;
if (!((_a = this.defaultPaths) === null || _a === void 0 ? void 0 : _a.length))
return null;
const configs = await Promise.all(this.defaultPaths.map(async (filePath) => {
if (!await this._isConfigurationFileExists(filePath))
return { filePath, options: null };
let options = null;
if (this._isJSConfiguration(filePath))
options = this._readJsConfigurationFileContent(filePath);
else {
const configurationFileContent = await this._readConfigurationFileContent(filePath);
if (configurationFileContent)
options = this._parseConfigurationFileContent(configurationFileContent, filePath);
}
return { filePath, options };
}));
const existedConfigs = configs.filter(config => !!config.options);
if (!existedConfigs.length)
return null;
this._filePath = existedConfigs[0].filePath;
if (existedConfigs.length > 1)
Configuration._showConsoleWarning((0, render_template_1.default)(warning_message_1.default.multipleConfigurationFilesFound, this._filePath));
return existedConfigs[0].options;
}
async _isConfigurationFileExists(filePath = this.filePath) {
try {
await (0, promisified_functions_1.stat)(filePath);
return true;
}
catch (error) {
DEBUG_LOGGER((0, render_template_1.default)(warning_message_1.default.cannotFindConfigurationFile, filePath, error.stack));
return false;
}
}
static _hasExtention(filePath, extention) {
return !!filePath && (0, path_1.extname)(filePath) === extention;
}
_isJSConfiguration(filePath = this.filePath) {
return Configuration._hasExtention(filePath, formats_1.JS_CONFIGURATION_EXTENSION);
}
_isJSONConfiguration(filePath = this.filePath) {
return Configuration._hasExtention(filePath, formats_1.JSON_CONFIGURATION_EXTENSION);
}
_readJsConfigurationFileContent(filePath = this.filePath) {
if (filePath) {
try {
delete require.cache[filePath];
return require(filePath);
}
catch (error) {
Configuration._showWarningForError(error, warning_message_1.default.cannotReadConfigFile, filePath);
}
}
return null;
}
async _readConfigurationFileContent(filePath = this.filePath) {
try {
return await (0, promisified_functions_1.readFile)(filePath);
}
catch (error) {
Configuration._showWarningForError(error, warning_message_1.default.cannotReadConfigFile, filePath);
}
return null;
}
_parseConfigurationFileContent(configurationFileContent, filePath = this.filePath) {
try {
return json5_1.default.parse(configurationFileContent.toString());
}
catch (error) {
Configuration._showWarningForError(error, warning_message_1.default.cannotParseConfigFile, filePath);
}
return null;
}
_ensureArrayOption(name) {
const options = this._options[name];
if (!options)
return;
// NOTE: a hack to fix lodash type definitions
// @ts-ignore
options.value = (0, lodash_1.castArray)(options.value);
}
_ensureOption(name, value, source) {
let option = null;
if (name in this._options)
option = this._options[name];
else {
option = new option_1.default(name, value, source);
this._options[name] = option;
}
return option;
}
_ensureOptionWithValue(name, defaultValue, source) {
const option = this._ensureOption(name, defaultValue, source);
if (option.value !== void 0)
return;
option.value = defaultValue;
option.source = source;
}
_addOverriddenOptionIfNecessary(value1, value2, source, optionName) {
if (source === option_source_1.default.Default)
return;
if (value1 === void 0 || value2 === void 0 || value1 === value2 || source !== option_source_1.default.Configuration)
return;
this._overriddenOptions.push(optionName);
}
_setOptionValue(option, value) {
if ((0, lodash_1.isPlainObject)(option.value) && (0, lodash_1.isPlainObject)(value))
this.mergeDeep(option, value);
else {
this._addOverriddenOptionIfNecessary(option.value, value, option.source, option.name);
option.value = value;
}
option.source = option_source_1.default.Input;
}
}
exports.default = Configuration;
module.exports = exports.default;
//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vcHRpb24gPSB0aGlzLl9vcHRpb25zW2tleV07XG5cbiAgICAgICAgaWYgKCFvcHRpb24pXG4gICAgICAgICAgICByZXR1cm4gdm9pZCAwO1xuXG4gICAgICAgIHJldHVybiBvcHRpb24udmFsdWU7XG4gICAgfVxuXG4gICAgcHVibGljIGdldE9wdGlvbnMgKHByZWRpY2F0ZT86IChuYW1lOiBzdHJpbmcsIG9wdGlvbjogT3B0aW9uKSA9PiBib29sZWFuKTogRGljdGlvbmFyeTxPcHRpb25WYWx1ZT4ge1xuICAgICAgICBjb25zdCByZXN1bHQgICAgICAgID0gT2JqZWN0LmNyZWF0ZShudWxsKTtcbiAgICAgICAgbGV0IGluY2x1ZGVJblJlc3VsdCA9IHRydWU7XG5cbiAgICAgICAgT2JqZWN0LmVudHJpZXModGhpcy5fb3B0aW9ucykuZm9yRWFjaCgoW25hbWUsIG9wdGlvbl0pID0+IHtcbiAgICAgICAgICAgIGluY2x1ZGVJblJlc3VsdCA9IHByZWRpY2F0ZSA/IHByZWRpY2F0ZShuYW1lLCBvcHRpb24pIDogdHJ1ZTtcblxuICAgICAgICAgICAgaWYgKGluY2x1ZGVJblJlc3VsdClcbiAgICAgICAgICAgICAgICByZXN1bHRbbmFtZV0gPSBvcHRpb24udmFsdWU7XG4gICAgICAgIH0pO1xuXG4gICAgICAgIHJldHVybiByZXN1bHQ7XG4gICAgfVxuXG4gICAgcHVibGljIGNsb25lIChub25DbG9uZWRPcHRpb25zPzogc3RyaW5nIHwgc3RyaW5nW10pOiBDb25maWd1cmF0aW9uIHtcbiAgICAgICAgY29uc3QgY29uZmlndXJhdGlvbiA9IGNsb25lRGVlcCh0aGlzKTtcblxuICAgICAgICBpZiAobm9uQ2xvbmVkT3B0aW9ucykge1xuICAgICAgICAgICAgY2FzdEFycmF5KG5vbkNsb25lZE9wdGlvbnMpLmZvckVhY2goa2V5ID0+IHtcbiAgICAgICAgICAgICAgICBpZiAoY29uZmlndXJhdGlvbi5fb3B0aW9uc1trZXldKV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