Skip to content

Commit

Permalink
Add command to to generate cover image
Browse files Browse the repository at this point in the history
  • Loading branch information
jandrad committed Apr 27, 2024
1 parent 6c53858 commit 109523b
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 35 deletions.
71 changes: 49 additions & 22 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.6 darwin-arm64 node-v18.19.1
@nefty/cli/0.2.7 darwin-arm64 node-v18.19.1
$ nefty --help [COMMAND]
USAGE
$ nefty COMMAND
Expand Down Expand Up @@ -251,6 +251,7 @@ The token transfer file is used to define the tokens to be transferred, the reci
* [`nefty help [COMMAND]`](#nefty-help-command)
* [`nefty pfps`](#nefty-pfps)
* [`nefty pfps build INPUT`](#nefty-pfps-build-input)
* [`nefty pfps cover INPUT`](#nefty-pfps-cover-input)
* [`nefty pfps generate INPUT OUTPUT`](#nefty-pfps-generate-input-output)
* [`nefty pfps mint INPUT`](#nefty-pfps-mint-input)
* [`nefty templates`](#nefty-templates)
Expand All @@ -271,7 +272,7 @@ DESCRIPTION
Manages a collection's assets.
```

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

## `nefty assets mint INPUT`

Expand All @@ -298,7 +299,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.6/src/commands/assets/mint.ts)_
_See code: [src/commands/assets/mint.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.7/src/commands/assets/mint.ts)_

## `nefty config`

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

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

## `nefty config auth`

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

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

## `nefty config get`

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

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

## `nefty config init`

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

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

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

Expand All @@ -391,7 +392,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.6/src/commands/config/set.ts)_
_See code: [src/commands/config/set.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.7/src/commands/config/set.ts)_

## `nefty generate`

Expand All @@ -405,7 +406,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.6/src/commands/generate/index.ts)_
_See code: [src/commands/generate/index.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.7/src/commands/generate/index.ts)_

## `nefty generate mint-file OUTPUT`

Expand Down Expand Up @@ -437,7 +438,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.6/src/commands/generate/mint-file.ts)_
_See code: [src/commands/generate/mint-file.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.7/src/commands/generate/mint-file.ts)_

## `nefty generate pfp-file OUTPUT`

Expand Down Expand Up @@ -469,7 +470,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.6/src/commands/generate/pfp-file.ts)_
_See code: [src/commands/generate/pfp-file.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.7/src/commands/generate/pfp-file.ts)_

## `nefty generate template-file OUTPUT`

Expand Down Expand Up @@ -501,7 +502,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.6/src/commands/generate/template-file.ts)_
_See code: [src/commands/generate/template-file.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.7/src/commands/generate/template-file.ts)_

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

Expand All @@ -523,7 +524,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.6/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.7/src/commands/generate/token-transfer-file.ts)_

## `nefty help [COMMAND]`

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

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

## `nefty pfps build INPUT`

Expand Down Expand Up @@ -588,7 +589,33 @@ 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.6/src/commands/pfps/build.ts)_
_See code: [src/commands/pfps/build.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.7/src/commands/pfps/build.ts)_

## `nefty pfps cover INPUT`

Generates a cover image based on the generated pfps.

```
USAGE
$ nefty pfps cover INPUT -q <value> [-i <value>]
ARGUMENTS
INPUT Directory where the pfps are saved.
FLAGS
-i, --include=<value>... Include specific dnas in the cover.
-q, --quantity=<value> (required) [default: 20] Number of images to use in the cover.
DESCRIPTION
Generates a cover image based on the generated pfps.
EXAMPLES
Generates the cover image with a width of 400 and 50 pfps.
$ nefty pfps cover pfps -w 400 -q 50
```

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

## `nefty pfps generate INPUT OUTPUT`

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

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

## `nefty pfps mint INPUT`

Expand All @@ -643,7 +670,7 @@ EXAMPLES
$ nefty pfps mint ./pfps-folder
```

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

## `nefty templates`

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

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

## `nefty templates create INPUT`

Expand All @@ -681,7 +708,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.6/src/commands/templates/create.ts)_
_See code: [src/commands/templates/create.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.7/src/commands/templates/create.ts)_

## `nefty templates export OUTPUT`

Expand Down Expand Up @@ -713,7 +740,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.6/src/commands/templates/export.ts)_
_See code: [src/commands/templates/export.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.7/src/commands/templates/export.ts)_

## `nefty tokens`

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

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

## `nefty tokens transfer INPUT`

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

_See code: [src/commands/tokens/transfer.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.6/src/commands/tokens/transfer.ts)_
_See code: [src/commands/tokens/transfer.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.7/src/commands/tokens/transfer.ts)_
<!-- commandsstop -->
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nefty/cli",
"version": "0.2.6",
"version": "0.2.7",
"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,12 +69,14 @@
"@wharfkit/wallet-plugin-anchor": "^1.3.0",
"atomicassets": "^1.5.1",
"cli-progress": "^3.12.0",
"gifenc": "^1.0.3",
"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",
"sharp-gif2": "^0.1.3",
"terminal-link": "^3.0.0",
"undici": "^6.14.1",
"write-excel-file": "^1.4.27"
Expand Down Expand Up @@ -112,5 +114,8 @@
"eslint",
"prettier --check"
]
},
"resolutions": {
"sharp": "0.32.5"
}
}
2 changes: 1 addition & 1 deletion src/commands/config/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class SetCommand extends Command {
return { ...accumulator, [key]: config[key as keyof SettingsConfig] };
}, {}) as SettingsConfig;

const spinner = makeSpinner('Validating configurations...');
const spinner = makeSpinner('Validating configurations...').start();
const validConfi = await validate(updatedConf);
spinner.succeed();

Expand Down
2 changes: 1 addition & 1 deletion src/commands/generate/pfp-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export default class GeneratePfpFileCommand extends BaseCommand {
})),
]);

