aptechka 0.11.0 → 0.11.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aptechka",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/denisavitski/aptechka.git"
|
|
@@ -528,6 +528,7 @@
|
|
|
528
528
|
"detect-gpu": "^5.0.38",
|
|
529
529
|
"favicons": "^7.2.0",
|
|
530
530
|
"fluent-ffmpeg": "^2.1.3",
|
|
531
|
+
"node-html-parser": "^6.1.13",
|
|
531
532
|
"sharp": "^0.33.4",
|
|
532
533
|
"three": "^0.166.1",
|
|
533
534
|
"urlpattern-polyfill": "^10.0.0"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdir, readFile, readdir } from "fs/promises";
|
|
2
2
|
import { dirname, join, sep, extname } from "path";
|
|
3
3
|
import Ffmpeg from "fluent-ffmpeg";
|
|
4
|
-
import { getTmpPath, outputFile, getFolderFiles, removeExtension, clear, replaceExtension, outputFiles } from "../utils/index.js";
|
|
4
|
+
import { getTmpPath, outputFile, getFolderFiles, removeExtension, clear, getBuffer, replaceExtension, outputFiles } from "../utils/index.js";
|
|
5
5
|
import favicons from "favicons";
|
|
6
6
|
import { parse } from "node-html-parser";
|
|
7
7
|
import { statSync } from "fs";
|
|
@@ -55,7 +55,8 @@ async function FFmpeg({
|
|
|
55
55
|
async function generateFavicon(source) {
|
|
56
56
|
const output = [];
|
|
57
57
|
const { settings } = source;
|
|
58
|
-
const
|
|
58
|
+
const buffer = await getBuffer(source.content);
|
|
59
|
+
const response = await favicons(buffer, settings);
|
|
59
60
|
output.push(
|
|
60
61
|
...[...response.images, ...response.files].map((item) => {
|
|
61
62
|
return {
|
|
@@ -72,10 +73,11 @@ async function generateFavicon(source) {
|
|
|
72
73
|
}
|
|
73
74
|
async function generateSequence(source) {
|
|
74
75
|
const { settings } = source;
|
|
76
|
+
const buffer = await getBuffer(source.content);
|
|
75
77
|
return FFmpeg({
|
|
76
78
|
inputPath: settings.destinationPath,
|
|
77
79
|
outputPath: `${removeExtension(settings.destinationPath)}/frame-%04d.${settings.frameExtension || "jpg"}`,
|
|
78
|
-
fileContent:
|
|
80
|
+
fileContent: buffer,
|
|
79
81
|
instructions: (command) => {
|
|
80
82
|
if (settings.fps) {
|
|
81
83
|
command.addOutputOption([`-r ${Math.max(1, settings.fps | 0)}`]);
|
|
@@ -91,7 +93,8 @@ async function generateSprite(source) {
|
|
|
91
93
|
const svgCloseTag = "</svg>";
|
|
92
94
|
let spriteString = svgOpenTag;
|
|
93
95
|
for await (const item of source.content) {
|
|
94
|
-
const
|
|
96
|
+
const buffer = await getBuffer(item.data);
|
|
97
|
+
const svgString = buffer.toString();
|
|
95
98
|
const root = parse(svgString);
|
|
96
99
|
const icon = root.querySelector("svg");
|
|
97
100
|
icon.removeAttribute("width");
|
|
@@ -163,7 +166,7 @@ async function inputFiles({
|
|
|
163
166
|
if (file.ext === ".svg") {
|
|
164
167
|
content.push({
|
|
165
168
|
name: file.name,
|
|
166
|
-
|
|
169
|
+
data: file.buffer
|
|
167
170
|
});
|
|
168
171
|
}
|
|
169
172
|
});
|
|
@@ -210,8 +213,7 @@ async function inputFiles({
|
|
|
210
213
|
})
|
|
211
214
|
}
|
|
212
215
|
});
|
|
213
|
-
}
|
|
214
|
-
if (destinationPath.includes("@sequence")) {
|
|
216
|
+
} else if (destinationPath.includes("@sequence")) {
|
|
215
217
|
const path = specialPath(destinationPath, "@sequence");
|
|
216
218
|
sources.push({
|
|
217
219
|
content,
|
|
@@ -263,8 +265,9 @@ async function inputFiles({
|
|
|
263
265
|
}
|
|
264
266
|
async function optimizeImage(source) {
|
|
265
267
|
const { settings } = source;
|
|
268
|
+
const content = await getBuffer(source.content);
|
|
266
269
|
const ext = extname(settings.destinationPath).toLowerCase();
|
|
267
|
-
const image = sharp(
|
|
270
|
+
const image = sharp(content);
|
|
268
271
|
const meta = await image.metadata();
|
|
269
272
|
const width = meta.width;
|
|
270
273
|
const height = meta.height;
|
|
@@ -319,9 +322,10 @@ async function optimizeImage(source) {
|
|
|
319
322
|
}
|
|
320
323
|
async function optimizeVideo(source) {
|
|
321
324
|
const { settings } = source;
|
|
325
|
+
const buffer = await getBuffer(source.content);
|
|
322
326
|
return FFmpeg({
|
|
323
327
|
inputPath: settings.destinationPath,
|
|
324
|
-
fileContent:
|
|
328
|
+
fileContent: buffer,
|
|
325
329
|
instructions: (command) => {
|
|
326
330
|
command.addOutputOption(
|
|
327
331
|
`-crf ${Math.round((100 - ((settings == null ? void 0 : settings.quality) || 80)) * 51 / 100)}`
|
|
@@ -350,7 +354,7 @@ async function optimize(sources, options) {
|
|
|
350
354
|
output.push(...await generateSequence(source));
|
|
351
355
|
} else {
|
|
352
356
|
output.push({
|
|
353
|
-
data: source.content,
|
|
357
|
+
data: await getBuffer(source.content),
|
|
354
358
|
destinationPath: source.settings.destinationPath
|
|
355
359
|
});
|
|
356
360
|
}
|
|
@@ -3,41 +3,41 @@ import { FaviconOptions } from 'favicons';
|
|
|
3
3
|
export type SourceSettings = {
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
};
|
|
6
|
-
export interface Source<B = Buffer, T extends string = string, S extends SourceSettings = {}> {
|
|
6
|
+
export interface Source<B = Buffer | File, T extends string = string, S extends SourceSettings = {}> {
|
|
7
7
|
content: B;
|
|
8
8
|
type: T;
|
|
9
9
|
settings: S;
|
|
10
10
|
}
|
|
11
|
-
export type SkipSource = Source<Buffer, 'skip', {
|
|
11
|
+
export type SkipSource = Source<Buffer | File, 'skip', {
|
|
12
12
|
destinationPath: string;
|
|
13
13
|
}>;
|
|
14
|
-
export type ImageSource = Source<Buffer, 'image', {
|
|
14
|
+
export type ImageSource = Source<Buffer | File, 'image', {
|
|
15
15
|
destinationPath: string;
|
|
16
16
|
quality?: number;
|
|
17
17
|
scale?: number;
|
|
18
18
|
placeholder?: boolean;
|
|
19
19
|
webp?: boolean;
|
|
20
20
|
}>;
|
|
21
|
-
export type VideoSource = Source<Buffer, 'video', {
|
|
21
|
+
export type VideoSource = Source<Buffer | File, 'video', {
|
|
22
22
|
destinationPath: string;
|
|
23
23
|
quality?: number;
|
|
24
24
|
scale?: number;
|
|
25
25
|
fps?: number;
|
|
26
26
|
}>;
|
|
27
|
-
export type FaviconSource = Source<Buffer, 'favicon', {
|
|
27
|
+
export type FaviconSource = Source<Buffer | File, 'favicon', {
|
|
28
28
|
destinationPath: string;
|
|
29
29
|
destinationHtmlPath: string;
|
|
30
30
|
} & FaviconOptions>;
|
|
31
31
|
export type SpriteSource = Source<Array<{
|
|
32
32
|
name: string;
|
|
33
|
-
|
|
33
|
+
data: Buffer | File;
|
|
34
34
|
}>, 'sprite', {
|
|
35
35
|
destinationPath: string;
|
|
36
36
|
name?: string;
|
|
37
37
|
removeStroke?: boolean;
|
|
38
38
|
removeFill?: boolean;
|
|
39
39
|
}>;
|
|
40
|
-
export type SequenceSource = Source<Buffer, 'sequence', {
|
|
40
|
+
export type SequenceSource = Source<Buffer | File, 'sequence', {
|
|
41
41
|
destinationPath: string;
|
|
42
42
|
fps?: number;
|
|
43
43
|
frameExtension?: 'png' | 'jpg';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getBuffer(data: Buffer | File): Promise<Buffer>;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
2
|
import { extname, dirname, join } from "path";
|
|
3
3
|
import { mkdir, writeFile, rm, readdir, readFile } from "fs/promises";
|
|
4
|
+
async function getBuffer(data) {
|
|
5
|
+
if (data instanceof Buffer) {
|
|
6
|
+
return data;
|
|
7
|
+
}
|
|
8
|
+
return Buffer.from(await data.arrayBuffer());
|
|
9
|
+
}
|
|
4
10
|
function removeExtension(path) {
|
|
5
11
|
return path.replace(/\.[^/.]+$/, "");
|
|
6
12
|
}
|
|
@@ -45,6 +51,7 @@ async function getFolderFiles(folderPath) {
|
|
|
45
51
|
}
|
|
46
52
|
export {
|
|
47
53
|
clear,
|
|
54
|
+
getBuffer,
|
|
48
55
|
getFolderFiles,
|
|
49
56
|
getTmpPath,
|
|
50
57
|
outputFile,
|