dicebear 4.10.2 → 5.0.0-alpha.11

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
@@ -4,7 +4,7 @@
4
4
  </p>
5
5
 
6
6
  <p align="center">
7
- <a href="https://avatars.dicebear.com/integrations/cli">
7
+ <a href="https://dicebear.com/integrations/cli">
8
8
  Read Documentation
9
9
  </a>
10
10
  </p>
package/bin/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require('../lib');
3
+ import '../lib/index.js';
package/lib/index.js CHANGED
@@ -1,19 +1,12 @@
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");
10
- const makeProjectCommand_1 = require("./utils/command/makeProjectCommand");
1
+ import { Command } from 'commander';
2
+ import updateNotifier from 'update-notifier';
3
+ import { getPackageJson } from './utils/getPackageJson.js';
4
+ import { makeCreateCommand } from './utils/command/makeCreateCommand.js';
11
5
  (async () => {
12
- const pkg = await (0, getPackageJson_1.getPackageJson)();
13
- const program = new commander_1.Command('dicebear');
14
- (0, update_notifier_1.default)({ pkg }).notify();
6
+ const pkg = await getPackageJson();
7
+ const program = new Command('dicebear');
8
+ updateNotifier({ pkg }).notify();
15
9
  program.version(pkg.version, '-v, --version');
16
- program.addCommand(await (0, makeCreateCommand_1.makeCreateCommand)());
17
- program.addCommand(await (0, makeProjectCommand_1.makeProjectCommand)());
10
+ program.addCommand(await makeCreateCommand());
18
11
  await program.parseAsync(process.argv);
19
12
  })();
