UNPKG

@newos/cli

Version:
164 lines 7.51 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (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.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.options = exports.args = exports.description = exports.name = void 0; const utils_1 = require("../utils"); const defaults_1 = require("../../models/network/defaults"); const chalk_1 = __importDefault(require("chalk")); function kindChoice(kind, description) { return { name: `${kind}\t${chalk_1.default.reset.dim(description)}`, value: kind, short: kind, }; } const kinds = [ kindChoice('regular', 'standard non-upgradeable contract'), kindChoice('upgradeable', 'upgradeable instance using a delegating proxy (EIP1967)'), kindChoice('minimal', 'non-upgradeable minimal proxy instance (EIP1167)'), ]; exports.name = 'deploy'; exports.description = 'deploy a contract instance'; exports.args = [ { name: 'contract', async details() { const choices = await Promise.resolve().then(() => __importStar(require('../../prompts/choices'))); const contracts = choices.contracts('all'); return { prompt: 'Pick a contract to deploy', choices: contracts, }; }, }, { name: 'arguments', variadic: true, async details(params) { const { fromContractFullName } = await Promise.resolve().then(() => __importStar(require('../../utils/naming'))); const { default: ContractManager } = await Promise.resolve().then(() => __importStar(require('../../models/local/ContractManager'))); const { argLabelWithIndex } = await Promise.resolve().then(() => __importStar(require('../../prompts/prompt'))); const { parseArg, getSampleInput } = await Promise.resolve().then(() => __importStar(require('../../utils/input'))); const { getConstructorInputs } = await Promise.resolve().then(() => __importStar(require('@newos/upgrades'))); const contractFullName = params.contract; const { package: packageName, contractName } = fromContractFullName(contractFullName); const contract = new ContractManager().getContractClass(packageName, contractName); const constructorInputs = getConstructorInputs(contract); return constructorInputs.map((arg, index) => ({ prompt: `${argLabelWithIndex(arg, index)}:`, validationError: (value) => { try { parseArg(value, arg); } catch (err) { const placeholder = getSampleInput(arg); if (placeholder) { return `Enter a valid ${arg.type} such as: ${placeholder}`; } else { return `Enter a valid ${arg.type}`; } } }, })); }, }, ]; exports.options = [ { format: '--skip-compile', description: 'use existing compilation artifacts', default: false, }, { format: '-k, --kind <kind>', description: `the kind of deployment (${kinds.map(k => k.value).join(', ')})`, async details() { return { prompt: 'Choose the kind of deployment', choices: kinds, }; }, }, { format: '-n, --network <network>', description: 'network to use', async details() { const { default: ConfigManager } = await Promise.resolve().then(() => __importStar(require('../../models/config/ConfigManager'))); const { default: Session } = await Promise.resolve().then(() => __importStar(require('../../models/network/Session'))); const networks = ConfigManager.getNetworkNamesFromConfig(); const { network: lastNetwork, expired } = Session.getNetwork(); if (expired || lastNetwork === undefined) { return { prompt: 'Pick a network', choices: networks, preselect: lastNetwork, }; } }, async after(options) { if (options.network) { const { default: Session } = await Promise.resolve().then(() => __importStar(require('../../models/network/Session'))); // Used for network preselection in subsequent runs. Session.setDefaultNetworkIfNeeded(options.network); } }, }, { format: '--timeout <timeout>', description: `timeout in seconds for each transaction (default: ${defaults_1.DEFAULT_TX_TIMEOUT})`, }, { format: '-f, --from <address>', description: 'sender for the contract creation transaction', async after(options) { // Once we have all required params (network, timeout, from) we initialize the config. // We need to do this because it's necessary for the details of 'arguments' later. if (process.env.NODE_ENV !== 'test') { const { default: ConfigManager } = await Promise.resolve().then(() => __importStar(require('../../models/config/ConfigManager'))); const userNetwork = options.network; const config = await ConfigManager.initNetworkConfiguration(options); Object.assign(options, config, { userNetwork }); } }, }, { format: '--migrate-manifest', description: 'enable automatic migration of manifest format', async details(options) { const { isMigratableManifestVersion } = await Promise.resolve().then(() => __importStar(require('../../models/files/ManifestVersion'))); const { default: NetworkFile } = await Promise.resolve().then(() => __importStar(require('../../models/files/NetworkFile'))); const version = NetworkFile.getManifestVersion(options.network); if (isMigratableManifestVersion(version)) { return { prompt: 'An old manifest version was detected and needs to be migrated to the latest one. Proceed?', promptType: 'confirm', validationError: (migrate) => migrate ? undefined : 'Cannot proceed without migrating the manifest file.', }; } }, }, utils_1.commonOptions.noInteractive, ]; //# sourceMappingURL=spec.js.map