Skip to content

Commit

Permalink
Replace ux with alternative libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
jandrad committed Apr 26, 2024
1 parent 28f1210 commit 6c53858
Show file tree
Hide file tree
Showing 23 changed files with 285 additions and 330 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $ npm install -g @nefty/cli
$ nefty COMMAND
running command...
$ nefty (--version)
@nefty/cli/0.2.5 darwin-arm64 node-v18.19.1
@nefty/cli/0.2.6 darwin-arm64 node-v18.19.1
$ nefty --help [COMMAND]
USAGE
$ nefty COMMAND
Expand Down Expand Up @@ -271,7 +271,7 @@ DESCRIPTION
Manages a collection's assets.
```

_See code: [src/commands/assets/index.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/assets/index.ts)_
_See code: [src/commands/assets/index.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/assets/index.ts)_

## `nefty assets mint INPUT`

Expand All @@ -298,7 +298,7 @@ EXAMPLES
$ nefty assets mint test.xls -c alpacaworlds
```

_See code: [src/commands/assets/mint.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/assets/mint.ts)_
_See code: [src/commands/assets/mint.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/assets/mint.ts)_

## `nefty config`

Expand All @@ -312,7 +312,7 @@ DESCRIPTION
Manages the configuration.
```

_See code: [src/commands/config/index.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/config/index.ts)_
_See code: [src/commands/config/index.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/config/index.ts)_

## `nefty config auth`

Expand All @@ -331,7 +331,7 @@ EXAMPLES
$ nefty config auth auth
```

_See code: [src/commands/config/auth.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/config/auth.ts)_
_See code: [src/commands/config/auth.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/config/auth.ts)_

## `nefty config get`

Expand All @@ -348,7 +348,7 @@ EXAMPLES
$ nefty config get
```

_See code: [src/commands/config/get.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/config/get.ts)_
_See code: [src/commands/config/get.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/config/get.ts)_

## `nefty config init`

Expand All @@ -368,7 +368,7 @@ EXAMPLES
$ nefty config init
```

_See code: [src/commands/config/init.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/config/init.ts)_
_See code: [src/commands/config/init.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/config/init.ts)_

## `nefty config set [PROPERTY] [VALUE]`

Expand All @@ -391,7 +391,7 @@ EXAMPLES
$ nefty config set explorerUrl https://waxblock.io
```

_See code: [src/commands/config/set.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/config/set.ts)_
_See code: [src/commands/config/set.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/config/set.ts)_

## `nefty generate`

Expand All @@ -405,7 +405,7 @@ DESCRIPTION
Generates excel files to use in other batch commands.
```

_See code: [src/commands/generate/index.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/generate/index.ts)_
_See code: [src/commands/generate/index.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/generate/index.ts)_

## `nefty generate mint-file OUTPUT`

Expand Down Expand Up @@ -437,7 +437,7 @@ EXAMPLES
$ nefty generate mint-file mints.xlsx -c alpacaworlds
```

_See code: [src/commands/generate/mint-file.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/generate/mint-file.ts)_
_See code: [src/commands/generate/mint-file.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/generate/mint-file.ts)_

## `nefty generate pfp-file OUTPUT`

Expand Down Expand Up @@ -469,7 +469,7 @@ EXAMPLES
$ nefty generate pfp-file pfp-layers.xlsx -l Body -l Face -l Hair -a
```

_See code: [src/commands/generate/pfp-file.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/generate/pfp-file.ts)_
_See code: [src/commands/generate/pfp-file.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/generate/pfp-file.ts)_

## `nefty generate template-file OUTPUT`

Expand Down Expand Up @@ -501,7 +501,7 @@ EXAMPLES
$ nefty generate template-file templates.xlsx -c alpacaworlds
```

_See code: [src/commands/generate/template-file.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/generate/template-file.ts)_
_See code: [src/commands/generate/template-file.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/generate/template-file.ts)_

## `nefty generate token-transfer-file OUTPUT`

Expand All @@ -523,7 +523,7 @@ EXAMPLES
$ nefty generate token-transfer-file transfers.xlsx
```

_See code: [src/commands/generate/token-transfer-file.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/generate/token-transfer-file.ts)_
_See code: [src/commands/generate/token-transfer-file.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/generate/token-transfer-file.ts)_

## `nefty help [COMMAND]`

Expand Down Expand Up @@ -557,7 +557,7 @@ DESCRIPTION
Commands to manage a PFP collection.
```

_See code: [src/commands/pfps/index.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/pfps/index.ts)_
_See code: [src/commands/pfps/index.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/pfps/index.ts)_

## `nefty pfps build INPUT`

Expand Down Expand Up @@ -588,7 +588,7 @@ EXAMPLES
$ nefty pfps build ./pfps-folder -c alpacaworls -t 11324 -a alpacaworlds -n "My NFT" -r
```

