UNPKG

@ganache/cli

Version:
70 lines 2.93 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.configureStartCommandForFlavor = exports.loadFlavorFromArgs = void 0; const flavor_1 = require("@ganache/flavor"); const chalk_1 = __importDefault(require("chalk")); const helpers_1 = require("./helpers"); function loadFlavorFromArgs(args) { // the next entry after `--flavor` is treated as a flavor name, if it isn't a // valid npm package we'll throw an error via `load` or const flavorArgIndex = args.indexOf("--flavor") + 1; if (flavorArgIndex > 0) { const flavor = args[flavorArgIndex]; if (flavor) { if (flavor !== "ethereum") { // load flavor plugin: return (0, flavor_1.load)(flavor === "filecoin" ? "@ganache/filecoin" : flavor); } } else { throw new Error("No flavor specified after `--flavor` flag."); } } // fallback to ethereum return require("@ganache/ethereum").default; } exports.loadFlavorFromArgs = loadFlavorFromArgs; function addFlavorFlag(yargs) { // Usage: `ganache --flavor [string]` yargs.option("flavor", { type: "string", description: (0, chalk_1.default) `Load an installed npm package as a Ganache flavor, e.g., {bold ganache --flavor @ganache/filecoin}.` }); } function addDetachFlag(yargs) { yargs.option("detach", { type: "boolean", description: `Run Ganache in detached (daemon) mode. See \`ganache instances --help\` for information on managing detached instances.`, alias: ["D", "😈"] }); } function configureStartCommandForFlavor(yargs, flavor, options) { // Usage: `ganache` // If the user has specified a --flavor, we use this command's `help` option // to show it. yargs.command(["$0"], (0, chalk_1.default) `Use the {bold ${flavor}} flavor of Ganache`, args => { // flavor defaults must be merged onto the ganache defaults, in order to // support overriding ganache defaults const combinedCliOptions = { ...flavor_1.cliDefaults, ...options?.cli?.defaults }; const combinedServerOptions = { ...flavor_1.serverDefaults, ...options?.server?.defaults }; if (options && options.provider) { (0, helpers_1.applyDefaults)(options.provider.defaults, args); } (0, helpers_1.applyDefaults)(combinedCliOptions, args); (0, helpers_1.applyDefaults)(combinedServerOptions, args); addFlavorFlag(args); addDetachFlag(args); }, parsed => (parsed.action = parsed.detach ? "start-detached" : "start")); } exports.configureStartCommandForFlavor = configureStartCommandForFlavor; //# sourceMappingURL=flavors.js.map