Skip to content

Commit

Permalink
Add command to generate mosaic
Browse files Browse the repository at this point in the history
  • Loading branch information
jandrad committed Apr 28, 2024
1 parent f84989c commit 806a722
Show file tree
Hide file tree
Showing 6 changed files with 291 additions and 72 deletions.
92 changes: 66 additions & 26 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.8 darwin-arm64 node-v18.19.1
@nefty/cli/0.2.9 darwin-arm64 node-v18.19.1
$ nefty --help [COMMAND]
USAGE
$ nefty COMMAND
Expand Down Expand Up @@ -254,6 +254,7 @@ The token transfer file is used to define the tokens to be transferred, the reci
* [`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 pfps mosaic INPUT`](#nefty-pfps-mosaic-input)
* [`nefty templates`](#nefty-templates)
* [`nefty templates create INPUT`](#nefty-templates-create-input)
* [`nefty templates export OUTPUT`](#nefty-templates-export-output)
Expand All @@ -272,7 +273,7 @@ DESCRIPTION
Manages a collection's assets.
```

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

## `nefty assets mint INPUT`

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

## `nefty config`

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

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

## `nefty config auth`

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

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

## `nefty config get`

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

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

## `nefty config init`

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

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

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

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

## `nefty generate`

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

## `nefty generate mint-file OUTPUT`

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

## `nefty generate pfp-file OUTPUT`

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

## `nefty generate template-file OUTPUT`

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

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

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

## `nefty help [COMMAND]`

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

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

## `nefty pfps build INPUT`

Expand Down Expand Up @@ -589,33 +590,39 @@ 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.8/src/commands/pfps/build.ts)_
_See code: [src/commands/pfps/build.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.9/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>]
$ nefty pfps cover INPUT -q <value> [-i <value>] [--delay <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.
--delay=<value> [default: 200] Delay in ms between each image 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.
Generates the cover image with 50 pfps.
$ nefty pfps cover pfps -w 400 -q 50
$ nefty pfps cover pfps -q 50
Generates the cover image with 50 pfps, forcing the use of dnas 0b1b...b5b and ff28...0c6b
$ nefty pfps cover pfps -q 50 -i 0b1b2e8ad9672bed621e8259894ea8152857d3dfcc15d6dcccebc98b618d8b5b \
ff28ca1c5749e6a6369dae7fe7d334b5b5ca40e43f1c345e7f0b4b22b36c0c6b
```

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

## `nefty pfps generate INPUT OUTPUT`

Expand Down Expand Up @@ -644,7 +651,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.8/src/commands/pfps/generate.ts)_
_See code: [src/commands/pfps/generate.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.9/src/commands/pfps/generate.ts)_

## `nefty pfps mint INPUT`

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

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

## `nefty pfps mosaic INPUT`

Generates a mosaic based on the generated pfps.

```
USAGE
$ nefty pfps mosaic INPUT -q <value> [-i <value>] [--delay <value>] [-w <value>]
ARGUMENTS
INPUT Directory where the pfps are saved.
FLAGS
-i, --include=<value>... Include specific dnas in the cover.
-q, --quantity=<value> (required) [default: 25] Number of images to use in the cover.
-w, --width=<value> [default: 1600] Expected final width of the mosaic.
--delay=<value> [default: 200] Delay in ms between each image in the cover.
DESCRIPTION
Generates a mosaic based on the generated pfps.
EXAMPLES
Generates a mosaic with 25 pfps.
$ nefty pfps mosaic pfps -q 25
Generates a mosaic 25 pfps, forcing the use of dnas 0b1b...b5b and ff28...0c6b
$ nefty pfps mosaic pfps -q 25 -i 0b1b2e8ad9672bed621e8259894ea8152857d3dfcc15d6dcccebc98b618d8b5b \
ff28ca1c5749e6a6369dae7fe7d334b5b5ca40e43f1c345e7f0b4b22b36c0c6b
```

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

## `nefty templates`

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

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

## `nefty templates create INPUT`

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

## `nefty templates export OUTPUT`

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

## `nefty tokens`

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

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

## `nefty tokens transfer INPUT`

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

_See code: [src/commands/tokens/transfer.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.8/src/commands/tokens/transfer.ts)_
_See code: [src/commands/tokens/transfer.ts](https://github.com/neftyblocks/neftyblocks-cli/blob/v0.2.9/src/commands/tokens/transfer.ts)_
<!-- commandsstop -->
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nefty/cli",
"version": "0.2.8",
"version": "0.2.9",
"description": "The NeftyBlocks cli will help you manage your collection with commands to create templates, mint assets, and more.",
"keywords": [
"oclif"
Expand Down
45 changes: 20 additions & 25 deletions src/commands/pfps/cover.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
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 { generateCover, getPfpsSample } 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.',
command: '<%= config.bin %> <%= command.id %> pfps -q 50',
description: 'Generates the cover image with 50 pfps.',
},
{
command:
'<%= config.bin %> <%= command.id %> pfps -q 50 -i 0b1b2e8ad9672bed621e8259894ea8152857d3dfcc15d6dcccebc98b618d8b5b ff28ca1c5749e6a6369dae7fe7d334b5b5ca40e43f1c345e7f0b4b22b36c0c6b',
description: 'Generates the cover image with 50 pfps, forcing the use of dnas 0b1b...b5b and ff28...0c6b',
},
];
static description = 'Generates a cover image based on the generated pfps.';
Expand All @@ -34,12 +39,16 @@ export default class PfpCoverCommand extends BaseCommand {
description: 'Include specific dnas in the cover.',
multiple: true,
}),
delay: Flags.integer({
description: 'Delay in ms between each image in the cover.',
default: 200,
}),
};

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

const manifestPath = join(input, 'manifest.json');
if (!existsSync(manifestPath)) {
Expand All @@ -49,31 +58,17 @@ export default class PfpCoverCommand extends BaseCommand {
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 samplePfps = getPfpsSample({
manifest,
quantity,
include,
randomize: true,
});

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

0 comments on commit 806a722

Please sign in to comment.