_See code: [src/commands/pfps/build.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/pfps/build.ts)_
_See code: [src/commands/pfps/build.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/pfps/build.ts)_

## `nefty pfps generate INPUT OUTPUT`

Expand Down Expand Up @@ -617,21 +617,22 @@ EXAMPLES
$ nefty pfps generate pfps-specs.xlsx pfps
```

_See code: [src/commands/pfps/generate.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/pfps/generate.ts)_
_See code: [src/commands/pfps/generate.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/pfps/generate.ts)_

## `nefty pfps mint INPUT`

Mints the NFTS in the mint-pfps.xlsx file.

```
USAGE
$ nefty pfps mint INPUT [--skip <value>]
$ nefty pfps mint INPUT [--skip <value>] [--batchSize <value>]
ARGUMENTS
INPUT Directory where the pfps are saved.
FLAGS
--skip=<value> Number of mints to skip
--batchSize=<value> [default: 50] Batch size for minting
--skip=<value> Number of mints to skip
DESCRIPTION
Mints the NFTS in the mint-pfps.xlsx file.
Expand All @@ -642,7 +643,7 @@ EXAMPLES
$ nefty pfps mint ./pfps-folder
```

_See code: [src/commands/pfps/mint.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/pfps/mint.ts)_
_See code: [src/commands/pfps/mint.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/pfps/mint.ts)_

## `nefty templates`

Expand All @@ -656,7 +657,7 @@ DESCRIPTION
Manages a collection's templates.
```

_See code: [src/commands/templates/index.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/templates/index.ts)_
_See code: [src/commands/templates/index.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/templates/index.ts)_

## `nefty templates create INPUT`

Expand All @@ -680,7 +681,7 @@ EXAMPLES
$ nefty templates create template.xls -c alpacaworlds
```

_See code: [src/commands/templates/create.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/templates/create.ts)_
_See code: [src/commands/templates/create.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/templates/create.ts)_

## `nefty templates export OUTPUT`

Expand Down Expand Up @@ -712,7 +713,7 @@ EXAMPLES
$ nefty templates export templates.xlsx -c alpacaworlds
```

_See code: [src/commands/templates/export.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/templates/export.ts)_
_See code: [src/commands/templates/export.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/templates/export.ts)_

## `nefty tokens`

Expand All @@ -726,7 +727,7 @@ DESCRIPTION
Manages an account's tokens
```

_See code: [src/commands/tokens/index.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/tokens/index.ts)_
_See code: [src/commands/tokens/index.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/tokens/index.ts)_

## `nefty tokens transfer INPUT`

Expand All @@ -749,5 +750,5 @@ EXAMPLES
$ nefty tokens transfer test.xls
```

_See code: [src/commands/tokens/transfer.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.5/src/commands/tokens/transfer.ts)_
_See code: [src/commands/tokens/transfer.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/tokens/transfer.ts)_
<!-- commandsstop -->
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nefty/cli",
"version": "0.2.5",
"version": "0.2.6",
"description": "The NeftyBlocks cli will help you manage your collection with commands to create templates, mint assets, and more.",
"keywords": [
"oclif"
Expand Down Expand Up @@ -69,13 +69,13 @@
"@wharfkit/wallet-plugin-anchor": "^1.3.0",
"atomicassets": "^1.5.1",
"cli-progress": "^3.12.0",
"inquirer": "^9.2.19",
"kubo-rpc-client": "^4.1.1",
"node-fetch": "2.6.7",
"ora": "^8.0.1",
"qrcode-terminal": "^0.12.0",
"read-excel-file": "^5.6.1",
"sharp": "^0.32.5",
"terminal-link": "^3.0.0",
"undici": "^6.14.1",
"write-excel-file": "^1.4.27"
},
Expand Down
50 changes: 31 additions & 19 deletions src/commands/assets/mint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ux, Flags, Args } from '@oclif/core';
import { Flags, Args } from '@oclif/core';
import { mintAssets } from '../../services/asset-service.js';
import { getBatchesFromArray } from '../../utils/array-utils.js';
import { getCollectionSchemas } from '../../services/schema-service.js';
Expand All @@ -8,6 +8,7 @@ import { BaseCommand } from '../../base/BaseCommand.js';
import { readExcelContents } from '../../utils/excel-utils.js';
import { readExcelMintRows } from '../../services/mint-service.js';
import { confirmTransaction } from '../../services/antelope-service.js';
import { confirmPrompt, makeSpinner, printTable } from '../../utils/tty-utils.js';

