@nuvler/cli 0.3.1 → 0.4.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.
Files changed (53) hide show
  1. package/README.md +258 -38
  2. package/dist/api/client.js.map +1 -1
  3. package/dist/api/theme-registry.js.map +1 -1
  4. package/dist/commands/theme/create.js +74 -18
  5. package/dist/commands/theme/create.js.map +1 -1
  6. package/dist/commands/theme/migrate.js +117 -0
  7. package/dist/commands/theme/migrate.js.map +1 -0
  8. package/dist/config/developer-session.js.map +1 -1
  9. package/dist/index.js +28 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/migrate/analyzer.js +479 -0
  12. package/dist/migrate/analyzer.js.map +1 -0
  13. package/dist/migrate/asset-copier.js +40 -0
  14. package/dist/migrate/asset-copier.js.map +1 -0
  15. package/dist/migrate/classifier.js +107 -0
  16. package/dist/migrate/classifier.js.map +1 -0
  17. package/dist/migrate/generator.js +500 -0
  18. package/dist/migrate/generator.js.map +1 -0
  19. package/dist/migrate/transformer.js +150 -0
  20. package/dist/migrate/transformer.js.map +1 -0
  21. package/dist/migrate/types.js +2 -0
  22. package/dist/migrate/types.js.map +1 -0
  23. package/dist/migrate/validator.js +40 -0
  24. package/dist/migrate/validator.js.map +1 -0
  25. package/dist/nuvler.js +1643 -33
  26. package/dist/nuvler.js.map +1 -1
  27. package/dist/preview/launcher.js.map +1 -1
  28. package/dist/templates/nuvler-atelier/README.md +17 -1
  29. package/dist/templates/nuvler-atelier/nuvler.theme.json +10 -3
  30. package/dist/templates/nuvler-atelier/package.json +3 -3
  31. package/dist/templates/nuvler-atelier/src/definition.tsx +11 -1
  32. package/dist/templates/nuvler-atelier/src/theme.css +26 -26
  33. package/dist/templates/nuvler-atelier/src/theme.tsx +12 -1
  34. package/dist/templates/nuvler-default/README.md +18 -4
  35. package/dist/templates/nuvler-default/nuvler.theme.json +10 -3
  36. package/dist/templates/nuvler-default/package.json +2 -2
  37. package/dist/templates/nuvler-default/src/definition.ts +11 -0
  38. package/dist/templates/nuvler-default/src/theme-component.tsx +11 -0
  39. package/dist/templates/nuvler-default/src/theme.css +27 -16
  40. package/dist/templates/starter/README.md +18 -1
  41. package/dist/templates/starter/nuvler.theme.json +9 -2
  42. package/dist/templates/starter/package.json +2 -2
  43. package/dist/templates/starter/src/definition.tsx +8 -1
  44. package/dist/templates/starter/src/theme.css +10 -10
  45. package/dist/templates/starter/src/theme.tsx +11 -0
  46. package/package.json +4 -3
  47. package/preview-host/index.html +1 -0
  48. package/preview-host/package.json +1 -1
  49. package/preview-host/public/nuvler-icon.ico +0 -0
  50. package/preview-host/public/nuvler-logo-white.png +0 -0
  51. package/preview-host/src/app/globals.css +28 -0
  52. package/preview-host/src/main.tsx +11 -1
  53. package/preview-host/vendor/theme-runtime/default-theme.tsx +24 -2
