@kubiklabs/wasmkit
Version:
Wasmkit is a development environment to compile, deploy, test, run cosmwasm contracts on different networks.
121 lines (120 loc) • 4.76 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveProjectPaths = exports.resolveConfig = void 0;
const deepmerge_1 = __importDefault(require("deepmerge"));
const path = __importStar(require("path"));
const lang_1 = require("../../util/lang");
function mergeUserAndDefaultConfigs(defaultConfig, userConfig) {
return (0, deepmerge_1.default)(defaultConfig, userConfig, {
arrayMerge: (destination, source) => source // eslint-disable-line @typescript-eslint/no-explicit-any
});
}
/**
* This functions resolves the WasmKit config by merging the user provided config
* and the WasmKit default config.
*
* @param userConfigPath the user config filepath
* @param defaultConfig the WasmKit's default config object
* @param userConfig the user config object
* @param configExtenders An array of ConfigExtenders
*
* @returns the resolved config
*/
function resolveConfig(userConfigPath, defaultConfig, userConfig, configExtenders) {
const config = mergeUserAndDefaultConfigs(defaultConfig, userConfig);
const paths = userConfigPath !== undefined
? resolveProjectPaths(userConfigPath, userConfig.paths)
: undefined;
const resolved = {
...config,
paths,
networks: config.networks ?? {},
localnetworks: config.localnetworks ?? {},
commands: config.commands ?? {
// TODO: clean this up
compile: "",
schema: ""
},
playground: config.playground ?? {
title: "",
tagline: "",
favicon: "",
logoLight: "",
logoDark: "",
theme: {
light_background: "",
dark_background: ""
},
socials: {
twitter: "",
discord: "",
telegram: "",
github: ""
}
}
};
for (const extender of configExtenders) {
extender(resolved, userConfig);
}
return resolved;
}
exports.resolveConfig = resolveConfig;
function resolvePathFrom(from, defaultPath, relativeOrAbsolutePath = defaultPath) {
if (path.isAbsolute(relativeOrAbsolutePath)) {
return relativeOrAbsolutePath;
}
return path.join(from, relativeOrAbsolutePath);
}
/**
* This function resolves the ProjectPaths object from the user-provided config
* and its path. The logic of this is not obvious and should well be document.
* The good thing is that most users will never use this.
*
* Explanation:
* - paths.configFile is not overridable
* - If a path is absolute it is used "as is".
* - If the root path is relative, it's resolved from paths.configFile's dir.
* - If any other path is relative, it's resolved from paths.root.
*/
function resolveProjectPaths(userConfigPath, userPaths = {}) {
const configDir = path.dirname(userConfigPath);
const root = resolvePathFrom(configDir, "", userPaths.root);
const otherPathsEntries = Object.entries(userPaths).map(([name, value]) => [name, resolvePathFrom(root, value)]);
const otherPaths = (0, lang_1.fromEntries)(otherPathsEntries);
return {
...otherPaths,
root,
configFile: userConfigPath,
sources: resolvePathFrom(root, "contracts", userPaths.sources),
cache: resolvePathFrom(root, "cache", userPaths.cache),
artifacts: resolvePathFrom(root, "artifacts", userPaths.artifacts),
tests: resolvePathFrom(root, "test", userPaths.tests)
};
}
exports.resolveProjectPaths = resolveProjectPaths;