@kivacore/logo-asset-generator 0.0.0 → 0.3.4
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 +124 -1
- package/dist/chunk-YAKKFHGX.js +137 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +27 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +12 -0
- package/package.json +43 -4
package/README.md
CHANGED
|
@@ -1,3 +1,126 @@
|
|
|
1
1
|
# @kivacore/logo-asset-generator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Generate favicon and app icons from a PNG/SVG logo, update your `index.html` with the correct `<link>`/`<meta>` tags, and create/update a `manifest.json` — all in one command.
|
|
4
|
+
|
|
5
|
+
- Input: Local file path or URL to a logo (PNG or SVG, ideally 512x512)
|
|
6
|
+
- Output: Common favicon/app icon set (+ `favicon.ico`) and updated HTML meta tags
|
|
7
|
+
- HTML: Rewrites icon-related tags in your `index.html` and ensures PWA manifest icons
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
- Generates PNG assets:
|
|
11
|
+
- `favicon-16x16.png`, `favicon-32x32.png`, `favicon-96x96.png`
|
|
12
|
+
- `android-chrome-192x192.png`, `android-chrome-512x512.png`
|
|
13
|
+
- `apple-touch-icon.png` and explicit sizes: `60x60`, `76x76`, `120x120`, `152x152`, `180x180`
|
|
14
|
+
- `mstile-150x150.png`
|
|
15
|
+
- Social preview: `og-image.png` (1200x1200)
|
|
16
|
+
- Generates `favicon.ico` from available favicon sizes (includes 16 and 32 by default)
|
|
17
|
+
- Updates `index.html` `<head>` with:
|
|
18
|
+
- `<link rel="icon" ...>` for `.ico` and PNG sizes (16, 32, 96)
|
|
19
|
+
- `<link rel="apple-touch-icon" ...>` variants
|
|
20
|
+
- `<link rel="manifest" href="/manifest.json">`
|
|
21
|
+
- `<meta name="msapplication-TileColor" content="#ffffff">`
|
|
22
|
+
- `<meta name="msapplication-TileImage" content="/mstile-150x150.png">`
|
|
23
|
+
- `<meta name="theme-color" content="#ffffff">`
|
|
24
|
+
- OpenGraph image tags for `og-image.png`
|
|
25
|
+
- Creates/updates `manifest.json` (in same directory as `index.html`) with Android icon entries
|
|
26
|
+
|
|
27
|
+
## Requirements
|
|
28
|
+
- Node.js 18+ (sharp 0.33+)
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
Using pnpm (recommended):
|
|
32
|
+
```sh
|
|
33
|
+
pnpm add -D @kivacore/logo-asset-generator
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## CLI Usage
|
|
37
|
+
```sh
|
|
38
|
+
logo-asset-generator --logo <path-or-url> --index <path-to-index.html> [--output <output-dir>]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
- `--logo, -l` (required): Path or URL to PNG/SVG logo (ideally 512x512)
|
|
42
|
+
- `--index, -i` (required): Path to `index.html` to update
|
|
43
|
+
- `--output, -o` (optional): Output directory for generated assets
|
|
44
|
+
- Defaults to the directory of `index.html`
|
|
45
|
+
|
|
46
|
+
Examples:
|
|
47
|
+
- Minimal:
|
|
48
|
+
```sh
|
|
49
|
+
logo-asset-generator -l ./public/logo.svg -i ./public/index.html
|
|
50
|
+
```
|
|
51
|
+
- Custom output directory:
|
|
52
|
+
```sh
|
|
53
|
+
logo-asset-generator -l https://example.com/logo.png -i ./apps/web/public/index.html -o ./apps/web/public
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Monorepo execution (from repo root) with pnpm workspace filter:
|
|
57
|
+
```sh
|
|
58
|
+
pnpm -w --filter @kivacore/logo-asset-generator exec logo-asset-generator \
|
|
59
|
+
-l ./apps/test/public/logo.svg \
|
|
60
|
+
-i ./apps/test/public/index.html \
|
|
61
|
+
-o ./apps/test/public
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## What gets generated
|
|
65
|
+
In the output directory (`--output` or the directory of `index.html`):
|
|
66
|
+
- PNG icons listed in Features
|
|
67
|
+
- `favicon.ico` (ico contains 16x16 and 32x32 PNGs by default)
|
|
68
|
+
- Updated `index.html` (icon/meta tags replaced under `<head>`)
|
|
69
|
+
- `manifest.json` created/updated with Android icon entries
|
|
70
|
+
|
|
71
|
+
Note: Existing icon-related `<link>` tags and `og:image` meta tags in `index.html` will be removed and regenerated.
|
|
72
|
+
|
|
73
|
+
## Programmatic API
|
|
74
|
+
ESM import (Node 18+):
|
|
75
|
+
```ts
|
|
76
|
+
import { generateAssets, updateHtmlMetaTags, loadImage, downloadImage } from '@kivacore/logo-asset-generator'
|
|
77
|
+
|
|
78
|
+
await generateAssets({
|
|
79
|
+
logoPath: './public/logo.svg',
|
|
80
|
+
htmlPath: './public/index.html',
|
|
81
|
+
// outputDir: './public', // optional, defaults to dirname(htmlPath)
|
|
82
|
+
// sizes: [ { name: 'favicon-16x16.png', size: 16 }, ... ] // optional
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Types:
|
|
87
|
+
```ts
|
|
88
|
+
interface AssetSize {
|
|
89
|
+
name: string
|
|
90
|
+
size: number
|
|
91
|
+
purpose?: string // e.g. 'og' for social preview image
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface GeneratorOptions {
|
|
95
|
+
logoPath: string
|
|
96
|
+
htmlPath: string
|
|
97
|
+
outputDir?: string
|
|
98
|
+
sizes?: AssetSize[]
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Customize sizes (advanced):
|
|
103
|
+
```ts
|
|
104
|
+
import { generateAssets } from '@kivacore/logo-asset-generator'
|
|
105
|
+
|
|
106
|
+
await generateAssets({
|
|
107
|
+
logoPath: './logo.png',
|
|
108
|
+
htmlPath: './index.html',
|
|
109
|
+
sizes: [
|
|
110
|
+
{ name: 'favicon-16x16.png', size: 16 },
|
|
111
|
+
{ name: 'favicon-32x32.png', size: 32 },
|
|
112
|
+
{ name: 'android-chrome-192x192.png', size: 192 },
|
|
113
|
+
{ name: 'android-chrome-512x512.png', size: 512 },
|
|
114
|
+
{ name: 'og-image.png', size: 1200, purpose: 'og' },
|
|
115
|
+
],
|
|
116
|
+
})
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Notes
|
|
120
|
+
- Input SVGs are rasterized to PNG at the target sizes via sharp.
|
|
121
|
+
- The tool writes to disk and mutates `index.html`; commit changes as needed.
|
|
122
|
+
- `manifest.json` is created if missing; otherwise only its `icons` array is overwritten.
|
|
123
|
+
- Default theme and tile color are set to `#ffffff`.
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
MIT © Docyrus, Inc.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import fs from "fs/promises";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import sharp from "sharp";
|
|
5
|
+
import toIco from "to-ico";
|
|
6
|
+
import { parse as parseHtml } from "node-html-parser";
|
|
7
|
+
var DEFAULT_SIZES = [
|
|
8
|
+
{ name: "favicon-16x16.png", size: 16 },
|
|
9
|
+
{ name: "favicon-32x32.png", size: 32 },
|
|
10
|
+
{ name: "favicon-96x96.png", size: 96 },
|
|
11
|
+
{ name: "android-chrome-192x192.png", size: 192 },
|
|
12
|
+
{ name: "android-chrome-512x512.png", size: 512 },
|
|
13
|
+
{ name: "apple-touch-icon-60x60.png", size: 60 },
|
|
14
|
+
{ name: "apple-touch-icon-76x76.png", size: 76 },
|
|
15
|
+
{ name: "apple-touch-icon-120x120.png", size: 120 },
|
|
16
|
+
{ name: "apple-touch-icon-152x152.png", size: 152 },
|
|
17
|
+
{ name: "apple-touch-icon-180x180.png", size: 180 },
|
|
18
|
+
{ name: "apple-touch-icon.png", size: 180 },
|
|
19
|
+
{ name: "mstile-150x150.png", size: 150 },
|
|
20
|
+
{ name: "og-image.png", size: 1200, purpose: "og" }
|
|
21
|
+
];
|
|
22
|
+
async function downloadImage(url) {
|
|
23
|
+
const response = await fetch(url);
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
throw new Error(`Failed to download image: ${response.status} ${response.statusText}`);
|
|
26
|
+
}
|
|
27
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
28
|
+
return Buffer.from(arrayBuffer);
|
|
29
|
+
}
|
|
30
|
+
async function loadImage(imagePath) {
|
|
31
|
+
if (imagePath.startsWith("http://") || imagePath.startsWith("https://")) {
|
|
32
|
+
return downloadImage(imagePath);
|
|
33
|
+
}
|
|
34
|
+
const resolvedPath = path.resolve(imagePath);
|
|
35
|
+
return fs.readFile(resolvedPath);
|
|
36
|
+
}
|
|
37
|
+
async function generateAssets(options) {
|
|
38
|
+
const {
|
|
39
|
+
logoPath,
|
|
40
|
+
htmlPath,
|
|
41
|
+
outputDir,
|
|
42
|
+
sizes = DEFAULT_SIZES
|
|
43
|
+
} = options;
|
|
44
|
+
const resolvedOutputDir = outputDir || path.dirname(htmlPath);
|
|
45
|
+
await fs.mkdir(resolvedOutputDir, { recursive: true });
|
|
46
|
+
const imageBuffer = await loadImage(logoPath);
|
|
47
|
+
const isSvg = logoPath.toLowerCase().endsWith(".svg") || logoPath.startsWith("http") && imageBuffer.toString("utf8", 0, 5).includes("<svg");
|
|
48
|
+
const processedImages = [];
|
|
49
|
+
for (const sizeConfig of sizes) {
|
|
50
|
+
const outputPath = path.join(resolvedOutputDir, sizeConfig.name);
|
|
51
|
+
let processedBuffer;
|
|
52
|
+
if (isSvg) {
|
|
53
|
+
processedBuffer = await sharp(imageBuffer).resize(sizeConfig.size, sizeConfig.size).png().toBuffer();
|
|
54
|
+
} else {
|
|
55
|
+
processedBuffer = await sharp(imageBuffer).resize(sizeConfig.size, sizeConfig.size).png().toBuffer();
|
|
56
|
+
}
|
|
57
|
+
await fs.writeFile(outputPath, processedBuffer);
|
|
58
|
+
if ([
|
|
59
|
+
16,
|
|
60
|
+
32,
|
|
61
|
+
48,
|
|
62
|
+
64,
|
|
63
|
+
128,
|
|
64
|
+
256
|
|
65
|
+
].includes(sizeConfig.size)) {
|
|
66
|
+
processedImages.push({ buffer: processedBuffer, size: sizeConfig.size });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const icoBuffers = await Promise.all(
|
|
70
|
+
processedImages.map((img) => sharp(img.buffer).toBuffer())
|
|
71
|
+
);
|
|
72
|
+
const icoBuffer = await toIco(icoBuffers);
|
|
73
|
+
await fs.writeFile(path.join(resolvedOutputDir, "favicon.ico"), icoBuffer);
|
|
74
|
+
await updateHtmlMetaTags(htmlPath, sizes);
|
|
75
|
+
}
|
|
76
|
+
async function updateHtmlMetaTags(htmlPath, sizes) {
|
|
77
|
+
const htmlContent = await fs.readFile(htmlPath, "utf-8");
|
|
78
|
+
const root = parseHtml(htmlContent);
|
|
79
|
+
const head = root.querySelector("head");
|
|
80
|
+
if (!head) {
|
|
81
|
+
throw new Error("No <head> tag found in HTML file");
|
|
82
|
+
}
|
|
83
|
+
const existingLinks = head.querySelectorAll('link[rel*="icon"], link[rel="apple-touch-icon"], meta[property^="og:image"]');
|
|
84
|
+
existingLinks.forEach((link) => link.remove());
|
|
85
|
+
const metaTags = [];
|
|
86
|
+
metaTags.push('<link rel="icon" type="image/x-icon" href="/favicon.ico">');
|
|
87
|
+
metaTags.push('<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">');
|
|
88
|
+
metaTags.push('<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">');
|
|
89
|
+
metaTags.push('<link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">');
|
|
90
|
+
const appleTouchIcon = sizes.find((s) => s.name === "apple-touch-icon.png");
|
|
91
|
+
if (appleTouchIcon) {
|
|
92
|
+
metaTags.push('<link rel="apple-touch-icon" href="/apple-touch-icon.png">');
|
|
93
|
+
}
|
|
94
|
+
sizes.filter((s) => s.name.startsWith("apple-touch-icon-") && s.name !== "apple-touch-icon.png").forEach((size) => {
|
|
95
|
+
const sizeMatch = size.name.match(/(\d+)x\d+/);
|
|
96
|
+
if (sizeMatch) {
|
|
97
|
+
metaTags.push(`<link rel="apple-touch-icon" sizes="${sizeMatch[0]}" href="/${size.name}">`);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
metaTags.push('<link rel="manifest" href="/manifest.json">');
|
|
101
|
+
metaTags.push('<meta name="msapplication-TileColor" content="#ffffff">');
|
|
102
|
+
metaTags.push('<meta name="msapplication-TileImage" content="/mstile-150x150.png">');
|
|
103
|
+
metaTags.push('<meta name="theme-color" content="#ffffff">');
|
|
104
|
+
const ogImage = sizes.find((s) => s.purpose === "og");
|
|
105
|
+
if (ogImage) {
|
|
106
|
+
metaTags.push(`<meta property="og:image" content="/${ogImage.name}">`);
|
|
107
|
+
metaTags.push('<meta property="og:image:width" content="1200">');
|
|
108
|
+
metaTags.push('<meta property="og:image:height" content="1200">');
|
|
109
|
+
}
|
|
110
|
+
const titleTag = head.querySelector("title");
|
|
111
|
+
if (titleTag) {
|
|
112
|
+
titleTag.insertAdjacentHTML("afterend", `
|
|
113
|
+
${metaTags.join("\n")}`);
|
|
114
|
+
} else {
|
|
115
|
+
head.innerHTML = `${metaTags.join("\n")}
|
|
116
|
+
${head.innerHTML}`;
|
|
117
|
+
}
|
|
118
|
+
await fs.writeFile(htmlPath, root.toString());
|
|
119
|
+
const manifestPath = path.join(path.dirname(htmlPath), "manifest.json");
|
|
120
|
+
const manifest = {
|
|
121
|
+
icons: [{ src: "/android-chrome-192x192.png", sizes: "192x192", type: "image/png" }, { src: "/android-chrome-512x512.png", sizes: "512x512", type: "image/png" }]
|
|
122
|
+
};
|
|
123
|
+
try {
|
|
124
|
+
const existingManifest = JSON.parse(await fs.readFile(manifestPath, "utf-8"));
|
|
125
|
+
existingManifest.icons = manifest.icons;
|
|
126
|
+
await fs.writeFile(manifestPath, JSON.stringify(existingManifest, null, 2));
|
|
127
|
+
} catch {
|
|
128
|
+
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export {
|
|
133
|
+
downloadImage,
|
|
134
|
+
loadImage,
|
|
135
|
+
generateAssets,
|
|
136
|
+
updateHtmlMetaTags
|
|
137
|
+
};
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
generateAssets
|
|
4
|
+
} from "./chunk-YAKKFHGX.js";
|
|
5
|
+
|
|
6
|
+
// src/cli.ts
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { Command } from "commander";
|
|
9
|
+
var program = new Command();
|
|
10
|
+
program.name("logo-asset-generator").description("Generate favicon and app icons from a source logo").version("0.0.1").requiredOption("-l, --logo <path>", "Path or URL to the 512x512px logo (PNG or SVG)").requiredOption("-i, --index <path>", "Path to the index.html file to update").option("-o, --output <path>", "Output directory for generated assets (defaults to same directory as index.html)").action(async (options) => {
|
|
11
|
+
try {
|
|
12
|
+
console.info("\u{1F3A8} Starting logo asset generation...");
|
|
13
|
+
const htmlPath = path.resolve(options.index);
|
|
14
|
+
const outputDir = options.output ? path.resolve(options.output) : void 0;
|
|
15
|
+
await generateAssets({
|
|
16
|
+
logoPath: options.logo,
|
|
17
|
+
htmlPath,
|
|
18
|
+
outputDir
|
|
19
|
+
});
|
|
20
|
+
console.info("\u2705 Successfully generated all assets and updated HTML meta tags!");
|
|
21
|
+
console.info(`\u{1F4C1} Assets saved to: ${outputDir || path.dirname(htmlPath)}`);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.warn("\u274C Error generating assets:", error);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
program.parse();
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface AssetSize {
|
|
2
|
+
name: string;
|
|
3
|
+
size: number;
|
|
4
|
+
purpose?: string;
|
|
5
|
+
}
|
|
6
|
+
interface GeneratorOptions {
|
|
7
|
+
logoPath: string;
|
|
8
|
+
htmlPath: string;
|
|
9
|
+
outputDir?: string;
|
|
10
|
+
sizes?: AssetSize[];
|
|
11
|
+
}
|
|
12
|
+
declare function downloadImage(url: string): Promise<Buffer>;
|
|
13
|
+
declare function loadImage(imagePath: string): Promise<Buffer>;
|
|
14
|
+
declare function generateAssets(options: GeneratorOptions): Promise<void>;
|
|
15
|
+
declare function updateHtmlMetaTags(htmlPath: string, sizes: AssetSize[]): Promise<void>;
|
|
16
|
+
|
|
17
|
+
export { downloadImage, generateAssets, loadImage, updateHtmlMetaTags };
|
|
18
|
+
export type { AssetSize, GeneratorOptions };
|
package/dist/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kivacore/logo-asset-generator",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Placeholder that lets CI publish this package with npm trusted publishing. Install the latest version.",
|
|
5
|
-
"license": "MIT",
|
|
3
|
+
"version": "0.3.4",
|
|
6
4
|
"repository": {
|
|
7
5
|
"type": "git",
|
|
8
6
|
"url": "https://github.com/Docyrus/docyrus-devkit.git",
|
|
9
7
|
"directory": "packages/logo-asset-generator"
|
|
8
|
+
},
|
|
9
|
+
"description": "CLI tool to generate favicon and app icons from a source logo",
|
|
10
|
+
"author": "Docyrus, Inc.",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"logo",
|
|
14
|
+
"asset",
|
|
15
|
+
"favicon",
|
|
16
|
+
"app-icon",
|
|
17
|
+
"docyrus"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"bin": {
|
|
22
|
+
"logo-asset-generator": "./dist/cli.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"commander": "15.1.0",
|
|
29
|
+
"node-html-parser": "7.1.0",
|
|
30
|
+
"sharp": "0.35.5",
|
|
31
|
+
"to-ico": "1.1.5"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "26.6.6",
|
|
35
|
+
"tsup": "9.0.0",
|
|
36
|
+
"tsx": "4.23.15",
|
|
37
|
+
"typescript": "7.0.2",
|
|
38
|
+
"vitest": "5.1.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsup src/cli.ts src/index.ts --format esm --dts",
|
|
42
|
+
"dev": "tsx watch src/cli.ts",
|
|
43
|
+
"lint": "eslint src",
|
|
44
|
+
"format": "eslint src --fix",
|
|
45
|
+
"typecheck": "eslint src && tsc --noEmit",
|
|
46
|
+
"test": "vitest run --passWithNoTests",
|
|
47
|
+
"test:watch": "vitest",
|
|
48
|
+
"deploy": "pnpm run build && pnpm publish --access public"
|
|
10
49
|
}
|
|
11
|
-
}
|
|
50
|
+
}
|