@erikbernardo/white-label-icons 1.0.0 → 1.0.1
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 +41 -24
- package/bin/cli.js +372 -65
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@ Biblioteca de ícones moderna, ultraleve, **100% White-Label** e agnóstica a fr
|
|
|
4
4
|
|
|
5
5
|
Permite que **qualquer empresa ou projeto** utilize sua própria identidade de tags (`<empresa-icone>` ou `<meuapp-icon>`), classes CSS (`<i class="empresa-bx-user"></i>`) e diretórios de assets com zero acoplamento de marca e máxima performance com carregamento sob demanda (Lazy Loading e In-Memory Caching).
|
|
6
6
|
|
|
7
|
+
🌐 **Demonstração & Catálogo Oficial**: [https://erikbernard.github.io/white-label-icons/](https://erikbernard.github.io/white-label-icons/)
|
|
8
|
+
|
|
7
9
|
---
|
|
8
10
|
|
|
9
11
|
## ⚡ Início Rápido com CLI (Recomendado)
|
|
@@ -23,13 +25,14 @@ npx wl-icons init --prefix=empresa --tag=empresa-icone --assets=src/assets/icone
|
|
|
23
25
|
```
|
|
24
26
|
|
|
25
27
|
#### Opções do CLI:
|
|
26
|
-
| Flag | Descrição | Padrão |
|
|
28
|
+
| Flag | Descrição | Opções / Padrão |
|
|
27
29
|
| :--- | :--- | :--- |
|
|
30
|
+
| `-f, --framework <tipo>` | Framework do seu projeto | `angular-legacy` (8-18), `angular` (19/20+), `react`, `vue`, `vanilla` |
|
|
28
31
|
| `-p, --prefix <valor>` | Prefixo das classes CSS (`<i class="{prefix}-user">`) | `wl` |
|
|
29
32
|
| `-t, --tag <valor>` | Nome da tag Web Component | `{prefix}-icone` |
|
|
30
|
-
| `-a, --assets <pasta>` | Pasta onde os SVGs serão copiados |
|
|
31
|
-
| `-i, --init-file <caminho>` | Arquivo
|
|
32
|
-
| `-y, --yes` | Pular perguntas e usar
|
|
33
|
+
| `-a, --assets <pasta>` | Pasta onde os 6.919 SVGs serão copiados | Auto-detectado por framework |
|
|
34
|
+
| `-i, --init-file <caminho>` | Arquivo customizado gerado para o framework | Auto-detectado por framework |
|
|
35
|
+
| `-y, --yes` | Pular perguntas e usar detecção automática | `false` |
|
|
33
36
|
|
|
34
37
|
---
|
|
35
38
|
|
|
@@ -41,33 +44,47 @@ npm install @erikbernardo/white-label-icons
|
|
|
41
44
|
|
|
42
45
|
---
|
|
43
46
|
|
|
44
|
-
## 🚀
|
|
47
|
+
## 🚀 Integração por Framework
|
|
45
48
|
|
|
46
|
-
### 1. Angular (
|
|
49
|
+
### 1. Angular 19 e 20+ (Standalone APIs / `app.config.ts`)
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
No seu `src/main.ts` (ou `app.config.ts`):
|
|
51
|
+
O CLI gera automaticamente o `src/app/icons.config.ts`. Adicione o provider no seu `src/app/app.config.ts`:
|
|
50
52
|
|
|
51
53
|
```typescript
|
|
52
|
-
import {
|
|
54
|
+
import { ApplicationConfig } from '@angular/core';
|
|
55
|
+
import { provideWhiteLabelIcons } from './icons.config';
|
|
56
|
+
|
|
57
|
+
export const appConfig: ApplicationConfig = {
|
|
58
|
+
providers: [
|
|
59
|
+
provideWhiteLabelIcons()
|
|
60
|
+
]
|
|
61
|
+
};
|
|
62
|
+
```
|
|
53
63
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
autoReplace: true // Converte automaticamente tags <i> no DOM
|
|
59
|
-
});
|
|
64
|
+
No template HTML dos seus componentes:
|
|
65
|
+
```html
|
|
66
|
+
<empresa-icone nome="bx-user" tamanho="24" cor="#3b82f6"></empresa-icone>
|
|
67
|
+
<i class="empresa-bx-user"></i>
|
|
60
68
|
```
|
|
61
69
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
### 2. Angular 8 a 18 (NgModules / `AppModule` Clássico)
|
|
73
|
+
|
|
74
|
+
O CLI gera o `src/app/icons.module.ts` já com `CUSTOM_ELEMENTS_SCHEMA` e inicialização no boot. Basta importar no seu `src/app/app.module.ts`:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { NgModule } from '@angular/core';
|
|
78
|
+
import { IconsModule } from './icons.module';
|
|
79
|
+
|
|
80
|
+
@NgModule({
|
|
81
|
+
imports: [
|
|
82
|
+
IconsModule,
|
|
83
|
+
// ...
|
|
84
|
+
]
|
|
85
|
+
})
|
|
86
|
+
export class AppModule {}
|
|
87
|
+
```
|
|
71
88
|
|
|
72
89
|
#### Passo 2: Utilização nos Templates HTML
|
|
73
90
|
|
package/bin/cli.js
CHANGED
|
@@ -20,6 +20,7 @@ const c = {
|
|
|
20
20
|
blue: '\x1b[34m',
|
|
21
21
|
magenta: '\x1b[35m',
|
|
22
22
|
red: '\x1b[31m',
|
|
23
|
+
gray: '\x1b[90m',
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
function printBanner() {
|
|
@@ -35,19 +36,26 @@ function printHelp() {
|
|
|
35
36
|
${c.green}npx wl-icons init${c.reset} [opções]
|
|
36
37
|
|
|
37
38
|
Opções:
|
|
38
|
-
${c.yellow}-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
${c.yellow}-
|
|
39
|
+
${c.yellow}-f, --framework <tipo>${c.reset} Ambiente do projeto:
|
|
40
|
+
${c.bright}angular-legacy${c.reset} (Angular 8 a 18 - NgModule)
|
|
41
|
+
${c.bright}angular${c.reset} (Angular 19/20+ - Standalone)
|
|
42
|
+
${c.bright}react${c.reset} (React / Next.js / Vite)
|
|
43
|
+
${c.bright}vue${c.reset} (Vue 2 / Vue 3 / Nuxt)
|
|
44
|
+
${c.bright}vanilla${c.reset} (JavaScript Puro / HTML)
|
|
45
|
+
${c.yellow}-p, --prefix <valor>${c.reset} Prefixo das classes CSS (ex: 'empresa' para <i class="empresa-bx-user">)
|
|
46
|
+
${c.yellow}-t, --tag <valor>${c.reset} Nome da tag Web Component (ex: 'empresa-icone' ou 'empresa-icon')
|
|
47
|
+
${c.yellow}-a, --assets <pasta>${c.reset} Caminho de destino para os arquivos SVG
|
|
48
|
+
${c.yellow}-i, --init-file <caminho>${c.reset}Arquivo gerado específico para o framework
|
|
49
|
+
${c.yellow}-y, --yes${c.reset} Aceitar todos os padrões detectados sem perguntas interativas
|
|
50
|
+
${c.yellow}-h, --help${c.reset} Exibir esta ajuda
|
|
51
|
+
${c.yellow}-v, --version${c.reset} Exibir a versão instalada
|
|
45
52
|
`);
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
function parseArgs(args) {
|
|
49
56
|
const parsed = {
|
|
50
57
|
command: 'init',
|
|
58
|
+
framework: '',
|
|
51
59
|
prefix: '',
|
|
52
60
|
tag: '',
|
|
53
61
|
assets: '',
|
|
@@ -67,6 +75,10 @@ function parseArgs(args) {
|
|
|
67
75
|
parsed.version = true;
|
|
68
76
|
} else if (arg === '-y' || arg === '--yes') {
|
|
69
77
|
parsed.yes = true;
|
|
78
|
+
} else if (arg.startsWith('--framework=')) {
|
|
79
|
+
parsed.framework = arg.split('=')[1];
|
|
80
|
+
} else if (arg === '-f' && args[i + 1]) {
|
|
81
|
+
parsed.framework = args[++i];
|
|
70
82
|
} else if (arg.startsWith('--prefix=')) {
|
|
71
83
|
parsed.prefix = arg.split('=')[1];
|
|
72
84
|
} else if (arg === '-p' && args[i + 1]) {
|
|
@@ -135,9 +147,288 @@ function getPackageVersion() {
|
|
|
135
147
|
}
|
|
136
148
|
}
|
|
137
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Detecta o ambiente do projeto no diretório atual.
|
|
152
|
+
*/
|
|
153
|
+
function detectEnvironment() {
|
|
154
|
+
const cwd = process.cwd();
|
|
155
|
+
let pkg = {};
|
|
156
|
+
try {
|
|
157
|
+
const pkgPath = path.join(cwd, 'package.json');
|
|
158
|
+
if (fs.existsSync(pkgPath)) {
|
|
159
|
+
pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
160
|
+
}
|
|
161
|
+
} catch {}
|
|
162
|
+
|
|
163
|
+
const deps = { ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) };
|
|
164
|
+
|
|
165
|
+
// Angular
|
|
166
|
+
if (fs.existsSync(path.join(cwd, 'angular.json')) || deps['@angular/core']) {
|
|
167
|
+
if (fs.existsSync(path.join(cwd, 'src/app/app.config.ts')) || (deps['@angular/core'] && deps['@angular/core'].match(/(\^|~)?(19|20|[2-9][0-9])/))) {
|
|
168
|
+
return 'angular'; // Standalone
|
|
169
|
+
}
|
|
170
|
+
return 'angular-legacy'; // NgModule (Angular 8-18)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// React
|
|
174
|
+
if (deps['react'] || deps['next'] || fs.existsSync(path.join(cwd, 'next.config.js')) || fs.existsSync(path.join(cwd, 'next.config.mjs'))) {
|
|
175
|
+
return 'react';
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Vue
|
|
179
|
+
if (deps['vue'] || deps['nuxt'] || fs.existsSync(path.join(cwd, 'nuxt.config.ts'))) {
|
|
180
|
+
return 'vue';
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return 'vanilla';
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function normalizeFramework(fw) {
|
|
187
|
+
if (!fw) return '';
|
|
188
|
+
const val = fw.toLowerCase().trim();
|
|
189
|
+
if (val === '1' || val === 'angular-legacy' || val === 'angular8' || val === 'angular-8' || val === 'angular-18' || val === 'ngmodule') {
|
|
190
|
+
return 'angular-legacy';
|
|
191
|
+
}
|
|
192
|
+
if (val === '2' || val === 'angular' || val === 'angular-standalone' || val === 'angular19' || val === 'angular20' || val === 'angular-19' || val === 'angular-20') {
|
|
193
|
+
return 'angular';
|
|
194
|
+
}
|
|
195
|
+
if (val === '3' || val === 'react' || val === 'next' || val === 'nextjs') {
|
|
196
|
+
return 'react';
|
|
197
|
+
}
|
|
198
|
+
if (val === '4' || val === 'vue' || val === 'vue3' || val === 'vue2' || val === 'nuxt') {
|
|
199
|
+
return 'vue';
|
|
200
|
+
}
|
|
201
|
+
if (val === '5' || val === 'vanilla' || val === 'js' || val === 'html') {
|
|
202
|
+
return 'vanilla';
|
|
203
|
+
}
|
|
204
|
+
return 'vanilla';
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function getFrameworkLabel(fw) {
|
|
208
|
+
switch (fw) {
|
|
209
|
+
case 'angular-legacy': return 'Angular 8 a 18 (NgModules / AppModule)';
|
|
210
|
+
case 'angular': return 'Angular 19 / 20+ (Standalone APIs / app.config.ts)';
|
|
211
|
+
case 'react': return 'React / Next.js / Vite';
|
|
212
|
+
case 'vue': return 'Vue 2 / Vue 3 / Nuxt';
|
|
213
|
+
default: return 'JavaScript Puro / Vanilla HTML';
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function getDefaultPathsForFramework(fw, isTs) {
|
|
218
|
+
const cwd = process.cwd();
|
|
219
|
+
let defaultAssets = 'public/icones';
|
|
220
|
+
let defaultInitFile = isTs ? 'src/icons-init.ts' : 'src/icons-init.js';
|
|
221
|
+
|
|
222
|
+
switch (fw) {
|
|
223
|
+
case 'angular-legacy':
|
|
224
|
+
defaultAssets = 'src/assets/icones';
|
|
225
|
+
defaultInitFile = isTs ? 'src/app/icons.module.ts' : 'src/app/icons.module.js';
|
|
226
|
+
break;
|
|
227
|
+
|
|
228
|
+
case 'angular':
|
|
229
|
+
defaultAssets = fs.existsSync(path.join(cwd, 'public')) ? 'public/icones' : 'src/assets/icones';
|
|
230
|
+
defaultInitFile = 'src/app/icons.config.ts';
|
|
231
|
+
break;
|
|
232
|
+
|
|
233
|
+
case 'react':
|
|
234
|
+
defaultAssets = 'public/icones';
|
|
235
|
+
defaultInitFile = isTs ? 'src/icons.tsx' : 'src/icons.jsx';
|
|
236
|
+
break;
|
|
237
|
+
|
|
238
|
+
case 'vue':
|
|
239
|
+
defaultAssets = 'public/icones';
|
|
240
|
+
defaultInitFile = isTs ? 'src/plugins/icons.ts' : 'src/plugins/icons.js';
|
|
241
|
+
break;
|
|
242
|
+
|
|
243
|
+
default: // vanilla
|
|
244
|
+
defaultAssets = fs.existsSync(path.join(cwd, 'public')) ? 'public/icones' : 'icones';
|
|
245
|
+
defaultInitFile = isTs ? 'src/icons-init.ts' : 'icons-init.js';
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return { defaultAssets, defaultInitFile };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Gera o código do arquivo de inicialização de acordo com o framework escolhido.
|
|
254
|
+
*/
|
|
255
|
+
function generateInitFileContent(framework, prefix, tag, webBasePath, isTs) {
|
|
256
|
+
switch (framework) {
|
|
257
|
+
case 'angular-legacy':
|
|
258
|
+
return `/**
|
|
259
|
+
* Módulo de Ícones White-Label para Angular 8 a 18 (NgModule)
|
|
260
|
+
* Gerado automaticamente pelo CLI @erikbernardo/white-label-icons
|
|
261
|
+
*/
|
|
262
|
+
import { NgModule, CUSTOM_ELEMENTS_SCHEMA, APP_INITIALIZER } from '@angular/core';
|
|
263
|
+
import { configureIcons } from '@erikbernardo/white-label-icons';
|
|
264
|
+
|
|
265
|
+
export function initializeWhiteLabelIcons() {
|
|
266
|
+
return () => {
|
|
267
|
+
configureIcons({
|
|
268
|
+
prefix: '${prefix}',
|
|
269
|
+
tagName: '${tag}',
|
|
270
|
+
basePath: '${webBasePath}',
|
|
271
|
+
autoReplace: true,
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
@NgModule({
|
|
277
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
278
|
+
providers: [
|
|
279
|
+
{
|
|
280
|
+
provide: APP_INITIALIZER,
|
|
281
|
+
useFactory: initializeWhiteLabelIcons,
|
|
282
|
+
multi: true,
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
})
|
|
286
|
+
export class IconsModule {}
|
|
287
|
+
`;
|
|
288
|
+
|
|
289
|
+
case 'angular':
|
|
290
|
+
return `/**
|
|
291
|
+
* Provider de Ícones White-Label para Angular 19 e 20+ (Standalone APIs)
|
|
292
|
+
* Gerado automaticamente pelo CLI @erikbernardo/white-label-icons
|
|
293
|
+
*/
|
|
294
|
+
import { EnvironmentProviders, makeEnvironmentProviders, ENVIRONMENT_INITIALIZER, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
|
295
|
+
import { configureIcons, IconOptions } from '@erikbernardo/white-label-icons';
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Adicione este provider no seu app.config.ts:
|
|
299
|
+
* export const appConfig: ApplicationConfig = {
|
|
300
|
+
* providers: [provideWhiteLabelIcons(), ...]
|
|
301
|
+
* };
|
|
302
|
+
*/
|
|
303
|
+
export function provideWhiteLabelIcons(options?: Partial<IconOptions>): EnvironmentProviders {
|
|
304
|
+
return makeEnvironmentProviders([
|
|
305
|
+
{
|
|
306
|
+
provide: ENVIRONMENT_INITIALIZER,
|
|
307
|
+
useValue: () => {
|
|
308
|
+
configureIcons({
|
|
309
|
+
prefix: '${prefix}',
|
|
310
|
+
tagName: '${tag}',
|
|
311
|
+
basePath: '${webBasePath}',
|
|
312
|
+
autoReplace: true,
|
|
313
|
+
...options,
|
|
314
|
+
});
|
|
315
|
+
},
|
|
316
|
+
multi: true,
|
|
317
|
+
},
|
|
318
|
+
]);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Schemas para componentes standalone que usam a tag <${tag}>
|
|
322
|
+
export const ICONS_SCHEMAS = [CUSTOM_ELEMENTS_SCHEMA];
|
|
323
|
+
`;
|
|
324
|
+
|
|
325
|
+
case 'react':
|
|
326
|
+
return `/**
|
|
327
|
+
* Wrapper de Ícones White-Label para React / Next.js
|
|
328
|
+
* Gerado automaticamente pelo CLI @erikbernardo/white-label-icons
|
|
329
|
+
*/
|
|
330
|
+
import React from 'react';
|
|
331
|
+
import { configureIcons } from '@erikbernardo/white-label-icons';
|
|
332
|
+
|
|
333
|
+
// Inicializa no cliente
|
|
334
|
+
export function initIcons(): void {
|
|
335
|
+
configureIcons({
|
|
336
|
+
prefix: '${prefix}',
|
|
337
|
+
tagName: '${tag}',
|
|
338
|
+
basePath: '${webBasePath}',
|
|
339
|
+
autoReplace: true,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (typeof window !== 'undefined') {
|
|
344
|
+
initIcons();
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export interface IconProps extends React.HTMLAttributes<HTMLElement> {
|
|
348
|
+
name: string;
|
|
349
|
+
size?: number | string;
|
|
350
|
+
color?: string;
|
|
351
|
+
rotate?: number | string;
|
|
352
|
+
flip?: 'horizontal' | 'vertical' | 'ambos';
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Componente React reutilizável para ícones
|
|
357
|
+
* Exemplo: <Icon name="bx-user" size={24} color="#3b82f6" />
|
|
358
|
+
*/
|
|
359
|
+
export const Icon: React.FC<IconProps> = ({ name, size, color, rotate, flip, className, ...props }) => {
|
|
360
|
+
return React.createElement('${tag}', {
|
|
361
|
+
nome: name,
|
|
362
|
+
tamanho: size,
|
|
363
|
+
cor: color,
|
|
364
|
+
rotacao: rotate,
|
|
365
|
+
espelhar: flip,
|
|
366
|
+
class: className,
|
|
367
|
+
...props,
|
|
368
|
+
});
|
|
369
|
+
};
|
|
370
|
+
`;
|
|
371
|
+
|
|
372
|
+
case 'vue':
|
|
373
|
+
return `/**
|
|
374
|
+
* Plugin de Ícones White-Label para Vue 2 / Vue 3
|
|
375
|
+
* Gerado automaticamente pelo CLI @erikbernardo/white-label-icons
|
|
376
|
+
*/
|
|
377
|
+
import { configureIcons } from '@erikbernardo/white-label-icons';
|
|
378
|
+
|
|
379
|
+
export const IconsPlugin = {
|
|
380
|
+
install(${isTs ? 'app: any' : 'app'}) {
|
|
381
|
+
configureIcons({
|
|
382
|
+
prefix: '${prefix}',
|
|
383
|
+
tagName: '${tag}',
|
|
384
|
+
basePath: '${webBasePath}',
|
|
385
|
+
autoReplace: true,
|
|
386
|
+
});
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// Auto-inicializa se estiver no navegador
|
|
391
|
+
if (typeof window !== 'undefined') {
|
|
392
|
+
configureIcons({
|
|
393
|
+
prefix: '${prefix}',
|
|
394
|
+
tagName: '${tag}',
|
|
395
|
+
basePath: '${webBasePath}',
|
|
396
|
+
autoReplace: true,
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
`;
|
|
400
|
+
|
|
401
|
+
default: // vanilla
|
|
402
|
+
return `/**
|
|
403
|
+
* Configuração dos Ícones White-Label (JavaScript Puro / HTML)
|
|
404
|
+
* Gerado automaticamente pelo CLI @erikbernardo/white-label-icons
|
|
405
|
+
*/
|
|
406
|
+
import { configureIcons } from '@erikbernardo/white-label-icons';
|
|
407
|
+
|
|
408
|
+
export function initAppIcons()${isTs ? ': void' : ''} {
|
|
409
|
+
configureIcons({
|
|
410
|
+
prefix: '${prefix}',
|
|
411
|
+
tagName: '${tag}',
|
|
412
|
+
basePath: '${webBasePath}',
|
|
413
|
+
autoReplace: true,
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// Inicializa automaticamente no navegador
|
|
418
|
+
if (typeof window !== 'undefined') {
|
|
419
|
+
initAppIcons();
|
|
420
|
+
}
|
|
421
|
+
`;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
138
425
|
async function runInit(options) {
|
|
139
426
|
printBanner();
|
|
140
427
|
|
|
428
|
+
const isTs = fs.existsSync(path.resolve(process.cwd(), 'tsconfig.json'));
|
|
429
|
+
const detectedFw = detectEnvironment();
|
|
430
|
+
|
|
431
|
+
let framework = normalizeFramework(options.framework);
|
|
141
432
|
let prefix = options.prefix;
|
|
142
433
|
let tag = options.tag;
|
|
143
434
|
let assetsPath = options.assets;
|
|
@@ -151,42 +442,62 @@ async function runInit(options) {
|
|
|
151
442
|
output: process.stdout,
|
|
152
443
|
});
|
|
153
444
|
|
|
154
|
-
console.log(`${c.bright}Vamos configurar a biblioteca White-Label
|
|
445
|
+
console.log(`${c.bright}Vamos configurar a biblioteca White-Label de acordo com o seu ambiente:${c.reset}\n`);
|
|
446
|
+
|
|
447
|
+
if (!framework) {
|
|
448
|
+
console.log(`${c.cyan}1. Selecione o ambiente / framework do projeto:${c.reset}`);
|
|
449
|
+
console.log(` ${c.yellow}[1]${c.reset} Angular 8 a 18 (NgModules / AppModule clássico)`);
|
|
450
|
+
console.log(` ${c.yellow}[2]${c.reset} Angular 19 / 20+ (Standalone APIs / app.config.ts)`);
|
|
451
|
+
console.log(` ${c.yellow}[3]${c.reset} React / Next.js / Vite`);
|
|
452
|
+
console.log(` ${c.yellow}[4]${c.reset} Vue 2 / Vue 3 / Nuxt`);
|
|
453
|
+
console.log(` ${c.yellow}[5]${c.reset} JavaScript Puro / Vanilla HTML\n`);
|
|
454
|
+
|
|
455
|
+
const fwChoiceMap = {
|
|
456
|
+
'angular-legacy': '1',
|
|
457
|
+
'angular': '2',
|
|
458
|
+
'react': '3',
|
|
459
|
+
'vue': '4',
|
|
460
|
+
'vanilla': '5'
|
|
461
|
+
};
|
|
462
|
+
const defaultChoice = fwChoiceMap[detectedFw] || '1';
|
|
463
|
+
|
|
464
|
+
const answer = await askQuestion(rl, 'Digite o número correspondente', defaultChoice);
|
|
465
|
+
framework = normalizeFramework(answer) || detectedFw;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const { defaultAssets, defaultInitFile } = getDefaultPathsForFramework(framework, isTs);
|
|
155
469
|
|
|
156
470
|
if (!prefix) {
|
|
157
|
-
prefix = await askQuestion(rl, '
|
|
471
|
+
prefix = await askQuestion(rl, '2. Qual prefixo de classe deseja usar para os ícones? (ex: empresa, app, wl)', 'wl');
|
|
158
472
|
}
|
|
159
473
|
|
|
160
474
|
if (!tag) {
|
|
161
475
|
const defaultTag = `${prefix}-icone`;
|
|
162
|
-
tag = await askQuestion(rl, `
|
|
476
|
+
tag = await askQuestion(rl, `3. Qual tag Web Component deseja registrar?`, defaultTag);
|
|
163
477
|
}
|
|
164
478
|
|
|
165
479
|
if (!assetsPath) {
|
|
166
|
-
assetsPath = await askQuestion(rl, '
|
|
480
|
+
assetsPath = await askQuestion(rl, '4. Onde deseja copiar os arquivos SVG no seu projeto?', defaultAssets);
|
|
167
481
|
}
|
|
168
482
|
|
|
169
483
|
if (!initFilePath) {
|
|
170
|
-
|
|
171
|
-
const defaultInit = isTs ? 'src/icons-init.ts' : 'src/icons-init.js';
|
|
172
|
-
initFilePath = await askQuestion(rl, '4. Caminho para o arquivo de inicialização:', defaultInit);
|
|
484
|
+
initFilePath = await askQuestion(rl, '5. Caminho para o arquivo de inicialização gerado:', defaultInitFile);
|
|
173
485
|
}
|
|
174
486
|
|
|
175
487
|
rl.close();
|
|
176
488
|
console.log('');
|
|
177
489
|
} else {
|
|
178
|
-
//
|
|
490
|
+
// Modo não interativo
|
|
491
|
+
framework = framework || detectedFw || 'vanilla';
|
|
179
492
|
prefix = prefix || 'wl';
|
|
180
493
|
tag = tag || `${prefix}-icone`;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
initFilePath = isTs ? 'src/icons-init.ts' : 'src/icons-init.js';
|
|
185
|
-
}
|
|
494
|
+
const { defaultAssets, defaultInitFile } = getDefaultPathsForFramework(framework, isTs);
|
|
495
|
+
assetsPath = assetsPath || defaultAssets;
|
|
496
|
+
initFilePath = initFilePath || defaultInitFile;
|
|
186
497
|
}
|
|
187
498
|
|
|
188
499
|
// Normalização
|
|
189
|
-
prefix = prefix.toLowerCase().replace(/[^a-z0-9_-]/g, '');
|
|
500
|
+
prefix = prefix.toLowerCase().replace(/[^a-z0-9_-]/g, '') || 'wl';
|
|
190
501
|
if (!tag.includes('-')) {
|
|
191
502
|
tag = `${tag}-icone`;
|
|
192
503
|
}
|
|
@@ -195,13 +506,14 @@ async function runInit(options) {
|
|
|
195
506
|
const targetInitFile = path.resolve(process.cwd(), initFilePath);
|
|
196
507
|
|
|
197
508
|
console.log(`${c.cyan}⚙️ Configurações selecionadas:${c.reset}`);
|
|
198
|
-
console.log(` •
|
|
199
|
-
console.log(` •
|
|
200
|
-
console.log(` •
|
|
201
|
-
console.log(` •
|
|
509
|
+
console.log(` • Ambiente / Framework: ${c.green}${getFrameworkLabel(framework)}${c.reset}`);
|
|
510
|
+
console.log(` • Prefixo CSS: ${c.green}${prefix}${c.reset} (ex: <i class="${prefix}-bx-user"></i>)`);
|
|
511
|
+
console.log(` • Tag Web Component: ${c.green}<${tag}>${c.reset} (ex: <${tag} nome="bx-user"></${tag}>)`);
|
|
512
|
+
console.log(` • Pasta de SVGs: ${c.green}${assetsPath}${c.reset}`);
|
|
513
|
+
console.log(` • Arquivo de Init: ${c.green}${initFilePath}${c.reset}\n`);
|
|
202
514
|
|
|
203
515
|
// 1. Cópia de SVGs
|
|
204
|
-
console.log(`${c.bright}📦 Copiando ícones SVG para "${assetsPath}"...${c.reset}`);
|
|
516
|
+
console.log(`${c.bright}📦 Copiando 6.919 ícones SVG para "${assetsPath}"...${c.reset}`);
|
|
205
517
|
try {
|
|
206
518
|
const copiedCount = copyDirectoryRecursive(SOURCE_ICONS_DIR, targetAssetsDir);
|
|
207
519
|
console.log(`${c.green}✔ ${copiedCount} ícones SVG copiados com sucesso!${c.reset}\n`);
|
|
@@ -210,35 +522,14 @@ async function runInit(options) {
|
|
|
210
522
|
process.exit(1);
|
|
211
523
|
}
|
|
212
524
|
|
|
213
|
-
// 2. Criação do arquivo de inicialização
|
|
214
|
-
console.log(`${c.bright}📝 Gerando arquivo de inicialização
|
|
525
|
+
// 2. Criação do arquivo de inicialização específico do framework
|
|
526
|
+
console.log(`${c.bright}📝 Gerando arquivo de inicialização customizado para ${getFrameworkLabel(framework)}...${c.reset}`);
|
|
215
527
|
|
|
216
|
-
// Calcula o basePath web relativo esperado pelo navegador
|
|
217
528
|
let webBasePath = assetsPath.replace(/^src\//, '').replace(/^public\//, '');
|
|
218
529
|
if (!webBasePath.startsWith('/')) webBasePath = '/' + webBasePath;
|
|
219
530
|
if (!webBasePath.endsWith('/')) webBasePath += '/';
|
|
220
531
|
|
|
221
|
-
const
|
|
222
|
-
const code = `/**
|
|
223
|
-
* Configuração dos Ícones White-Label
|
|
224
|
-
* Gerado automaticamente pelo CLI @erikbernardo/white-label-icons
|
|
225
|
-
*/
|
|
226
|
-
import { configureIcons } from '@erikbernardo/white-label-icons';
|
|
227
|
-
|
|
228
|
-
export function initAppIcons()${isTypeScript ? ': void' : ''} {
|
|
229
|
-
configureIcons({
|
|
230
|
-
prefix: '${prefix}',
|
|
231
|
-
tagName: '${tag}',
|
|
232
|
-
basePath: '${webBasePath}',
|
|
233
|
-
autoReplace: true,
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Inicializa automaticamente no navegador
|
|
238
|
-
if (typeof window !== 'undefined') {
|
|
239
|
-
initAppIcons();
|
|
240
|
-
}
|
|
241
|
-
`;
|
|
532
|
+
const code = generateInitFileContent(framework, prefix, tag, webBasePath, isTs);
|
|
242
533
|
|
|
243
534
|
try {
|
|
244
535
|
fs.mkdirSync(path.dirname(targetInitFile), { recursive: true });
|
|
@@ -248,23 +539,39 @@ if (typeof window !== 'undefined') {
|
|
|
248
539
|
console.error(`${c.red}❌ Falha ao criar arquivo de inicialização:${c.reset}`, err.message);
|
|
249
540
|
}
|
|
250
541
|
|
|
251
|
-
// 3.
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
console.log(`
|
|
256
|
-
console.log(` ${c.
|
|
542
|
+
// 3. Verificações de Projetos e Instruções Específicas
|
|
543
|
+
console.log(`${c.cyan}${c.bright}🚀 Pronto! Como utilizar no seu projeto:${c.reset}\n`);
|
|
544
|
+
|
|
545
|
+
if (framework === 'angular-legacy') {
|
|
546
|
+
console.log(`1. Importe o ${c.yellow}IconsModule${c.reset} no seu ${c.yellow}src/app/app.module.ts${c.reset}:`);
|
|
547
|
+
console.log(` ${c.green}import { IconsModule } from './icons.module';${c.reset}`);
|
|
548
|
+
console.log(` ${c.green}@NgModule({ imports: [IconsModule, ...], ... })${c.reset}\n`);
|
|
549
|
+
console.log(`2. Certifique-se de que "${assetsPath}" está em "assets" no seu ${c.yellow}angular.json${c.reset}.`);
|
|
550
|
+
} else if (framework === 'angular') {
|
|
551
|
+
console.log(`1. Adicione o provider no seu ${c.yellow}src/app/app.config.ts${c.reset}:`);
|
|
552
|
+
console.log(` ${c.green}import { provideWhiteLabelIcons } from './icons.config';${c.reset}`);
|
|
553
|
+
console.log(` ${c.green}export const appConfig: ApplicationConfig = { providers: [provideWhiteLabelIcons(), ...] };${c.reset}\n`);
|
|
554
|
+
console.log(`2. Em componentes Standalone que usam a tag <${tag}>, inclua o schema:`);
|
|
555
|
+
console.log(` ${c.green}import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';${c.reset}`);
|
|
556
|
+
console.log(` ${c.green}@Component({ schemas: [CUSTOM_ELEMENTS_SCHEMA], ... })${c.reset}`);
|
|
557
|
+
} else if (framework === 'react') {
|
|
558
|
+
console.log(`1. Importe o componente no seu JSX/TSX:`);
|
|
559
|
+
console.log(` ${c.green}import { Icon } from './${path.basename(initFilePath, path.extname(initFilePath))}';${c.reset}`);
|
|
560
|
+
console.log(` ${c.green}<Icon name="bx-user" size={24} color="#3b82f6" />${c.reset}\n`);
|
|
561
|
+
} else if (framework === 'vue') {
|
|
562
|
+
console.log(`1. Registre o plugin no seu ${c.yellow}src/main.ts${c.reset} / ${c.yellow}src/main.js${c.reset}:`);
|
|
563
|
+
console.log(` ${c.green}import { IconsPlugin } from './plugins/icons';${c.reset}`);
|
|
564
|
+
console.log(` ${c.green}app.use(IconsPlugin);${c.reset}\n`);
|
|
565
|
+
console.log(`2. Se usar Vite, adicione a tag aos custom elements no ${c.yellow}vite.config.ts${c.reset}:`);
|
|
566
|
+
console.log(` ${c.gray}vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.startsWith('${prefix}-') } } })${c.reset}`);
|
|
567
|
+
} else {
|
|
568
|
+
console.log(`1. Importe o arquivo gerado no seu ponto de entrada (ex: ${c.yellow}index.html${c.reset} ou ${c.yellow}main.js${c.reset}):`);
|
|
569
|
+
console.log(` ${c.green}<script type="module" src="./${initFilePath}"></script>${c.reset}`);
|
|
257
570
|
}
|
|
258
571
|
|
|
259
|
-
|
|
260
|
-
console.log(
|
|
261
|
-
console.log(
|
|
262
|
-
console.log(` ${c.green}import './${path.relative(path.dirname(path.resolve(process.cwd(), 'src/main.ts')), targetInitFile).replace(/\\/g, '/').replace(/\.ts$/, '')}';${c.reset}`);
|
|
263
|
-
|
|
264
|
-
console.log(`\n2. Use as tags no seu HTML / Templates:`);
|
|
265
|
-
console.log(` ${c.green}<${tag} nome="bx-user" tamanho="24" cor="#3b82f6"></${tag}>${c.reset}`);
|
|
266
|
-
console.log(` ${c.bright}ou simplesmente via classe CSS:${c.reset}`);
|
|
267
|
-
console.log(` ${c.green}<i class="${prefix}-bx-user"></i>${c.reset}\n`);
|
|
572
|
+
console.log(`\n${c.bright}Uso nos Templates / HTML:${c.reset}`);
|
|
573
|
+
console.log(` • Via Custom Element: ${c.green}<${tag} nome="bx-user" tamanho="24" cor="#3b82f6"></${tag}>${c.reset}`);
|
|
574
|
+
console.log(` • Via Classe CSS: ${c.green}<i class="${prefix}-bx-user"></i>${c.reset}\n`);
|
|
268
575
|
}
|
|
269
576
|
|
|
270
577
|
async function main() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@erikbernardo/white-label-icons",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Biblioteca de ícones agnóstica de framework e 100% white-label (Angular, React, Vue, Web Components) com suporte a prefixos customizados e CLI de setup.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|