hardhat
Version:
Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
68 lines • 2.23 kB
JavaScript
import { HardhatError } from "@nomicfoundation/hardhat-errors";
import { ArgumentType } from "../../types/arguments.js";
import { CONFIGURATION_VARIABLE_MARKER } from "./configuration-variables.js";
import { buildGlobalOptionDefinition } from "./global-options.js";
import { EmptyTaskDefinitionBuilderImplementation, NewTaskDefinitionBuilderImplementation, TaskOverrideDefinitionBuilderImplementation, } from "./tasks/builders.js";
export function configVariable(name, formatOrOptions = {}) {
const { format = CONFIGURATION_VARIABLE_MARKER, default: defaultValue } = typeof formatOrOptions === "string"
? { format: formatOrOptions }
: formatOrOptions;
if (!format.includes(CONFIGURATION_VARIABLE_MARKER)) {
throw new HardhatError(HardhatError.ERRORS.CORE.GENERAL
.CONFIG_VARIABLE_FORMAT_MUST_INCLUDE_VARIABLE, { format, marker: CONFIGURATION_VARIABLE_MARKER });
}
const configurationVariable = {
_type: "ConfigurationVariable",
name,
format,
};
if (defaultValue !== undefined) {
configurationVariable.default = defaultValue;
}
return configurationVariable;
}
/**
* Creates a builder to define a new task.
*/
export function task(id, description = "") {
return new NewTaskDefinitionBuilderImplementation(id, description);
}
/**
* Defines a new empty task.
*/
export function emptyTask(id, description) {
return new EmptyTaskDefinitionBuilderImplementation(id, description);
}
/**
* Creates a builder to override a task.
*/
export function overrideTask(id) {
return new TaskOverrideDefinitionBuilderImplementation(id);
}
/**
* Defines a global option.
*/
export function globalOption(options) {
return buildGlobalOptionDefinition(options);
}
/**
* Defines a global flag.
*/
export function globalFlag(options) {
return buildGlobalOptionDefinition({
...options,
type: ArgumentType.FLAG,
defaultValue: false,
});
}
/**
* Defines a global level.
*/
export function globalLevel(options) {
return buildGlobalOptionDefinition({
...options,
type: ArgumentType.LEVEL,
defaultValue: options.defaultValue ?? 0,
});
}
//# sourceMappingURL=config.js.map