@stacksjs/iconify-generator 0.2.35 → 0.2.90

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/dist/cli.js ADDED
@@ -0,0 +1,791 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+ var __require = import.meta.require;
4
+
5
+ // src/index.ts
6
+ import { mkdir, writeFile } from "fs/promises";
7
+ import { join } from "path";
8
+ var ICONIFY_API = "https://api.iconify.design";
9
+ async function fetchCollections() {
10
+ const response = await fetch(`${ICONIFY_API}/collections`);
11
+ if (!response.ok) {
12
+ throw new Error(`Failed to fetch collections: ${response.statusText}`);
13
+ }
14
+ return await response.json();
15
+ }
16
+ async function fetchCollectionIcons(prefix, icons) {
17
+ try {
18
+ const iconifyJsonPath = __require.resolve("/home/runner/work/stx/stx/node_modules/@iconify/json/dist/index.cjs");
19
+ const basePath = `${iconifyJsonPath.substring(0, iconifyJsonPath.lastIndexOf("/node_modules/@iconify/json/"))}/node_modules/@iconify/json`;
20
+ const jsonPath = `${basePath}/json/${prefix}.json`;
21
+ const file = Bun.file(jsonPath);
22
+ if (await file.exists()) {
23
+ const data = await file.json();
24
+ if (icons && icons.length > 0) {
25
+ const filteredIcons = {};
26
+ for (const iconName of icons) {
27
+ if (data.icons[iconName]) {
28
+ filteredIcons[iconName] = data.icons[iconName];
29
+ }
30
+ }
31
+ return {
32
+ ...data,
33
+ icons: filteredIcons
34
+ };
35
+ }
36
+ return data;
37
+ }
38
+ } catch {}
39
+ const url = icons && icons.length > 0 ? `${ICONIFY_API}/${prefix}.json?icons=${icons.join(",")}` : `${ICONIFY_API}/${prefix}.json`;
40
+ const response = await fetch(url);
41
+ if (!response.ok) {
42
+ throw new Error(`Failed to fetch icons for ${prefix}: ${response.statusText}`);
43
+ }
44
+ return await response.json();
45
+ }
46
+ function convertIconData(data, defaultWidth = 24, defaultHeight = 24) {
47
+ return {
48
+ body: data.body,
49
+ width: data.width || defaultWidth,
50
+ height: data.height || defaultHeight,
51
+ viewBox: `0 0 ${data.width || defaultWidth} ${data.height || defaultHeight}`
52
+ };
53
+ }
54
+ function generateIconData(name, iconData) {
55
+ const camelCaseName = toCamelCase(name);
56
+ return `import type { IconData } from '@stacksjs/iconify-core'
57
+
58
+ export const ${camelCaseName}: IconData = ${JSON.stringify(iconData, null, 2)}
59
+
60
+ export default ${camelCaseName}
61
+ `;
62
+ }
63
+ function generateIconComponent(_name, iconData) {
64
+ return `<script>
65
+ // Get props with defaults (handle undefined)
66
+ const iconWidth = (typeof width !== 'undefined' ? width : null) || (typeof size !== 'undefined' ? size : null) || ${iconData.width || 24}
67
+ const iconHeight = (typeof height !== 'undefined' ? height : null) || (typeof size !== 'undefined' ? size : null) || ${iconData.height || 24}
68
+ const iconColor = typeof color !== 'undefined' ? color : 'currentColor'
69
+ const viewBox = "${iconData.viewBox || `0 0 ${iconData.width || 24} ${iconData.height || 24}`}"
70
+
71
+ // Build transform
72
+ const transforms = []
73
+ if (typeof hFlip !== 'undefined' && hFlip) transforms.push('scaleX(-1)')
74
+ if (typeof vFlip !== 'undefined' && vFlip) transforms.push('scaleY(-1)')
75
+ if (typeof rotate !== 'undefined' && rotate) {
76
+ const rotateNum = typeof rotate === 'string' ? parseInt(rotate, 10) : rotate
77
+ const deg = typeof rotateNum === 'number' && rotateNum < 4 ? rotateNum * 90 : rotateNum
78
+ transforms.push(\`rotate(\${deg}deg)\`)
79
+ }
80
+
81
+ const transform = transforms.length > 0 ? transforms.join(' ') : ''
82
+ const transformStyle = transform ? \`transform: \${transform};\` : ''
83
+
84
+ // Build style
85
+ const styles = []
86
+ if (transformStyle) styles.push(transformStyle)
87
+ if (typeof style !== 'undefined' && style) styles.push(style)
88
+
89
+ const styleAttr = styles.length > 0 ? \` style="\${styles.join(' ')}"\` : ''
90
+ const classAttr = typeof className !== 'undefined' && className ? \` class="\${className}"\` : ''
91
+
92
+ // Icon body
93
+ let body = ${JSON.stringify(iconData.body)}
94
+ if (iconColor && iconColor !== 'currentColor') {
95
+ body = body.replace(/currentColor/g, iconColor)
96
+ }
97
+
98
+ // Generate SVG
99
+ const svg = \`<svg xmlns="http://www.w3.org/2000/svg" width="\${iconWidth}" height="\${iconHeight}" viewBox="\${viewBox}"\${classAttr}\${styleAttr}>\${body}</svg>\`
100
+ </script>
101
+
102
+ {!! svg !!}
103
+ `;
104
+ }
105
+ function generateIndexFile(iconNames) {
106
+ const used = new Set;
107
+ const dataExports = iconNames.map((name) => {
108
+ const primary = toCamelCase(name);
109
+ let id = primary;
110
+ if (used.has(id)) {
111
+ let candidate = name.replace(/[^a-zA-Z0-9]/g, "_");
112
+ if (/^[0-9]/.test(candidate))
113
+ candidate = `_${candidate}`;
114
+ id = candidate;
115
+ let n = 2;
116
+ while (used.has(id)) {
117
+ id = `${candidate}_${n}`;
118
+ n++;
119
+ }
120
+ }
121
+ used.add(id);
122
+ return `export { default as ${id} } from './${name}.js'`;
123
+ }).join(`
124
+ `);
125
+ return `// Icon data exports
126
+ ${dataExports}
127
+
128
+ export * from './types.js'
129
+ `;
130
+ }
131
+ function generateTypesFile(prefix) {
132
+ return `import type { IconData, IconProps } from '@stacksjs/iconify-core'
133
+
134
+ export type { IconData, IconProps }
135
+
136
+ export type ${toPascalCase(prefix)}Icon = IconData
137
+ `;
138
+ }
139
+ function generatePackageJson(prefix, collectionInfo, _iconCount) {
140
+ const packageJson = {
141
+ name: `@stacksjs/iconify-${prefix}`,
142
+ type: "module",
143
+ version: "0.0.1",
144
+ description: `${collectionInfo.name} icons for stx from Iconify`,
145
+ author: collectionInfo.author?.name || "Iconify",
146
+ license: collectionInfo.license?.spdx || "MIT",
147
+ repository: {
148
+ type: "git",
149
+ url: "https://github.com/stacksjs/stx.git",
150
+ directory: `packages/iconify-${prefix}`
151
+ },
152
+ keywords: [
153
+ "iconify",
154
+ "icons",
155
+ "svg",
156
+ prefix,
157
+ collectionInfo.name,
158
+ "stx"
159
+ ],
160
+ sideEffects: false,
161
+ exports: {
162
+ ".": {
163
+ types: "./dist/index.d.ts",
164
+ import: "./dist/index.js"
165
+ },
166
+ "./*": "./dist/*"
167
+ },
168
+ main: "./dist/index.js",
169
+ module: "./dist/index.js",
170
+ types: "./dist/index.d.ts",
171
+ files: [
172
+ "dist"
173
+ ],
174
+ scripts: {
175
+ build: "bun build.ts",
176
+ prepublishOnly: "bun build.ts"
177
+ },
178
+ dependencies: {
179
+ "@stacksjs/iconify-core": "workspace:*"
180
+ }
181
+ };
182
+ return JSON.stringify(packageJson, null, 2);
183
+ }
184
+ function generateBuildFile(prefix) {
185
+ return `import { existsSync, readdirSync, statSync } from 'node:fs'
186
+ import { dirname, join } from 'node:path'
187
+ import { fileURLToPath } from 'node:url'
188
+ import dts from 'bun-plugin-dtsx'
189
+
190
+ const __dirname = dirname(fileURLToPath(import.meta.url))
191
+ const srcDir = join(__dirname, 'src')
192
+ const distDir = join(__dirname, 'dist')
193
+ const distEntry = join(distDir, 'index.js')
194
+
195
+ // Skip rebuild when dist is already up to date. Makes prepublishOnly a
196
+ // no-op when CI pre-built the package in parallel earlier in the
197
+ // pipeline \u2014 and a no-op for local re-runs that didn't touch src/.
198
+ //
199
+ // Walks src/ recursively so changes inside subdirectories (if we ever
200
+ // add them) properly invalidate the cached dist.
201
+ function isDistFresh() {
202
+ if (!existsSync(distEntry)) return false
203
+ const distMtime = statSync(distEntry).mtimeMs
204
+ function newer(dir) {
205
+ for (const name of readdirSync(dir)) {
206
+ const p = join(dir, name)
207
+ const s = statSync(p)
208
+ if (s.isDirectory()) {
209
+ if (newer(p)) return true
210
+ } else if (s.mtimeMs > distMtime) {
211
+ return true
212
+ }
213
+ }
214
+ return false
215
+ }
216
+ return !newer(srcDir)
217
+ }
218
+
219
+ if (isDistFresh()) {
220
+ console.log('\u2713 @stacksjs/iconify-${prefix} dist is fresh, skipping rebuild')
221
+ } else {
222
+ await Bun.build({
223
+ entrypoints: [join(srcDir, 'index.ts')],
224
+ outdir: distDir,
225
+ target: 'bun',
226
+ format: 'esm',
227
+ plugins: [dts()],
228
+ minify: false,
229
+ sourcemap: 'external',
230
+ splitting: true,
231
+ })
232
+ console.log('\u2713 Built @stacksjs/iconify-${prefix}')
233
+ }
234
+ `;
235
+ }
236
+ function generateReadme(prefix, collectionInfo, iconCount) {
237
+ return `# @stacksjs/iconify-${prefix}
238
+
239
+ ${collectionInfo.name} icons for stx from Iconify.
240
+
241
+ ## Installation
242
+
243
+ \`\`\`bash
244
+ bun add @stacksjs/iconify-${prefix}
245
+ \`\`\`
246
+
247
+ ## Usage
248
+
249
+ ### In stx templates
250
+
251
+ \`\`\`html
252
+ <script>
253
+ import { home } from '@stacksjs/iconify-${prefix}'
254
+ import { renderIcon } from '@stacksjs/iconify-core'
255
+
256
+ export const homeIcon = renderIcon(home, { size: 24, color: 'currentColor' })
257
+ </script>
258
+
259
+ <div class="icon">
260
+ {!! homeIcon !!}
261
+ </div>
262
+ \`\`\`
263
+
264
+ ### In TypeScript/JavaScript
265
+
266
+ \`\`\`typescript
267
+ import { home, account, settings } from '@stacksjs/iconify-${prefix}'
268
+ import { renderIcon } from '@stacksjs/iconify-core'
269
+
270
+ const svg = renderIcon(home, {
271
+ size: 24,
272
+ color: '#000000',
273
+ })
274
+ \`\`\`
275
+
276
+ ## Available Icons
277
+
278
+ This package contains ${iconCount} icons from ${collectionInfo.name}.
279
+
280
+ ## License
281
+
282
+ ${collectionInfo.license?.title || "MIT"}
283
+
284
+ ${collectionInfo.license?.url ? `License: ${collectionInfo.license.url}` : ""}
285
+
286
+ ## Credits
287
+
288
+ - Icons: ${collectionInfo.author?.name || "Iconify"}${collectionInfo.author?.url ? ` (${collectionInfo.author.url})` : ""}
289
+ - Iconify: https://iconify.design/
290
+ `;
291
+ }
292
+ function generateDocumentation(prefix, collectionInfo, iconNames) {
293
+ const iconCount = iconNames.length;
294
+ const exampleIcons = iconNames.slice(0, 5).map(toCamelCase);
295
+ const exampleComponents = exampleIcons.map((name) => `${name.charAt(0).toUpperCase()}${name.slice(1)}Icon`);
296
+ const allIconsList = iconNames.map((name) => {
297
+ const camelName = toCamelCase(name);
298
+ return `- \`${camelName}\``;
299
+ }).join(`
300
+ `);
301
+ return `# ${collectionInfo.name}
302
+
303
+ > ${collectionInfo.name} icons for stx from Iconify
304
+
305
+ ## Overview
306
+
307
+ This package provides access to ${iconCount} icons from the ${collectionInfo.name} collection through the stx iconify integration.
308
+
309
+ **Collection ID:** \`${prefix}\`
310
+ **Total Icons:** ${iconCount}
311
+ ${collectionInfo.author?.name ? `**Author:** ${collectionInfo.author.name}${collectionInfo.author.url ? ` ([Website](${collectionInfo.author.url}))` : ""}` : ""}
312
+ ${collectionInfo.license?.title ? `**License:** ${collectionInfo.license.title}${collectionInfo.license.url ? ` ([Details](${collectionInfo.license.url}))` : ""}` : ""}
313
+ ${collectionInfo.category ? `**Category:** ${collectionInfo.category}` : ""}
314
+ ${collectionInfo.palette !== undefined ? `**Palette:** ${collectionInfo.palette ? "Yes (color icons)" : "No (monotone icons)"}` : ""}
315
+
316
+ ## Installation
317
+
318
+ \`\`\`bash
319
+ bun add @stacksjs/iconify-${prefix}
320
+ \`\`\`
321
+
322
+ ## Quick Start
323
+
324
+ ### Component Usage (Recommended)
325
+
326
+ Icons are available as .stx components that can be used directly in templates:
327
+
328
+ \`\`\`html
329
+ <${exampleComponents[0] || "Icon"} height="1em" />
330
+ <${exampleComponents[0] || "Icon"} width="1em" height="1em" />
331
+ <${exampleComponents[0] || "Icon"} height="24" />
332
+ \`\`\`
333
+
334
+ ### With Properties
335
+
336
+ \`\`\`html
337
+ <!-- Using size property -->
338
+ <${exampleComponents[0] || "Icon"} size="24" />
339
+ <${exampleComponents[0] || "Icon"} size="1em" />
340
+
341
+ <!-- Using width and height -->
342
+ <${exampleComponents[0] || "Icon"} width="24" height="32" />
343
+
344
+ <!-- With color -->
345
+ <${exampleComponents[0] || "Icon"} size="24" color="red" />
346
+ <${exampleComponents[0] || "Icon"} size="24" color="#4a90e2" />
347
+
348
+ <!-- With CSS class -->
349
+ <${exampleComponents[0] || "Icon"} size="24" class="icon-primary" />
350
+
351
+ <!-- With all properties -->
352
+ <${exampleComponents[0] || "Icon"}
353
+ size="32"
354
+ color="#4a90e2"
355
+ class="my-icon"
356
+ style="opacity: 0.8;"
357
+ />
358
+ \`\`\`
359
+
360
+ ### In stx Templates
361
+
362
+ \`\`\`html
363
+ <!DOCTYPE html>
364
+ <html>
365
+ <head>
366
+ <title>Icon Demo</title>
367
+ <style>
368
+ .icon-grid {
369
+ display: flex;
370
+ gap: 1rem;
371
+ align-items: center;
372
+ }
373
+ </style>
374
+ </head>
375
+ <body>
376
+ <div class="icon-grid">
377
+ <${exampleComponents[0] || "Icon"} size="24" />
378
+ <${exampleComponents[1] || "Icon"} size="24" color="#4a90e2" />
379
+ <${exampleComponents[2] || "Icon"} size="32" class="my-icon" />
380
+ </div>
381
+ </body>
382
+ </html>
383
+ \`\`\`
384
+
385
+ ### Data-Only Import
386
+
387
+ You can also import icon data and use the \`renderIcon\` function directly:
388
+
389
+ \`\`\`typescript
390
+ import { ${exampleIcons.slice(0, 3).join(", ")} } from '@stacksjs/iconify-${prefix}'
391
+ import { renderIcon } from '@stacksjs/iconify-core'
392
+
393
+ const svg = renderIcon(${exampleIcons[0] || "icon"}, { size: 24 })
394
+ \`\`\`
395
+
396
+ ## Icon Properties
397
+
398
+ All icon component functions and \`renderIcon\` accept the following properties:
399
+
400
+ | Property | Type | Default | Description |
401
+ |----------|------|---------|-------------|
402
+ | \`size\` | \`string \\| number\` | - | Icon size (sets both width and height) |
403
+ | \`width\` | \`string \\| number\` | - | Icon width (overrides size) |
404
+ | \`height\` | \`string \\| number\` | - | Icon height (overrides size) |
405
+ | \`color\` | \`string\` | \`'currentColor'\` | Icon color (CSS color or hex) |
406
+ | \`hFlip\` | \`boolean\` | \`false\` | Flip horizontally |
407
+ | \`vFlip\` | \`boolean\` | \`false\` | Flip vertically |
408
+ | \`rotate\` | \`0 \\| 90 \\| 180 \\| 270\` | \`0\` | Rotation in degrees |
409
+ | \`class\` | \`string\` | - | Additional CSS classes |
410
+ | \`style\` | \`string\` | - | Inline styles |
411
+
412
+ ## Color
413
+
414
+ ${collectionInfo.palette ? `### Color Icons
415
+
416
+ This collection contains color icons. While you can still set a color property, it may override the original colors.` : "### Monotone Icons\n\nMonotone icons use `currentColor` by default, allowing you to change icon color via the `color` property or CSS:"}
417
+
418
+ \`\`\`html
419
+ <!-- Via color property -->
420
+ <${exampleComponents[0] || "Icon"} size="24" color="red" />
421
+ <${exampleComponents[0] || "Icon"} size="24" color="#4a90e2" />
422
+
423
+ <!-- Via inline style -->
424
+ <${exampleComponents[0] || "Icon"} size="24" style="color: green;" />
425
+
426
+ <!-- Via CSS class -->
427
+ <${exampleComponents[0] || "Icon"} size="24" class="text-primary" />
428
+ \`\`\`
429
+
430
+ ${!collectionInfo.palette ? `\`\`\`css
431
+ /* In your CSS */
432
+ .text-primary {
433
+ color: #4a90e2;
434
+ }
435
+
436
+ .icon:hover {
437
+ color: #357abd;
438
+ }
439
+ \`\`\`` : ""}
440
+
441
+ ## Size
442
+
443
+ Unlike other components, SVG + CSS components do not set icon size by default. This has advantages and disadvantages.
444
+
445
+ **Disadvantages:**
446
+ - You need to set size yourself.
447
+
448
+ **Advantages:**
449
+ - You have full control over icon size.
450
+
451
+ You can change icon size by:
452
+ - Setting \`width\` and \`height\` properties
453
+ - Using CSS
454
+
455
+ ### Properties
456
+
457
+ All icon components support \`width\` and \`height\` properties.
458
+
459
+ Value is a string or number.
460
+
461
+ You do not need to set both properties. If you set one property, the other property will automatically be calculated from the icon's width/height ratio.
462
+
463
+ **Examples:**
464
+
465
+ \`\`\`html
466
+ <${exampleComponents[0] || "DraftsIcon"} height="1em" />
467
+ <${exampleComponents[0] || "DraftsIcon"} width="1em" height="1em" />
468
+ <${exampleComponents[0] || "DraftsIcon"} height="24" />
469
+ \`\`\`
470
+
471
+ You can also use the \`size\` property as a shorthand for setting both width and height:
472
+
473
+ \`\`\`html
474
+ <${exampleComponents[0] || "DraftsIcon"} size="24" />
475
+ <${exampleComponents[0] || "DraftsIcon"} size="1em" />
476
+ \`\`\`
477
+
478
+ ### CSS Sizing
479
+
480
+ You can also control icon size via CSS:
481
+
482
+ \`\`\`css
483
+ .${toCamelCase(prefix)}-icon {
484
+ width: 1em;
485
+ height: 1em;
486
+ }
487
+ \`\`\`
488
+
489
+ \`\`\`html
490
+ <${exampleComponents[0] || "DraftsIcon"} class="${toCamelCase(prefix)}-icon" />
491
+ \`\`\`
492
+
493
+ ## Available Icons
494
+
495
+ This package contains **${iconCount}** icons:
496
+
497
+ ${allIconsList}
498
+
499
+ ## Usage Examples
500
+
501
+ ### Navigation Menu
502
+
503
+ \`\`\`html
504
+ <nav>
505
+ <a href="/"><${exampleComponents[0] || "Icon"} size="20" class="nav-icon" /> Home</a>
506
+ <a href="/about"><${exampleComponents[1] || "Icon"} size="20" class="nav-icon" /> About</a>
507
+ <a href="/contact"><${exampleComponents[2] || "Icon"} size="20" class="nav-icon" /> Contact</a>
508
+ <a href="/settings"><${exampleComponents[3] || "Icon"} size="20" class="nav-icon" /> Settings</a>
509
+ </nav>
510
+
511
+ <style>
512
+ nav {
513
+ display: flex;
514
+ gap: 1rem;
515
+ }
516
+ nav a {
517
+ display: flex;
518
+ align-items: center;
519
+ gap: 0.5rem;
520
+ }
521
+ .nav-icon {
522
+ color: currentColor;
523
+ }
524
+ </style>
525
+ \`\`\`
526
+
527
+ ### Custom Styling
528
+
529
+ \`\`\`html
530
+ <${exampleComponents[0] || "Icon"}
531
+ size="24"
532
+ class="icon icon-primary"
533
+ style="opacity: 0.8; transition: opacity 0.2s;"
534
+ />
535
+
536
+ <style>
537
+ .icon-primary {
538
+ color: #4a90e2;
539
+ }
540
+ .icon-primary:hover {
541
+ opacity: 1;
542
+ }
543
+ </style>
544
+ \`\`\`
545
+
546
+ ### Status Indicators
547
+
548
+ \`\`\`html
549
+ <div class="status-grid">
550
+ <div class="status-item">
551
+ <${exampleComponents[0] || "Icon"} size="16" color="#22c55e" />
552
+ <span>Success</span>
553
+ </div>
554
+ <div class="status-item">
555
+ <${exampleComponents[1] || "Icon"} size="16" color="#f59e0b" />
556
+ <span>Warning</span>
557
+ </div>
558
+ <div class="status-item">
559
+ <${exampleComponents[2] || "Icon"} size="16" color="#ef4444" />
560
+ <span>Error</span>
561
+ </div>
562
+ </div>
563
+ \`\`\`
564
+
565
+ ## Best Practices
566
+
567
+ 1. **Use Components Directly**: Import and use icon components in your templates
568
+ \`\`\`html
569
+ <!-- Recommended -->
570
+ <${exampleComponents[0] || "Icon"} size="24" />
571
+ <${exampleComponents[1] || "Icon"} size="24" color="#4a90e2" />
572
+ \`\`\`
573
+
574
+ 2. **Use CSS for Theming**: Apply consistent styling through CSS classes
575
+ \`\`\`css
576
+ .icon {
577
+ color: currentColor;
578
+ opacity: 0.8;
579
+ transition: opacity 0.2s;
580
+ }
581
+
582
+ .icon:hover {
583
+ opacity: 1;
584
+ }
585
+ \`\`\`
586
+
587
+ \`\`\`html
588
+ <${exampleComponents[0] || "Icon"} size="24" class="icon" />
589
+ \`\`\`
590
+
591
+ 3. **Set Appropriate Sizes**: Use \`1em\` for inline icons, fixed pixel sizes for standalone icons
592
+ \`\`\`html
593
+ <!-- Inline with text -->
594
+ <p>Click the <${exampleComponents[0] || "Icon"} height="1em" /> icon to continue</p>
595
+
596
+ <!-- Standalone -->
597
+ <${exampleComponents[0] || "Icon"} size="24" />
598
+ \`\`\`
599
+
600
+ 4. **Use Data Import for Advanced Use Cases**: When you need more control
601
+ \`\`\`html
602
+ @js
603
+ import { ${exampleIcons[0] || "icon"} } from '@stacksjs/iconify-${prefix}'
604
+ import { renderIcon } from '@stacksjs/iconify-core'
605
+ global.customIcon = renderIcon(${exampleIcons[0] || "icon"}, { size: 24 })
606
+ @endjs
607
+
608
+ {!! customIcon !!}
609
+ \`\`\`
610
+
611
+ ## TypeScript Support
612
+
613
+ This package includes full TypeScript support with type definitions for all icons.
614
+
615
+ \`\`\`typescript
616
+ import type { IconData } from '@stacksjs/iconify-core'
617
+ import { ${exampleIcons[0] || "icon"} } from '@stacksjs/iconify-${prefix}'
618
+
619
+ // Icons are typed as IconData
620
+ const myIcon: IconData = ${exampleIcons[0] || "icon"}
621
+ \`\`\`
622
+
623
+ ## Related Packages
624
+
625
+ - [\`@stacksjs/iconify-core\`](../iconify#installation) - Core rendering functions and utilities
626
+ - [Iconify Integration Guide](../iconify) - Complete guide to using Iconify with stx
627
+ - [stx Documentation](../) - Main stx documentation
628
+
629
+ ## License
630
+
631
+ ${collectionInfo.license?.title || "MIT"}
632
+
633
+ ${collectionInfo.license?.url ? `See [license details](${collectionInfo.license.url}) for more information.` : ""}
634
+
635
+ ## Credits
636
+
637
+ - **Icons**: ${collectionInfo.author?.name || "Iconify"}${collectionInfo.author?.url ? ` ([Website](${collectionInfo.author.url}))` : ""}
638
+ - **Iconify**: [https://iconify.design/](https://iconify.design/)
639
+ - **Icon Set**: [View on Iconify](https://icon-sets.iconify.design/${prefix}/)
640
+
641
+ ## Resources
642
+
643
+ - [Browse all icons in this collection](https://icon-sets.iconify.design/${prefix}/)
644
+ - [Iconify documentation](https://iconify.design/docs/)
645
+ - [stx iconify integration guide](../../docs/iconify.md)
646
+ `;
647
+ }
648
+ async function generatePackage(prefix, outputDir, icons, docsDir) {
649
+ console.log(`
650
+ \uD83D\uDCE6 Generating package for ${prefix}...`);
651
+ const collections = await fetchCollections();
652
+ const collectionInfo = collections[prefix];
653
+ if (!collectionInfo) {
654
+ throw new Error(`Collection ${prefix} not found`);
655
+ }
656
+ console.log(` Collection: ${collectionInfo.name}`);
657
+ console.log(` Total icons: ${collectionInfo.total}`);
658
+ const collectionData = await fetchCollectionIcons(prefix, icons);
659
+ const iconNames = Object.keys(collectionData.icons);
660
+ console.log(` Generating ${iconNames.length} icons...`);
661
+ const packageDir = join(outputDir, `iconify-${prefix}`);
662
+ const srcDir = join(packageDir, "src");
663
+ await mkdir(srcDir, { recursive: true });
664
+ const defaultWidth = collectionData.width || 24;
665
+ const defaultHeight = collectionData.height || 24;
666
+ for (const iconName of iconNames) {
667
+ const iconData = collectionData.icons[iconName];
668
+ const converted = convertIconData(iconData, defaultWidth, defaultHeight);
669
+ const dataFile = generateIconData(iconName, converted);
670
+ await writeFile(join(srcDir, `${iconName}.ts`), dataFile);
671
+ const componentFile = generateIconComponent(iconName, converted);
672
+ await writeFile(join(srcDir, `${iconName}-icon.stx`), componentFile);
673
+ }
674
+ const indexContent = generateIndexFile(iconNames);
675
+ await writeFile(join(srcDir, "index.ts"), indexContent);
676
+ const typesContent = generateTypesFile(prefix);
677
+ await writeFile(join(srcDir, "types.ts"), typesContent);
678
+ const packageJsonContent = generatePackageJson(prefix, collectionInfo, iconNames.length);
679
+ await writeFile(join(packageDir, "package.json"), packageJsonContent);
680
+ const buildContent = generateBuildFile(prefix);
681
+ await writeFile(join(packageDir, "build.ts"), buildContent);
682
+ const readmeContent = generateReadme(prefix, collectionInfo, iconNames.length);
683
+ await writeFile(join(packageDir, "README.md"), readmeContent);
684
+ if (docsDir) {
685
+ const docsPath = join(docsDir, `iconify-${prefix}.md`);
686
+ const docContent = generateDocumentation(prefix, collectionInfo, iconNames);
687
+ await mkdir(docsDir, { recursive: true });
688
+ await writeFile(docsPath, docContent);
689
+ console.log(` \u2713 Generated documentation in ${docsPath}`);
690
+ }
691
+ console.log(` \u2713 Generated ${iconNames.length} icons in ${packageDir}`);
692
+ }
693
+ function toCamelCase(str) {
694
+ let camel = str.replace(/-([a-z0-9])/g, (g) => g[1].toUpperCase());
695
+ camel = camel.replace(/[^a-zA-Z0-9_$]/g, "_");
696
+ if (/^[0-9]/.test(camel))
697
+ camel = `_${camel}`;
698
+ return camel;
699
+ }
700
+ function toPascalCase(str) {
701
+ const camel = toCamelCase(str);
702
+ return camel.charAt(0).toUpperCase() + camel.slice(1);
703
+ }
704
+
705
+ // src/cli.ts
706
+ import { join as join2 } from "path";
707
+ import process from "process";
708
+ var args = process.argv.slice(2);
709
+ async function main() {
710
+ if (args.length === 0 || args.includes("--help") || args.includes("-h")) {
711
+ console.log(`
712
+ stx-iconify - Generate Iconify icon packages for stx
713
+
714
+ Usage:
715
+ stx-iconify <command> [options]
716
+
717
+ Commands:
718
+ list List all available icon collections
719
+ generate <prefix> Generate an icon package for a collection
720
+ generate <prefix> <icons...> Generate specific icons from a collection
721
+
722
+ Options:
723
+ --output, -o <dir> Output directory for packages (default: ./packages)
724
+ --docs, -d <dir> Generate documentation in specified directory
725
+ --help, -h Show this help message
726
+
727
+ Examples:
728
+ stx-iconify list
729
+ stx-iconify generate mdi
730
+ stx-iconify generate lucide home settings user
731
+ stx-iconify generate tabler --output ./packages
732
+ stx-iconify generate lucide --docs ./docs/collections
733
+ stx-iconify generate mdi --output ./packages --docs ./docs/collections
734
+ `);
735
+ process.exit(0);
736
+ }
737
+ const command = args[0];
738
+ if (command === "list") {
739
+ console.log(`
740
+ \uD83D\uDCDA Fetching available icon collections...
741
+ `);
742
+ const collections = await fetchCollections();
743
+ const sortedCollections = Object.entries(collections).sort((a, b) => b[1].total - a[1].total);
744
+ console.log(`Available collections:
745
+ `);
746
+ for (const [prefix, info] of sortedCollections) {
747
+ console.log(` ${prefix.padEnd(30)} ${info.name} (${info.total} icons)`);
748
+ }
749
+ console.log(`
750
+ Total: ${sortedCollections.length} collections`);
751
+ } else if (command === "generate") {
752
+ const prefix = args[1];
753
+ if (!prefix) {
754
+ console.error("Error: Please specify a collection prefix");
755
+ console.error("Usage: stx-iconify generate <prefix> [icons...]");
756
+ process.exit(1);
757
+ }
758
+ let outputDir = join2(process.cwd(), "packages");
759
+ let docsDir;
760
+ const icons = [];
761
+ for (let i = 2;i < args.length; i++) {
762
+ if (args[i] === "--output" || args[i] === "-o") {
763
+ outputDir = args[i + 1];
764
+ i++;
765
+ } else if (args[i] === "--docs" || args[i] === "-d") {
766
+ docsDir = args[i + 1];
767
+ i++;
768
+ } else if (!args[i].startsWith("--") && !args[i].startsWith("-")) {
769
+ icons.push(args[i]);
770
+ }
771
+ }
772
+ await generatePackage(prefix, outputDir, icons.length > 0 ? icons : undefined, docsDir);
773
+ console.log(`
774
+ \u2713 Package generated successfully!`);
775
+ console.log(`
776
+ To use the package:`);
777
+ console.log(` 1. cd packages/iconify-${prefix}`);
778
+ console.log(` 2. bun install`);
779
+ console.log(` 3. bun run build`);
780
+ } else {
781
+ console.error(`Unknown command: ${command}`);
782
+ console.error('Run "stx-iconify --help" for usage information');
783
+ process.exit(1);
784
+ }
785
+ }
786
+ main().catch((error) => {
787
+ console.error("Error:", error.message);
788
+ process.exit(1);
789
+ });
790
+
791
+ //# debugId=5970B62405FA22C264756E2164756E21