@@ -1,41 +1,15 @@
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`.');
1
+ import { Command } from 'commander';
2
+ import { makeCreateStyleCommand } from './makeCreateStyleCommand.js';
3
+ import * as collection from '@dicebear/collection';
4
+ export async function makeCreateCommand() {
5
+ const cmd = new Command('create');
6
+ for (let name of Object.keys(collection)) {
7
+ const style = collection[name];
8
+ console.log({
9
+ name,
10
+ style,
37
11
  });
12
+ cmd.addCommand(await makeCreateStyleCommand(name, style));
38
13
  }
39
14
  return cmd;
40
15
  }
41
- exports.makeCreateCommand = makeCreateCommand;
@@ -1,2 +1,2 @@
1
- import type { Style } from '@dicebear/avatars';
1
+ import type { Style } from '@dicebear/core';
2
2
  export declare function makeCreateStyleCommand(name: string, style: Style<any>): Promise<import("commander").Command>;
@@ -1,40 +1,16 @@
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 avatars_1 = require("@dicebear/avatars");
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)({
1
+ import { createAvatar, schema as coreSchema } from '@dicebear/core';
2
+ import { Command } from 'commander';
3
+ import * as path from 'path';
4
+ import fs from 'fs-extra';
5
+ import sharp from 'sharp';
6
+ import { renderAsync } from '@resvg/resvg-js';
7
+ import cliProgress from 'cli-progress';
8
+ import { validateInputBySchema } from '../validateInputBySchema.js';
9
+ import { outputStyleLicenseBanner } from '../outputStyleLicenseBanner.js';
10
+ import { getOptionsBySchema } from '../getOptionsBySchema.js';
11
+ import mergeAllOf from 'json-schema-merge-allof';
12
+ export async function makeCreateStyleCommand(name, style) {
13
+ const schema = mergeAllOf({
38
14
  allOf: [
39
15
  {
40
16
  properties: {
@@ -52,24 +28,24 @@ async function makeCreateStyleCommand(name, style) {
52
28
  },
53
29
  },
54
30
  },
55
- avatars_1.schema,
31
+ coreSchema,
56
32
  style.schema,
57
33
  ],
58
34
  additionalItems: true,
59
35
  }, { ignoreAdditionalProperties: true });
60
- const cmd = new commander_1.Command(name);
36
+ const cmd = new Command(name);
61
37
  cmd.arguments('[outputPath]');
62
- for (let option of await (0, getOptionsBySchema_1.getOptionsBySchema)(schema)) {
38
+ for (let option of await getOptionsBySchema(schema)) {
63
39
  cmd.addOption(option);
64
40
  }
65
41
  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);
42
+ const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
43
+ const validated = validateInputBySchema(options, schema);
68
44
  const promises = [];
69
- (0, outputStyleLicenseBanner_1.outputStyleLicenseBanner)(name, style);
45
+ outputStyleLicenseBanner(name, style);
70
46
  bar.start(validated.count, 0);
71
47
  outputPath = path.resolve(process.cwd(), outputPath);
72
- await fs_extra_1.default.ensureDir(outputPath);
48
+ await fs.ensureDir(outputPath);
73
49
  for (let i = 0; i < validated.count; i++) {
74
50
  promises.push((async () => {
75
51
  if (validated.format !== 'svg') {
@@ -79,17 +55,27 @@ async function makeCreateStyleCommand(name, style) {
79
55
  validated.height = validated.width;
80
56
  }
81
57
  const fileName = path.resolve(process.cwd(), outputPath, `${name}-${i}.${validated.format}`);
82
- let avatar = (0, avatars_1.createAvatar)(style, validated);
58
+ const avatar = createAvatar(style, validated);
59
+ const png = await renderAsync(avatar, {
60
+ font: {
61
+ loadSystemFonts: false,
62
+ defaultFontFamily: 'Inter',
63
+ fontFiles: [
64
+ new URL('../../../fonts/inter/inter-regular.otf', import.meta.url).pathname,
65
+ new URL('../../../fonts/inter/inter-bold.otf', import.meta.url).pathname,
66
+ ],
67
+ },
68
+ });
83
69
  switch (validated.format) {
84
70
  case 'png':
85
- await (0, sharp_1.default)(Buffer.from(avatar)).png().toFile(fileName);
71
+ await fs.writeFile(fileName, png);
86
72
  break;
87
73
  case 'jpg':
88
74
  case 'jpeg':
89
- await (0, sharp_1.default)(Buffer.from(avatar)).jpeg().toFile(fileName);
75
+ await sharp(png).jpeg().toFile(fileName);
90
76
  break;
91
77
  default:
92
- await fs_extra_1.default.writeFile(fileName, avatar, { encoding: 'utf-8' });
78
+ await fs.writeFile(fileName, avatar, { encoding: 'utf-8' });
93
79
  }
94
80
  bar.increment();
95
81
  })());
@@ -99,4 +85,3 @@ async function makeCreateStyleCommand(name, style) {
99
85
  });
100
86
  return cmd;
101
87
  }
102
- exports.makeCreateStyleCommand = makeCreateStyleCommand;
@@ -1,21 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOptionsBySchema = void 0;
4
- const commander_1 = require("commander");
5
- const avatars_1 = require("@dicebear/avatars");
6
- async function getOptionsBySchema(schema) {
1
+ import { Option } from 'commander';
2
+ export async function getOptionsBySchema(schema) {
7
3
  const result = [];
8
- const aliases = avatars_1.utils.schema.aliases(schema);
9
4
  for (var key in schema.properties) {
10
5
  if (false === schema.properties.hasOwnProperty(key)) {
11
6
  continue;
12
7
  }
13
8
  const property = schema.properties[key];
14
- const names = aliases.find((v) => v.includes(key)) ?? [key];
15
- const isPrimary = names[0] === key;
16
- if (isPrimary && typeof property === 'object') {
17
- const options = names.map((name) => (name.length === 1 ? `-${name}` : `--${name}`));
18
- const option = new commander_1.Option(`${options.join(', ')} <value>`);
9
+ if (typeof property === 'object') {
10
+ const option = new Option(`-${key} <value>`);
19
11
  let description = [property.title, property.description].filter((v) => v).join(' - ');
20
12
  let choices = [];
21
13
  if (property.enum) {
@@ -36,4 +28,3 @@ async function getOptionsBySchema(schema) {
36
28
  }
37
29
  return result;
38
30
  }
39
- 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;
@@ -1,2 +1,2 @@
1
- import type { Style } from '@dicebear/avatars';
1
+ import type { Style } from '@dicebear/core';
2
2
  export declare function outputStyleLicenseBanner(name: string, style: Style<any>): void;
@@ -1,32 +1,25 @@
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 link from 'terminal-link';
3
+ export function outputStyleLicenseBanner(name, style) {
10
4
  let banner = ['-'.repeat(64)];
11
5
  let creator = Array.isArray(style.meta.creator) ? style.meta.creator.join(', ') : style.meta.creator;
12
6
  if (style.meta.title && creator) {
13
- banner.push((0, chalk_1.default) `{bold ${style.meta.title}} by {bold ${creator}}`);
7
+ banner.push(chalk `{bold ${style.meta.title}} by {bold ${creator}}`);
14
8
  }
15
9
  else if (style.meta.title) {
16
- banner.push((0, chalk_1.default) `{bold ${style.meta.title}}`);
10
+ banner.push(chalk `{bold ${style.meta.title}}`);
17
11
  }
18
12
  else if (creator) {
19
- banner.push((0, chalk_1.default) `{bold ${name}} by {bold ${creator}}`);
13
+ banner.push(chalk `{bold ${name}} by {bold ${creator}}`);
20
14
  }
21
15
  banner.push('');
22
16
  if (style.meta.source) {
23
17
  banner.push(`Source: ${style.meta.source}`);
24
18
  }
25
19
  if (style.meta.license) {
26
- banner.push(`License: ${(0, terminal_link_1.default)(style.meta.license.name, style.meta.license.url)}`);
20
+ banner.push(`License: ${link(style.meta.license.name, style.meta.license.url)}`);
27
21
  }
28
22
  banner.push('-'.repeat(64));
29
23
  banner.push('');
30
- console.log(chalk_1.default.blueBright(banner.join('\n')));
24
+ console.log(chalk.blueBright(banner.join('\n')));
31
25
  }
32
- exports.outputStyleLicenseBanner = outputStyleLicenseBanner;
@@ -1,12 +1,6 @@
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,
@@ -39,4 +33,3 @@ function validateInputBySchema(input, schema) {
39
33
  }
40
34
  return data;
41
35
  }
42
- exports.validateInputBySchema = validateInputBySchema;
package/package.json CHANGED
@@ -1,61 +1,62 @@
1
1
  {
2
2
  "name": "dicebear",
3
- "version": "4.10.2",
3
+ "version": "5.0.0-alpha.11",
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
- "@apidevtools/json-schema-ref-parser": "^9.0.7",
29
- "@dicebear/avatars": "^4.10.2",
30
- "@dicebear/collection": "^4.10.2",
28
+ "@dicebear/collection": "^5.0.0-alpha.11",
29
+ "@dicebear/core": "^5.0.0-alpha.11",
30
+ "@resvg/resvg-js": "^1.2.0",
31
31
  "ajv": "^8.1.0",
32
32
  "chalk": "^4.1.1",
33
33
  "cli-progress": "^3.9.0",
34
34
  "commander": "^7.2.0",
35
- "dicebear-project": "^4.10.2",
36
35
  "download": "^8.0.0",
37
36
  "execa": "^4.1.0",
38
- "fs-extra": "^9.1.0",
37
+ "fs-extra": "^10.0.0",
39
38
  "json-schema-merge-allof": "^0.8.1",
40
39
  "ora": "^5.4.0",
41
40
  "replace-in-file": "^6.2.0",
42
- "sharp": "^0.28.1",
41
+ "sharp": "^0.29.3",
43
42
  "terminal-link": "^2.1.1",
44
43
  "update-notifier": "^5.1.0"
45
44
  },
46
45
  "devDependencies": {
47
- "@tsconfig/node14": "^1.0.1",
46
+ "@tsconfig/recommended": "^1.0.0",
48
47
  "@types/cli-progress": "^3.9.1",
49
48
  "@types/download": "^6.2.4",
50
- "@types/fs-extra": "^9.0.11",
49
+ "@types/fs-extra": "^9.0.13",
51
50
  "@types/json-schema": "^7.0.7",
52
51
  "@types/json-schema-merge-allof": "^0.6.0",
53
52
  "@types/semver": "^7.3.6",
54
- "@types/sharp": "^0.28.0",
53
+ "@types/sharp": "^0.29.5",
55
54
  "@types/update-notifier": "^5.0.0",
56
- "shx": "^0.3.3",
57
- "typescript": "^4.3.5"
55
+ "del-cli": "^4.0.1",
56
+ "typescript": "^4.5.4"
58
57
  },
59
- "homepage": "https://github.com/dicebear/dicebear",
60
- "gitHead": "28ffc2046de961f814b3c5804c562dd318821a7b"
58
+ "engines": {
59
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
60
+ },
61
+ "gitHead": "93e6f1be9fff392ded1f18c8320b6a0ca8e695c1"
61
62
  }
@@ -1 +0,0 @@
1
- export declare function makeProjectCommand(): Promise<import("commander").Command>;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeProjectCommand = void 0;
4
- const commander_1 = require("commander");
5
- const makeNewCommand_1 = require("dicebear-project/lib/utils/command/makeNewCommand");
6
- const makeBuildCommand_1 = require("dicebear-project/lib/utils/command/makeBuildCommand");
7
- async function makeProjectCommand() {
8
- const cmd = new commander_1.Command('project');
9
- cmd.addCommand(await (0, makeNewCommand_1.makeNewCommand)());
10
- cmd.addCommand(await (0, makeBuildCommand_1.makeBuildCommand)());
11
- return cmd;
12
- }
13
- exports.makeProjectCommand = makeProjectCommand;