export default class MintAssetsCommand extends BaseCommand {
static description = 'Mints assets in batches using a spreadsheet.';
Expand Down Expand Up @@ -53,27 +54,38 @@ export default class MintAssetsCommand extends BaseCommand {
const mintsFile = args.input;
const { batchSize, skip, confirm, ignoreSupply, collectionName } = flags;
const config = await this.getCliConfig();
const spinner = makeSpinner();

ux.action.start('Getting collection schemas');
spinner.start('Getting collection schemas');
const schema = await getCollectionSchemas(collectionName, config);
const schemasMap = Object.fromEntries(schema.map((row) => [row.name, row]));
ux.action.stop();
spinner.stop();

// Read XLS file
const mintRows: MintRow[] = [];
try {
ux.action.start('Reading mints in file');
spinner.start('Reading mints in file');
const sheets = await readExcelContents(mintsFile);
for (let i = 0; i < sheets.length; i++) {
const { name, rows } = sheets[i];
const schemaName = name.trim();
const schema = schemasMap[schemaName];
mintRows.push(...(await readExcelMintRows(rows, schema, config, ignoreSupply, skip)));
}
spinner.succeed();
} catch (error: any) {
spinner.fail();
throw new Error(`Error reading file: ${error.message}`);
} finally {
ux.action.stop();
}

if (mintRows.length === 0) {
this.log('Nothing to mint');
return;
}

const sample = [mintRows[0]];
if (mintRows.length > 1) {
sample.push(mintRows[mintRows.length - 1]);
}

// Create table columns and print table
Expand All @@ -89,12 +101,14 @@ export default class MintAssetsCommand extends BaseCommand {
.join('\n'),
},
};
ux.table(mintRows, columns);

const proceed = await ux.confirm('Continue? y/n');
printTable(columns, sample);

const proceed = await confirmPrompt(
`About to mint ${mintRows.length} NFTs. (Only first and last NFTs are displayed above) Continue?`,
);
if (!proceed) return;

ux.action.start('Minting assets...');
const mintActions = [];
for (const mint of mintRows) {
for (let i = 0; i < mint.amount; i++) {
Expand All @@ -107,11 +121,11 @@ export default class MintAssetsCommand extends BaseCommand {
let totalMintCount = 0;
try {
for (const mintActions of actionBatches) {
spinner.start(`Minting ${mintActions.length} assets`);
const result = (await mintAssets(mintActions, config)) as TransactResult;
const txId = result.resolved!.transaction.id;
this.log(
`${mintActions.length} Assets minted successfully. Transaction: ${config.explorerUrl}/transaction/${txId}`,
);
const message = `${mintActions.length} Assets minted successfully. Transaction: ${config.explorerUrl}/transaction/${txId}`;
spinner.text = message + (confirm ? ' Confirming...' : '');

const templateAmountMap: any = {};
for (const mintAction of mintActions) {
Expand All @@ -122,10 +136,6 @@ export default class MintAssetsCommand extends BaseCommand {
}
}

for (const templateId in templateAmountMap) {
this.log(`Minted ${templateAmountMap[templateId]} of template ${templateId}`);
}

totalMintCount += mintActions.length;

if (confirm) {
Expand All @@ -138,13 +148,15 @@ export default class MintAssetsCommand extends BaseCommand {
}
if (!confirmed) {
throw new Error('Transaction not confirmed');
} else {
spinner.succeed(
`${mintActions.length} Assets minted successfully. Transaction: ${config.explorerUrl}/transaction/${txId} Confirmed`,
);
}
}
}
} catch (error: any) {
throw new Error(`Error after minting: ${totalMintCount} successfully:` + error.message);
spinner.fail(`Error after minting: ${totalMintCount} successfully: ` + error.message);
}

ux.action.stop();
}
}
4 changes: 2 additions & 2 deletions src/commands/config/get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ux } from '@oclif/core';
import { Session } from '@wharfkit/session';
import { BaseCommand } from '../../base/BaseCommand.js';
import { printTable } from '../../utils/tty-utils.js';

export default class GetCommand extends BaseCommand {
static examples = ['<%= config.bin %> <%= command.id %>'];
Expand Down Expand Up @@ -49,6 +49,6 @@ export default class GetCommand extends BaseCommand {
params.push(param);
}
});
ux.table(params, columns);
printTable(columns, params);
}
}
Loading

0 comments on commit 6c53858

Please sign in to comment.