create-tezos-smart-contract
Version:
Node.js toolset to write, test and deploy Tezos smart contracts
49 lines (48 loc) • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.deploy = exports.addDeployCommand = void 0;
const console_1 = require("../../console");
const bundle_1 = require("../../modules/bundle");
const config_1 = require("../../modules/config");
const deploy_1 = require("../../modules/deploy");
const addDeployCommand = (program, debugHook) => {
program
.command('deploy')
.description('Deploy a smart contract on a Tezos network.')
.option('-c, --contract <contract>', 'Compile a single smart contract source file')
.option('-n, --network <network>', `Choose to perform origination in, either ${config_1.ToolchainNetworks.SANDBOX}, ${config_1.ToolchainNetworks.TESTNET} or ${config_1.ToolchainNetworks.MAINNET} networks`)
.option('--old-build', 'Use the latest contract build found instead of stopping/rebuilding')
.action((options) => {
(0, exports.deploy)(options);
})
.hook('preAction', debugHook);
};
exports.addDeployCommand = addDeployCommand;
// Deploy a Smart Contract
const deploy = async (options) => {
// Read configfile
const contractsBundle = new bundle_1.ContractsBundle((0, console_1.getCWD)());
// Read the config so contracts folder settings will be there later
await contractsBundle.readConfigFile();
const contracts = await contractsBundle.getContractsFiles();
if (contracts.length === 0) {
(0, console_1.error)('This repository contains no contract files, slipping deploy.');
return;
}
else if (contracts.length > 1 && !options.contract) {
(0, console_1.error)('This repository contains more than one contract, but no contract was specified in command options (use --contract <contractName>).');
return;
}
const contract = options.contract || contracts[0];
(0, console_1.em)(`Deploying contract "${contract}"...\n`);
// Deploy configuration
const defaultOptions = {
network: config_1.ToolchainNetworks.SANDBOX,
contract,
oldBuild: false,
};
// Build final options
const deployOptions = Object.assign({}, defaultOptions, options);
await (0, deploy_1.deployContract)(contractsBundle, deployOptions);
};
exports.deploy = deploy;