@hyperpackai/hypericons-cli 0.1.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 ADDED
@@ -0,0 +1 @@
1
+ MIT
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # HyperIcons CLI
2
+
3
+ ```bash
4
+ hypericons optimize --in raw --out optimized
5
+ hypericons generate --in raw --out src
6
+ hypericons sprite --out sprite.svg
7
+ hypericons preview --out preview.html
8
+ hypericons build
9
+ ```
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import "../dist/index.js";
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,119 @@
1
+ import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { createIconSprite, generateDataIndex, generateHyperionIcon, generateIconDataModule, generateReactIcon, generateVueIcon, optimizeSvg, parseSvgToIconData, renderIconToSvg, } from "@hyperpackai/hypericons-core";
4
+ import { hyperIconCatalog } from "@hyperpackai/hypericons-icons/catalog";
5
+ import { loadIconData } from "@hyperpackai/hypericons-icons/lazy";
6
+ const args = process.argv.slice(2);
7
+ const command = args[0] ?? "help";
8
+ function value(name, fallback) {
9
+ const index = args.indexOf(`--${name}`);
10
+ return index === -1 ? fallback : args[index + 1];
11
+ }
12
+ function ensureDir(dir) {
13
+ mkdirSync(dir, { recursive: true });
14
+ }
15
+ function readRawIcons(inputDir) {
16
+ if (!existsSync(inputDir))
17
+ return [];
18
+ return readdirSync(inputDir)
19
+ .filter((file) => file.endsWith(".svg"))
20
+ .sort()
21
+ .map((file) => ({
22
+ name: path.basename(file, ".svg").replace(/(^\w|-\w)/g, (m) => m.replace("-", "").toUpperCase()),
23
+ file,
24
+ svg: readFileSync(path.join(inputDir, file), "utf8"),
25
+ }));
26
+ }
27
+ function help() {
28
+ console.log(`HyperIcons CLI
29
+
30
+ Commands:
31
+ hypericons build --in raw --out src Optimize and generate icon data
32
+ hypericons optimize --in raw --out raw Write optimized SVG files
33
+ hypericons generate --in raw --out src Generate TypeScript icon data
34
+ hypericons sprite --out sprite.svg Generate an SVG sprite from built-ins or raw input
35
+ hypericons preview --out preview.html Generate a static icon preview
36
+
37
+ Flags:
38
+ --in <dir> Raw SVG input directory
39
+ --out <path> Output directory or file
40
+ --framework <name> data | hyperion | react | vue (generate only)
41
+ `);
42
+ }
43
+ function optimizeCommand() {
44
+ const input = value("in", "packages/hypericons-icons/raw");
45
+ const out = value("out", input);
46
+ ensureDir(out);
47
+ for (const icon of readRawIcons(input)) {
48
+ writeFileSync(path.join(out, icon.file), optimizeSvg(icon.svg) + "\n");
49
+ }
50
+ console.log(`Optimized SVGs: ${input} -> ${out}`);
51
+ }
52
+ function generateCommand() {
53
+ const input = value("in", "packages/hypericons-icons/raw");
54
+ const out = value("out", "packages/hypericons-icons/src");
55
+ const framework = value("framework", "data");
56
+ const rawIcons = readRawIcons(input);
57
+ ensureDir(out);
58
+ const names = [];
59
+ for (const icon of rawIcons) {
60
+ names.push(icon.name);
61
+ const contents = framework === "hyperion" ? generateHyperionIcon(icon.name)
62
+ : framework === "react" ? generateReactIcon(icon.name)
63
+ : framework === "vue" ? generateVueIcon(icon.name)
64
+ : generateIconDataModule(icon.name, icon.svg);
65
+ writeFileSync(path.join(out, `${icon.name}.ts`), contents);
66
+ }
67
+ if (framework === "data") {
68
+ writeFileSync(path.join(out, "index.ts"), generateDataIndex(names));
69
+ }
70
+ else {
71
+ writeFileSync(path.join(out, "index.ts"), names.map((name) => `export { ${name}Icon } from "./${name}.js";`).join("\n") + "\n");
72
+ }
73
+ console.log(`Generated ${rawIcons.length} ${framework} icon file(s) into ${out}`);
74
+ }
75
+ async function getBuiltInIcons() {
76
+ return Promise.all(hyperIconCatalog.map((icon) => loadIconData(icon.name)));
77
+ }
78
+ async function spriteCommand() {
79
+ const input = value("in");
80
+ const out = value("out", "sprite.svg");
81
+ const icons = input
82
+ ? readRawIcons(input).map((icon) => parseSvgToIconData(icon.name, icon.svg))
83
+ : await getBuiltInIcons();
84
+ writeFileSync(out, createIconSprite(icons) + "\n");
85
+ console.log(`Generated sprite with ${icons.length} icons: ${out}`);
86
+ }
87
+ async function previewCommand() {
88
+ const out = value("out", "hypericons-preview.html");
89
+ const icons = await getBuiltInIcons();
90
+ const grid = icons.map((icon) => {
91
+ const svg = renderIconToSvg(icon, { title: icon.displayName, size: 28 });
92
+ return `<figure>${svg}<figcaption>${icon.displayName}</figcaption></figure>`;
93
+ }).join("");
94
+ writeFileSync(out, `<!doctype html><html><head><meta charset="utf-8"><title>HyperIcons Preview</title><style>body{font-family:system-ui;margin:32px;color:#111827}main{display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:16px}figure{display:grid;gap:10px;place-items:center;padding:16px;border:1px solid #e5e7eb;border-radius:8px}svg{color:#2563eb}figcaption{font-size:13px}</style></head><body><h1>HyperIcons</h1><p>${hyperIconCatalog.length} original icons.</p><main>${grid}</main></body></html>`);
95
+ console.log(`Generated preview: ${out}`);
96
+ }
97
+ async function main() {
98
+ if (command === "help" || command === "--help" || command === "-h")
99
+ return help();
100
+ if (command === "optimize")
101
+ return optimizeCommand();
102
+ if (command === "generate")
103
+ return generateCommand();
104
+ if (command === "build") {
105
+ optimizeCommand();
106
+ return generateCommand();
107
+ }
108
+ if (command === "sprite")
109
+ return spriteCommand();
110
+ if (command === "preview")
111
+ return previewCommand();
112
+ console.error(`Unknown command: ${command}`);
113
+ help();
114
+ process.exit(1);
115
+ }
116
+ main().catch((error) => {
117
+ console.error(error instanceof Error ? error.message : error);
118
+ process.exit(1);
119
+ });
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@hyperpackai/hypericons-cli",
3
+ "version": "0.1.0",
4
+ "description": "HyperIcons CLI for optimizing SVGs, generating icon data/components, sprites, and previews.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "hypericons": "./bin/hypericons.js"
10
+ },
11
+ "files": ["dist", "bin", "LICENSE", "README.md"],
12
+ "license": "MIT",
13
+ "engines": { "node": ">=20.0.0" },
14
+ "scripts": {
15
+ "build": "tsc -b",
16
+ "dev": "tsc -b --watch"
17
+ },
18
+ "dependencies": {
19
+ "@hyperpackai/hypericons-core": "0.1.0",
20
+ "@hyperpackai/hypericons-icons": "0.1.0"
21
+ },
22
+ "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
23
+ "repository": { "type": "git", "url": "https://github.com/tharikajis-dev/HyperPack" }
24
+ }