dicebear 5.0.0-alpha.2 → 5.0.0-alpha.20
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/command/makeStyleCommand.d.ts +3 -0
- package/lib/command/makeStyleCommand.js +84 -0
- package/lib/index.js +12 -15
- package/lib/utils/getOptionsBySchema.d.ts +2 -1
- package/lib/utils/getOptionsBySchema.js +3 -7
- package/lib/utils/getPackageJson.d.ts +1 -1
- package/lib/utils/getPackageJson.js +4 -26
- package/lib/utils/outputStyleLicenseBanner.js +14 -16
- package/lib/utils/validateInputBySchema.js +6 -15
- package/package.json +37 -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/lib/utils/command/makeProjectCommand.d.ts +0 -1
- package/lib/utils/command/makeProjectCommand.js +0 -13
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';
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createAvatar, schema as coreSchema } from '@dicebear/core';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import cliProgress from 'cli-progress';
|
|
6
|
+
import { validateInputBySchema } from '../utils/validateInputBySchema.js';
|
|
7
|
+
import { outputStyleLicenseBanner } from '../utils/outputStyleLicenseBanner.js';
|
|
8
|
+
import { getOptionsBySchema } from '../utils/getOptionsBySchema.js';
|
|
9
|
+
import mergeAllOf from 'json-schema-merge-allof';
|
|
10
|
+
import PQueue from 'p-queue';
|
|
11
|
+
import os from 'node:os';
|
|
12
|
+
import { exiftool } from 'exiftool-vendored';
|
|
13
|
+
export async function makeStyleCommand(name, style) {
|
|
14
|
+
const schema = mergeAllOf({
|
|
15
|
+
allOf: [
|
|
16
|
+
{
|
|
17
|
+
properties: {
|
|
18
|
+
count: {
|
|
19
|
+
title: 'Count',
|
|
20
|
+
description: 'Defines how many avatars to create. Does not work in combination with a "seed".',
|
|
21
|
+
type: 'number',
|
|
22
|
+
default: 1,
|
|
23
|
+
},
|
|
24
|
+
format: {
|
|
25
|
+
title: 'Format',
|
|
26
|
+
type: 'string',
|
|
27
|
+
enum: ['svg', 'png', 'jpg', 'jpeg'],
|
|
28
|
+
default: 'svg',
|
|
29
|
+
},
|
|
30
|
+
exif: {
|
|
31
|
+
title: 'Include Exif Metadata',
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
default: false,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
coreSchema,
|
|
38
|
+
style.schema,
|
|
39
|
+
],
|
|
40
|
+
additionalItems: true,
|
|
41
|
+
}, { ignoreAdditionalProperties: true });
|
|
42
|
+
const cmd = new Command(name);
|
|
43
|
+
cmd.arguments('[outputPath]');
|
|
44
|
+
for (let option of await getOptionsBySchema(schema)) {
|
|
45
|
+
cmd.addOption(option);
|
|
46
|
+
}
|
|
47
|
+
cmd.action(async (outputPath = '.', options = {}) => {
|
|
48
|
+
const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
|
|
49
|
+
const validated = validateInputBySchema(options, schema);
|
|
50
|
+
const count = validated.count;
|
|
51
|
+
const includeExif = validated.exif;
|
|
52
|
+
outputStyleLicenseBanner(name, style);
|
|
53
|
+
bar.start(count, 0);
|
|
54
|
+
const queue = new PQueue({ concurrency: os.cpus().length });
|
|
55
|
+
queue.on('next', () => {
|
|
56
|
+
bar.update(count - queue.size - queue.pending);
|
|
57
|
+
});
|
|
58
|
+
outputPath = path.resolve(process.cwd(), outputPath);
|
|
59
|
+
await fs.ensureDir(outputPath);
|
|
60
|
+
for (let i = 0; i < count; i++) {
|
|
61
|
+
queue.add(async () => {
|
|
62
|
+
const fileName = path.resolve(process.cwd(), outputPath, `${name}-${i}.${validated.format}`);
|
|
63
|
+
const avatar = createAvatar(style, validated);
|
|
64
|
+
switch (validated.format) {
|
|
65
|
+
case 'svg':
|
|
66
|
+
await avatar.svg().toFile(fileName);
|
|
67
|
+
break;
|
|
68
|
+
case 'png':
|
|
69
|
+
await avatar.png({ includeExif }).toFile(fileName);
|
|
70
|
+
break;
|
|
71
|
+
case 'jpg':
|
|
72
|
+
case 'jpeg':
|
|
73
|
+
await avatar.jpeg({ includeExif }).toFile(fileName);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
bar.increment();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
await queue.onIdle();
|
|
80
|
+
bar.stop();
|
|
81
|
+
exiftool.end();
|
|
82
|
+
});
|
|
83
|
+
return cmd;
|
|
84
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
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 * as collection from '@dicebear/collection';
|
|
4
|
+
import { getPackageJson } from './utils/getPackageJson.js';
|
|
5
|
+
import { makeStyleCommand } from './command/makeStyleCommand.js';
|
|
11
6
|
(async () => {
|
|
12
|
-
const pkg = await
|
|
13
|
-
const program = new
|
|
14
|
-
(
|
|
7
|
+
const pkg = await getPackageJson();
|
|
8
|
+
const program = new Command('dicebear');
|
|
9
|
+
updateNotifier({ pkg }).notify();
|
|
15
10
|
program.version(pkg.version, '-v, --version');
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
for (let name of Object.keys(collection)) {
|
|
12
|
+
const style = collection[name];
|
|
13
|
+
program.addCommand(await makeStyleCommand(name, style));
|
|
14
|
+
}
|
|
18
15
|
await program.parseAsync(process.argv);
|
|
19
16
|
})();
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getOptionsBySchema = void 0;
|
|
4
|
-
const commander_1 = require("commander");
|
|
5
|
-
async function getOptionsBySchema(schema) {
|
|
1
|
+
import { Option } from 'commander';
|
|
2
|
+
export async function getOptionsBySchema(schema) {
|
|
6
3
|
const result = [];
|
|
7
4
|
for (var key in schema.properties) {
|
|
8
5
|
if (false === schema.properties.hasOwnProperty(key)) {
|
|
@@ -10,7 +7,7 @@ async function getOptionsBySchema(schema) {
|
|
|
10
7
|
}
|
|
11
8
|
const property = schema.properties[key];
|
|
12
9
|
if (typeof property === 'object') {
|
|
13
|
-
const option = new
|
|
10
|
+
const option = new Option(`--${key} <value>`);
|
|
14
11
|
let description = [property.title, property.description].filter((v) => v).join(' - ');
|
|
15
12
|
let choices = [];
|
|
16
13
|
if (property.enum) {
|
|
@@ -31,4 +28,3 @@ async function getOptionsBySchema(schema) {
|
|
|
31
28
|
}
|
|
32
29
|
return result;
|
|
33
30
|
}
|
|
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;
|
|
@@ -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,16 +1,10 @@
|
|
|
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
10
|
const data = {};
|
|
@@ -29,14 +23,11 @@ function validateInputBySchema(input, schema) {
|
|
|
29
23
|
}
|
|
30
24
|
if (false === validate(data)) {
|
|
31
25
|
if (validate.errors) {
|
|
32
|
-
for (var
|
|
33
|
-
|
|
34
|
-
new Error(`${errorKey} - ${validate.errors[errorKey]}`);
|
|
35
|
-
}
|
|
26
|
+
for (var error of validate.errors) {
|
|
27
|
+
throw new Error(`${error.keyword} - ${error.message}`);
|
|
36
28
|
}
|
|
37
29
|
}
|
|
38
30
|
throw new Error('Unknown error');
|
|
39
31
|
}
|
|
40
32
|
return data;
|
|
41
33
|
}
|
|
42
|
-
exports.validateInputBySchema = validateInputBySchema;
|
package/package.json
CHANGED
|
@@ -1,60 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dicebear",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.20",
|
|
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-alpha.
|
|
29
|
-
"@dicebear/core": "^5.0.0-alpha.
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"fs-extra": "^
|
|
28
|
+
"@dicebear/collection": "^5.0.0-alpha.20",
|
|
29
|
+
"@dicebear/core": "^5.0.0-alpha.20",
|
|
30
|
+
"@resvg/resvg-js": "^1.4.0",
|
|
31
|
+
"ajv": "^8.11.0",
|
|
32
|
+
"chalk": "^5.0.1",
|
|
33
|
+
"chalk-template": "^0.4.0",
|
|
34
|
+
"cli-progress": "^3.10.0",
|
|
35
|
+
"commander": "^9.2.0",
|
|
36
|
+
"exiftool-vendored": "^16.3.0",
|
|
37
|
+
"fs-extra": "^10.1.0",
|
|
38
38
|
"json-schema-merge-allof": "^0.8.1",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"sharp": "^0.28.1",
|
|
42
|
-
"terminal-link": "^2.1.1",
|
|
39
|
+
"p-queue": "^7.2.0",
|
|
40
|
+
"sharp": "^0.30.4",
|
|
43
41
|
"update-notifier": "^5.1.0"
|
|
44
42
|
},
|
|
45
43
|
"devDependencies": {
|
|
46
|
-
"@tsconfig/
|
|
47
|
-
"@types/cli-progress": "^3.9.
|
|
48
|
-
"@types/
|
|
49
|
-
"@types/
|
|
50
|
-
"@types/json-schema": "^
|
|
51
|
-
"@types/
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"@types/update-notifier": "^5.0.0",
|
|
55
|
-
"shx": "^0.3.3",
|
|
56
|
-
"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": "^7.0.11",
|
|
48
|
+
"@types/json-schema-merge-allof": "^0.6.1",
|
|
49
|
+
"@types/update-notifier": "^5.1.0",
|
|
50
|
+
"del-cli": "^4.0.1",
|
|
51
|
+
"typescript": "^4.6.3"
|
|
57
52
|
},
|
|
58
|
-
"
|
|
59
|
-
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
55
|
+
},
|
|
56
|
+
"gitHead": "6b1c2bd64294365be21d0a133a362ede5ed62b5a"
|
|
60
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;
|
|
@@ -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;
|