@fugitivesclub/nft-cli
Version:
This CLI allow you to mint your NFT's
82 lines (81 loc) • 3.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const errors_1 = require("@oclif/errors");
const fs = (0, tslib_1.__importStar)(require("fs"));
require("reflect-metadata");
const configuration_1 = require("../../core/configuration");
const read_nfts_1 = require("../../core/nft/read-nfts");
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 the path is a directory...');
const isDirectory = fs.lstatSync(flags.from).isDirectory();
if (!isDirectory) {
throw new errors_1.CLIError('The given path is not a directory');
}
this.log('Reading the content of all the paired files...');
const nftFileContents = await (0, read_nfts_1.readNFTs)(flags.from);
if (nftFileContents.length === 0) {
this.log("Can't find any paired file in the provided folder.");
return;
}
this.log('Running minting of your directory...');
const res = await (0, mint_1.mint)(configuration, nftFileContents);
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 multiple metadata";
Mint.examples = [
`$ nft mint multiple -c sample.config.json -f ~/Downloads/nfts
Checking your configuration...
Checking if the path is a directory...
Reading the content of all the paired files...
Running minting of your directory...
...
`,
];
Mint.flags = {
config: core_1.Flags.string({
char: 'c',
description: 'Path of your config file',
default: `${process.cwd()}/config.json`,
required: false,
}),
from: core_1.Flags.string({
char: 'f',
description: "Path from which you want to create your NFT's",
required: true,
}),
};
Mint.args = [];