UNPKG

@fugitivesclub/nft-cli

Version:
87 lines (86 loc) 3.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const core_1 = require("@oclif/core"); const fs = (0, tslib_1.__importStar)(require("fs")); require("reflect-metadata"); const configuration_1 = require("../../core/configuration"); const read_nft_1 = require("../../core/nft/read-nft"); const mint_1 = require("../../core/nft/mint"); const validation_error_1 = require("../../utils/error/validation-error"); class Mint extends core_1.Command { async catch(error) { if ((0, validation_error_1.instanceOfValidationErrors)(error)) { const { message, suggestions } = (0, validation_error_1.formatValidationErrors)(error); this.error(message, { code: 'ValidationError', exit: 3, suggestions, }); } else if (error.code === 'ENOENT') { this.error('The given path seems to be invalid.', { code: 'ENOENT', exit: 2, suggestions: [ 'Check if your path is a valid path', 'Check if you path exist', ], }); } else { this.error(error); } } async run() { const { flags } = await this.parse(Mint); this.log('Checking your configuration...'); const configuration = await (0, configuration_1.getConfiguration)(flags.config); this.log('Checking if your paths...'); // Check if files exist fs.lstatSync(flags.metadata).isFile(); fs.lstatSync(flags.config).isFile(); this.log('Reading the content of your files...'); const nftFileContents = await (0, read_nft_1.readNFT)(flags.metadata, flags.image); this.log('Running minting...'); const res = await (0, mint_1.mint)(configuration, nftFileContents, flags.supply); this.log(`Your tokenId is: ${res.tokenId}`); this.log(`Your nftId's are: ${JSON.stringify(res.nftIds)}`); } } exports.default = Mint; Mint.description = "Mint NFT's with single metadata"; Mint.examples = [ `$ nft mint single -c sample.config.json -m ~/Downloads/nft/metadata.json -i ~/Downloads/nft/image.png -s 1500 Checking your configuration... Checking if your paths... Reading the content of your file... Running minting... ... `, ]; Mint.flags = { config: core_1.Flags.string({ char: 'c', description: 'Path of your config file', default: `${process.cwd()}/config.json`, required: false, }), metadata: core_1.Flags.string({ char: 'm', description: 'Path of your json metadata file', required: true, }), image: core_1.Flags.string({ char: 'i', description: 'Path of your image file', required: true, }), supply: core_1.Flags.integer({ char: 's', description: 'Amount of supply', default: 1, required: false, }), }; Mint.args = [];