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 +11 -8
- package/lib/index.js +10 -10
- package/lib/utils/addStyleCommand.d.ts +3 -0
- package/lib/utils/addStyleCommand.js +74 -0
- package/lib/utils/getPackageJson.d.ts +2 -0
- package/lib/utils/getPackageJson.js +5 -0
- package/lib/{commands/create/utils/getSchema.d.ts → utils/getStyleCommandSchema.d.ts} +1 -1
- package/lib/{commands/create/utils/getSchema.js → utils/getStyleCommandSchema.js} +1 -1
- package/package.json +6 -6
- package/lib/commands/create/index.d.ts +0 -2
- package/lib/commands/create/index.js +0 -85
- /package/lib/{commands/create/utils → utils}/createRandomSeed.d.ts +0 -0
- /package/lib/{commands/create/utils → utils}/createRandomSeed.js +0 -0
- /package/lib/{commands/create/utils → utils}/getOptionsBySchema.d.ts +0 -0
- /package/lib/{commands/create/utils → utils}/getOptionsBySchema.js +0 -0
- /package/lib/{commands/create/utils → utils}/outputStyleLicenseBanner.d.ts +0 -0
- /package/lib/{commands/create/utils → utils}/outputStyleLicenseBanner.js +0 -0
- /package/lib/{commands/create/utils → utils}/validateInputBySchema.d.ts +0 -0
- /package/lib/{commands/create/utils → utils}/validateInputBySchema.js +0 -0
package/README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
<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
|
|
7
|
-
<
|
|
8
|
-
|
|
9
|
-
|
|
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 {
|
|
5
|
-
import {
|
|
5
|
+
import { getPackageJson } from './utils/getPackageJson.js';
|
|
6
|
+
import { addStyleCommand } from './utils/addStyleCommand.js';
|
|
6
7
|
(async () => {
|
|
7
|
-
const pkg = await
|
|
8
|
+
const pkg = await getPackageJson();
|
|
8
9
|
updateNotifier({ pkg }).notify();
|
|
9
|
-
yargs(hideBin(process.argv))
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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,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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dicebear",
|
|
3
|
-
"version": "8.0.
|
|
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.
|
|
29
|
-
"@dicebear/core": "8.0.
|
|
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": "^
|
|
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.
|
|
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": "
|
|
56
|
+
"gitHead": "dc11ff0fa0328c521e5769fde4414ad5a6dc7d2d"
|
|
57
57
|
}
|
|
@@ -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
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|