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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Florian Körner
3
+ Copyright (c) 2022 Florian Körner
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/bin/index.js CHANGED
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node --no-warnings
2
2
 
3
- require('../lib');
3
+ import '../lib/index.js';
package/lib/index.js CHANGED
@@ -1,17 +1,16 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const commander_1 = require("commander");
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 (0, getPackageJson_1.getPackageJson)();
12
- const program = new commander_1.Command('dicebear');
13
- (0, update_notifier_1.default)({ pkg }).notify();
14
- program.version(pkg.version, '-v, --version');
15
- program.addCommand(await (0, makeCreateCommand_1.makeCreateCommand)());
16
- await program.parseAsync(process.argv);
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): Promise<import("commander").Option[]>;
2
+ export declare function getOptionsBySchema(schema: JSONSchema7): Record<string, any>;
@@ -1,34 +1,40 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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 = new commander_1.Option(`-${key} <value>`);
14
- let description = [property.title, property.description].filter((v) => v).join(' - ');
15
- let choices = [];
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' && 'enum' in property.items && property.items.enum) {
20
- choices.push(...property.items.enum.filter((v) => typeof v === 'string'));
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 > 0) {
23
- description += ` (choices: "${choices.join('", "')})`;
24
+ if (option.choices.length === 0) {
25
+ delete option.choices;
24
26
  }
25
27
  if (property.default !== undefined && property.default !== null) {
26
- option.default(typeof property.default === 'boolean' ? property.default : property.default.toString());
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
- option.description = description;
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(packageName?: string): Promise<Package>;
2
+ export declare function getPackageJson(): Promise<Package>;
@@ -1,27 +1,5 @@
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.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,3 @@
1
+ import type { Style } from '@dicebear/core';
2
+ import type { JSONSchema7 } from 'json-schema';
3
+ export declare function getStyleCommandSchema(style: Style<any>): JSONSchema7;
@@ -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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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) ? style.meta.creator.join(', ') : 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((0, chalk_1.default) `{bold ${style.meta.title}} by {bold ${creator}}`);
9
+ banner.push(chalkTemplate `{bold ${style.meta.title}} by {bold ${creator}}`);
14
10
  }
15
11
  else if (style.meta.title) {
16
- banner.push((0, chalk_1.default) `{bold ${style.meta.title}}`);
12
+ banner.push(chalkTemplate `{bold ${style.meta.title}}`);
17
13
  }
18
14
  else if (creator) {
19
- banner.push((0, chalk_1.default) `{bold ${name}} by {bold ${creator}}`);
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: ${(0, terminal_link_1.default)(style.meta.license.name, style.meta.license.url)}`);
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(chalk_1.default.blueBright(banner.join('\n')));
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
- export declare function validateInputBySchema(input: Record<string, string | number>, schema: JSONSchema7): Record<string, string | number | boolean | string[] | number[] | boolean[]>;
2
+ import { ArgumentsCamelCase } from 'yargs';
3
+ export declare function validateInputBySchema(input: ArgumentsCamelCase<unknown>, schema: JSONSchema7): any;
@@ -1,42 +1,20 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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: false,
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 errorKey in validate.errors) {
33
- if (validate.errors.hasOwnProperty(errorKey)) {
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-alpha.9",
3
+ "version": "5.0.0-beta.0",
4
+ "private": false,
4
5
  "description": "CLI for DiceBear - An avatar library for designers and developers",
5
- "bin": "bin/index.js",
6
- "types": "lib/index.d.ts",
6
+ "homepage": "https://github.com/dicebear/dicebear",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git@github.com:dicebear/dicebear.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
- "private": false,
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
- "prepublishOnly": "npm run build",
23
- "prebuild": "shx rm -rf lib",
24
- "build": "npm run build:ts",
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-alpha.9",
29
- "@dicebear/core": "^5.0.0-alpha.9",
30
- "ajv": "^8.1.0",
31
- "chalk": "^4.1.1",
32
- "cli-progress": "^3.9.0",
33
- "commander": "^7.2.0",
34
- "download": "^8.0.0",
35
- "execa": "^4.1.0",
36
- "fs-extra": "^9.1.0",
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
- "ora": "^5.4.0",
39
- "replace-in-file": "^6.2.0",
40
- "sharp": "^0.28.1",
41
- "terminal-link": "^2.1.1",
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/node14": "^1.0.1",
46
- "@types/cli-progress": "^3.9.1",
47
- "@types/download": "^6.2.4",
48
- "@types/fs-extra": "^9.0.11",
49
- "@types/json-schema": "^7.0.7",
50
- "@types/json-schema-merge-allof": "^0.6.0",
51
- "@types/semver": "^7.3.6",
52
- "@types/sharp": "^0.28.0",
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
- "homepage": "https://github.com/dicebear/dicebear",
58
- "gitHead": "d2861228315afd1fef06969d1eaf9655a027fbbb"
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,2 +0,0 @@
1
- import type { Style } from '@dicebear/core';
2
- export declare function makeCreateStyleCommand(name: string, style: Style<any>): Promise<import("commander").Command>;
@@ -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;