const spinner = makeSpinner('Generating file...');
const spinner = makeSpinner('Generating file...').start();
await writeXlsxFile(data, {
sheets: [...layers.map((layer) => layer), '_force_'],
filePath: output,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/generate/token-transfer-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class GenerateTokenTransferFileCommand extends BaseCommand {
],
];

const spinner = makeSpinner('Generating file...');
const spinner = makeSpinner('Generating file...').start();
await writeXlsxFile(data, {
filePath: output,
});
Expand Down
81 changes: 81 additions & 0 deletions src/commands/pfps/cover.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Args, Flags } from '@oclif/core';
import { BaseCommand } from '../../base/BaseCommand.js';
import { join } from 'node:path';
import { generateCover } from '../../services/pfp-service.js';
import { existsSync, readFileSync } from 'node:fs';
import { PfpManifest } from '../../types/pfps.js';
import { makeSpinner } from '../../utils/tty-utils.js';

export default class PfpCoverCommand extends BaseCommand {
static examples = [
{
command: '<%= config.bin %> <%= command.id %> pfps -w 400 -q 50',
description: 'Generates the cover image with a width of 400 and 50 pfps.',
},
];
static description = 'Generates a cover image based on the generated pfps.';

static args = {
input: Args.directory({
description: 'Directory where the pfps are saved.',
required: true,
}),
};

static flags = {
quantity: Flags.integer({
char: 'q',
description: 'Number of images to use in the cover.',
default: 20,
required: true,
}),
include: Flags.string({
char: 'i',
description: 'Include specific dnas in the cover.',
multiple: true,
}),
};

public async run(): Promise<void> {
const { flags, args } = await this.parse(PfpCoverCommand);
const { input } = args;
const { quantity, include } = flags;

const manifestPath = join(input, 'manifest.json');
if (!existsSync(manifestPath)) {
throw new Error('No manifest file found. Run the build command first.');
}

const spinner = makeSpinner('Generating cover image...').start();

const manifest: PfpManifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
const pfps = [...manifest.pfps].sort(() => Math.random() - 0.5);
const samplePfps = [];
for (let i = pfps.length - 1; i >= 0; i--) {
const pfp = pfps[i];
if (include && !include.includes(pfp.dna)) {
continue;
}
samplePfps.push(pfp);
pfps.splice(i, 1);
if (samplePfps.length >= quantity) {
break;
}
}

const missingPfps = quantity - samplePfps.length;
if (missingPfps > 0) {
const pfsToAdd = pfps.slice(0, missingPfps);
samplePfps.push(...pfsToAdd);
}

samplePfps.sort(() => Math.random() - 0.5);

const imagePaths = samplePfps.map((pfp) => join(input, 'images', `${pfp.dna}.png`));
await generateCover({
imagePaths,
outputFolder: input,
});
spinner.succeed();
}
}
Loading

0 comments on commit 109523b

Please sign in to comment.