dicebear 5.0.0-alpha.9 → 5.0.0-beta.0
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/LICENSE +1 -1
- package/bin/index.js +2 -2
- package/lib/index.js +14 -15
- package/lib/utils/addStyleCommand.d.ts +5 -0
- package/lib/utils/addStyleCommand.js +59 -0
- package/lib/utils/getOptionsBySchema.d.ts +1 -1
- package/lib/utils/getOptionsBySchema.js +24 -18
- package/lib/utils/getPackageJson.d.ts +1 -1
- package/lib/utils/getPackageJson.js +4 -26
- package/lib/utils/getStyleCommandSchema.d.ts +3 -0
- package/lib/utils/getStyleCommandSchema.js +30 -0
- package/lib/utils/outputStyleLicenseBanner.js +14 -16
- package/lib/utils/validateInputBySchema.d.ts +2 -1
- package/lib/utils/validateInputBySchema.js +7 -29
- package/package.json +38 -40
- package/lib/utils/command/makeCreateCommand.d.ts +0 -1
- package/lib/utils/command/makeCreateCommand.js +0 -41
- package/lib/utils/command/makeCreateStyleCommand.d.ts +0 -2
- package/lib/utils/command/makeCreateStyleCommand.js +0 -102
package/LICENSE
CHANGED
package/bin/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node --no-warnings
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import '../lib/index.js';
|
package/lib/index.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const update_notifier_1 = __importDefault(require("update-notifier"));
|
|
8
|
-
const getPackageJson_1 = require("./utils/getPackageJson");
|
|
9
|
-
const makeCreateCommand_1 = require("./utils/command/makeCreateCommand");
|
|
1
|
+
import updateNotifier from 'update-notifier';
|
|
2
|
+
import * as collection from '@dicebear/collection';
|
|
3
|
+
import yargs from 'yargs';
|
|
4
|
+
import { hideBin } from 'yargs/helpers';
|
|
5
|
+
import { getPackageJson } from './utils/getPackageJson.js';
|
|
6
|
+
import { addStyleCommand } from './utils/addStyleCommand.js';
|
|
10
7
|
(async () => {
|
|
11
|
-
const pkg = await
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
const pkg = await getPackageJson();
|
|
9
|
+
updateNotifier({ pkg }).notify();
|
|
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();
|
|
17
16
|
})();
|
|
@@ -0,0 +1,5 @@
|
|
|
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<yargs.Omit<{
|
|
4
|
+
outputPath: string;
|
|
5
|
+
}, string> & yargs.InferredOptionTypes<Record<string, any>>>;
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
export function addStyleCommand(cli, name, style) {
|
|
13
|
+
const schema = getStyleCommandSchema(style);
|
|
14
|
+
return cli.command({
|
|
15
|
+
command: `${name} [outputPath]`,
|
|
16
|
+
describe: `Generate "${name}" avatar(s)`,
|
|
17
|
+
builder: (yargs) => {
|
|
18
|
+
return yargs
|
|
19
|
+
.default('outputPath', '.')
|
|
20
|
+
.options(getOptionsBySchema(schema));
|
|
21
|
+
},
|
|
22
|
+
handler: async (argv) => {
|
|
23
|
+
const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
|
|
24
|
+
const validated = validateInputBySchema(argv, schema);
|
|
25
|
+
const count = validated.count;
|
|
26
|
+
const includeExif = validated.exif;
|
|
27
|
+
outputStyleLicenseBanner(name, style);
|
|
28
|
+
bar.start(count, 0);
|
|
29
|
+
const queue = new PQueue({ concurrency: os.cpus().length });
|
|
30
|
+
queue.on('next', () => {
|
|
31
|
+
bar.update(count - queue.size - queue.pending);
|
|
32
|
+
});
|
|
33
|
+
const outputPath = path.resolve(process.cwd(), argv.outputPath);
|
|
34
|
+
await fs.ensureDir(outputPath);
|
|
35
|
+
for (let i = 0; i < count; i++) {
|
|
36
|
+
queue.add(async () => {
|
|
37
|
+
const fileName = path.resolve(process.cwd(), outputPath, `${name}-${i}.${validated.format}`);
|
|
38
|
+
const avatar = createAvatar(style, validated);
|
|
39
|
+
switch (validated.format) {
|
|
40
|
+
case 'svg':
|
|
41
|
+
await avatar.toFile(fileName);
|
|
42
|
+
break;
|
|
43
|
+
case 'png':
|
|
44
|
+
await avatar.png({ includeExif }).toFile(fileName);
|
|
45
|
+
break;
|
|
46
|
+
case 'jpg':
|
|
47
|
+
case 'jpeg':
|
|
48
|
+
await avatar.jpeg({ includeExif }).toFile(fileName);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
bar.increment();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
await queue.onIdle();
|
|
55
|
+
bar.stop();
|
|
56
|
+
exiftool.end();
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { JSONSchema7 } from 'json-schema';
|
|
2
|
-
export declare function getOptionsBySchema(schema: JSONSchema7):
|
|
2
|
+
export declare function getOptionsBySchema(schema: JSONSchema7): Record<string, any>;
|
|
@@ -1,34 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getOptionsBySchema = void 0;
|
|
4
|
-
const commander_1 = require("commander");
|
|
5
|
-
async function getOptionsBySchema(schema) {
|
|
6
|
-
const result = [];
|
|
1
|
+
export function getOptionsBySchema(schema) {
|
|
2
|
+
const result = {};
|
|
7
3
|
for (var key in schema.properties) {
|
|
8
4
|
if (false === schema.properties.hasOwnProperty(key)) {
|
|
9
5
|
continue;
|
|
10
6
|
}
|
|
11
7
|
const property = schema.properties[key];
|
|
12
8
|
if (typeof property === 'object') {
|
|
13
|
-
const option =
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
const option = {
|
|
10
|
+
type: property.type,
|
|
11
|
+
};
|
|
12
|
+
if (option.type === 'integer') {
|
|
13
|
+
option.type = 'number';
|
|
14
|
+
}
|
|
15
|
+
option.choices = [];
|
|
16
16
|
if (property.enum) {
|
|
17
|
-
choices.push(...property.enum.filter((v) => typeof v === 'string'));
|
|
17
|
+
option.choices.push(...property.enum.filter((v) => typeof v === 'string'));
|
|
18
18
|
}
|
|
19
|
-
if (typeof property.items === 'object' &&
|
|
20
|
-
|
|
19
|
+
if (typeof property.items === 'object' &&
|
|
20
|
+
'enum' in property.items &&
|
|
21
|
+
property.items.enum) {
|
|
22
|
+
option.choices.push(...property.items.enum.filter((v) => typeof v === 'string'));
|
|
21
23
|
}
|
|
22
|
-
if (choices.length
|
|
23
|
-
|
|
24
|
+
if (option.choices.length === 0) {
|
|
25
|
+
delete option.choices;
|
|
24
26
|
}
|
|
25
27
|
if (property.default !== undefined && property.default !== null) {
|
|
26
|
-
option.default
|
|
28
|
+
option.default =
|
|
29
|
+
typeof property.default === 'boolean'
|
|
30
|
+
? property.default
|
|
31
|
+
: property.default;
|
|
32
|
+
}
|
|
33
|
+
if (property.description) {
|
|
34
|
+
option.description = property.description;
|
|
27
35
|
}
|
|
28
|
-
|
|
29
|
-
result.push(option);
|
|
36
|
+
result[key] = option;
|
|
30
37
|
}
|
|
31
38
|
}
|
|
32
39
|
return result;
|
|
33
40
|
}
|
|
34
|
-
exports.getOptionsBySchema = getOptionsBySchema;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Package } from 'update-notifier';
|
|
2
|
-
export declare function getPackageJson(
|
|
2
|
+
export declare function getPackageJson(): Promise<Package>;
|
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.getPackageJson = void 0;
|
|
23
|
-
function getPackageJson(packageName) {
|
|
24
|
-
const packageJson = packageName ? `${packageName}/package.json` : '../../package.json';
|
|
25
|
-
return Promise.resolve().then(() => __importStar(require(packageJson)));
|
|
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);
|
|
26
5
|
}
|
|
27
|
-
exports.getPackageJson = getPackageJson;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { schema as coreSchema } from '@dicebear/core';
|
|
2
|
+
import mergeAllOf from 'json-schema-merge-allof';
|
|
3
|
+
export function getStyleCommandSchema(style) {
|
|
4
|
+
return mergeAllOf({
|
|
5
|
+
allOf: [
|
|
6
|
+
{
|
|
7
|
+
properties: {
|
|
8
|
+
count: {
|
|
9
|
+
description: 'Defines how many avatars to create.',
|
|
10
|
+
type: 'number',
|
|
11
|
+
default: 1,
|
|
12
|
+
},
|
|
13
|
+
format: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
enum: ['svg', 'png', 'jpg', 'jpeg'],
|
|
16
|
+
default: 'svg',
|
|
17
|
+
},
|
|
18
|
+
exif: {
|
|
19
|
+
description: 'Include Exif Metadata',
|
|
20
|
+
type: 'boolean',
|
|
21
|
+
default: false,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
coreSchema,
|
|
26
|
+
style.schema,
|
|
27
|
+
],
|
|
28
|
+
additionalItems: true,
|
|
29
|
+
}, { ignoreAdditionalProperties: true });
|
|
30
|
+
}
|
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.outputStyleLicenseBanner = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const terminal_link_1 = __importDefault(require("terminal-link"));
|
|
9
|
-
function outputStyleLicenseBanner(name, style) {
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import chalkTemplate from 'chalk-template';
|
|
3
|
+
export function outputStyleLicenseBanner(name, style) {
|
|
10
4
|
let banner = ['-'.repeat(64)];
|
|
11
|
-
let creator = Array.isArray(style.meta.creator)
|
|
5
|
+
let creator = Array.isArray(style.meta.creator)
|
|
6
|
+
? style.meta.creator.join(', ')
|
|
7
|
+
: style.meta.creator;
|
|
12
8
|
if (style.meta.title && creator) {
|
|
13
|
-
banner.push(
|
|
9
|
+
banner.push(chalkTemplate `{bold ${style.meta.title}} by {bold ${creator}}`);
|
|
14
10
|
}
|
|
15
11
|
else if (style.meta.title) {
|
|
16
|
-
banner.push(
|
|
12
|
+
banner.push(chalkTemplate `{bold ${style.meta.title}}`);
|
|
17
13
|
}
|
|
18
14
|
else if (creator) {
|
|
19
|
-
banner.push(
|
|
15
|
+
banner.push(chalkTemplate `{bold ${name}} by {bold ${creator}}`);
|
|
20
16
|
}
|
|
21
17
|
banner.push('');
|
|
18
|
+
if (style.meta.homepage) {
|
|
19
|
+
banner.push(`Homepage: ${style.meta.homepage}`);
|
|
20
|
+
}
|
|
22
21
|
if (style.meta.source) {
|
|
23
22
|
banner.push(`Source: ${style.meta.source}`);
|
|
24
23
|
}
|
|
25
24
|
if (style.meta.license) {
|
|
26
|
-
banner.push(`License: ${
|
|
25
|
+
banner.push(`License: ${style.meta.license.name} - ${style.meta.license.url}`);
|
|
27
26
|
}
|
|
28
27
|
banner.push('-'.repeat(64));
|
|
29
28
|
banner.push('');
|
|
30
|
-
console.log(
|
|
29
|
+
console.log(chalk.blueBright(banner.join('\n')));
|
|
31
30
|
}
|
|
32
|
-
exports.outputStyleLicenseBanner = outputStyleLicenseBanner;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { JSONSchema7 } from 'json-schema';
|
|
2
|
-
|
|
2
|
+
import { ArgumentsCamelCase } from 'yargs';
|
|
3
|
+
export declare function validateInputBySchema(input: ArgumentsCamelCase<unknown>, schema: JSONSchema7): any;
|
|
@@ -1,42 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.validateInputBySchema = void 0;
|
|
7
|
-
const ajv_1 = __importDefault(require("ajv"));
|
|
8
|
-
function validateInputBySchema(input, schema) {
|
|
9
|
-
const validator = new ajv_1.default({
|
|
1
|
+
import Ajv from 'ajv';
|
|
2
|
+
export function validateInputBySchema(input, schema) {
|
|
3
|
+
const validator = new Ajv({
|
|
10
4
|
strict: false,
|
|
11
5
|
coerceTypes: true,
|
|
12
6
|
useDefaults: false,
|
|
13
|
-
removeAdditional:
|
|
7
|
+
removeAdditional: true,
|
|
14
8
|
});
|
|
15
9
|
const validate = validator.compile(schema);
|
|
16
|
-
const data =
|
|
17
|
-
for (var key in input) {
|
|
18
|
-
if (false === input.hasOwnProperty(key)) {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
if (schema.properties && key in schema.properties) {
|
|
22
|
-
const property = schema.properties[key];
|
|
23
|
-
if (typeof property === 'object' && property.type === 'array') {
|
|
24
|
-
data[key] = input[key].toString().split(',');
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
data[key] = input[key];
|
|
29
|
-
}
|
|
10
|
+
const data = JSON.parse(JSON.stringify(input));
|
|
30
11
|
if (false === validate(data)) {
|
|
31
12
|
if (validate.errors) {
|
|
32
|
-
for (var
|
|
33
|
-
|
|
34
|
-
new Error(`${errorKey} - ${validate.errors[errorKey]}`);
|
|
35
|
-
}
|
|
13
|
+
for (var error of validate.errors) {
|
|
14
|
+
throw new Error(`${error.keyword} - ${error.message}`);
|
|
36
15
|
}
|
|
37
16
|
}
|
|
38
17
|
throw new Error('Unknown error');
|
|
39
18
|
}
|
|
40
19
|
return data;
|
|
41
20
|
}
|
|
42
|
-
exports.validateInputBySchema = validateInputBySchema;
|
package/package.json
CHANGED
|
@@ -1,59 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dicebear",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-beta.0",
|
|
4
|
+
"private": false,
|
|
4
5
|
"description": "CLI for DiceBear - An avatar library for designers and developers",
|
|
5
|
-
"
|
|
6
|
-
"types": "lib/index.d.ts",
|
|
6
|
+
"homepage": "https://github.com/dicebear/dicebear",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git
|
|
10
|
-
"directory": "/packages/dicebear"
|
|
9
|
+
"url": "git+https://github.com/dicebear/dicebear.git"
|
|
11
10
|
},
|
|
12
|
-
"author": "Florian Körner <contact@florian-koerner.com>",
|
|
13
11
|
"license": "MIT",
|
|
14
|
-
"
|
|
12
|
+
"author": "Florian Körner <contact@florian-koerner.com>",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": "./lib/index.js",
|
|
15
|
+
"types": "./lib/index.d.ts",
|
|
16
|
+
"bin": "./bin/index.js",
|
|
15
17
|
"files": [
|
|
16
|
-
"bin",
|
|
17
|
-
"lib",
|
|
18
18
|
"LICENSE",
|
|
19
|
+
"lib",
|
|
19
20
|
"README.md"
|
|
20
21
|
],
|
|
21
22
|
"scripts": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"build:ts": "tsc"
|
|
23
|
+
"prebuild": "del-cli lib",
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"prepublishOnly": "npm run build"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@dicebear/collection": "^5.0.0-
|
|
29
|
-
"@dicebear/core": "^5.0.0-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"fs-extra": "^
|
|
28
|
+
"@dicebear/collection": "^5.0.0-beta.0",
|
|
29
|
+
"@dicebear/core": "^5.0.0-beta.0",
|
|
30
|
+
"@resvg/resvg-js": "^2.0.0",
|
|
31
|
+
"ajv": "^8.11.0",
|
|
32
|
+
"chalk": "^5.0.1",
|
|
33
|
+
"chalk-template": "^0.4.0",
|
|
34
|
+
"cli-progress": "^3.10.0",
|
|
35
|
+
"exiftool-vendored": "^16.3.0",
|
|
36
|
+
"fs-extra": "^10.1.0",
|
|
37
37
|
"json-schema-merge-allof": "^0.8.1",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"update-notifier": "^5.1.0"
|
|
38
|
+
"p-queue": "^7.2.0",
|
|
39
|
+
"sharp": "^0.30.4",
|
|
40
|
+
"update-notifier": "^5.1.0",
|
|
41
|
+
"yargs": "^17.4.1"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
|
-
"@tsconfig/
|
|
46
|
-
"@types/cli-progress": "^3.9.
|
|
47
|
-
"@types/
|
|
48
|
-
"@types/
|
|
49
|
-
"@types/
|
|
50
|
-
"@types/
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"@types/update-notifier": "^5.0.0",
|
|
54
|
-
"shx": "^0.3.3",
|
|
55
|
-
"typescript": "^4.3.5"
|
|
44
|
+
"@tsconfig/recommended": "^1.0.1",
|
|
45
|
+
"@types/cli-progress": "^3.9.2",
|
|
46
|
+
"@types/fs-extra": "^9.0.13",
|
|
47
|
+
"@types/json-schema-merge-allof": "^0.6.1",
|
|
48
|
+
"@types/update-notifier": "^5.1.0",
|
|
49
|
+
"@types/yargs": "^17.0.10",
|
|
50
|
+
"del-cli": "^4.0.1",
|
|
51
|
+
"typescript": "^4.6.3"
|
|
56
52
|
},
|
|
57
|
-
"
|
|
58
|
-
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
55
|
+
},
|
|
56
|
+
"gitHead": "f939afabe6ade034e344b1983caa21de49873dda"
|
|
59
57
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function makeCreateCommand(): Promise<import("commander").Command>;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.makeCreateCommand = void 0;
|
|
23
|
-
const commander_1 = require("commander");
|
|
24
|
-
const makeCreateStyleCommand_1 = require("./makeCreateStyleCommand");
|
|
25
|
-
const collection = __importStar(require("@dicebear/collection"));
|
|
26
|
-
async function makeCreateCommand() {
|
|
27
|
-
const cmd = new commander_1.Command('create');
|
|
28
|
-
try {
|
|
29
|
-
for (let name of Object.keys(collection)) {
|
|
30
|
-
const style = collection[name];
|
|
31
|
-
cmd.addCommand(await (0, makeCreateStyleCommand_1.makeCreateStyleCommand)(name, style));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
cmd.action(() => {
|
|
36
|
-
throw new Error('Could not load `@dicebear/collection`.');
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return cmd;
|
|
40
|
-
}
|
|
41
|
-
exports.makeCreateCommand = makeCreateCommand;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.makeCreateStyleCommand = void 0;
|
|
26
|
-
const core_1 = require("@dicebear/core");
|
|
27
|
-
const commander_1 = require("commander");
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
30
|
-
const sharp_1 = __importDefault(require("sharp"));
|
|
31
|
-
const cli_progress_1 = __importDefault(require("cli-progress"));
|
|
32
|
-
const validateInputBySchema_1 = require("../validateInputBySchema");
|
|
33
|
-
const outputStyleLicenseBanner_1 = require("../outputStyleLicenseBanner");
|
|
34
|
-
const getOptionsBySchema_1 = require("../getOptionsBySchema");
|
|
35
|
-
const json_schema_merge_allof_1 = __importDefault(require("json-schema-merge-allof"));
|
|
36
|
-
async function makeCreateStyleCommand(name, style) {
|
|
37
|
-
const schema = (0, json_schema_merge_allof_1.default)({
|
|
38
|
-
allOf: [
|
|
39
|
-
{
|
|
40
|
-
properties: {
|
|
41
|
-
count: {
|
|
42
|
-
title: 'Count',
|
|
43
|
-
description: 'Defines how many avatars to create. Does not work in combination with a "seed".',
|
|
44
|
-
type: 'number',
|
|
45
|
-
default: 1,
|
|
46
|
-
},
|
|
47
|
-
format: {
|
|
48
|
-
title: 'Format',
|
|
49
|
-
type: 'string',
|
|
50
|
-
enum: ['svg', 'png', 'jpg', 'jpeg'],
|
|
51
|
-
default: 'svg',
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
core_1.schema,
|
|
56
|
-
style.schema,
|
|
57
|
-
],
|
|
58
|
-
additionalItems: true,
|
|
59
|
-
}, { ignoreAdditionalProperties: true });
|
|
60
|
-
const cmd = new commander_1.Command(name);
|
|
61
|
-
cmd.arguments('[outputPath]');
|
|
62
|
-
for (let option of await (0, getOptionsBySchema_1.getOptionsBySchema)(schema)) {
|
|
63
|
-
cmd.addOption(option);
|
|
64
|
-
}
|
|
65
|
-
cmd.action(async (outputPath = '.', options = {}) => {
|
|
66
|
-
const bar = new cli_progress_1.default.SingleBar({}, cli_progress_1.default.Presets.shades_classic);
|
|
67
|
-
const validated = (0, validateInputBySchema_1.validateInputBySchema)(options, schema);
|
|
68
|
-
const promises = [];
|
|
69
|
-
(0, outputStyleLicenseBanner_1.outputStyleLicenseBanner)(name, style);
|
|
70
|
-
bar.start(validated.count, 0);
|
|
71
|
-
outputPath = path.resolve(process.cwd(), outputPath);
|
|
72
|
-
await fs_extra_1.default.ensureDir(outputPath);
|
|
73
|
-
for (let i = 0; i < validated.count; i++) {
|
|
74
|
-
promises.push((async () => {
|
|
75
|
-
if (validated.format !== 'svg') {
|
|
76
|
-
validated.base64 = false;
|
|
77
|
-
validated.dataUri = false;
|
|
78
|
-
validated.width = validated.width || validated.height || 512;
|
|
79
|
-
validated.height = validated.width;
|
|
80
|
-
}
|
|
81
|
-
const fileName = path.resolve(process.cwd(), outputPath, `${name}-${i}.${validated.format}`);
|
|
82
|
-
let avatar = (0, core_1.createAvatar)(style, validated);
|
|
83
|
-
switch (validated.format) {
|
|
84
|
-
case 'png':
|
|
85
|
-
await (0, sharp_1.default)(Buffer.from(avatar)).png().toFile(fileName);
|
|
86
|
-
break;
|
|
87
|
-
case 'jpg':
|
|
88
|
-
case 'jpeg':
|
|
89
|
-
await (0, sharp_1.default)(Buffer.from(avatar)).jpeg().toFile(fileName);
|
|
90
|
-
break;
|
|
91
|
-
default:
|
|
92
|
-
await fs_extra_1.default.writeFile(fileName, avatar, { encoding: 'utf-8' });
|
|
93
|
-
}
|
|
94
|
-
bar.increment();
|
|
95
|
-
})());
|
|
96
|
-
}
|
|
97
|
-
await Promise.all(promises);
|
|
98
|
-
bar.stop();
|
|
99
|
-
});
|
|
100
|
-
return cmd;
|
|
101
|
-
}
|
|
102
|
-
exports.makeCreateStyleCommand = makeCreateStyleCommand;
|