@@ -0,0 +1,107 @@
1
+ const RULES = [
2
+ { role: "HEADER", keywords: ["header", "navbar", "navigation", "menu", "cabecalho"], tags: ["header", "nav"], minimum: 5 },
3
+ { role: "FOOTER", keywords: ["footer", "rodape"], tags: ["footer"], minimum: 5 },
4
+ { role: "HERO", keywords: ["hero", "banner", "jumbotron", "masthead", "destaque"], tags: ["section"], minimum: 5 },
5
+ { role: "PRODUCT_CARD", keywords: ["productcard", "product-card", "produto-card", "cardproduto", "productitem"], tags: ["article"], minimum: 6 },
6
+ { role: "PRODUCT_GRID", keywords: ["productgrid", "product-grid", "products-grid", "produtos-grid", "productlist", "catalog"], minimum: 6 },
7
+ { role: "PRODUCT_DETAIL", keywords: ["productdetail", "product-detail", "produto-detalhe", "productpage", "produto/", "product/"], minimum: 6 },
8
+ { role: "HOME", keywords: ["homepage", "home-page", "landing", "inicio", "app.tsx", "page.tsx"], tags: ["main"], minimum: 6 },
9
+ { role: "SECTION", keywords: ["section", "features", "benefits", "services", "about", "cta"], tags: ["section"], minimum: 6 },
10
+ { role: "PAGE", keywords: ["page", "screen", "view"], tags: ["main"], minimum: 6 },
11
+ ];
12
+ function normalized(value) {
13
+ return value.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
14
+ }
15
+ function componentCorpus(component) {
16
+ return normalized([
17
+ component.name,
18
+ component.file,
19
+ ...component.rootClasses,
20
+ ...component.jsx.flatMap(({ classes, text }) => [...classes, ...text]),
21
+ ].join(" "));
22
+ }
23
+ function roleScore(component, rule) {
24
+ const corpus = componentCorpus(component);
25
+ const name = normalized(component.name);
26
+ const file = normalized(component.file);
27
+ const reasons = [];
28
+ let score = 0;
29
+ for (const keyword of rule.keywords) {
30
+ const term = normalized(keyword);
31
+ if (name.includes(term)) {
32
+ score += 7;
33
+ reasons.push(`nome contém "${keyword}"`);
34
+ }
35
+ else if (file.includes(term)) {
36
+ score += 5;
37
+ reasons.push(`caminho contém "${keyword}"`);
38
+ }
39
+ else if (corpus.includes(term)) {
40
+ score += 3;
41
+ reasons.push(`JSX/classes contêm "${keyword}"`);
42
+ }
43
+ }
44
+ for (const tag of rule.tags ?? []) {
45
+ if (component.jsx.some((node) => normalized(node.tag) === tag)) {
46
+ score += 6;
47
+ reasons.push(`usa <${tag}>`);
48
+ }
49
+ }
50
+ if (component.page && rule.role === "HOME" && /(^|\/)(?:app\/)?page\.tsx$/.test(component.file)) {
51
+ score += 7;
52
+ reasons.push("página inicial do framework");
53
+ }
54
+ if (component.page && rule.role === "PAGE") {
55
+ score += 4;
56
+ reasons.push("arquivo de página");
57
+ }
58
+ if (rule.role === "PRODUCT_CARD") {
59
+ const hasProduct = corpus.includes("product") || corpus.includes("produto");
60
+ const hasCard = corpus.includes("card") || component.jsx.some(({ tag }) => tag === "article");
61
+ if (hasProduct && hasCard) {
62
+ score += 7;
63
+ reasons.push("combina produto e card/article");
64
+ }
65
+ }
66
+ if (rule.role === "PRODUCT_GRID") {
67
+ if (component.jsx.some(({ classes }) => classes.some((item) => /grid|list/.test(normalized(item))))) {
68
+ score += 5;
69
+ reasons.push("possui estrutura de grid/lista");
70
+ }
71
+ }
72
+ if (rule.role === "PRODUCT_DETAIL") {
73
+ if (corpus.includes("price") || corpus.includes("preco") || corpus.includes("sku")) {
74
+ score += 4;
75
+ reasons.push("exibe campos de detalhe de produto");
76
+ }
77
+ }
78
+ if (rule.role === "HERO" && component.text.some((text) => text.length > 20)) {
79
+ score += 2;
80
+ reasons.push("possui chamada textual de destaque");
81
+ }
82
+ if (component.defaultExport)
83
+ score += 1;
84
+ return { role: rule.role, score, reasons };
85
+ }
86
+ export function classifyProject(input) {
87
+ const components = input.components.map((component) => ({
88
+ ...component,
89
+ roles: RULES
90
+ .map((rule) => roleScore(component, rule))
91
+ .filter((candidate) => candidate.score >= (RULES.find(({ role }) => role === candidate.role)?.minimum ?? 6))
92
+ .sort((left, right) => right.score - left.score),
93
+ }));
94
+ const ignoredFiles = [...input.ignoredFiles];
95
+ for (const component of components) {
96
+ if (!component.businessSignals.length || component.roles.length)
97
+ continue;
98
+ if (ignoredFiles.some(({ file }) => file === component.file))
99
+ continue;
100
+ ignoredFiles.push({
101
+ file: component.file,
102
+ reason: component.businessSignals.join(", "),
103
+ });
104
+ }
105
+ return { ...input, components, ignoredFiles };
106
+ }
107
+ //# sourceMappingURL=classifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classifier.js","sourceRoot":"","sources":["../../src/migrate/classifier.ts"],"names":[],"mappings":"AAaA,MAAM,KAAK,GAAe;IACxB,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;IAC1H,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;IAChF,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,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readFile, rm, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { themeCreate } from "../commands/theme/create.js";
4
+ import { copyMigrationAssets } from "./asset-copier.js";
5
+ function portable(file) {
6
+ return file.split(path.sep).join("/");
7
+ }
8
+ function classes(base, source = "") {
9
+ return JSON.stringify([base, source].filter(Boolean).join(" "));
10
+ }
11
+ function profile(plan, role) {
12
+ return plan.selected[role]?.classes ?? {
13
+ root: "", brand: "", navigation: "", title: "", text: "", action: "",
14
+ media: "", grid: "", card: "", content: "",
15
+ };
16
+ }
17
+ function sourceText(plan, role, fallback) {
18
+ const text = plan.selected[role]?.component.text
19
+ .find((candidate) => candidate.length >= 3 && candidate.length <= 140);
20
+ return text || fallback;
21
+ }
22
+ function headerSource(plan) {
23
+ const style = profile(plan, "HEADER");
24
+ return `import type { HeaderProps } from "@nuvler/theme-sdk";
25
+
26
+ export function Header({ site, categories, pages }: HeaderProps) {
27
+ const name = site.settings?.siteName || site.tenant.name;
28
+ return <header className=${classes("nuvler-migrated-header", style.root)}>
29
+ <div className=${classes("nuvler-migrated-header-inner", style.content)}>
30
+ <a className=${classes("nuvler-migrated-brand", style.brand)} href="/">
31
+ {site.settings?.logo?.url ? <img src={site.settings.logo.url} alt={site.settings.logo.alt || name} /> : <span>{name}</span>}
32
+ </a>
33
+ <nav className=${classes("nuvler-migrated-nav", style.navigation)} aria-label="Navegação principal">
34
+ <a href="/">Início</a>
35
+ {site.modules.includes("PRODUCTS") && <a href="/produtos">Produtos</a>}
36
+ {categories.slice(0, 6).map((category) => <a href={\`/categoria/\${category.slug}\`} key={category.slug}>{category.name}</a>)}
37
+ {pages.slice(0, 4).map((page) => <a href={\`/\${page.slug}\`} key={page.slug}>{page.title}</a>)}
38
+ </nav>
39
+ {site.modules.includes("PRODUCTS") && <form className="nuvler-migrated-search" action="/produtos">
40
+ <input name="busca" type="search" placeholder="Buscar produtos" />
41
+ <button className=${classes("nuvler-migrated-action", style.action)} type="submit">Buscar</button>
42
+ </form>}
43
+ </div>
44
+ </header>;
45
+ }
46
+ `;
47
+ }
48
+ function footerSource(plan) {
49
+ const style = profile(plan, "FOOTER");
50
+ return `import type { FooterProps } from "@nuvler/theme-sdk";
51
+
52
+ export function Footer({ site, pages, template }: FooterProps) {
53
+ const name = site.settings?.siteName || site.tenant.name;
54
+ return <footer className=${classes("nuvler-migrated-footer", style.root)}>
55
+ <div className=${classes("nuvler-migrated-footer-inner", style.content)}>
56
+ <div><strong className=${classes("nuvler-migrated-footer-brand", style.brand)}>{name}</strong><p className=${classes("nuvler-migrated-copy", style.text)}>{site.settings?.description || template.footerTagline}</p></div>
57
+ <nav className=${classes("nuvler-migrated-footer-nav", style.navigation)} aria-label={template.footerNavigationLabel}>
58
+ <a href="/">Início</a>
59
+ {site.modules.includes("PRODUCTS") && <a href="/produtos">Produtos</a>}
60
+ {pages.map((page) => <a href={\`/\${page.slug}\`} key={page.slug}>{page.title}</a>)}
61
+ </nav>
62
+ <div className="nuvler-migrated-contact">
63
+ {site.settings?.contact.phone && <a href={\`tel:\${site.settings.contact.phone}\`}>{site.settings.contact.phone}</a>}
64
+ {site.settings?.contact.email && <a href={\`mailto:\${site.settings.contact.email}\`}>{site.settings.contact.email}</a>}
65
+ </div>
66
+ </div>
67
+ <small>{template.footerNote}</small>
68
+ </footer>;
69
+ }
70
+ `;
71
+ }
72
+ function productCardSource(plan) {
73
+ const style = profile(plan, "PRODUCT_CARD");
74
+ return `import type { ThemeProduct } from "@nuvler/theme-sdk";
75
+
76
+ function money(value: number | null): string {
77
+ return value === null ? "Consulte" : new Intl.NumberFormat("pt-BR", { style: "currency", currency: "BRL" }).format(value);
78
+ }
79
+
80
+ export function ProductCard({ product, showCategory = true, showDescription = true }: { product: ThemeProduct; showCategory?: boolean; showDescription?: boolean }) {
81
+ const price = product.promotionalPrice ?? product.price;
82
+ return <article className=${classes("nuvler-migrated-product-card", style.root || style.card)}>
83
+ <a className=${classes("nuvler-migrated-product-media", style.media)} href={\`/produto/\${product.slug}\`}>
84
+ {product.image?.url ? <img src={product.image.url} alt={product.image.alt || product.title} /> : <span aria-hidden="true" />}
85
+ </a>
86
+ <div className=${classes("nuvler-migrated-product-content", style.content)}>
87
+ {showCategory && <small>{product.categories[0]?.name || product.brand || "Produto"}</small>}
88
+ <h3 className=${classes("nuvler-migrated-product-title", style.title)}><a href={\`/produto/\${product.slug}\`}>{product.title}</a></h3>
89
+ {showDescription && product.description && <p className=${classes("nuvler-migrated-copy", style.text)}>{product.description}</p>}
90
+ <strong>{money(price)}</strong>
91
+ <a className=${classes("nuvler-migrated-action", style.action)} href={\`/produto/\${product.slug}\`}>Ver produto</a>
92
+ </div>
93
+ </article>;
94
+ }
95
+ `;
96
+ }
97
+ function productGridSource(plan) {
98
+ const style = profile(plan, "PRODUCT_GRID");
99
+ return `import type { ProductGridProps } from "@nuvler/theme-sdk";
100
+ import { ProductCard } from "./ProductCard.js";
101
+
102
+ export function ProductGrid({ products, columns = 3, showCategory, showDescription }: ProductGridProps) {
103
+ return <div className=${classes("nuvler-migrated-product-grid", style.root || style.grid)} data-columns={columns}>
104
+ {products.map((product) => <ProductCard product={product} showCategory={showCategory} showDescription={showDescription} key={product.slug} />)}
105
+ </div>;
106
+ }
107
+ `;
108
+ }
109
+ function productDetailSource(plan) {
110
+ const style = profile(plan, "PRODUCT_DETAIL");
111
+ return `import type { ProductDetailProps } from "@nuvler/theme-sdk";
112
+
113
+ function money(value: number | null): string {
114
+ return value === null ? "Consulte" : new Intl.NumberFormat("pt-BR", { style: "currency", currency: "BRL" }).format(value);
115
+ }
116
+
117
+ export function ProductDetail({ product, descriptionContent, onAddToCart }: ProductDetailProps) {
118
+ const image = product.images[0] ?? product.image;
119
+ return <article className=${classes("nuvler-migrated-product-detail", style.root)}>
120
+ <div className=${classes("nuvler-migrated-detail-media", style.media)}>{image?.url ? <img src={image.url} alt={image.alt || product.title} /> : <span aria-hidden="true" />}</div>
121
+ <div className=${classes("nuvler-migrated-detail-content", style.content)}>
122
+ <small>{product.categories[0]?.name || product.brand || "Produto"}</small>
123
+ <h1 className=${classes("nuvler-migrated-detail-title", style.title)}>{product.title}</h1>
124
+ <strong className="nuvler-migrated-price">{money(product.promotionalPrice ?? product.price)}</strong>
125
+ <div className=${classes("nuvler-migrated-copy", style.text)}>{descriptionContent}</div>
126
+ <button className=${classes("nuvler-migrated-action", style.action)} type="button" onClick={() => onAddToCart?.({ productSlug: product.slug, title: product.title, sku: product.sku, image: product.image, unitPrice: product.promotionalPrice ?? product.price })}>Adicionar ao orçamento</button>
127
+ </div>
128
+ </article>;
129
+ }
130
+ `;
131
+ }
132
+ function homeSource(plan, assets) {
133
+ const home = profile(plan, "HOME");
134
+ const hero = profile(plan, "HERO");
135
+ const section = profile(plan, "SECTION");
136
+ const heroText = sourceText(plan, "HERO", "Uma experiência criada para sua marca");
137
+ const visual = assets.find(({ kind }) => ["image", "svg"].includes(kind));
138
+ const visualDeclaration = visual
139
+ ? `const migratedHeroAsset = new URL(${JSON.stringify(visual.importPath)}, import.meta.url).href;`
140
+ : "const migratedHeroAsset: string | null = null;";
141
+ return `import type { HomeProps, ThemeHomeSection } from "@nuvler/theme-sdk";
142
+ import { ProductGrid } from "../components/ProductGrid.js";
143
+
144
+ ${visualDeclaration}
145
+
146
+ function value(section: ThemeHomeSection | undefined, key: string): string {
147
+ const candidate = section?.data[key];
148
+ return typeof candidate === "string" ? candidate : "";
149
+ }
150
+
151
+ export function Home({ sections, products, site, template }: HomeProps) {
152
+ const enabled = sections.filter((item) => item.enabled).sort((left, right) => left.order - right.order);
153
+ const heroSection = enabled.find((item) => item.type === "hero" || item.type === "banner-carousel");
154
+ const productSection = enabled.find((item) => item.type === "products-grid" || item.type === "products-carousel");
155
+ const name = site.settings?.siteName || site.tenant.name;
156
+ const action = template.primaryAction(site.modules);
157
+ return <main className=${classes("nuvler-migrated-home", home.root)}>
158
+ <section className=${classes("nuvler-migrated-hero", hero.root || home.content)}>
159
+ <div className=${classes("nuvler-migrated-hero-content", hero.content)}>
160
+ <span>{${JSON.stringify(heroText)}}</span>
161
+ <h1 className=${classes("nuvler-migrated-hero-title", hero.title)}>{value(heroSection, "title") || name}</h1>
162
+ <p className=${classes("nuvler-migrated-copy", hero.text)}>{value(heroSection, "description") || site.settings?.description || "Conheça nossos produtos e soluções."}</p>
163
+ <a className=${classes("nuvler-migrated-action", hero.action)} href={value(heroSection, "buttonUrl") || action.href}>{value(heroSection, "buttonLabel") || action.label}</a>
164
+ </div>
165
+ {migratedHeroAsset && <div className=${classes("nuvler-migrated-hero-media", hero.media)}><img src={migratedHeroAsset} alt="" /></div>}
166
+ </section>
167
+ {site.modules.includes("PRODUCTS") && <section className=${classes("nuvler-migrated-section", section.root)}>
168
+ <header><span>Destaques</span><h2 className=${classes("nuvler-migrated-section-title", section.title)}>{value(productSection, "title") || "Produtos em destaque"}</h2></header>
169
+ <ProductGrid products={products} columns={site.settings?.catalog?.desktopColumns || 3} showCategory={site.settings?.catalog?.showCategory} showDescription={site.settings?.catalog?.showDescription} />
170
+ </section>}
171
+ {enabled.filter((item) => ["image-text", "rich-text", "cta"].includes(item.type)).map((item) => <section className=${classes("nuvler-migrated-section nuvler-migrated-generic", section.content)} key={item.id || \`\${item.type}-\${item.order}\`}><h2>{value(item, "title")}</h2><p>{value(item, "description") || value(item, "content")}</p>{value(item, "buttonUrl") && <a className="nuvler-migrated-action" href={value(item, "buttonUrl")}>{value(item, "buttonLabel") || "Saiba mais"}</a>}</section>)}
172
+ </main>;
173
+ }
174
+ `;
175
+ }
176
+ function definitionSource(plan) {
177
+ const tokens = plan.tokens;
178
+ return `import manifestData from "../nuvler.theme.json" with { type: "json" };
179
+ import { defineTheme, type ThemeHomeSection, type ThemeManifest } from "@nuvler/theme-sdk";
180
+ import { Footer } from "./components/Footer.js";
181
+ import { Header } from "./components/Header.js";
182
+ import { ProductDetail } from "./components/ProductDetail.js";
183
+ import { ProductGrid } from "./components/ProductGrid.js";
184
+ import { Home } from "./sections/Home.js";
185
+
186
+ function section(id: string, type: ThemeHomeSection["type"], order: number): ThemeHomeSection {
187
+ return { id, type, enabled: true, order, data: {} };
188
+ }
189
+
190
+ export const manifest = manifestData as ThemeManifest;
191
+ export const themeDefinition = defineTheme({
192
+ manifest,
193
+ tokens: {
194
+ colors: ${JSON.stringify({
195
+ primary: tokens.primary, primaryText: tokens.primaryText,
196
+ secondary: tokens.secondary, secondaryText: tokens.secondaryText, accent: tokens.accent,
197
+ background: tokens.background, surface: tokens.surface, surfaceAlt: tokens.surfaceAlt,
198
+ text: tokens.text, textMuted: tokens.textMuted, border: tokens.border,
199
+ headerBackground: tokens.headerBackground, headerText: tokens.headerText,
200
+ footerBackground: tokens.footerBackground, footerText: tokens.footerText,
201
+ })},
202
+ layout: ${JSON.stringify({ containerWidth: tokens.containerWidth, borderRadius: tokens.borderRadius })},
203
+ },
204
+ template: {
205
+ announcement: ${JSON.stringify(plan.themeName)},
206
+ footerTagline: "Experiência visual migrada para a plataforma Nuvler.",
207
+ footerNavigationLabel: "Navegação",
208
+ footerNote: ${JSON.stringify(plan.themeName)},
209
+ socialLabel: "Redes sociais",
210
+ benefits: [],
211
+ fallbackSections: () => [section("migrated-hero", "hero", 0), section("migrated-products", "products-grid", 1)],
212
+ primaryAction: (modules) => modules.includes("PRODUCTS") ? { label: "Ver produtos", href: "/produtos" } : { label: "Saiba mais", href: "/" },
213
+ },
214
+ components: { Header, Footer, Home, ProductGrid, ProductDetail },
215
+ });
216
+ `;
217
+ }
218
+ function catalogPageSource() {
219
+ return `import type { ThemeRoute, ThemeSite } from "@nuvler/theme-sdk";
220
+ import { ProductGrid } from "../components/ProductGrid.js";
221
+
222
+ type CatalogRoute = Extract<ThemeRoute, { type: "catalog" }>;
223
+
224
+ export function CatalogPage({ route, site }: { route: CatalogRoute; site: ThemeSite }) {
225
+ return <main className="nuvler-migrated-section nuvler-migrated-catalog">
226
+ <header><span>Catálogo</span><h1>{route.search ? \`Busca: \${route.search}\` : "Produtos"}</h1><p>{route.pagination.total} produto(s)</p></header>
227
+ <ProductGrid products={route.products} columns={site.settings?.catalog?.desktopColumns || 3} showCategory={site.settings?.catalog?.showCategory} showDescription={site.settings?.catalog?.showDescription} />
228
+ </main>;
229
+ }
230
+ `;
231
+ }
232
+ function productPageSource() {
233
+ return `import type { ThemeRoute, ThemeRuntimeSdk, ThemeSite } from "@nuvler/theme-sdk";
234
+ import { ProductDetail } from "../components/ProductDetail.js";
235
+
236
+ type ProductRoute = Extract<ThemeRoute, { type: "product" }>;
237
+
238
+ export function ProductPage({ route, site, cart }: { route: ProductRoute; site: ThemeSite; cart?: ThemeRuntimeSdk["cart"] }) {
239
+ return <main className="nuvler-migrated-section"><ProductDetail product={route.product} contact={site.settings?.contact} productUrl={null} descriptionContent={<p>{route.product.description}</p>} onAddToCart={cart?.add} /></main>;
240
+ }
241
+ `;
242
+ }
243
+ function editorialPageSource() {
244
+ return `import type { ThemeRoute } from "@nuvler/theme-sdk";
245
+
246
+ type EditorialRoute = Extract<ThemeRoute, { type: "editorial-list" | "editorial-detail" }>;
247
+
248
+ export function EditorialPage({ route }: { route: EditorialRoute }) {
249
+ if (route.type === "editorial-detail") return <main className="nuvler-migrated-section"><article><span>Conteúdo</span><h1>{route.item.title}</h1><p>{route.item.description}</p></article></main>;
250
+ return <main className="nuvler-migrated-section"><h1>{route.title}</h1><div className="nuvler-migrated-editorial-grid">{route.items.map((item) => <article key={item.slug}><h2><a href={\`\${route.basePath}/\${item.slug}\`}>{item.title}</a></h2><p>{item.description}</p></article>)}</div></main>;
251
+ }
252
+ `;
253
+ }
254
+ function statePageSource() {
255
+ return `export function StatePage({ title, pathname }: { title: string; pathname?: string }) {
256
+ return <main className="nuvler-migrated-section nuvler-migrated-state"><span>{pathname || "Nuvler"}</span><h1>{title}</h1></main>;
257
+ }
258
+ `;
259
+ }
260
+ function themeSource() {
261
+ return `import type { CSSProperties } from "react";
262
+ import type { NuvlerThemeProps, ThemeSite } from "@nuvler/theme-sdk";
263
+ import { themeDefinition } from "./definition.js";
264
+ import { CatalogPage } from "./pages/CatalogPage.js";
265
+ import { EditorialPage } from "./pages/EditorialPage.js";
266
+ import { ProductPage } from "./pages/ProductPage.js";
267
+ import { StatePage } from "./pages/StatePage.js";
268
+ import "./styles/theme.css";
269
+
270
+ export { manifest, themeDefinition } from "./definition.js";
271
+
272
+ export default function Theme({ context, route = { type: "home" }, sdk }: NuvlerThemeProps) {
273
+ const { Header, Footer, Home } = themeDefinition.components;
274
+ const site: ThemeSite = { tenant: context.store, ...context.site };
275
+ const configured = site.settings?.theme;
276
+ const tokens = {
277
+ colors: { ...themeDefinition.tokens.colors, ...configured?.colors },
278
+ layout: { ...themeDefinition.tokens.layout, ...configured?.layout },
279
+ };
280
+ const style = {
281
+ "--theme-primary": tokens.colors.primary,
282
+ "--theme-primary-text": tokens.colors.primaryText,
283
+ "--theme-secondary": tokens.colors.secondary,
284
+ "--theme-secondary-text": tokens.colors.secondaryText,
285
+ "--theme-accent": tokens.colors.accent,
286
+ "--theme-background": tokens.colors.background,
287
+ "--theme-surface": tokens.colors.surface,
288
+ "--theme-surface-alt": tokens.colors.surfaceAlt,
289
+ "--theme-text": tokens.colors.text,
290
+ "--theme-text-muted": tokens.colors.textMuted,
291
+ "--theme-border": tokens.colors.border,
292
+ "--theme-header-background": tokens.colors.headerBackground,
293
+ "--theme-header-text": tokens.colors.headerText,
294
+ "--theme-footer-background": tokens.colors.footerBackground,
295
+ "--theme-footer-text": tokens.colors.footerText,
296
+ "--theme-radius": \`\${tokens.layout.borderRadius}px\`,
297
+ "--theme-container": \`\${tokens.layout.containerWidth}px\`,
298
+ } as CSSProperties;
299
+ let content;
300
+ if (route.type === "home") content = <Home sections={context.home.content.sections} products={context.catalog.products} posts={context.editorial.posts} services={context.editorial.services} cases={context.editorial.cases} site={site} template={themeDefinition.template} />;
301
+ else if (route.type === "catalog") content = <CatalogPage route={route} site={site} />;
302
+ else if (route.type === "product") content = <ProductPage route={route} site={site} cart={sdk?.cart} />;
303
+ else if (route.type === "editorial-list" || route.type === "editorial-detail") content = <EditorialPage route={route} />;
304
+ else content = <StatePage title={route.type === "loading" ? "Carregando…" : route.type === "page" ? route.title : "Conteúdo não encontrado"} pathname={"pathname" in route ? route.pathname : undefined} />;
305
+ return <div className="nuvler-migrated-theme" style={style}><Header site={site} categories={context.navigation.categories} pages={context.navigation.pages} template={themeDefinition.template} /><div className="nuvler-migrated-page">{content}</div><Footer site={site} pages={context.navigation.pages} template={themeDefinition.template} /></div>;
306
+ }
307
+ `;
308
+ }
309
+ function baseCss(plan) {
310
+ return `/* Fallback estrutural do adaptador Nuvler. Os estilos extraídos vêm depois deste bloco. */
311
+ * { box-sizing: border-box; }
312
+ body { margin: 0; }
313
+ .nuvler-migrated-theme { min-height: 100vh; background: var(--theme-background); color: var(--theme-text); font-family: Inter, system-ui, sans-serif; }
314
+ .nuvler-migrated-header-inner, .nuvler-migrated-footer-inner, .nuvler-migrated-section, .nuvler-migrated-hero { width: min(calc(100% - 32px), var(--theme-container)); margin-inline: auto; }
315
+ .nuvler-migrated-header { background: var(--theme-header-background); color: var(--theme-header-text); }
316
+ .nuvler-migrated-header-inner { min-height: 72px; display: flex; align-items: center; gap: 24px; justify-content: space-between; }
317
+ .nuvler-migrated-brand img { display: block; width: auto; max-width: 200px; max-height: 56px; }
318
+ .nuvler-migrated-nav { display: flex; flex-wrap: wrap; gap: 18px; }
319
+ .nuvler-migrated-nav a, .nuvler-migrated-brand, .nuvler-migrated-footer a { color: inherit; text-decoration: none; }
320
+ .nuvler-migrated-search { display: flex; gap: 8px; }
321
+ .nuvler-migrated-search input { min-width: 220px; border: 1px solid var(--theme-border); border-radius: var(--theme-radius); background: var(--theme-surface); color: var(--theme-header-text); padding: 10px 13px; }
322
+ .nuvler-migrated-action { display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: var(--theme-radius); background: var(--theme-primary); color: var(--theme-primary-text); padding: 12px 18px; text-decoration: none; cursor: pointer; }
323
+ .nuvler-migrated-hero { display: grid; min-height: 520px; grid-template-columns: minmax(0, 1fr) minmax(320px, .9fr); align-items: center; gap: 40px; padding-block: 64px; }
324
+ .nuvler-migrated-hero-title { margin: 12px 0; font-size: clamp(42px, 7vw, 82px); line-height: .98; }
325
+ .nuvler-migrated-hero-media, .nuvler-migrated-product-media, .nuvler-migrated-detail-media { overflow: hidden; border-radius: var(--theme-radius); }
326
+ .nuvler-migrated-hero-media img, .nuvler-migrated-product-media img, .nuvler-migrated-detail-media img { display: block; width: 100%; height: 100%; object-fit: cover; }
327
+ .nuvler-migrated-section { padding-block: 56px; }
328
+ .nuvler-migrated-product-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
329
+ .nuvler-migrated-product-grid[data-columns="4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
330
+ .nuvler-migrated-product-card { overflow: hidden; border: 1px solid var(--theme-border); border-radius: var(--theme-radius); background: var(--theme-surface); }
331
+ .nuvler-migrated-product-media { display: block; aspect-ratio: 1; background: var(--theme-surface-alt); }
332
+ .nuvler-migrated-product-content { display: grid; gap: 12px; padding: 20px; }
333
+ .nuvler-migrated-product-content p { overflow: hidden; display: -webkit-box; color: var(--theme-text-muted); -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
334
+ .nuvler-migrated-product-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, .8fr); gap: 48px; }
335
+ .nuvler-migrated-price { display: block; margin-block: 18px; color: var(--theme-accent); font-size: 28px; }
336
+ .nuvler-migrated-footer { margin-top: 64px; background: var(--theme-footer-background); color: var(--theme-footer-text); padding: 56px max(16px, calc((100% - var(--theme-container)) / 2)); }
337
+ .nuvler-migrated-footer-inner { width: 100%; display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 40px; }
338
+ .nuvler-migrated-footer-nav, .nuvler-migrated-contact { display: grid; gap: 8px; }
339
+ @media (max-width: 850px) { .nuvler-migrated-header-inner, .nuvler-migrated-hero { grid-template-columns: 1fr; flex-direction: column; align-items: stretch; } .nuvler-migrated-nav { overflow-x: auto; flex-wrap: nowrap; } .nuvler-migrated-search input { width: 100%; min-width: 0; } .nuvler-migrated-product-grid, .nuvler-migrated-product-grid[data-columns="4"], .nuvler-migrated-product-detail, .nuvler-migrated-footer-inner { grid-template-columns: 1fr; } }
340
+
341
+ :root {
342
+ --theme-primary: ${plan.tokens.primary};
343
+ --theme-primary-text: ${plan.tokens.primaryText};
344
+ --theme-secondary: ${plan.tokens.secondary};
345
+ --theme-secondary-text: ${plan.tokens.secondaryText};
346
+ --theme-accent: ${plan.tokens.accent};
347
+ --theme-background: ${plan.tokens.background};
348
+ --theme-surface: ${plan.tokens.surface};
349
+ --theme-surface-alt: ${plan.tokens.surfaceAlt};
350
+ --theme-text: ${plan.tokens.text};
351
+ --theme-text-muted: ${plan.tokens.textMuted};
352
+ --theme-border: ${plan.tokens.border};
353
+ --theme-header-background: ${plan.tokens.headerBackground};
354
+ --theme-header-text: ${plan.tokens.headerText};
355
+ --theme-footer-background: ${plan.tokens.footerBackground};
356
+ --theme-footer-text: ${plan.tokens.footerText};
357
+ --theme-radius: ${plan.tokens.borderRadius}px;
358
+ --theme-container: ${plan.tokens.containerWidth}px;
359
+ }
360
+ `;
361
+ }
362
+ function copiedAssetFor(style, reference, plan, copied) {
363
+ const absolute = reference.startsWith("/")
364
+ ? path.join(plan.analysis.sourceDirectory, "public", reference.replace(/^\/+/, ""))
365
+ : path.resolve(path.dirname(style.absolutePath), reference);
366
+ return copied.find((asset) => path.resolve(asset.sourceFile) === path.resolve(absolute));
367
+ }
368
+ function preservedCss(plan, copied) {
369
+ return plan.styles.map((style) => {
370
+ let content = style.content;
371
+ content = content.replace(/@import\s+(["'])(?!https?:)(?!tailwindcss)([^"']+)\1\s*;?/gi, "");
372
+ content = content.replace(/@tailwind\s+(?:base|components|utilities)\s*;?/gi, "");
373
+ content = content.replace(/@import\s+["']tailwindcss["']\s*;?/gi, "");
374
+ content = content.replace(/:global\(([^)]+)\)/g, "$1");
375
+ content = content.replace(/url\(\s*(["']?)([^)'"\s]+)\1\s*\)/gi, (full, _quote, reference) => {
376
+ if (/^(?:data:|https?:|#)/i.test(reference))
377
+ return full;
378
+ const asset = copiedAssetFor(style, reference, plan, copied);
379
+ if (!asset)
380
+ return full;
381
+ const output = portable(asset.outputFile);
382
+ const marker = "/src/assets/";
383
+ const markerIndex = output.lastIndexOf(marker);
384
+ if (markerIndex < 0)
385
+ return full;
386
+ return `url(${JSON.stringify(`../assets/${output.slice(markerIndex + marker.length)}`)})`;
387
+ });
388
+ return `/* Origem: ${style.file}${style.module ? " (CSS Module convertido para CSS comum)" : ""} */\n${content}`;
389
+ }).join("\n\n");
390
+ }
391
+ async function configureTailwind(plan, directory) {
392
+ if (!plan.analysis.tailwind.detected)
393
+ return "";
394
+ const packageFile = path.join(directory, "package.json");
395
+ const metadata = JSON.parse(await readFile(packageFile, "utf8"));
396
+ metadata.devDependencies ??= {};
397
+ const major = plan.analysis.tailwind.major ?? 3;
398
+ metadata.devDependencies.tailwindcss = plan.analysis.tailwind.version || (major >= 4 ? "^4.0.0" : "^3.4.0");
399
+ metadata.devDependencies.postcss = plan.analysis.dependencies.postcss || "^8.4.0";
400
+ if (major >= 4) {
401
+ metadata.devDependencies["@tailwindcss/postcss"] = plan.analysis.dependencies["@tailwindcss/postcss"] || "^4.0.0";
402
+ await writeFile(path.join(directory, "postcss.config.mjs"), "export default { plugins: { \"@tailwindcss/postcss\": {} } };\n", "utf8");
403
+ await writeFile(packageFile, `${JSON.stringify(metadata, null, 2)}\n`, "utf8");
404
+ return '@import "tailwindcss";\n';
405
+ }
406
+ metadata.devDependencies.autoprefixer = plan.analysis.dependencies.autoprefixer || "^10.4.0";
407
+ await writeFile(path.join(directory, "tailwind.config.cjs"), "module.exports = { content: [\"./src/**/*.{ts,tsx}\"], theme: { extend: {} }, plugins: [] };\n", "utf8");
408
+ await writeFile(path.join(directory, "postcss.config.cjs"), "module.exports = { plugins: { tailwindcss: {}, autoprefixer: {} } };\n", "utf8");
409
+ await writeFile(packageFile, `${JSON.stringify(metadata, null, 2)}\n`, "utf8");
410
+ return "@tailwind base;\n@tailwind components;\n@tailwind utilities;\n";
411
+ }
412
+ export async function generateMigratedTheme(plan, directory) {
413
+ await themeCreate({
414
+ directory,
415
+ id: plan.themeId,
416
+ name: plan.themeName,
417
+ template: "starter",
418
+ silent: true,
419
+ });
420
+ await rm(path.join(directory, "src"), { recursive: true, force: true });
421
+ await Promise.all([
422
+ mkdir(path.join(directory, "src", "components"), { recursive: true }),
423
+ mkdir(path.join(directory, "src", "sections"), { recursive: true }),
424
+ mkdir(path.join(directory, "src", "styles"), { recursive: true }),
425
+ mkdir(path.join(directory, "src", "pages"), { recursive: true }),
426
+ ]);
427
+ const copiedAssets = await copyMigrationAssets(plan, directory);
428
+ const tailwindHeader = await configureTailwind(plan, directory);
429
+ await Promise.all([
430
+ writeFile(path.join(directory, "src/components/Header.tsx"), headerSource(plan), "utf8"),
431
+ writeFile(path.join(directory, "src/components/Footer.tsx"), footerSource(plan), "utf8"),
432
+ writeFile(path.join(directory, "src/components/ProductCard.tsx"), productCardSource(plan), "utf8"),
433
+ writeFile(path.join(directory, "src/components/ProductGrid.tsx"), productGridSource(plan), "utf8"),
434
+ writeFile(path.join(directory, "src/components/ProductDetail.tsx"), productDetailSource(plan), "utf8"),
435
+ writeFile(path.join(directory, "src/sections/Home.tsx"), homeSource(plan, copiedAssets), "utf8"),
436
+ writeFile(path.join(directory, "src/pages/CatalogPage.tsx"), catalogPageSource(), "utf8"),
437
+ writeFile(path.join(directory, "src/pages/ProductPage.tsx"), productPageSource(), "utf8"),
438
+ writeFile(path.join(directory, "src/pages/EditorialPage.tsx"), editorialPageSource(), "utf8"),
439
+ writeFile(path.join(directory, "src/pages/StatePage.tsx"), statePageSource(), "utf8"),
440
+ writeFile(path.join(directory, "src/definition.tsx"), definitionSource(plan), "utf8"),
441
+ writeFile(path.join(directory, "src/theme.tsx"), themeSource(), "utf8"),
442
+ writeFile(path.join(directory, "src/styles/theme.css"), `${tailwindHeader}${baseCss(plan)}\n${preservedCss(plan, copiedAssets)}\n`, "utf8"),
443
+ writeFile(path.join(directory, "src/styles.d.ts"), 'declare module "*.css";\ndeclare module "*.svg";\n', "utf8"),
444
+ ]);
445
+ const manifestFile = path.join(directory, "nuvler.theme.json");
446
+ const manifest = JSON.parse(await readFile(manifestFile, "utf8"));
447
+ manifest.entry = "src/theme.tsx";
448
+ manifest.styles = ["src/styles/theme.css"];
449
+ manifest.presentation = {
450
+ description: `Tema ${plan.themeName} migrado de um projeto React + ${plan.analysis.framework === "next" ? "Next.js" : "Vite"}.`,
451
+ templateId: "starter",
452
+ colors: {
453
+ primary: plan.tokens.primary,
454
+ primaryText: plan.tokens.primaryText,
455
+ secondary: plan.tokens.secondary,
456
+ secondaryText: plan.tokens.secondaryText,
457
+ accent: plan.tokens.accent,
458
+ background: plan.tokens.background,
459
+ surface: plan.tokens.surface,
460
+ surfaceAlt: plan.tokens.surfaceAlt,
461
+ text: plan.tokens.text,
462
+ textMuted: plan.tokens.textMuted,
463
+ border: plan.tokens.border,
464
+ headerBackground: plan.tokens.headerBackground,
465
+ headerText: plan.tokens.headerText,
466
+ footerBackground: plan.tokens.footerBackground,
467
+ footerText: plan.tokens.footerText,
468
+ },
469
+ layout: {
470
+ containerWidth: plan.tokens.containerWidth,
471
+ borderRadius: plan.tokens.borderRadius,
472
+ },
473
+ };
474
+ await writeFile(manifestFile, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
475
+ const selectedComponents = {};
476
+ for (const [role, selected] of Object.entries(plan.selected)) {
477
+ if (selected)
478
+ selectedComponents[role] = {
479
+ name: selected.component.name,
480
+ file: selected.component.file,
481
+ };
482
+ }
483
+ const report = {
484
+ framework: plan.analysis.framework,
485
+ sourceRoots: plan.analysis.sourceRoots,
486
+ componentsAnalyzed: plan.analysis.components.length,
487
+ selectedComponents,
488
+ assetsCopied: copiedAssets.length,
489
+ styleFilesPreserved: plan.styles.length,
490
+ tailwind: plan.analysis.tailwind,
491
+ ignoredFiles: plan.analysis.ignoredFiles,
492
+ warnings: [...new Set(plan.warnings)],
493
+ validation: { manifest: false, typecheck: false, build: false },
494
+ };
495
+ return { copiedAssets, report };
496
+ }
497
+ export async function writeMigrationReport(directory, report) {
498
+ await writeFile(path.join(directory, "migration-report.json"), `${JSON.stringify(report, null, 2)}\n`, "utf8");
499
+ }
500
+ //# sourceMappingURL=generator.js.map