dicebear 8.0.0-rc.2 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,13 @@
1
- <h1 align="center"><img src="https://dicebear.com/api/male/seed.svg?mood=happy" width="124" /> <br />DiceBear CLI</h1>
2
- <p align="center">
3
- <strong>CLI for DiceBear - An avatar library for designers and developers.</strong>
4
- </p>
1
+ <h1><img src="https://www.dicebear.com/logo-readme.svg" width="28" /> DiceBear CLI</h1>
5
2
 
6
- <p align="center">
7
- <a href="https://dicebear.com/integrations/cli">
8
- Read Documentation
9
- </a>
3
+ <p>
4
+ <img src="https://api.dicebear.com/8.x/adventurer/svg?seed=Mimi&backgroundColor=0077b6&radius=10" width="64" />
5
+ <img src="https://api.dicebear.com/8.x/open-peeps/svg?seed=Kitty&backgroundColor=0096c7&radius=10" width="64" />
6
+ <img src="https://api.dicebear.com/8.x/pixel-art/svg?seed=Lilly&backgroundColor=00b4d8&radius=10" width="64" />
7
+ <img src="https://api.dicebear.com/8.x/lorelei/svg?seed=Tigger&backgroundColor=48cae4&radius=10" width="64" />
8
+ <img src="https://api.dicebear.com/8.x/bottts/svg?seed=Zoe&backgroundColor=90e0ef&radius=10" width="64" />
9
+ <img src="https://api.dicebear.com/8.x/initials/svg?seed=..&backgroundColor=ade8f4&radius=10" width="64" />
10
10
  </p>
