@promptui-lib/codegen 0.1.9 → 0.1.11

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.
@@ -1 +1 @@
1
- {"version":3,"file":"antd.template.d.ts","sourceRoot":"","sources":["../../src/frameworks/antd.template.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAmD,MAAM,oBAAoB,CAAC;AA4LzG;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAiChE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAoB9E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAwC7D"}
1
+ {"version":3,"file":"antd.template.d.ts","sourceRoot":"","sources":["../../src/frameworks/antd.template.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAkE,MAAM,oBAAoB,CAAC;AAuMxH;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAiChE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAoB9E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAwC7D"}
@@ -84,6 +84,12 @@ function stylesToInline(styles) {
84
84
  function isTextNode(child) {
85
85
  return 'type' in child && child.type === 'text';
86
86
  }
87
+ /**
88
+ * Check if a child is a component node
89
+ */
90
+ function isComponentNode(child) {
91
+ return 'type' in child && child.type === 'component';
92
+ }
87
93
  /**
88
94
  * Check if a child is a JSX node
89
95
  */
@@ -152,6 +158,10 @@ function generateJSX(node, indent = 2) {
152
158
  if (isTextNode(child)) {
153
159
  return `${spaces} ${child.value}`;
154
160
  }
161
+ if (isComponentNode(child)) {
162
+ // Render child component as <ComponentName />
163
+ return `${spaces} <${child.componentName} />`;
164
+ }
155
165
  if (isJSXNode(child)) {
156
166
  return generateJSX(child, indent + 2);
157
167
  }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Fonts Generator
3
+ * Gera arquivo SCSS com imports de Google Fonts
4
+ */
5
+ /**
6
+ * Extrai nomes de fontes de um conteúdo SCSS
7
+ */
8
+ export declare function extractFontsFromSCSS(scssContent: string): string[];
9
+ /**
10
+ * Gera URL do Google Fonts para uma fonte
11
+ */
12
+ export declare function getGoogleFontUrl(fontName: string): string | null;
13
+ /**
14
+ * Gera conteúdo do arquivo _fonts.scss
15
+ */
16
+ export declare function generateFontsScss(fonts: string[]): string;
17
+ /**
18
+ * Verifica se uma fonte precisa de import (não é fonte de sistema)
19
+ */
20
+ export declare function needsFontImport(fontName: string): boolean;
21
+ /**
22
+ * Lista de fontes disponíveis no Google Fonts (para referência)
23
+ */
24
+ export declare function getAvailableFonts(): string[];
25
+ //# sourceMappingURL=fonts-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fonts-generator.d.ts","sourceRoot":"","sources":["../../src/generators/fonts-generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkEH;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,CAsBlE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAiBhE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAwBzD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,EAAE,CAE5C"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Fonts Generator
3
+ * Gera arquivo SCSS com imports de Google Fonts
4
+ */
5
+ // Mapeamento de fontes conhecidas para URLs do Google Fonts
6
+ const GOOGLE_FONTS_MAP = {
7
+ 'Manrope': 'https://fonts.googleapis.com/css2?family=Manrope:wght@200;300;400;500;600;700;800&display=swap',
8
+ 'Inter': 'https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap',
9
+ 'Roboto': 'https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;400;500;700;900&display=swap',
10
+ 'Open Sans': 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;500;600;700;800&display=swap',
11
+ 'Lato': 'https://fonts.googleapis.com/css2?family=Lato:wght@100;300;400;700;900&display=swap',
12
+ 'Poppins': 'https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap',
13
+ 'Montserrat': 'https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200;300;400;500;600;700;800;900&display=swap',
14
+ 'Source Sans Pro': 'https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@200;300;400;600;700;900&display=swap',
15
+ 'Oswald': 'https://fonts.googleapis.com/css2?family=Oswald:wght@200;300;400;500;600;700&display=swap',
16
+ 'Raleway': 'https://fonts.googleapis.com/css2?family=Raleway:wght@100;200;300;400;500;600;700;800;900&display=swap',
17
+ 'Nunito': 'https://fonts.googleapis.com/css2?family=Nunito:wght@200;300;400;500;600;700;800;900&display=swap',
18
+ 'Nunito Sans': 'https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@200;300;400;500;600;700;800;900&display=swap',
19
+ 'Work Sans': 'https://fonts.googleapis.com/css2?family=Work+Sans:wght@100;200;300;400;500;600;700;800;900&display=swap',
20
+ 'Fira Code': 'https://fonts.googleapis.com/css2?family=Fira+Code:wght@300;400;500;600;700&display=swap',
21
+ 'DM Sans': 'https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&display=swap',
22
+ 'Playfair Display': 'https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500;600;700;800;900&display=swap',
23
+ 'Ubuntu': 'https://fonts.googleapis.com/css2?family=Ubuntu:wght@300;400;500;700&display=swap',
24
+ 'Rubik': 'https://fonts.googleapis.com/css2?family=Rubik:wght@300;400;500;600;700;800;900&display=swap',
25
+ 'Quicksand': 'https://fonts.googleapis.com/css2?family=Quicksand:wght@300;400;500;600;700&display=swap',
26
+ 'Karla': 'https://fonts.googleapis.com/css2?family=Karla:wght@200;300;400;500;600;700;800&display=swap',
27
+ 'Mulish': 'https://fonts.googleapis.com/css2?family=Mulish:wght@200;300;400;500;600;700;800;900&display=swap',
28
+ 'Barlow': 'https://fonts.googleapis.com/css2?family=Barlow:wght@100;200;300;400;500;600;700;800;900&display=swap',
29
+ 'Josefin Sans': 'https://fonts.googleapis.com/css2?family=Josefin+Sans:wght@100;200;300;400;500;600;700&display=swap',
30
+ 'Space Grotesk': 'https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&display=swap',
31
+ 'Plus Jakarta Sans': 'https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@200;300;400;500;600;700;800&display=swap',
32
+ 'Sora': 'https://fonts.googleapis.com/css2?family=Sora:wght@100;200;300;400;500;600;700;800&display=swap',
33
+ 'Lexend': 'https://fonts.googleapis.com/css2?family=Lexend:wght@100;200;300;400;500;600;700;800;900&display=swap',
34
+ 'Outfit': 'https://fonts.googleapis.com/css2?family=Outfit:wght@100;200;300;400;500;600;700;800;900&display=swap',
35
+ 'Figtree': 'https://fonts.googleapis.com/css2?family=Figtree:wght@300;400;500;600;700;800;900&display=swap',
36
+ 'Onest': 'https://fonts.googleapis.com/css2?family=Onest:wght@100;200;300;400;500;600;700;800;900&display=swap',
37
+ 'Geist': 'https://fonts.googleapis.com/css2?family=Geist:wght@100;200;300;400;500;600;700;800;900&display=swap',
38
+ };
39
+ // Fontes de sistema (não precisam de import)
40
+ const SYSTEM_FONTS = new Set([
41
+ 'Arial',
42
+ 'Helvetica',
43
+ 'Helvetica Neue',
44
+ 'Times New Roman',
45
+ 'Times',
46
+ 'Georgia',
47
+ 'Courier New',
48
+ 'Courier',
49
+ 'Verdana',
50
+ 'Tahoma',
51
+ 'Trebuchet MS',
52
+ 'Impact',
53
+ 'Comic Sans MS',
54
+ 'sans-serif',
55
+ 'serif',
56
+ 'monospace',
57
+ 'cursive',
58
+ 'fantasy',
59
+ '-apple-system',
60
+ 'BlinkMacSystemFont',
61
+ 'Segoe UI',
62
+ 'system-ui',
63
+ 'SF Pro',
64
+ 'SF Pro Display',
65
+ 'SF Pro Text',
66
+ ]);
67
+ /**
68
+ * Extrai nomes de fontes de um conteúdo SCSS
69
+ */
70
+ export function extractFontsFromSCSS(scssContent) {
71
+ const fonts = new Set();
72
+ // Regex para encontrar font-family: "FontName" ou font-family: FontName
73
+ const fontFamilyRegex = /font-family:\s*["']?([^"';,]+)["']?/gi;
74
+ let match;
75
+ while ((match = fontFamilyRegex.exec(scssContent)) !== null) {
76
+ const fontName = match[1].trim();
77
+ // Ignora variáveis SCSS ($font-family-xxx)
78
+ if (fontName.startsWith('$')) {
79
+ continue;
80
+ }
81
+ // Ignora fontes de sistema
82
+ if (!SYSTEM_FONTS.has(fontName)) {
83
+ fonts.add(fontName);
84
+ }
85
+ }
86
+ return Array.from(fonts);
87
+ }
88
+ /**
89
+ * Gera URL do Google Fonts para uma fonte
90
+ */
91
+ export function getGoogleFontUrl(fontName) {
92
+ // Procura match exato
93
+ if (GOOGLE_FONTS_MAP[fontName]) {
94
+ return GOOGLE_FONTS_MAP[fontName];
95
+ }
96
+ // Procura match case-insensitive
97
+ const lowerFontName = fontName.toLowerCase();
98
+ for (const [name, url] of Object.entries(GOOGLE_FONTS_MAP)) {
99
+ if (name.toLowerCase() === lowerFontName) {
100
+ return url;
101
+ }
102
+ }
103
+ // Gera URL dinamicamente (pode não funcionar para todas as fontes)
104
+ const encodedName = fontName.replace(/\s+/g, '+');
105
+ return `https://fonts.googleapis.com/css2?family=${encodedName}:wght@300;400;500;600;700&display=swap`;
106
+ }
107
+ /**
108
+ * Gera conteúdo do arquivo _fonts.scss
109
+ */
110
+ export function generateFontsScss(fonts) {
111
+ if (fonts.length === 0) {
112
+ return `// PromptUI - Font Imports
113
+ // Auto-generated by PromptUI CLI
114
+ // No custom fonts detected
115
+ `;
116
+ }
117
+ const lines = [
118
+ '// PromptUI - Font Imports',
119
+ '// Auto-generated by PromptUI CLI',
120
+ '',
121
+ ];
122
+ for (const font of fonts) {
123
+ const url = getGoogleFontUrl(font);
124
+ if (url) {
125
+ lines.push(`@import url('${url}');`);
126
+ }
127
+ }
128
+ lines.push('');
129
+ return lines.join('\n');
130
+ }
131
+ /**
132
+ * Verifica se uma fonte precisa de import (não é fonte de sistema)
133
+ */
134
+ export function needsFontImport(fontName) {
135
+ return !SYSTEM_FONTS.has(fontName);
136
+ }
137
+ /**
138
+ * Lista de fontes disponíveis no Google Fonts (para referência)
139
+ */
140
+ export function getAvailableFonts() {
141
+ return Object.keys(GOOGLE_FONTS_MAP);
142
+ }
@@ -1,4 +1,5 @@
1
1
  export { generateTSX, generateIndex } from './tsx-generator.js';
2
2
  export { generateSCSS, generateFlatSCSS } from './scss-generator.js';
3
3
  export { generateDefaultVariables } from './variables-generator.js';
4
+ export { generateFontsScss, extractFontsFromSCSS, getGoogleFontUrl, needsFontImport, getAvailableFonts, } from './fonts-generator.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAClB,MAAM,sBAAsB,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export { generateTSX, generateIndex } from './tsx-generator.js';
2
2
  export { generateSCSS, generateFlatSCSS } from './scss-generator.js';
3
3
  export { generateDefaultVariables } from './variables-generator.js';
4
+ export { generateFontsScss, extractFontsFromSCSS, getGoogleFontUrl, needsFontImport, getAvailableFonts, } from './fonts-generator.js';
@@ -1 +1 @@
1
- {"version":3,"file":"tsx-generator.d.ts","sourceRoot":"","sources":["../../src/generators/tsx-generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,aAAa,EAMd,MAAM,oBAAoB,CAAC;AAkI5B;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CA4BtD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAUxD"}
1
+ {"version":3,"file":"tsx-generator.d.ts","sourceRoot":"","sources":["../../src/generators/tsx-generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,aAAa,EAQd,MAAM,oBAAoB,CAAC;AA0O5B;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAmCtD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAUxD"}
@@ -2,6 +2,64 @@
2
2
  * TSX Generator
3
3
  * Gera código TypeScript/JSX a partir do AST do componente
4
4
  */
5
+ /**
6
+ * Coleta todos os componentes filhos de uma árvore JSX recursivamente
7
+ */
8
+ function collectChildComponents(node) {
9
+ const components = [];
10
+ for (const child of node.children) {
11
+ if ('type' in child && child.type === 'component') {
12
+ components.push(child);
13
+ }
14
+ else if ('tag' in child) {
15
+ // Recursivamente busca em nós JSX
16
+ components.push(...collectChildComponents(child));
17
+ }
18
+ }
19
+ return components;
20
+ }
21
+ /**
22
+ * Calcula o caminho relativo de import entre duas camadas do Atomic Design
23
+ */
24
+ function getRelativeImportPath(fromLayer, toLayer, toFileName) {
25
+ // Mapeamento de camadas para profundidade relativa
26
+ const layerDepth = {
27
+ atoms: 0,
28
+ molecules: 1,
29
+ organisms: 2,
30
+ };
31
+ const fromDepth = layerDepth[fromLayer];
32
+ const toDepth = layerDepth[toLayer];
33
+ // Se estão na mesma camada
34
+ if (fromLayer === toLayer) {
35
+ return `../${toFileName}`;
36
+ }
37
+ // Calcula o caminho relativo
38
+ // De organisms para atoms: ../../atoms/button
39
+ // De molecules para atoms: ../../atoms/button
40
+ // De organisms para molecules: ../../molecules/header
41
+ return `../../${toLayer}/${toFileName}`;
42
+ }
43
+ /**
44
+ * Gera imports de componentes filhos
45
+ */
46
+ function generateComponentImports(components, parentLayer) {
47
+ const imports = [];
48
+ const seen = new Set();
49
+ for (const comp of components) {
50
+ // Evita duplicatas
51
+ if (seen.has(comp.componentName)) {
52
+ continue;
53
+ }
54
+ seen.add(comp.componentName);
55
+ const importPath = getRelativeImportPath(parentLayer, comp.layer, comp.fileName);
56
+ imports.push({
57
+ from: importPath,
58
+ named: [comp.componentName],
59
+ });
60
+ }
61
+ return imports;
62
+ }
5
63
  /**
6
64
  * Gera string de imports
7
65
  */
@@ -55,6 +113,29 @@ function generatePropsDestructuring(props) {
55
113
  });
56
114
  return `{\n ${parts.join(',\n ')},\n}`;
57
115
  }
116
+ /**
117
+ * Gera JSX de um componente filho (self-closing)
118
+ */
119
+ function generateComponentJSX(component, indent) {
120
+ const spaces = ' '.repeat(indent);
121
+ let jsx = `${spaces}<${component.componentName}`;
122
+ // Adiciona props se existirem
123
+ if (component.props) {
124
+ for (const [key, value] of Object.entries(component.props)) {
125
+ if (typeof value === 'boolean') {
126
+ jsx += value ? ` ${key}` : '';
127
+ }
128
+ else if (typeof value === 'object' && value.type === 'expression') {
129
+ jsx += ` ${key}={${value.value}}`;
130
+ }
131
+ else {
132
+ jsx += ` ${key}="${value}"`;
133
+ }
134
+ }
135
+ }
136
+ jsx += ' />';
137
+ return jsx;
138
+ }
58
139
  /**
59
140
  * Gera JSX de um node
60
141
  */
@@ -103,6 +184,10 @@ function generateJSX(node, indent = 2) {
103
184
  else if ('type' in child && child.type === 'expression') {
104
185
  childrenJSX.push(`${childSpaces}{${child.value}}`);
105
186
  }
187
+ else if ('type' in child && child.type === 'component') {
188
+ // Renderiza componente filho como <ComponentName />
189
+ childrenJSX.push(generateComponentJSX(child, indent + 2));
190
+ }
106
191
  else {
107
192
  childrenJSX.push(generateJSX(child, indent + 2));
108
193
  }
@@ -117,8 +202,13 @@ function generateJSX(node, indent = 2) {
117
202
  */
118
203
  export function generateTSX(ast) {
119
204
  const lines = [];
205
+ // Coleta componentes filhos para gerar imports
206
+ const childComponents = collectChildComponents(ast.jsx);
207
+ const componentImports = generateComponentImports(childComponents, ast.layer);
208
+ // Combina imports existentes com imports de componentes
209
+ const allImports = [...(ast.imports ?? []), ...componentImports];
120
210
  // Imports
121
- const importsCode = generateImports(ast.imports ?? []);
211
+ const importsCode = generateImports(allImports);
122
212
  if (importsCode) {
123
213
  lines.push(importsCode);
124
214
  lines.push('');
@@ -1 +1 @@
1
- {"version":3,"file":"variables-generator.d.ts","sourceRoot":"","sources":["../../src/generators/variables-generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAuIjD"}
1
+ {"version":3,"file":"variables-generator.d.ts","sourceRoot":"","sources":["../../src/generators/variables-generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CA0IjD"}
@@ -10,6 +10,9 @@ export function generateDefaultVariables() {
10
10
  // Auto-generated by PromptUI CLI
11
11
  // Run 'promptui sync tokens' to update from Figma
12
12
 
13
+ // Import fonts (if _fonts.scss exists)
14
+ @import 'fonts';
15
+
13
16
  // =============================================================================
14
17
  // COLORS
15
18
  // =============================================================================
@@ -1 +1 @@
1
- {"version":3,"file":"file-writer.d.ts","sourceRoot":"","sources":["../../src/writers/file-writer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAKxF,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE;QACL,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAqBD;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,aAAa,GAAG,cAAc,CAM/D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,MAAM,GACf,MAAM,CAER;AA2BD;;GAEG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,aAAa,EAClB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAyDvB;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,aAAa,EAAE,EACrB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,EAAE,CAAC,CASzB"}
1
+ {"version":3,"file":"file-writer.d.ts","sourceRoot":"","sources":["../../src/writers/file-writer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAMxF,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE;QACL,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAqBD;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,aAAa,GAAG,cAAc,CAM/D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,MAAM,GACf,MAAM,CAER;AAyFD;;GAEG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,aAAa,EAClB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CA+DvB;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,aAAa,EAAE,EACrB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,EAAE,CAAC,CASzB"}
@@ -2,11 +2,12 @@
2
2
  * File Writer
3
3
  * Escreve arquivos gerados no sistema de arquivos
4
4
  */
5
- import { mkdir, writeFile, access } from 'node:fs/promises';
5
+ import { mkdir, writeFile, access, readFile } from 'node:fs/promises';
6
6
  import { join, dirname } from 'node:path';
7
7
  import { generateTSX, generateIndex } from '../generators/tsx-generator.js';
8
8
  import { generateSCSS } from '../generators/scss-generator.js';
9
9
  import { generateDefaultVariables } from '../generators/variables-generator.js';
10
+ import { extractFontsFromSCSS, generateFontsScss } from '../generators/fonts-generator.js';
10
11
  /**
11
12
  * Verifica se um arquivo existe
12
13
  */
@@ -53,7 +54,22 @@ async function ensureVariablesFile(basePath) {
53
54
  // Verifica se já existe
54
55
  const exists = await fileExists(variablesPath);
55
56
  if (exists) {
56
- return null; // existe, não precisa criar
57
+ // Verifica se tem o import de fonts
58
+ try {
59
+ const content = await readFile(variablesPath, 'utf-8');
60
+ if (!content.includes("@import 'fonts'") && !content.includes('@import "fonts"')) {
61
+ // Adiciona o import de fonts no início
62
+ const updatedContent = content.replace(/(\/\/ PromptUI - Design Tokens.*?\n)/s, "$1\n// Import fonts\n@import 'fonts';\n");
63
+ if (updatedContent !== content) {
64
+ await writeFile(variablesPath, updatedContent, 'utf-8');
65
+ return variablesPath; // Foi atualizado
66
+ }
67
+ }
68
+ }
69
+ catch {
70
+ // Ignora erros de leitura
71
+ }
72
+ return null; // Já existe e está ok
57
73
  }
58
74
  try {
59
75
  await ensureDir(stylesDir);
@@ -64,6 +80,43 @@ async function ensureVariablesFile(basePath) {
64
80
  return null;
65
81
  }
66
82
  }
83
+ /**
84
+ * Atualiza ou cria o arquivo de fontes baseado no SCSS gerado
85
+ */
86
+ async function ensureFontsFile(basePath, scssContent) {
87
+ const parentDir = dirname(basePath);
88
+ const stylesDir = join(parentDir, 'styles');
89
+ const fontsPath = join(stylesDir, '_fonts.scss');
90
+ try {
91
+ // Extrai fontes do SCSS gerado
92
+ const newFonts = extractFontsFromSCSS(scssContent);
93
+ if (newFonts.length === 0) {
94
+ return null; // Sem fontes customizadas
95
+ }
96
+ // Lê fontes existentes (se houver)
97
+ let existingFonts = [];
98
+ const exists = await fileExists(fontsPath);
99
+ if (exists) {
100
+ const existingContent = await readFile(fontsPath, 'utf-8');
101
+ existingFonts = extractFontsFromSCSS(existingContent);
102
+ }
103
+ // Combina fontes existentes com novas (sem duplicatas)
104
+ const allFonts = [...new Set([...existingFonts, ...newFonts])];
105
+ // Gera novo conteúdo
106
+ const fontsContent = generateFontsScss(allFonts);
107
+ await ensureDir(stylesDir);
108
+ await writeFile(fontsPath, fontsContent, 'utf-8');
109
+ // Retorna path apenas se adicionou novas fontes
110
+ const addedFonts = newFonts.filter((f) => !existingFonts.includes(f));
111
+ if (addedFonts.length > 0) {
112
+ return fontsPath;
113
+ }
114
+ return null;
115
+ }
116
+ catch {
117
+ return null;
118
+ }
119
+ }
67
120
  /**
68
121
  * Escreve os arquivos do componente
69
122
  */
@@ -93,6 +146,11 @@ export async function writeComponent(ast, options) {
93
146
  if (variablesCreated) {
94
147
  console.log(` 📁 Created: ${variablesCreated}`);
95
148
  }
149
+ // Garante que o arquivo de fontes existe (com as fontes do componente)
150
+ const fontsCreated = await ensureFontsFile(options.basePath, code.scss);
151
+ if (fontsCreated) {
152
+ console.log(` 🔤 Created/Updated: ${fontsCreated}`);
153
+ }
96
154
  // Cria diretório
97
155
  await ensureDir(componentDir);
98
156
  // Escreve arquivos
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptui-lib/codegen",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "private": false,
5
5
  "description": "Code generator for PromptUI - generates React TSX and SCSS",
6
6
  "license": "UNLICENSED",
@@ -30,7 +30,7 @@
30
30
  "dist"
31
31
  ],
32
32
  "dependencies": {
33
- "@promptui-lib/core": "0.1.9"
33
+ "@promptui-lib/core": "0.1.11"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^20.0.0",