11
+
12
+ [Playground](https://www.dicebear.com/playground) |
13
+ [Documentation](https://www.dicebear.com/how-to-use/cli/)
package/lib/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import updateNotifier from 'update-notifier';
2
+ import * as collection from '@dicebear/collection';
2
3
  import yargs from 'yargs';
3
4
  import { hideBin } from 'yargs/helpers';
4
- import { readJson } from 'fs-extra';
5
- import { createCommand } from './commands/create/index.js';
5
+ import { getPackageJson } from './utils/getPackageJson.js';
6
+ import { addStyleCommand } from './utils/addStyleCommand.js';
6
7
  (async () => {
7
- const pkg = await readJson(new URL('../../package.json', import.meta.url).pathname);
8
+ const pkg = await getPackageJson();
8
9
  updateNotifier({ pkg }).notify();
9
- yargs(hideBin(process.argv))
10
- .command(createCommand)
11
- .strictCommands()
12
- .demandCommand()
13
- .help()
14
- .locale('en')
15
- .parse();
10
+ const cli = yargs(hideBin(process.argv));
11
+ for (let name of Object.keys(collection)) {
12
+ const style = collection[name];
13
+ addStyleCommand(cli, name, style);
14
+ }
15
+ cli.demandCommand().help().locale('en').parse();
16
16
  })();
@@ -0,0 +1,3 @@
1
+ import { Style } from '@dicebear/core';
2
+ import yargs from 'yargs';
3
+ export declare function addStyleCommand(cli: yargs.Argv<{}>, name: string, style: Style<any>): yargs.Argv<{}>;
@@ -0,0 +1,74 @@
1
+ import { createAvatar } from '@dicebear/core';
2
+ import cliProgress from 'cli-progress';
3
+ import PQueue from 'p-queue';
4
+ import os from 'node:os';
5
+ import * as path from 'node:path';
6
+ import fs from 'fs-extra';
7
+ import { exiftool } from 'exiftool-vendored';
8
+ import { getStyleCommandSchema } from './getStyleCommandSchema.js';
9
+ import { getOptionsBySchema } from './getOptionsBySchema.js';
10
+ import { validateInputBySchema } from './validateInputBySchema.js';
11
+ import { outputStyleLicenseBanner } from './outputStyleLicenseBanner.js';
12
+ import { createRandomSeed } from './createRandomSeed.js';
13
+ export function addStyleCommand(cli, name, style) {
14
+ const schema = getStyleCommandSchema(style);
15
+ return cli.command({
16
+ command: `${name} [outputPath]`,
17
+ describe: `Generate "${name}" avatar(s)`,
18
+ builder: (yargs) => {
19
+ return yargs
20
+ .default('outputPath', '.')
21
+ .options(getOptionsBySchema(schema));
22
+ },
23
+ handler: async (argv) => {
24
+ const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
25
+ const validated = validateInputBySchema(argv, schema);
26
+ const format = validated.format;
27
+ const count = validated.count;
28
+ const includeExif = validated.exif;
29
+ const json = validated.json;
30
+ outputStyleLicenseBanner(name, style);
31
+ bar.start(count, 0);
32
+ const queue = new PQueue({ concurrency: os.cpus().length });
33
+ queue.on('next', () => {
34
+ bar.update(count - queue.size - queue.pending);
35
+ });
36
+ const outputPath = path.resolve(process.cwd(), argv.outputPath);
37
+ await fs.ensureDir(outputPath);
38
+ for (let i = 0; i < count; i++) {
39
+ queue.add(async () => {
40
+ const fileName = path.resolve(process.cwd(), outputPath, `${name}-${i}.${format}`);
41
+ const avatar = createAvatar(style, count <= 1
42
+ ? validated
43
+ : {
44
+ ...validated,
45
+ seed: createRandomSeed(),
46
+ });
47
+ switch (format) {
48
+ case 'svg':
49
+ await avatar.toFile(fileName);
50
+ break;
51
+ case 'png':
52
+ await avatar.png({ includeExif }).toFile(fileName);
53
+ break;
54
+ case 'jpg':
55
+ case 'jpeg':
56
+ await avatar.jpeg({ includeExif }).toFile(fileName);
57
+ break;
58
+ case 'json':
59
+ await fs.writeJSON(fileName, avatar.toJson(), { spaces: 2 });
60
+ break;
61
+ }
62
+ if (json && 'json' !== format) {
63
+ const jsonFileName = path.resolve(process.cwd(), outputPath, `${name}-${i}.json`);
64
+ await fs.writeJSON(jsonFileName, avatar.toJson(), { spaces: 2 });
65
+ }
66
+ bar.increment();
67
+ });
68
+ }
69
+ await queue.onIdle();
70
+ bar.stop();
71
+ exiftool.end();
72
+ },
73
+ });
74
+ }
@@ -0,0 +1,2 @@
1
+ import type { Package } from 'update-notifier';
2
+ export declare function getPackageJson(): Promise<Package>;
@@ -0,0 +1,5 @@
1
+ import fs from 'fs-extra';
2
+ export function getPackageJson() {
3
+ const packageJson = new URL('../../package.json', import.meta.url).pathname;
4
+ return fs.readJson(packageJson);
5
+ }
@@ -1,3 +1,3 @@
1
1
  import type { Style } from '@dicebear/core';
2
2
  import type { JSONSchema7 } from 'json-schema';
3
- export declare function getSchema(style: Style<any>): JSONSchema7;
3
+ export declare function getStyleCommandSchema(style: Style<any>): JSONSchema7;
@@ -1,6 +1,6 @@
1
1
  import { schema as coreSchema } from '@dicebear/core';
2
2
  import mergeAllOf from 'json-schema-merge-allof';
3
- export function getSchema(style) {
3
+ export function getStyleCommandSchema(style) {
4
4
  var _a;
5
5
  return mergeAllOf({
6
6
  allOf: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dicebear",
3
- "version": "8.0.0-rc.2",
3
+ "version": "8.0.1",
4
4
  "private": false,
5
5
  "description": "CLI for DiceBear - An avatar library for designers and developers",
6
6
  "homepage": "https://github.com/dicebear/dicebear",
@@ -25,18 +25,18 @@
25
25
  "prepublishOnly": "npm run build"
26
26
  },
27
27
  "dependencies": {
28
- "@dicebear/collection": "8.0.0-rc.2",
29
- "@dicebear/core": "8.0.0-rc.2",
28
+ "@dicebear/collection": "8.0.1",
29
+ "@dicebear/core": "8.0.1",
30
30
  "@resvg/resvg-js": "^2.4.1",
31
31
  "ajv": "^8.12.0",
32
32
  "chalk": "^5.2.0",
33
33
  "chalk-template": "^1.0.0",
34
34
  "cli-progress": "^3.12.0",
35
- "exiftool-vendored": "^22.0.0",
35
+ "exiftool-vendored": "^23.0.0",
36
36
  "fs-extra": "^11.1.1",
37
37
  "json-schema-merge-allof": "^0.8.1",
38
38
  "p-queue": "^7.3.4",
39
- "sharp": "^0.32.1",
39
+ "sharp": "^0.32.6",
40
40
  "update-notifier": "^6.0.2",
41
41
  "yargs": "^17.7.1"
42
42
  },
@@ -53,5 +53,5 @@
53
53
  "engines": {
54
54
  "node": ">=16.0.0"
55
55
  },
56
- "gitHead": "226c203a893f9e22401d35ab24c0418462d262c9"
56
+ "gitHead": "dc11ff0fa0328c521e5769fde4414ad5a6dc7d2d"
57
57
  }
@@ -1,2 +0,0 @@
1
- import type { CommandModule } from 'yargs';
2
- export declare const createCommand: CommandModule;
@@ -1,85 +0,0 @@
1
- import { createAvatar } from '@dicebear/core';
2
- import cliProgress from 'cli-progress';
3
- import PQueue from 'p-queue';
4
- import os from 'node:os';
5
- import * as path from 'node:path';
6
- import fs from 'fs-extra';
7
- import { exiftool } from 'exiftool-vendored';
8
- import * as collection from '@dicebear/collection';
9
- import { getSchema } from './utils/getSchema.js';
10
- import { getOptionsBySchema } from './utils/getOptionsBySchema.js';
11
- import { validateInputBySchema } from './utils/validateInputBySchema.js';
12
- import { outputStyleLicenseBanner } from './utils/outputStyleLicenseBanner.js';
13
- import { createRandomSeed } from './utils/createRandomSeed.js';
14
- export const createCommand = {
15
- command: `create`,
16
- describe: `Generate avatars`,
17
- builder: async (yargs) => {
18
- for (let name of Object.keys(collection)) {
19
- const style = collection[name];
20
- const schema = getSchema(style);
21
- yargs.command({
22
- command: `${name} [outputPath]`,
23
- describe: `Generate "${name}" avatars`,
24
- builder: (yargs) => {
25
- return yargs
26
- .default('outputPath', '.')
27
- .options(getOptionsBySchema(getSchema(style)));
28
- },
29
- handler: async (argv) => {
30
- const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
31
- const validated = validateInputBySchema(argv, schema);
32
- const format = validated.format;
33
- const count = validated.count;
34
- const includeExif = validated.exif;
35
- const json = validated.json;
36
- outputStyleLicenseBanner(name, style);
37
- bar.start(count, 0);
38
- const queue = new PQueue({ concurrency: os.cpus().length });
39
- queue.on('next', () => {
40
- bar.update(count - queue.size - queue.pending);
41
- });
42
- const outputPath = path.resolve(process.cwd(), argv.outputPath);
43
- await fs.ensureDir(outputPath);
44
- for (let i = 0; i < count; i++) {
45
- queue.add(async () => {
46
- const fileName = path.resolve(process.cwd(), outputPath, `${name}-${i}.${format}`);
47
- const avatar = createAvatar(style, count <= 1
48
- ? validated
49
- : {
50
- ...validated,
51
- seed: createRandomSeed(),
52
- });
53
- switch (format) {
54
- case 'svg':
55
- await avatar.toFile(fileName);
56
- break;
57
- case 'png':
58
- await avatar.png({ includeExif }).toFile(fileName);
59
- break;
60
- case 'jpg':
61
- case 'jpeg':
62
- await avatar.jpeg({ includeExif }).toFile(fileName);
63
- break;
64
- case 'json':
65
- await fs.writeJSON(fileName, avatar.toJson(), { spaces: 2 });
66
- break;
67
- }
68
- if (json && 'json' !== format) {
69
- const jsonFileName = path.resolve(process.cwd(), outputPath, `${name}-${i}.json`);
70
- await fs.writeJSON(jsonFileName, avatar.toJson(), { spaces: 2 });
71
- }
72
- bar.increment();
73
- });
74
- }
75
- await queue.onIdle();
76
- bar.stop();
77
- exiftool.end();
78
- },
79
- });
80
- }
81
- return yargs;
82
- },
83
- handler: async (argv) => {
84
- }
85
- };