@nuvler/cli 0.4.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -5
- package/dist/commands/theme/create.js +2 -2
- package/dist/commands/theme/dev.js +3 -1
- package/dist/commands/theme/dev.js.map +1 -1
- package/dist/commands/theme/migrate.js +7 -0
- package/dist/commands/theme/migrate.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/migrate/analysis/dependency-classifier.js +41 -0
- package/dist/migrate/analysis/dependency-classifier.js.map +1 -0
- package/dist/migrate/analysis/dependency-graph.js +210 -0
- package/dist/migrate/analysis/dependency-graph.js.map +1 -0
- package/dist/migrate/analyzer.js +12 -3
- package/dist/migrate/analyzer.js.map +1 -1
- package/dist/migrate/asset-copier.js +2 -2
- package/dist/migrate/asset-copier.js.map +1 -1
- package/dist/migrate/generation/fidelity-pass.js +223 -0
- package/dist/migrate/generation/fidelity-pass.js.map +1 -0
- package/dist/migrate/generator.js +1405 -55
- package/dist/migrate/generator.js.map +1 -1
- package/dist/migrate/resolvers/import-resolver.js +91 -0
- package/dist/migrate/resolvers/import-resolver.js.map +1 -0
- package/dist/migrate/transform/source-transformer.js +373 -0
- package/dist/migrate/transform/source-transformer.js.map +1 -0
- package/dist/migrate/transformer.js +272 -1
- package/dist/migrate/transformer.js.map +1 -1
- package/dist/nuvler.js +3391 -289
- package/dist/nuvler.js.map +1 -1
- package/dist/preview/prepare.js +84 -1
- package/dist/preview/prepare.js.map +1 -1
- package/dist/templates/nuvler-atelier/nuvler.theme.json +1 -1
- package/dist/templates/nuvler-atelier/package.json +2 -2
- package/dist/templates/nuvler-default/nuvler.theme.json +1 -1
- package/dist/templates/nuvler-default/package.json +1 -1
- package/dist/templates/nuvler-default/src/home.tsx +79 -2
- package/dist/templates/nuvler-default/src/theme-component.tsx +4 -3
- package/dist/templates/nuvler-default/src/theme.css +149 -0
- package/dist/templates/starter/nuvler.theme.json +1 -1
- package/dist/templates/starter/package.json +2 -2
- package/package.json +4 -4
- package/preview-host/package.json +1 -1
- package/preview-host/src/app/globals.css +5 -15
- package/preview-host/src/main.tsx +55 -5
- package/preview-host/vendor/theme-runtime/default-theme.tsx +131 -3
- package/preview-host/vite.config.ts +4 -0
package/dist/nuvler.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from "commander";
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
3
|
+
import { existsSync, statSync } from "node:fs";
|
|
4
4
|
import { access, chmod, copyFile, cp, lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
@@ -30,8 +30,8 @@ var __exportAll = (all, no_symbols) => {
|
|
|
30
30
|
//#region src/commands/theme/create.ts
|
|
31
31
|
var THEME_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
32
32
|
var NEW_THEME_VERSION = "0.1.0";
|
|
33
|
-
var CLI_VERSION_RANGE = "^0.
|
|
34
|
-
var SDK_VERSION_RANGE = "^1.
|
|
33
|
+
var CLI_VERSION_RANGE = "^0.5.0";
|
|
34
|
+
var SDK_VERSION_RANGE = "^1.3.0";
|
|
35
35
|
var THEME_TEMPLATES = [
|
|
36
36
|
{
|
|
37
37
|
id: "starter",
|
|
@@ -241,7 +241,7 @@ async function themeCreate(options) {
|
|
|
241
241
|
var THEME_BUILD_DIRECTORY = "dist";
|
|
242
242
|
var THEME_BUILD_ENTRY = "theme.js";
|
|
243
243
|
var THEME_BUILD_STYLE = "theme.css";
|
|
244
|
-
async function isFile(file) {
|
|
244
|
+
async function isFile$1(file) {
|
|
245
245
|
try {
|
|
246
246
|
return (await stat(file)).isFile();
|
|
247
247
|
} catch {
|
|
@@ -252,11 +252,11 @@ async function loadThemeBuild(project) {
|
|
|
252
252
|
const directory = path.join(project.directory, THEME_BUILD_DIRECTORY);
|
|
253
253
|
const entryPath = path.join(directory, THEME_BUILD_ENTRY);
|
|
254
254
|
const styleCandidate = path.join(directory, THEME_BUILD_STYLE);
|
|
255
|
-
if (!await isFile(entryPath)) throw new Error(`Build do tema não encontrado em ${entryPath}. Execute "nuvler theme build".`);
|
|
255
|
+
if (!await isFile$1(entryPath)) throw new Error(`Build do tema não encontrado em ${entryPath}. Execute "nuvler theme build".`);
|
|
256
256
|
return {
|
|
257
257
|
directory,
|
|
258
258
|
entryPath,
|
|
259
|
-
stylePath: await isFile(styleCandidate) ? styleCandidate : null
|
|
259
|
+
stylePath: await isFile$1(styleCandidate) ? styleCandidate : null
|
|
260
260
|
};
|
|
261
261
|
}
|
|
262
262
|
function createArtifactManifest(project, build) {
|
|
@@ -5288,7 +5288,7 @@ var schemas_exports = /* @__PURE__ */ __exportAll({
|
|
|
5288
5288
|
preprocess: () => preprocess,
|
|
5289
5289
|
promise: () => promise,
|
|
5290
5290
|
readonly: () => readonly,
|
|
5291
|
-
record: () => record,
|
|
5291
|
+
record: () => record$1,
|
|
5292
5292
|
refine: () => refine,
|
|
5293
5293
|
set: () => set,
|
|
5294
5294
|
strictObject: () => strictObject,
|
|
@@ -6147,7 +6147,7 @@ var ZodRecord = /*@__PURE__*/ $constructor("ZodRecord", (inst, def) => {
|
|
|
6147
6147
|
inst.keyType = def.keyType;
|
|
6148
6148
|
inst.valueType = def.valueType;
|
|
6149
6149
|
});
|
|
6150
|
-
function record(keyType, valueType, params) {
|
|
6150
|
+
function record$1(keyType, valueType, params) {
|
|
6151
6151
|
if (!valueType || !valueType._zod) return new ZodRecord({
|
|
6152
6152
|
type: "record",
|
|
6153
6153
|
keyType: string$1(),
|
|
@@ -6600,7 +6600,7 @@ function json(params) {
|
|
|
6600
6600
|
boolean$1(),
|
|
6601
6601
|
_null(),
|
|
6602
6602
|
array(jsonSchema),
|
|
6603
|
-
record(string$1(), jsonSchema)
|
|
6603
|
+
record$1(string$1(), jsonSchema)
|
|
6604
6604
|
]);
|
|
6605
6605
|
});
|
|
6606
6606
|
return jsonSchema;
|
|
@@ -6612,6 +6612,22 @@ function preprocess(fn, schema) {
|
|
|
6612
6612
|
out: schema
|
|
6613
6613
|
});
|
|
6614
6614
|
}
|
|
6615
|
+
//#endregion
|
|
6616
|
+
//#region ../../node_modules/zod/v4/classic/compat.js
|
|
6617
|
+
/** @deprecated Use the raw string literal codes instead, e.g. "invalid_type". */
|
|
6618
|
+
var ZodIssueCode = {
|
|
6619
|
+
invalid_type: "invalid_type",
|
|
6620
|
+
too_big: "too_big",
|
|
6621
|
+
too_small: "too_small",
|
|
6622
|
+
invalid_format: "invalid_format",
|
|
6623
|
+
not_multiple_of: "not_multiple_of",
|
|
6624
|
+
unrecognized_keys: "unrecognized_keys",
|
|
6625
|
+
invalid_union: "invalid_union",
|
|
6626
|
+
invalid_key: "invalid_key",
|
|
6627
|
+
invalid_element: "invalid_element",
|
|
6628
|
+
invalid_value: "invalid_value",
|
|
6629
|
+
custom: "custom"
|
|
6630
|
+
};
|
|
6615
6631
|
/** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
|
|
6616
6632
|
var ZodFirstPartyTypeKind;
|
|
6617
6633
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
@@ -6641,6 +6657,131 @@ var ThemeSiteColorsSchema = object({
|
|
|
6641
6657
|
footerBackground: hexColorSchema.optional(),
|
|
6642
6658
|
footerText: hexColorSchema.optional()
|
|
6643
6659
|
}).strict();
|
|
6660
|
+
var componentKeySchema = string$1().trim().min(2).max(80).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Use um identificador em kebab-case");
|
|
6661
|
+
var fieldKeySchema = string$1().trim().min(1).max(64).regex(/^[a-z][a-zA-Z0-9-]*$/, "Use uma chave iniciada por letra, sem espaços");
|
|
6662
|
+
var fieldControlSchema = _enum([
|
|
6663
|
+
"text",
|
|
6664
|
+
"textarea",
|
|
6665
|
+
"rich-text",
|
|
6666
|
+
"url",
|
|
6667
|
+
"image",
|
|
6668
|
+
"video",
|
|
6669
|
+
"number",
|
|
6670
|
+
"boolean",
|
|
6671
|
+
"select",
|
|
6672
|
+
"repeater",
|
|
6673
|
+
"contact-fields"
|
|
6674
|
+
]);
|
|
6675
|
+
var fieldOptionSchema = object({
|
|
6676
|
+
label: string$1().trim().min(1).max(120),
|
|
6677
|
+
value: string$1().trim().min(1).max(120)
|
|
6678
|
+
}).strict();
|
|
6679
|
+
var fieldBaseShape = {
|
|
6680
|
+
key: fieldKeySchema,
|
|
6681
|
+
label: string$1().trim().min(1).max(120),
|
|
6682
|
+
control: fieldControlSchema,
|
|
6683
|
+
help: string$1().trim().min(1).max(300).optional(),
|
|
6684
|
+
placeholder: string$1().trim().max(200).optional(),
|
|
6685
|
+
required: boolean$1().optional(),
|
|
6686
|
+
defaultValue: union([
|
|
6687
|
+
string$1().max(5e3),
|
|
6688
|
+
number$1().finite(),
|
|
6689
|
+
boolean$1(),
|
|
6690
|
+
_null()
|
|
6691
|
+
]).optional(),
|
|
6692
|
+
options: array(fieldOptionSchema).min(1).max(100).optional(),
|
|
6693
|
+
min: number$1().finite().optional(),
|
|
6694
|
+
max: number$1().finite().optional(),
|
|
6695
|
+
maxLength: number$1().int().positive().max(1e5).optional(),
|
|
6696
|
+
maxItems: number$1().int().positive().max(100).optional()
|
|
6697
|
+
};
|
|
6698
|
+
var ThemeHomeComponentItemFieldSchema = object(fieldBaseShape).strict().superRefine((field, context) => {
|
|
6699
|
+
if (field.control === "repeater") context.addIssue({
|
|
6700
|
+
code: ZodIssueCode.custom,
|
|
6701
|
+
path: ["control"],
|
|
6702
|
+
message: "Repetidores aninhados não são permitidos"
|
|
6703
|
+
});
|
|
6704
|
+
if (field.control === "select" && !field.options?.length) context.addIssue({
|
|
6705
|
+
code: ZodIssueCode.custom,
|
|
6706
|
+
path: ["options"],
|
|
6707
|
+
message: "Campos select exigem opções"
|
|
6708
|
+
});
|
|
6709
|
+
});
|
|
6710
|
+
var ThemeHomeComponentFieldSchema = object({
|
|
6711
|
+
...fieldBaseShape,
|
|
6712
|
+
itemFields: array(ThemeHomeComponentItemFieldSchema).min(1).max(30).optional()
|
|
6713
|
+
}).strict().superRefine((field, context) => {
|
|
6714
|
+
if (field.control === "select" && !field.options?.length) context.addIssue({
|
|
6715
|
+
code: ZodIssueCode.custom,
|
|
6716
|
+
path: ["options"],
|
|
6717
|
+
message: "Campos select exigem opções"
|
|
6718
|
+
});
|
|
6719
|
+
if (field.control === "repeater" && !field.itemFields?.length) context.addIssue({
|
|
6720
|
+
code: ZodIssueCode.custom,
|
|
6721
|
+
path: ["itemFields"],
|
|
6722
|
+
message: "Campos repeater exigem os campos de cada item"
|
|
6723
|
+
});
|
|
6724
|
+
if (field.control !== "repeater" && field.itemFields) context.addIssue({
|
|
6725
|
+
code: ZodIssueCode.custom,
|
|
6726
|
+
path: ["itemFields"],
|
|
6727
|
+
message: "itemFields só pode ser usado em campos repeater"
|
|
6728
|
+
});
|
|
6729
|
+
if (field.min !== void 0 && field.max !== void 0 && field.min > field.max) context.addIssue({
|
|
6730
|
+
code: ZodIssueCode.custom,
|
|
6731
|
+
path: ["min"],
|
|
6732
|
+
message: "O valor mínimo não pode superar o máximo"
|
|
6733
|
+
});
|
|
6734
|
+
const itemKeys = /* @__PURE__ */ new Set();
|
|
6735
|
+
field.itemFields?.forEach((item, index) => {
|
|
6736
|
+
if (itemKeys.has(item.key)) context.addIssue({
|
|
6737
|
+
code: ZodIssueCode.custom,
|
|
6738
|
+
path: [
|
|
6739
|
+
"itemFields",
|
|
6740
|
+
index,
|
|
6741
|
+
"key"
|
|
6742
|
+
],
|
|
6743
|
+
message: "A chave do campo repetível deve ser única"
|
|
6744
|
+
});
|
|
6745
|
+
itemKeys.add(item.key);
|
|
6746
|
+
});
|
|
6747
|
+
});
|
|
6748
|
+
var ThemeHomeComponentDefinitionSchema = object({
|
|
6749
|
+
key: componentKeySchema,
|
|
6750
|
+
name: string$1().trim().min(2).max(120),
|
|
6751
|
+
description: string$1().trim().min(1).max(300),
|
|
6752
|
+
category: _enum([
|
|
6753
|
+
"Destaques",
|
|
6754
|
+
"Conteúdo",
|
|
6755
|
+
"Listas",
|
|
6756
|
+
"Mídia",
|
|
6757
|
+
"Formulários"
|
|
6758
|
+
]),
|
|
6759
|
+
schemaVersion: number$1().int().positive().max(1e3),
|
|
6760
|
+
fields: array(ThemeHomeComponentFieldSchema).max(40),
|
|
6761
|
+
action: object({
|
|
6762
|
+
type: literal("contact.submit"),
|
|
6763
|
+
formKey: componentKeySchema
|
|
6764
|
+
}).strict().optional()
|
|
6765
|
+
}).strict().superRefine((component, context) => {
|
|
6766
|
+
const keys = /* @__PURE__ */ new Set();
|
|
6767
|
+
component.fields.forEach((field, index) => {
|
|
6768
|
+
if (keys.has(field.key)) context.addIssue({
|
|
6769
|
+
code: ZodIssueCode.custom,
|
|
6770
|
+
path: [
|
|
6771
|
+
"fields",
|
|
6772
|
+
index,
|
|
6773
|
+
"key"
|
|
6774
|
+
],
|
|
6775
|
+
message: "A chave do campo deve ser única no componente"
|
|
6776
|
+
});
|
|
6777
|
+
keys.add(field.key);
|
|
6778
|
+
});
|
|
6779
|
+
if (component.fields.some(({ control }) => control === "contact-fields") && !component.action) context.addIssue({
|
|
6780
|
+
code: ZodIssueCode.custom,
|
|
6781
|
+
path: ["action"],
|
|
6782
|
+
message: "Componentes com campos de contato exigem a ação contact.submit"
|
|
6783
|
+
});
|
|
6784
|
+
});
|
|
6644
6785
|
var ThemePresentationSchema = object({
|
|
6645
6786
|
description: string$1().trim().min(1).max(500),
|
|
6646
6787
|
templateId: string$1().trim().min(1).max(80).optional(),
|
|
@@ -6648,8 +6789,23 @@ var ThemePresentationSchema = object({
|
|
|
6648
6789
|
layout: object({
|
|
6649
6790
|
containerWidth: number$1().int().min(960).max(1600),
|
|
6650
6791
|
borderRadius: number$1().int().min(0).max(32)
|
|
6651
|
-
}).strict()
|
|
6652
|
-
|
|
6792
|
+
}).strict(),
|
|
6793
|
+
homeComponents: array(ThemeHomeComponentDefinitionSchema).max(50).optional()
|
|
6794
|
+
}).strict().superRefine((presentation, context) => {
|
|
6795
|
+
const keys = /* @__PURE__ */ new Set();
|
|
6796
|
+
presentation.homeComponents?.forEach((component, index) => {
|
|
6797
|
+
if (keys.has(component.key)) context.addIssue({
|
|
6798
|
+
code: ZodIssueCode.custom,
|
|
6799
|
+
path: [
|
|
6800
|
+
"homeComponents",
|
|
6801
|
+
index,
|
|
6802
|
+
"key"
|
|
6803
|
+
],
|
|
6804
|
+
message: "A chave do componente deve ser única no tema"
|
|
6805
|
+
});
|
|
6806
|
+
keys.add(component.key);
|
|
6807
|
+
});
|
|
6808
|
+
});
|
|
6653
6809
|
var ThemeManifestSchema = object({
|
|
6654
6810
|
schemaVersion: literal(THEME_SCHEMA_VERSION),
|
|
6655
6811
|
id: string$1().trim().min(2).max(80).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Use um identificador em kebab-case"),
|
|
@@ -6718,6 +6874,11 @@ var ThemeSiteSchema = object({
|
|
|
6718
6874
|
}).strict().nullable().optional()
|
|
6719
6875
|
}).strict().nullable()
|
|
6720
6876
|
}).strict();
|
|
6877
|
+
var ThemeComponentSectionDataSchema = object({
|
|
6878
|
+
componentKey: componentKeySchema,
|
|
6879
|
+
schemaVersion: number$1().int().positive().max(1e3),
|
|
6880
|
+
props: record$1(string$1(), unknown())
|
|
6881
|
+
}).strict();
|
|
6721
6882
|
var ThemeHomeSectionSchema = object({
|
|
6722
6883
|
id: string$1().optional(),
|
|
6723
6884
|
type: _enum([
|
|
@@ -6730,12 +6891,22 @@ var ThemeHomeSectionSchema = object({
|
|
|
6730
6891
|
"blog-grid",
|
|
6731
6892
|
"cases-grid",
|
|
6732
6893
|
"products-grid",
|
|
6733
|
-
"products-carousel"
|
|
6894
|
+
"products-carousel",
|
|
6895
|
+
"theme-component"
|
|
6734
6896
|
]),
|
|
6735
6897
|
enabled: boolean$1(),
|
|
6736
6898
|
order: number$1().int().nonnegative(),
|
|
6737
|
-
data: record(string$1(), unknown())
|
|
6738
|
-
}).strict()
|
|
6899
|
+
data: record$1(string$1(), unknown())
|
|
6900
|
+
}).strict().superRefine((section, context) => {
|
|
6901
|
+
if (section.type !== "theme-component") return;
|
|
6902
|
+
const parsed = ThemeComponentSectionDataSchema.safeParse(section.data);
|
|
6903
|
+
if (parsed.success) return;
|
|
6904
|
+
parsed.error.issues.forEach((issue) => context.addIssue({
|
|
6905
|
+
code: ZodIssueCode.custom,
|
|
6906
|
+
path: ["data", ...issue.path],
|
|
6907
|
+
message: issue.message
|
|
6908
|
+
}));
|
|
6909
|
+
});
|
|
6739
6910
|
var ThemeHomeSchema = object({
|
|
6740
6911
|
title: string$1(),
|
|
6741
6912
|
slug: string$1(),
|
|
@@ -7564,6 +7735,94 @@ async function loadThemeContext({ store, apiUrl }) {
|
|
|
7564
7735
|
}
|
|
7565
7736
|
//#endregion
|
|
7566
7737
|
//#region src/preview/prepare.ts
|
|
7738
|
+
function record(value) {
|
|
7739
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
7740
|
+
}
|
|
7741
|
+
function meaningful(value) {
|
|
7742
|
+
if (typeof value === "string") return Boolean(value.trim());
|
|
7743
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
7744
|
+
return value !== null && value !== void 0;
|
|
7745
|
+
}
|
|
7746
|
+
async function migrationSeedContext(directory, context) {
|
|
7747
|
+
let parsed;
|
|
7748
|
+
try {
|
|
7749
|
+
parsed = JSON.parse(await readFile(path.join(directory, "migration-content-seed.json"), "utf8"));
|
|
7750
|
+
} catch (error) {
|
|
7751
|
+
if (error.code === "ENOENT") return {
|
|
7752
|
+
context,
|
|
7753
|
+
sections: 0
|
|
7754
|
+
};
|
|
7755
|
+
throw new Error("migration-content-seed.json inválido; regenere o tema migrado.", { cause: error });
|
|
7756
|
+
}
|
|
7757
|
+
const seed = record(parsed);
|
|
7758
|
+
const rawSections = Array.isArray(seed?.sections) ? seed.sections : [];
|
|
7759
|
+
const supported = /* @__PURE__ */ new Set([
|
|
7760
|
+
"hero",
|
|
7761
|
+
"banner-carousel",
|
|
7762
|
+
"image-text",
|
|
7763
|
+
"rich-text",
|
|
7764
|
+
"cta",
|
|
7765
|
+
"services-grid",
|
|
7766
|
+
"blog-grid",
|
|
7767
|
+
"cases-grid",
|
|
7768
|
+
"products-grid",
|
|
7769
|
+
"products-carousel"
|
|
7770
|
+
]);
|
|
7771
|
+
const seeds = rawSections.flatMap((candidate) => {
|
|
7772
|
+
const section = record(candidate);
|
|
7773
|
+
const data = record(section?.data);
|
|
7774
|
+
if (!section || !data || typeof section.id !== "string" || typeof section.type !== "string" || !supported.has(section.type)) return [];
|
|
7775
|
+
return [{
|
|
7776
|
+
id: section.id,
|
|
7777
|
+
type: section.type,
|
|
7778
|
+
enabled: true,
|
|
7779
|
+
order: typeof section.order === "number" ? section.order : 0,
|
|
7780
|
+
data
|
|
7781
|
+
}];
|
|
7782
|
+
});
|
|
7783
|
+
if (!seeds.length) return {
|
|
7784
|
+
context,
|
|
7785
|
+
sections: 0
|
|
7786
|
+
};
|
|
7787
|
+
const merged = context.home.content.sections.map((section) => ({
|
|
7788
|
+
...section,
|
|
7789
|
+
data: { ...section.data }
|
|
7790
|
+
}));
|
|
7791
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
7792
|
+
for (const seedSection of seeds) {
|
|
7793
|
+
const exact = merged.findIndex(({ id }) => id === seedSection.id);
|
|
7794
|
+
const compatible = exact >= 0 ? exact : merged.findIndex((section, index) => !claimed.has(index) && section.type === seedSection.type);
|
|
7795
|
+
if (compatible < 0) {
|
|
7796
|
+
merged.push(seedSection);
|
|
7797
|
+
continue;
|
|
7798
|
+
}
|
|
7799
|
+
claimed.add(compatible);
|
|
7800
|
+
const configured = merged[compatible];
|
|
7801
|
+
const configuredValues = Object.fromEntries(Object.entries(configured.data).filter(([, value]) => meaningful(value)));
|
|
7802
|
+
merged[compatible] = {
|
|
7803
|
+
...configured,
|
|
7804
|
+
id: seedSection.id,
|
|
7805
|
+
data: {
|
|
7806
|
+
...seedSection.data,
|
|
7807
|
+
...configuredValues
|
|
7808
|
+
}
|
|
7809
|
+
};
|
|
7810
|
+
}
|
|
7811
|
+
merged.sort((left, right) => left.order - right.order);
|
|
7812
|
+
return {
|
|
7813
|
+
context: ThemeContextSchema.parse({
|
|
7814
|
+
...context,
|
|
7815
|
+
home: {
|
|
7816
|
+
...context.home,
|
|
7817
|
+
content: {
|
|
7818
|
+
...context.home.content,
|
|
7819
|
+
sections: merged
|
|
7820
|
+
}
|
|
7821
|
+
}
|
|
7822
|
+
}),
|
|
7823
|
+
sections: seeds.length
|
|
7824
|
+
};
|
|
7825
|
+
}
|
|
7567
7826
|
async function prepareThemePreview(options) {
|
|
7568
7827
|
const project = await loadThemeProject(options.themeDirectory);
|
|
7569
7828
|
const configured = await readThemeProjectConfig(project.directory);
|
|
@@ -7575,11 +7834,13 @@ async function prepareThemePreview(options) {
|
|
|
7575
7834
|
apiUrl: session.apiUrl
|
|
7576
7835
|
});
|
|
7577
7836
|
if (context.store.slug !== tenant.slug) throw new Error(`A API retornou contexto do tenant "${context.store.slug}" para "${tenant.slug}".`);
|
|
7837
|
+
const preview = await migrationSeedContext(project.directory, context);
|
|
7578
7838
|
return {
|
|
7579
7839
|
project,
|
|
7580
|
-
context,
|
|
7840
|
+
context: preview.context,
|
|
7581
7841
|
apiUrl: session.apiUrl,
|
|
7582
|
-
tenant
|
|
7842
|
+
tenant,
|
|
7843
|
+
migrationSeedSections: preview.sections
|
|
7583
7844
|
};
|
|
7584
7845
|
}
|
|
7585
7846
|
//#endregion
|
|
@@ -7588,7 +7849,7 @@ function countCategories(categories) {
|
|
|
7588
7849
|
return categories.reduce((total, category) => total + 1 + countCategories(category.children), 0);
|
|
7589
7850
|
}
|
|
7590
7851
|
async function themeDev(options) {
|
|
7591
|
-
const { project, context, apiUrl, tenant } = await prepareThemePreview({
|
|
7852
|
+
const { project, context, apiUrl, tenant, migrationSeedSections } = await prepareThemePreview({
|
|
7592
7853
|
themeDirectory: options.themeDirectory,
|
|
7593
7854
|
store: options.store,
|
|
7594
7855
|
apiUrl: options.apiUrl
|
|
@@ -7609,6 +7870,7 @@ async function themeDev(options) {
|
|
|
7609
7870
|
console.log("");
|
|
7610
7871
|
console.log("✓ Site carregado");
|
|
7611
7872
|
console.log("✓ Home carregada");
|
|
7873
|
+
if (migrationSeedSections) console.log(`✓ ${migrationSeedSections} seção(ões) preenchida(s) com o conteúdo extraído para o preview local`);
|
|
7612
7874
|
console.log(`✓ ${context.catalog.products.length} produtos carregados`);
|
|
7613
7875
|
console.log(`✓ ${countCategories(context.navigation.categories)} categorias carregadas`);
|
|
7614
7876
|
console.log(`✓ ${context.navigation.pages.length} páginas carregadas`);
|
|
@@ -7903,6 +8165,405 @@ async function themePublish(options) {
|
|
|
7903
8165
|
console.log("");
|
|
7904
8166
|
}
|
|
7905
8167
|
//#endregion
|
|
8168
|
+
//#region src/migrate/resolvers/import-resolver.ts
|
|
8169
|
+
var SOURCE_EXTENSIONS$1 = [
|
|
8170
|
+
".tsx",
|
|
8171
|
+
".ts",
|
|
8172
|
+
".jsx",
|
|
8173
|
+
".js",
|
|
8174
|
+
".mts",
|
|
8175
|
+
".mjs",
|
|
8176
|
+
".cts",
|
|
8177
|
+
".cjs"
|
|
8178
|
+
];
|
|
8179
|
+
var STYLE_EXTENSIONS$1 = [
|
|
8180
|
+
".css",
|
|
8181
|
+
".scss",
|
|
8182
|
+
".sass",
|
|
8183
|
+
".less"
|
|
8184
|
+
];
|
|
8185
|
+
var ASSET_EXTENSIONS$1 = [
|
|
8186
|
+
".avif",
|
|
8187
|
+
".bmp",
|
|
8188
|
+
".eot",
|
|
8189
|
+
".gif",
|
|
8190
|
+
".ico",
|
|
8191
|
+
".jpeg",
|
|
8192
|
+
".jpg",
|
|
8193
|
+
".mp4",
|
|
8194
|
+
".ogg",
|
|
8195
|
+
".otf",
|
|
8196
|
+
".png",
|
|
8197
|
+
".svg",
|
|
8198
|
+
".ttf",
|
|
8199
|
+
".webm",
|
|
8200
|
+
".webp",
|
|
8201
|
+
".woff",
|
|
8202
|
+
".woff2"
|
|
8203
|
+
];
|
|
8204
|
+
var RESOLVABLE_EXTENSIONS = [
|
|
8205
|
+
...SOURCE_EXTENSIONS$1,
|
|
8206
|
+
...STYLE_EXTENSIONS$1,
|
|
8207
|
+
...ASSET_EXTENSIONS$1,
|
|
8208
|
+
".json"
|
|
8209
|
+
];
|
|
8210
|
+
function inside$2(root, candidate) {
|
|
8211
|
+
const relative = path.relative(root, candidate);
|
|
8212
|
+
return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
8213
|
+
}
|
|
8214
|
+
function isFile(file) {
|
|
8215
|
+
try {
|
|
8216
|
+
return statSync(file).isFile();
|
|
8217
|
+
} catch {
|
|
8218
|
+
return false;
|
|
8219
|
+
}
|
|
8220
|
+
}
|
|
8221
|
+
function cleanSpecifier(specifier) {
|
|
8222
|
+
return specifier.replace(/[?#].*$/, "");
|
|
8223
|
+
}
|
|
8224
|
+
function compilerOptions(sourceDirectory) {
|
|
8225
|
+
const configFile = ts.findConfigFile(sourceDirectory, ts.sys.fileExists, "tsconfig.json");
|
|
8226
|
+
if (!configFile) return {};
|
|
8227
|
+
const config = ts.readConfigFile(configFile, ts.sys.readFile);
|
|
8228
|
+
if (config.error) return {};
|
|
8229
|
+
return ts.parseJsonConfigFileContent(config.config, ts.sys, path.dirname(configFile)).options;
|
|
8230
|
+
}
|
|
8231
|
+
function packageNameOf(specifier) {
|
|
8232
|
+
if (specifier.startsWith(".") || specifier.startsWith("/") || specifier.startsWith("@/") || specifier.startsWith("~/")) return null;
|
|
8233
|
+
const parts = specifier.split("/");
|
|
8234
|
+
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
8235
|
+
}
|
|
8236
|
+
function extensionKind(file) {
|
|
8237
|
+
const extension = path.extname(file).toLowerCase();
|
|
8238
|
+
if (SOURCE_EXTENSIONS$1.includes(extension)) return "SOURCE";
|
|
8239
|
+
if (STYLE_EXTENSIONS$1.includes(extension)) return "STYLE";
|
|
8240
|
+
if (ASSET_EXTENSIONS$1.includes(extension)) return "ASSET";
|
|
8241
|
+
if (extension === ".json") return "JSON";
|
|
8242
|
+
return null;
|
|
8243
|
+
}
|
|
8244
|
+
function createImportResolver(sourceDirectory) {
|
|
8245
|
+
const root = path.resolve(sourceDirectory);
|
|
8246
|
+
const options = compilerOptions(root);
|
|
8247
|
+
function candidates(base) {
|
|
8248
|
+
return [
|
|
8249
|
+
base,
|
|
8250
|
+
...RESOLVABLE_EXTENSIONS.map((extension) => `${base}${extension}`),
|
|
8251
|
+
...[
|
|
8252
|
+
...SOURCE_EXTENSIONS$1,
|
|
8253
|
+
...STYLE_EXTENSIONS$1,
|
|
8254
|
+
".json"
|
|
8255
|
+
].map((extension) => path.join(base, `index${extension}`))
|
|
8256
|
+
];
|
|
8257
|
+
}
|
|
8258
|
+
return { resolve(importer, originalSpecifier) {
|
|
8259
|
+
const specifier = cleanSpecifier(originalSpecifier);
|
|
8260
|
+
const resolved = ts.resolveModuleName(specifier, importer, options, {
|
|
8261
|
+
fileExists: ts.sys.fileExists,
|
|
8262
|
+
readFile: ts.sys.readFile
|
|
8263
|
+
}).resolvedModule?.resolvedFileName;
|
|
8264
|
+
if (resolved && inside$2(root, resolved) && !resolved.includes(`${path.sep}node_modules${path.sep}`) && isFile(resolved)) return path.resolve(resolved);
|
|
8265
|
+
const bases = specifier.startsWith(".") ? [path.resolve(path.dirname(importer), specifier)] : specifier.startsWith("@/") || specifier.startsWith("~/") ? [path.resolve(root, "src", specifier.slice(2)), path.resolve(root, specifier.slice(2))] : specifier.startsWith("/") ? [path.resolve(root, "public", specifier.replace(/^\/+/, ""))] : [];
|
|
8266
|
+
for (const candidate of bases.flatMap(candidates)) if (inside$2(root, candidate) && isFile(candidate)) return candidate;
|
|
8267
|
+
return null;
|
|
8268
|
+
} };
|
|
8269
|
+
}
|
|
8270
|
+
//#endregion
|
|
8271
|
+
//#region src/migrate/analysis/dependency-classifier.ts
|
|
8272
|
+
var VISUAL_PACKAGES = [
|
|
8273
|
+
"framer-motion",
|
|
8274
|
+
"motion",
|
|
8275
|
+
"lucide-react",
|
|
8276
|
+
"react-icons",
|
|
8277
|
+
"@mui/material",
|
|
8278
|
+
"@mui/icons-material",
|
|
8279
|
+
"@emotion/react",
|
|
8280
|
+
"@emotion/styled",
|
|
8281
|
+
"@radix-ui/",
|
|
8282
|
+
"embla-carousel",
|
|
8283
|
+
"react-slick",
|
|
8284
|
+
"recharts",
|
|
8285
|
+
"sonner",
|
|
8286
|
+
"vaul"
|
|
8287
|
+
];
|
|
8288
|
+
var UTILITY_PACKAGES = [
|
|
8289
|
+
"clsx",
|
|
8290
|
+
"classnames",
|
|
8291
|
+
"class-variance-authority",
|
|
8292
|
+
"tailwind-merge",
|
|
8293
|
+
"date-fns"
|
|
8294
|
+
];
|
|
8295
|
+
var BUSINESS_PACKAGES = [
|
|
8296
|
+
"axios",
|
|
8297
|
+
"@tanstack/react-query",
|
|
8298
|
+
"react-query",
|
|
8299
|
+
"zustand",
|
|
8300
|
+
"redux",
|
|
8301
|
+
"@reduxjs/",
|
|
8302
|
+
"firebase",
|
|
8303
|
+
"supabase",
|
|
8304
|
+
"stripe",
|
|
8305
|
+
"auth",
|
|
8306
|
+
"checkout",
|
|
8307
|
+
"shopify"
|
|
8308
|
+
];
|
|
8309
|
+
function matches(packageName, candidates) {
|
|
8310
|
+
return candidates.some((candidate) => packageName === candidate || packageName.startsWith(candidate));
|
|
8311
|
+
}
|
|
8312
|
+
function classifyDependency(specifier, resolvedFile) {
|
|
8313
|
+
if (resolvedFile) {
|
|
8314
|
+
const kind = extensionKind(resolvedFile);
|
|
8315
|
+
if (kind === "ASSET") return "ASSET";
|
|
8316
|
+
if (kind === "STYLE") return "VISUAL";
|
|
8317
|
+
const normalized = resolvedFile.split(path.sep).join("/").toLowerCase();
|
|
8318
|
+
if (/(?:^|\/)(?:api|auth|checkout|cart|carrinho|store|services?)(?:\/|\.)/.test(normalized)) return "BUSINESS";
|
|
8319
|
+
return kind === "SOURCE" ? "UNKNOWN" : "UTILITY";
|
|
8320
|
+
}
|
|
8321
|
+
const packageName = packageNameOf(specifier);
|
|
8322
|
+
if (!packageName || packageName === "react" || packageName === "react-dom") return "UTILITY";
|
|
8323
|
+
if (matches(packageName, VISUAL_PACKAGES)) return "VISUAL";
|
|
8324
|
+
if (matches(packageName, UTILITY_PACKAGES)) return "UTILITY";
|
|
8325
|
+
if (matches(packageName, BUSINESS_PACKAGES)) return "BUSINESS";
|
|
8326
|
+
return "UNKNOWN";
|
|
8327
|
+
}
|
|
8328
|
+
//#endregion
|
|
8329
|
+
//#region src/migrate/analysis/dependency-graph.ts
|
|
8330
|
+
function portable$4(file) {
|
|
8331
|
+
return file.split(path.sep).join("/");
|
|
8332
|
+
}
|
|
8333
|
+
async function exists(file) {
|
|
8334
|
+
try {
|
|
8335
|
+
return (await stat(file)).isFile();
|
|
8336
|
+
} catch {
|
|
8337
|
+
return false;
|
|
8338
|
+
}
|
|
8339
|
+
}
|
|
8340
|
+
function sourceFile(file, content) {
|
|
8341
|
+
const extension = path.extname(file).toLowerCase();
|
|
8342
|
+
const kind = extension === ".tsx" ? ts.ScriptKind.TSX : extension === ".jsx" ? ts.ScriptKind.JSX : extension === ".js" || extension === ".mjs" || extension === ".cjs" ? ts.ScriptKind.JS : ts.ScriptKind.TS;
|
|
8343
|
+
return ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true, kind);
|
|
8344
|
+
}
|
|
8345
|
+
function moduleSpecifiers(source) {
|
|
8346
|
+
const result = [];
|
|
8347
|
+
for (const statement of source.statements) {
|
|
8348
|
+
if (ts.isImportDeclaration(statement) && ts.isStringLiteralLike(statement.moduleSpecifier)) {
|
|
8349
|
+
const defaultBinding = statement.importClause?.name?.text ?? null;
|
|
8350
|
+
const firstNamed = statement.importClause?.namedBindings && ts.isNamedImports(statement.importClause.namedBindings) ? statement.importClause.namedBindings.elements[0] : null;
|
|
8351
|
+
result.push({
|
|
8352
|
+
specifier: statement.moduleSpecifier.text,
|
|
8353
|
+
dynamic: false,
|
|
8354
|
+
defaultBinding,
|
|
8355
|
+
importedName: firstNamed?.propertyName?.text ?? firstNamed?.name.text ?? null
|
|
8356
|
+
});
|
|
8357
|
+
}
|
|
8358
|
+
if (ts.isExportDeclaration(statement) && statement.moduleSpecifier && ts.isStringLiteralLike(statement.moduleSpecifier)) result.push({
|
|
8359
|
+
specifier: statement.moduleSpecifier.text,
|
|
8360
|
+
dynamic: false,
|
|
8361
|
+
defaultBinding: null,
|
|
8362
|
+
importedName: null
|
|
8363
|
+
});
|
|
8364
|
+
}
|
|
8365
|
+
function visit(node) {
|
|
8366
|
+
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
8367
|
+
const argument = node.arguments[0];
|
|
8368
|
+
if (argument && ts.isStringLiteralLike(argument)) result.push({
|
|
8369
|
+
specifier: argument.text,
|
|
8370
|
+
dynamic: true,
|
|
8371
|
+
defaultBinding: null,
|
|
8372
|
+
importedName: null
|
|
8373
|
+
});
|
|
8374
|
+
}
|
|
8375
|
+
ts.forEachChild(node, visit);
|
|
8376
|
+
}
|
|
8377
|
+
visit(source);
|
|
8378
|
+
return result;
|
|
8379
|
+
}
|
|
8380
|
+
function exportIdentity(source) {
|
|
8381
|
+
for (const statement of source.statements) {
|
|
8382
|
+
if (ts.isExportAssignment(statement) && !statement.isExportEquals) return {
|
|
8383
|
+
exportName: "default",
|
|
8384
|
+
defaultExport: true
|
|
8385
|
+
};
|
|
8386
|
+
if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) && statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword)) return {
|
|
8387
|
+
exportName: statement.name?.text ?? "default",
|
|
8388
|
+
defaultExport: true
|
|
8389
|
+
};
|
|
8390
|
+
}
|
|
8391
|
+
for (const statement of source.statements) if (ts.isFunctionDeclaration(statement) && statement.name && statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)) return {
|
|
8392
|
+
exportName: statement.name.text,
|
|
8393
|
+
defaultExport: false
|
|
8394
|
+
};
|
|
8395
|
+
return {
|
|
8396
|
+
exportName: "default",
|
|
8397
|
+
defaultExport: true
|
|
8398
|
+
};
|
|
8399
|
+
}
|
|
8400
|
+
async function viteEntrypoint(sourceDirectory) {
|
|
8401
|
+
const resolver = createImportResolver(sourceDirectory);
|
|
8402
|
+
for (const relative of [
|
|
8403
|
+
"src/main.tsx",
|
|
8404
|
+
"src/main.jsx",
|
|
8405
|
+
"src/index.tsx",
|
|
8406
|
+
"src/index.jsx",
|
|
8407
|
+
"main.tsx"
|
|
8408
|
+
]) {
|
|
8409
|
+
const bootstrap = path.join(sourceDirectory, relative);
|
|
8410
|
+
if (!await exists(bootstrap)) continue;
|
|
8411
|
+
const source = sourceFile(bootstrap, await readFile(bootstrap, "utf8"));
|
|
8412
|
+
const imports = moduleSpecifiers(source).map((item) => ({
|
|
8413
|
+
...item,
|
|
8414
|
+
resolved: resolver.resolve(bootstrap, item.specifier)
|
|
8415
|
+
})).filter((item) => item.resolved && extensionKind(item.resolved) === "SOURCE").sort((left, right) => Number(/app|home/i.test(path.basename(right.resolved))) - Number(/app|home/i.test(path.basename(left.resolved))));
|
|
8416
|
+
const rootImport = imports.find((item) => item.defaultBinding && new RegExp(`<${item.defaultBinding}\\b`).test(source.text)) ?? imports.find((item) => /app|home/i.test(path.basename(item.resolved)));
|
|
8417
|
+
if (rootImport?.resolved) return {
|
|
8418
|
+
bootstrapFile: portable$4(path.relative(sourceDirectory, bootstrap)),
|
|
8419
|
+
pageFile: portable$4(path.relative(sourceDirectory, rootImport.resolved)),
|
|
8420
|
+
exportName: rootImport.importedName ?? rootImport.defaultBinding ?? "default",
|
|
8421
|
+
defaultExport: Boolean(rootImport.defaultBinding),
|
|
8422
|
+
layoutFiles: []
|
|
8423
|
+
};
|
|
8424
|
+
}
|
|
8425
|
+
for (const relative of [
|
|
8426
|
+
"src/App.tsx",
|
|
8427
|
+
"src/app/App.tsx",
|
|
8428
|
+
"App.tsx",
|
|
8429
|
+
"src/Home.tsx"
|
|
8430
|
+
]) {
|
|
8431
|
+
const file = path.join(sourceDirectory, relative);
|
|
8432
|
+
if (!await exists(file)) continue;
|
|
8433
|
+
const identity = exportIdentity(sourceFile(file, await readFile(file, "utf8")));
|
|
8434
|
+
return {
|
|
8435
|
+
bootstrapFile: null,
|
|
8436
|
+
pageFile: portable$4(relative),
|
|
8437
|
+
...identity,
|
|
8438
|
+
layoutFiles: []
|
|
8439
|
+
};
|
|
8440
|
+
}
|
|
8441
|
+
return null;
|
|
8442
|
+
}
|
|
8443
|
+
async function nextEntrypoint(sourceDirectory) {
|
|
8444
|
+
for (const relative of [
|
|
8445
|
+
"src/app/page.tsx",
|
|
8446
|
+
"app/page.tsx",
|
|
8447
|
+
"src/pages/index.tsx",
|
|
8448
|
+
"pages/index.tsx"
|
|
8449
|
+
]) {
|
|
8450
|
+
const file = path.join(sourceDirectory, relative);
|
|
8451
|
+
if (!await exists(file)) continue;
|
|
8452
|
+
const identity = exportIdentity(sourceFile(file, await readFile(file, "utf8")));
|
|
8453
|
+
const layouts = [];
|
|
8454
|
+
if (relative.includes("/app/") || relative.startsWith("app/")) {
|
|
8455
|
+
let current = path.dirname(file);
|
|
8456
|
+
while (current.startsWith(sourceDirectory)) {
|
|
8457
|
+
const layout = path.join(current, "layout.tsx");
|
|
8458
|
+
if (await exists(layout)) layouts.unshift(portable$4(path.relative(sourceDirectory, layout)));
|
|
8459
|
+
if (current === sourceDirectory) break;
|
|
8460
|
+
current = path.dirname(current);
|
|
8461
|
+
}
|
|
8462
|
+
}
|
|
8463
|
+
return {
|
|
8464
|
+
bootstrapFile: null,
|
|
8465
|
+
pageFile: portable$4(relative),
|
|
8466
|
+
...identity,
|
|
8467
|
+
layoutFiles: layouts
|
|
8468
|
+
};
|
|
8469
|
+
}
|
|
8470
|
+
return null;
|
|
8471
|
+
}
|
|
8472
|
+
async function discoverEntrypoint(sourceDirectory, framework) {
|
|
8473
|
+
return framework === "next" ? nextEntrypoint(sourceDirectory) : viteEntrypoint(sourceDirectory);
|
|
8474
|
+
}
|
|
8475
|
+
function localLooking(specifier) {
|
|
8476
|
+
return specifier.startsWith(".") || specifier.startsWith("/") || specifier.startsWith("@/") || specifier.startsWith("~/");
|
|
8477
|
+
}
|
|
8478
|
+
async function buildSourceDependencyGraph(sourceDirectory, framework) {
|
|
8479
|
+
const root = path.resolve(sourceDirectory);
|
|
8480
|
+
const resolver = createImportResolver(root);
|
|
8481
|
+
const entrypoint = await discoverEntrypoint(root, framework);
|
|
8482
|
+
if (!entrypoint) return {
|
|
8483
|
+
entrypoint: null,
|
|
8484
|
+
modules: [],
|
|
8485
|
+
dependencies: [],
|
|
8486
|
+
unresolvedImports: []
|
|
8487
|
+
};
|
|
8488
|
+
const roots = [
|
|
8489
|
+
entrypoint.bootstrapFile,
|
|
8490
|
+
entrypoint.pageFile,
|
|
8491
|
+
...entrypoint.layoutFiles
|
|
8492
|
+
].filter((file) => Boolean(file)).map((file) => path.join(root, file));
|
|
8493
|
+
const queue = [...new Set(roots)];
|
|
8494
|
+
const visited = /* @__PURE__ */ new Set();
|
|
8495
|
+
const modules = [];
|
|
8496
|
+
const unresolvedImports = [];
|
|
8497
|
+
const external = /* @__PURE__ */ new Map();
|
|
8498
|
+
while (queue.length) {
|
|
8499
|
+
const absoluteFile = path.resolve(queue.shift());
|
|
8500
|
+
if (visited.has(absoluteFile) || !await exists(absoluteFile)) continue;
|
|
8501
|
+
visited.add(absoluteFile);
|
|
8502
|
+
const kind = extensionKind(absoluteFile);
|
|
8503
|
+
if (!kind) continue;
|
|
8504
|
+
const relativeFile = portable$4(path.relative(root, absoluteFile));
|
|
8505
|
+
const dependencies = [];
|
|
8506
|
+
let business = /(?:^|\/)(?:api|auth|checkout|cart|carrinho|store|services?)(?:\/|\.)/i.test(relativeFile);
|
|
8507
|
+
let visual = kind === "STYLE" || kind === "ASSET";
|
|
8508
|
+
if (kind === "SOURCE") {
|
|
8509
|
+
const content = await readFile(absoluteFile, "utf8");
|
|
8510
|
+
const source = sourceFile(absoluteFile, content);
|
|
8511
|
+
visual = /<\s*[A-Za-z][\w.]*(?:\s|\/?>)/.test(content);
|
|
8512
|
+
for (const item of moduleSpecifiers(source)) {
|
|
8513
|
+
const resolvedFile = resolver.resolve(absoluteFile, item.specifier);
|
|
8514
|
+
const type = classifyDependency(item.specifier, resolvedFile);
|
|
8515
|
+
const isExternal = !resolvedFile;
|
|
8516
|
+
dependencies.push({
|
|
8517
|
+
specifier: item.specifier,
|
|
8518
|
+
resolvedFile,
|
|
8519
|
+
type,
|
|
8520
|
+
external: isExternal,
|
|
8521
|
+
dynamic: item.dynamic
|
|
8522
|
+
});
|
|
8523
|
+
if (resolvedFile) {
|
|
8524
|
+
if (!visited.has(resolvedFile)) queue.push(resolvedFile);
|
|
8525
|
+
continue;
|
|
8526
|
+
}
|
|
8527
|
+
if (localLooking(item.specifier)) {
|
|
8528
|
+
unresolvedImports.push({
|
|
8529
|
+
importer: relativeFile,
|
|
8530
|
+
specifier: item.specifier
|
|
8531
|
+
});
|
|
8532
|
+
continue;
|
|
8533
|
+
}
|
|
8534
|
+
const packageName = packageNameOf(item.specifier);
|
|
8535
|
+
if (!packageName || packageName === "react" || packageName === "react-dom" || packageName === "react/jsx-runtime") continue;
|
|
8536
|
+
const dependency = external.get(packageName) ?? {
|
|
8537
|
+
specifier: item.specifier,
|
|
8538
|
+
packageName,
|
|
8539
|
+
type,
|
|
8540
|
+
resolvedFile: null,
|
|
8541
|
+
importedBy: []
|
|
8542
|
+
};
|
|
8543
|
+
if (!dependency.importedBy.includes(relativeFile)) dependency.importedBy.push(relativeFile);
|
|
8544
|
+
if (type === "BUSINESS") dependency.type = "BUSINESS";
|
|
8545
|
+
external.set(packageName, dependency);
|
|
8546
|
+
if (type === "BUSINESS") business = true;
|
|
8547
|
+
if (type === "VISUAL") visual = true;
|
|
8548
|
+
}
|
|
8549
|
+
}
|
|
8550
|
+
modules.push({
|
|
8551
|
+
file: relativeFile,
|
|
8552
|
+
absolutePath: absoluteFile,
|
|
8553
|
+
kind,
|
|
8554
|
+
dependencies,
|
|
8555
|
+
business,
|
|
8556
|
+
visual
|
|
8557
|
+
});
|
|
8558
|
+
}
|
|
8559
|
+
return {
|
|
8560
|
+
entrypoint,
|
|
8561
|
+
modules,
|
|
8562
|
+
dependencies: [...external.values()].sort((left, right) => (left.packageName ?? "").localeCompare(right.packageName ?? "")),
|
|
8563
|
+
unresolvedImports
|
|
8564
|
+
};
|
|
8565
|
+
}
|
|
8566
|
+
//#endregion
|
|
7906
8567
|
//#region src/migrate/analyzer.ts
|
|
7907
8568
|
var IGNORED_DIRECTORIES$1 = /* @__PURE__ */ new Set([
|
|
7908
8569
|
".git",
|
|
@@ -7944,7 +8605,7 @@ var ASSET_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
7944
8605
|
]);
|
|
7945
8606
|
var MAX_SOURCE_FILES = 2e3;
|
|
7946
8607
|
var MAX_SOURCE_BYTES = 2097152;
|
|
7947
|
-
function portable$
|
|
8608
|
+
function portable$3(file) {
|
|
7948
8609
|
return file.split(path.sep).join("/");
|
|
7949
8610
|
}
|
|
7950
8611
|
function inside$1(root, candidate) {
|
|
@@ -8251,7 +8912,7 @@ async function analyzeComponentFile(absoluteFile, sourceDirectory, framework) {
|
|
|
8251
8912
|
const content = await readFile(absoluteFile, "utf8");
|
|
8252
8913
|
const source = ts.createSourceFile(absoluteFile, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
|
8253
8914
|
const imports = importsOf(source);
|
|
8254
|
-
const relativeFile = portable$
|
|
8915
|
+
const relativeFile = portable$3(path.relative(sourceDirectory, absoluteFile));
|
|
8255
8916
|
const styles = [];
|
|
8256
8917
|
const assets = [];
|
|
8257
8918
|
for (const item of imports) {
|
|
@@ -8282,8 +8943,8 @@ async function analyzeComponentFile(absoluteFile, sourceDirectory, framework) {
|
|
|
8282
8943
|
page: pageFile(relativeFile, framework),
|
|
8283
8944
|
line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1,
|
|
8284
8945
|
imports,
|
|
8285
|
-
styleImports: styles.map((file) => portable$
|
|
8286
|
-
assetImports: assets.map((file) => portable$
|
|
8946
|
+
styleImports: styles.map((file) => portable$3(path.relative(sourceDirectory, file))),
|
|
8947
|
+
assetImports: assets.map((file) => portable$3(path.relative(sourceDirectory, file))),
|
|
8287
8948
|
jsx,
|
|
8288
8949
|
rootClasses: jsx.find(({ depth }) => depth === 0)?.classes ?? jsx[0]?.classes ?? [],
|
|
8289
8950
|
text: [...new Set(jsx.flatMap((item) => item.text))].slice(0, 30),
|
|
@@ -8332,8 +8993,8 @@ function tailwindAnalysis(files, dependencies, sourceDirectory) {
|
|
|
8332
8993
|
detected: Boolean(version || config),
|
|
8333
8994
|
version,
|
|
8334
8995
|
major: match ? Number(match[1]) : null,
|
|
8335
|
-
configFile: config ? portable$
|
|
8336
|
-
postcssFile: postcss ? portable$
|
|
8996
|
+
configFile: config ? portable$3(path.relative(sourceDirectory, config)) : null,
|
|
8997
|
+
postcssFile: postcss ? portable$3(path.relative(sourceDirectory, postcss)) : null,
|
|
8337
8998
|
colors: tailwindColors(config)
|
|
8338
8999
|
};
|
|
8339
9000
|
}
|
|
@@ -8346,7 +9007,7 @@ function addAsset(target, absolutePath, sourceDirectory, referencedBy) {
|
|
|
8346
9007
|
return;
|
|
8347
9008
|
}
|
|
8348
9009
|
target.set(key, {
|
|
8349
|
-
file: portable$
|
|
9010
|
+
file: portable$3(path.relative(sourceDirectory, key)),
|
|
8350
9011
|
absolutePath: key,
|
|
8351
9012
|
kind: assetKind(path.extname(key).toLowerCase()),
|
|
8352
9013
|
referencedBy: [referencedBy]
|
|
@@ -8387,7 +9048,7 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8387
9048
|
const analyzed = await analyzeComponentFile(file, sourceDirectory, framework);
|
|
8388
9049
|
components.push(...analyzed.components);
|
|
8389
9050
|
analyzed.styles.forEach((style) => referencedStyles.add(path.resolve(style)));
|
|
8390
|
-
analyzed.assets.forEach((asset) => addAsset(assetMap, asset, sourceDirectory, portable$
|
|
9051
|
+
analyzed.assets.forEach((asset) => addAsset(assetMap, asset, sourceDirectory, portable$3(path.relative(sourceDirectory, file))));
|
|
8391
9052
|
}
|
|
8392
9053
|
for (const file of files.filter((candidate) => candidate.endsWith(".ts") && !candidate.endsWith(".d.ts"))) {
|
|
8393
9054
|
if ((await stat(file)).size > MAX_SOURCE_BYTES) continue;
|
|
@@ -8396,7 +9057,7 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8396
9057
|
const signals = businessSignals(source, importsOf(source));
|
|
8397
9058
|
if (!signals.length) continue;
|
|
8398
9059
|
ignoredFiles.push({
|
|
8399
|
-
file: portable$
|
|
9060
|
+
file: portable$3(path.relative(sourceDirectory, file)),
|
|
8400
9061
|
reason: signals.join(", ")
|
|
8401
9062
|
});
|
|
8402
9063
|
}
|
|
@@ -8404,7 +9065,7 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8404
9065
|
for (const file of files.filter((candidate) => STYLE_EXTENSIONS.has(path.extname(candidate).toLowerCase()))) {
|
|
8405
9066
|
const content = await readFile(file, "utf8");
|
|
8406
9067
|
colorLiterals(content).forEach((color) => detectedColors.add(color));
|
|
8407
|
-
const relativeFile = portable$
|
|
9068
|
+
const relativeFile = portable$3(path.relative(sourceDirectory, file));
|
|
8408
9069
|
styles.push({
|
|
8409
9070
|
file: relativeFile,
|
|
8410
9071
|
absolutePath: file,
|
|
@@ -8427,9 +9088,12 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8427
9088
|
}
|
|
8428
9089
|
}
|
|
8429
9090
|
}
|
|
9091
|
+
const projectName = typeof packageJson.name === "string" && packageJson.name.trim() ? packageJson.name.trim() : path.basename(sourceDirectory);
|
|
9092
|
+
const sourceGraph = await buildSourceDependencyGraph(sourceDirectory, framework);
|
|
9093
|
+
const graphWarnings = sourceGraph.entrypoint ? sourceGraph.unresolvedImports.map(({ importer, specifier }) => `${importer}: import local não resolvido (${specifier}).`) : ["Entrypoint visual da Home não identificado; será usado o adaptador estrutural legado."];
|
|
8430
9094
|
return {
|
|
8431
9095
|
sourceDirectory,
|
|
8432
|
-
projectName
|
|
9096
|
+
projectName,
|
|
8433
9097
|
framework,
|
|
8434
9098
|
sourceRoots: detectSourceRoots(sourceDirectory, files),
|
|
8435
9099
|
packageJson,
|
|
@@ -8440,7 +9104,8 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8440
9104
|
tailwind: tailwindAnalysis(files, dependencies, sourceDirectory),
|
|
8441
9105
|
colorLiterals: [...detectedColors],
|
|
8442
9106
|
ignoredFiles,
|
|
8443
|
-
warnings: styles.some(({ file }) => /\.(?:scss|sass|less)$/.test(file)) ? ["
|
|
9107
|
+
warnings: [...styles.some(({ file }) => /\.(?:scss|sass|less)$/.test(file)) ? ["Sass/Less detectado: os arquivos alcançáveis serão preservados, mas exigem o compilador correspondente no tema."] : [], ...graphWarnings],
|
|
9108
|
+
sourceGraph
|
|
8444
9109
|
};
|
|
8445
9110
|
}
|
|
8446
9111
|
//#endregion
|
|
@@ -8654,16 +9319,16 @@ function classifyProject(input) {
|
|
|
8654
9319
|
}
|
|
8655
9320
|
//#endregion
|
|
8656
9321
|
//#region src/migrate/asset-copier.ts
|
|
8657
|
-
function portable$
|
|
9322
|
+
function portable$2(file) {
|
|
8658
9323
|
return file.split(path.sep).join("/");
|
|
8659
9324
|
}
|
|
8660
9325
|
function safeRelative(file) {
|
|
8661
|
-
return portable$
|
|
9326
|
+
return portable$2(file).split("/").filter((part) => part && part !== "." && part !== "..").map((part) => part.replace(/[^a-zA-Z0-9._-]/g, "-")).join("/");
|
|
8662
9327
|
}
|
|
8663
|
-
async function copyMigrationAssets(plan, outputDirectory) {
|
|
9328
|
+
async function copyMigrationAssets(plan, outputDirectory, assets = plan.assets) {
|
|
8664
9329
|
const copied = [];
|
|
8665
9330
|
const destinationRoot = path.join(outputDirectory, "src", "assets");
|
|
8666
|
-
for (const asset of
|
|
9331
|
+
for (const asset of assets) {
|
|
8667
9332
|
try {
|
|
8668
9333
|
if (!(await stat(asset.absolutePath)).isFile()) continue;
|
|
8669
9334
|
} catch {
|
|
@@ -8678,89 +9343,651 @@ async function copyMigrationAssets(plan, outputDirectory) {
|
|
|
8678
9343
|
copied.push({
|
|
8679
9344
|
sourceFile: asset.absolutePath,
|
|
8680
9345
|
outputFile: destination,
|
|
8681
|
-
importPath: `../assets/${portable$
|
|
9346
|
+
importPath: `../assets/${portable$2(relative)}`,
|
|
8682
9347
|
kind: asset.kind
|
|
8683
9348
|
});
|
|
8684
9349
|
}
|
|
8685
9350
|
return copied;
|
|
8686
9351
|
}
|
|
8687
9352
|
//#endregion
|
|
8688
|
-
//#region src/migrate/
|
|
8689
|
-
function portable(file) {
|
|
9353
|
+
//#region src/migrate/transform/source-transformer.ts
|
|
9354
|
+
function portable$1(file) {
|
|
8690
9355
|
return file.split(path.sep).join("/");
|
|
8691
9356
|
}
|
|
8692
|
-
function
|
|
8693
|
-
|
|
8694
|
-
|
|
8695
|
-
|
|
8696
|
-
return plan.selected[role]?.classes ?? {
|
|
8697
|
-
root: "",
|
|
8698
|
-
brand: "",
|
|
8699
|
-
navigation: "",
|
|
8700
|
-
title: "",
|
|
8701
|
-
text: "",
|
|
8702
|
-
action: "",
|
|
8703
|
-
media: "",
|
|
8704
|
-
grid: "",
|
|
8705
|
-
card: "",
|
|
8706
|
-
content: ""
|
|
8707
|
-
};
|
|
8708
|
-
}
|
|
8709
|
-
function sourceText(plan, role, fallback) {
|
|
8710
|
-
return plan.selected[role]?.component.text.find((candidate) => candidate.length >= 3 && candidate.length <= 140) || fallback;
|
|
8711
|
-
}
|
|
8712
|
-
function headerSource(plan) {
|
|
8713
|
-
const style = profile(plan, "HEADER");
|
|
8714
|
-
return `import type { HeaderProps } from "@nuvler/theme-sdk";
|
|
8715
|
-
|
|
8716
|
-
export function Header({ site, categories, pages }: HeaderProps) {
|
|
8717
|
-
const name = site.settings?.siteName || site.tenant.name;
|
|
8718
|
-
return <header className=${classes("nuvler-migrated-header", style.root)}>
|
|
8719
|
-
<div className=${classes("nuvler-migrated-header-inner", style.content)}>
|
|
8720
|
-
<a className=${classes("nuvler-migrated-brand", style.brand)} href="/">
|
|
8721
|
-
{site.settings?.logo?.url ? <img src={site.settings.logo.url} alt={site.settings.logo.alt || name} /> : <span>{name}</span>}
|
|
8722
|
-
</a>
|
|
8723
|
-
<nav className=${classes("nuvler-migrated-nav", style.navigation)} aria-label="Navegação principal">
|
|
8724
|
-
<a href="/">Início</a>
|
|
8725
|
-
{site.modules.includes("PRODUCTS") && <a href="/produtos">Produtos</a>}
|
|
8726
|
-
{categories.slice(0, 6).map((category) => <a href={\`/\${category.slug}\`} key={category.slug}>{category.name}</a>)}
|
|
8727
|
-
{pages.slice(0, 4).map((page) => <a href={\`/\${page.slug}\`} key={page.slug}>{page.title}</a>)}
|
|
8728
|
-
</nav>
|
|
8729
|
-
{site.modules.includes("PRODUCTS") && <form className="nuvler-migrated-search" action="/produtos">
|
|
8730
|
-
<input name="busca" type="search" placeholder="Buscar produtos" />
|
|
8731
|
-
<button className=${classes("nuvler-migrated-action", style.action)} type="submit">Buscar</button>
|
|
8732
|
-
</form>}
|
|
8733
|
-
</div>
|
|
8734
|
-
</header>;
|
|
8735
|
-
}
|
|
8736
|
-
`;
|
|
9357
|
+
function relativeImport(fromFile, toFile) {
|
|
9358
|
+
let relative = portable$1(path.relative(path.dirname(fromFile), toFile));
|
|
9359
|
+
if (/\.(?:tsx?|jsx?|mts|cts)$/i.test(relative)) relative = relative.replace(/\.(?:tsx?|jsx?|mts|cts)$/i, "");
|
|
9360
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
8737
9361
|
}
|
|
8738
|
-
function
|
|
8739
|
-
|
|
8740
|
-
return `import type { FooterProps } from "@nuvler/theme-sdk";
|
|
8741
|
-
|
|
8742
|
-
export function Footer({ site, pages, template }: FooterProps) {
|
|
8743
|
-
const name = site.settings?.siteName || site.tenant.name;
|
|
8744
|
-
return <footer className=${classes("nuvler-migrated-footer", style.root)}>
|
|
8745
|
-
<div className=${classes("nuvler-migrated-footer-inner", style.content)}>
|
|
8746
|
-
<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>
|
|
8747
|
-
<nav className=${classes("nuvler-migrated-footer-nav", style.navigation)} aria-label={template.footerNavigationLabel}>
|
|
8748
|
-
<a href="/">Início</a>
|
|
8749
|
-
{site.modules.includes("PRODUCTS") && <a href="/produtos">Produtos</a>}
|
|
8750
|
-
{pages.map((page) => <a href={\`/\${page.slug}\`} key={page.slug}>{page.title}</a>)}
|
|
8751
|
-
</nav>
|
|
8752
|
-
<div className="nuvler-migrated-contact">
|
|
8753
|
-
{site.settings?.contact.phone && <a href={\`tel:\${site.settings.contact.phone}\`}>{site.settings.contact.phone}</a>}
|
|
8754
|
-
{site.settings?.contact.email && <a href={\`mailto:\${site.settings.contact.email}\`}>{site.settings.contact.email}</a>}
|
|
8755
|
-
</div>
|
|
8756
|
-
</div>
|
|
8757
|
-
<small>{template.footerNote}</small>
|
|
8758
|
-
</footer>;
|
|
9362
|
+
function applyEdits(content, edits) {
|
|
9363
|
+
return edits.sort((left, right) => right.start - left.start).reduce((result, edit) => `${result.slice(0, edit.start)}${edit.text}${result.slice(edit.end)}`, content);
|
|
8759
9364
|
}
|
|
8760
|
-
|
|
9365
|
+
function scriptKind(file) {
|
|
9366
|
+
const extension = path.extname(file).toLowerCase();
|
|
9367
|
+
if (extension === ".tsx") return ts.ScriptKind.TSX;
|
|
9368
|
+
if (extension === ".jsx") return ts.ScriptKind.JSX;
|
|
9369
|
+
if ([
|
|
9370
|
+
".js",
|
|
9371
|
+
".mjs",
|
|
9372
|
+
".cjs"
|
|
9373
|
+
].includes(extension)) return ts.ScriptKind.JS;
|
|
9374
|
+
return ts.ScriptKind.TS;
|
|
9375
|
+
}
|
|
9376
|
+
function unwrappedExpression$1(expression) {
|
|
9377
|
+
if (ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression) || ts.isParenthesizedExpression(expression)) return unwrappedExpression$1(expression.expression);
|
|
9378
|
+
return expression;
|
|
9379
|
+
}
|
|
9380
|
+
function moduleLiteral(node) {
|
|
9381
|
+
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier && ts.isStringLiteralLike(node.moduleSpecifier)) return node.moduleSpecifier;
|
|
9382
|
+
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
9383
|
+
const argument = node.arguments[0];
|
|
9384
|
+
return argument && ts.isStringLiteralLike(argument) ? argument : null;
|
|
9385
|
+
}
|
|
9386
|
+
return null;
|
|
8761
9387
|
}
|
|
8762
|
-
function
|
|
8763
|
-
const
|
|
9388
|
+
function transformMigratedSource(module, content, graph, destinationFile, destinationBySource, options = {}) {
|
|
9389
|
+
const source = ts.createSourceFile(module.absolutePath, content, ts.ScriptTarget.Latest, true, scriptKind(module.absolutePath));
|
|
9390
|
+
const edits = [];
|
|
9391
|
+
const dependencyBySpecifier = new Map(module.dependencies.map((dependency) => [dependency.specifier, dependency]));
|
|
9392
|
+
const contentByComponent = new Map((options.content ?? []).map((item) => [item.componentName, item]));
|
|
9393
|
+
const removedComponents = new Set(options.removeComponents ?? []);
|
|
9394
|
+
function componentName(node) {
|
|
9395
|
+
if ("name" in node && node.name && ts.isIdentifier(node.name)) return node.name.text;
|
|
9396
|
+
const parent = node.parent;
|
|
9397
|
+
return ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name) ? parent.name.text : null;
|
|
9398
|
+
}
|
|
9399
|
+
function mappedField(key) {
|
|
9400
|
+
const normalized = key.toLowerCase();
|
|
9401
|
+
const parts = normalized.split(".");
|
|
9402
|
+
const last = parts.at(-1) ?? normalized;
|
|
9403
|
+
if (/(?:^|\.)(?:eyebrow|overline|kicker)$/.test(normalized)) return "eyebrow";
|
|
9404
|
+
if (["headline", "title"].includes(last) && parts.length <= 2) return "title";
|
|
9405
|
+
if ([
|
|
9406
|
+
"subtitle",
|
|
9407
|
+
"subheadline",
|
|
9408
|
+
"description",
|
|
9409
|
+
"desc",
|
|
9410
|
+
"text",
|
|
9411
|
+
"rights"
|
|
9412
|
+
].includes(last) && parts.length <= 2) return "description";
|
|
9413
|
+
if (/(?:^|\.)(?:cta|button|action|login)(?:\.|$)/.test(normalized)) return "buttonLabel";
|
|
9414
|
+
return null;
|
|
9415
|
+
}
|
|
9416
|
+
function adaptFunction(node, adaptation) {
|
|
9417
|
+
if (!node.body || !ts.isBlock(node.body)) return;
|
|
9418
|
+
const { bindingId, componentKey } = adaptation;
|
|
9419
|
+
const hookName = "__nuvlerSection";
|
|
9420
|
+
const mapped = /* @__PURE__ */ new Set();
|
|
9421
|
+
function findMapped(child) {
|
|
9422
|
+
if (ts.isCallExpression(child) && ts.isIdentifier(child.expression) && child.expression.text === "t" && child.arguments[0] && ts.isStringLiteralLike(child.arguments[0])) {
|
|
9423
|
+
const field = mappedField(child.arguments[0].text);
|
|
9424
|
+
if (field) mapped.add(field);
|
|
9425
|
+
}
|
|
9426
|
+
ts.forEachChild(child, findMapped);
|
|
9427
|
+
}
|
|
9428
|
+
findMapped(node.body);
|
|
9429
|
+
const fallbackUsed = new Set(mapped);
|
|
9430
|
+
const literalFieldsUsed = new Set(mapped);
|
|
9431
|
+
edits.push({
|
|
9432
|
+
start: node.body.getStart(source) + 1,
|
|
9433
|
+
end: node.body.getStart(source) + 1,
|
|
9434
|
+
text: `\n const ${hookName} = useMigratedSection(${JSON.stringify(bindingId)});${componentKey === "contact-form" ? `\n const __nuvlerSubmitContact = useMigratedContactForm(${JSON.stringify(bindingId)});` : ""}`
|
|
9435
|
+
});
|
|
9436
|
+
function adapt(child) {
|
|
9437
|
+
function jsxField(parent, literal = "") {
|
|
9438
|
+
if (!ts.isJsxElement(parent)) return null;
|
|
9439
|
+
const tag = parent.openingElement.tagName.getText(source).toLowerCase();
|
|
9440
|
+
let field = null;
|
|
9441
|
+
if (/^h[1-6]$/.test(tag)) field = "title";
|
|
9442
|
+
else if (tag === "p" || tag === "blockquote") field = "description";
|
|
9443
|
+
else if (tag === "a" || tag === "button") field = "buttonLabel";
|
|
9444
|
+
else if (tag === "span" || tag === "small") field = "eyebrow";
|
|
9445
|
+
else if (tag === "div" && literal.trim().length <= 100 && literal.trim() === literal.trim().toLocaleUpperCase("pt-BR") && /[A-ZÀ-Ü]/.test(literal)) field = "eyebrow";
|
|
9446
|
+
if (!field || literalFieldsUsed.has(field)) return null;
|
|
9447
|
+
literalFieldsUsed.add(field);
|
|
9448
|
+
return field;
|
|
9449
|
+
}
|
|
9450
|
+
if (componentKey === "contact-form" && ts.isJsxElement(child) && child.openingElement.tagName.getText(source).toLowerCase() === "form") {
|
|
9451
|
+
const submit = child.openingElement.attributes.properties.find((attribute) => ts.isJsxAttribute(attribute) && attribute.name.getText(source) === "onSubmit");
|
|
9452
|
+
if (submit?.initializer) edits.push({
|
|
9453
|
+
start: submit.initializer.getStart(source),
|
|
9454
|
+
end: submit.initializer.getEnd(),
|
|
9455
|
+
text: "{__nuvlerSubmitContact}"
|
|
9456
|
+
});
|
|
9457
|
+
else if (!submit) edits.push({
|
|
9458
|
+
start: child.openingElement.tagName.getEnd(),
|
|
9459
|
+
end: child.openingElement.tagName.getEnd(),
|
|
9460
|
+
text: " onSubmit={__nuvlerSubmitContact}"
|
|
9461
|
+
});
|
|
9462
|
+
edits.push({
|
|
9463
|
+
start: child.openingElement.getEnd(),
|
|
9464
|
+
end: child.closingElement.getStart(source),
|
|
9465
|
+
text: `\n <MigratedContactFields data={${hookName}} />\n `
|
|
9466
|
+
});
|
|
9467
|
+
return;
|
|
9468
|
+
}
|
|
9469
|
+
if (ts.isVariableDeclaration(child) && ts.isIdentifier(child.name) && child.initializer && ts.isArrayLiteralExpression(unwrappedExpression$1(child.initializer)) && (/(?:items?|faqs?|questions?|benefits?|features?|stats?|metrics?|numbers?|audiences?|profiles?|steps?)/i.test(child.name.text) || componentKey === "contacts" && /contacts?/i.test(child.name.text))) {
|
|
9470
|
+
edits.push({
|
|
9471
|
+
start: child.initializer.getStart(source),
|
|
9472
|
+
end: child.initializer.getEnd(),
|
|
9473
|
+
text: `migratedItems(${hookName})`
|
|
9474
|
+
});
|
|
9475
|
+
return;
|
|
9476
|
+
}
|
|
9477
|
+
if (ts.isPropertyAccessExpression(child) && child.name.text === "map" && ts.isIdentifier(child.expression) && (/(?:items?|faqs?|questions?|benefits?|features?|stats?|metrics?|numbers?|audiences?|profiles?|steps?)/i.test(child.expression.text) || componentKey === "contacts" && /contacts?/i.test(child.expression.text))) {
|
|
9478
|
+
edits.push({
|
|
9479
|
+
start: child.expression.getStart(source),
|
|
9480
|
+
end: child.expression.getEnd(),
|
|
9481
|
+
text: `migratedItems(${hookName})`
|
|
9482
|
+
});
|
|
9483
|
+
return;
|
|
9484
|
+
}
|
|
9485
|
+
if (componentKey === "feature-list" && ts.isPropertyAccessExpression(child) && child.name.text === "map" && ts.isArrayLiteralExpression(unwrappedExpression$1(child.expression))) {
|
|
9486
|
+
edits.push({
|
|
9487
|
+
start: child.expression.getStart(source),
|
|
9488
|
+
end: child.expression.getEnd(),
|
|
9489
|
+
text: `migratedItems(${hookName}).map((item) => migratedText(item, "title"))`
|
|
9490
|
+
});
|
|
9491
|
+
return;
|
|
9492
|
+
}
|
|
9493
|
+
if (ts.isCallExpression(child) && ts.isIdentifier(child.expression) && child.expression.text === "fetch") {
|
|
9494
|
+
edits.push({
|
|
9495
|
+
start: child.getStart(source),
|
|
9496
|
+
end: child.getEnd(),
|
|
9497
|
+
text: "Promise.reject(new Error(\"Fonte externa removida pela Nuvler Adaptation Pass\"))"
|
|
9498
|
+
});
|
|
9499
|
+
return;
|
|
9500
|
+
}
|
|
9501
|
+
if (ts.isCallExpression(child) && ts.isIdentifier(child.expression) && child.expression.text === "t" && child.arguments[0] && ts.isStringLiteralLike(child.arguments[0])) {
|
|
9502
|
+
let field = mappedField(child.arguments[0].text);
|
|
9503
|
+
if (!field) {
|
|
9504
|
+
const key = child.arguments[0].text.toLowerCase();
|
|
9505
|
+
const last = key.split(".").at(-1) ?? key;
|
|
9506
|
+
if (!fallbackUsed.has("description") && (/^(?:desc|description|subtitle|text|a\d+)$/.test(last) || key.includes(".typed."))) field = "description";
|
|
9507
|
+
else if (!fallbackUsed.has("title") && /^(?:title|headline|name|q\d+)$/.test(last)) field = "title";
|
|
9508
|
+
if (field) fallbackUsed.add(field);
|
|
9509
|
+
}
|
|
9510
|
+
edits.push({
|
|
9511
|
+
start: child.getStart(source),
|
|
9512
|
+
end: child.getEnd(),
|
|
9513
|
+
text: field ? `migratedText(${hookName}, ${JSON.stringify(field)})` : "\"\""
|
|
9514
|
+
});
|
|
9515
|
+
return;
|
|
9516
|
+
}
|
|
9517
|
+
if (ts.isJsxText(child) && child.text.trim()) {
|
|
9518
|
+
const field = jsxField(child.parent, child.text);
|
|
9519
|
+
const replacement = field ? `{migratedText(${hookName}, ${JSON.stringify(field)})}` : "{null}";
|
|
9520
|
+
edits.push({
|
|
9521
|
+
start: child.getStart(source),
|
|
9522
|
+
end: child.getEnd(),
|
|
9523
|
+
text: replacement
|
|
9524
|
+
});
|
|
9525
|
+
return;
|
|
9526
|
+
}
|
|
9527
|
+
if (ts.isJsxExpression(child) && child.expression && ts.isStringLiteralLike(child.expression)) {
|
|
9528
|
+
const field = jsxField(child.parent, child.expression.text);
|
|
9529
|
+
edits.push({
|
|
9530
|
+
start: child.getStart(source),
|
|
9531
|
+
end: child.getEnd(),
|
|
9532
|
+
text: field ? `{migratedText(${hookName}, ${JSON.stringify(field)})}` : "{null}"
|
|
9533
|
+
});
|
|
9534
|
+
return;
|
|
9535
|
+
}
|
|
9536
|
+
if (ts.isJsxAttribute(child)) {
|
|
9537
|
+
const name = child.name.getText(source);
|
|
9538
|
+
const tag = child.parent.parent.tagName.getText(source).toLowerCase();
|
|
9539
|
+
const imageTag = tag === "img" || tag === "image";
|
|
9540
|
+
if (child.initializer && (imageTag && name === "src" || tag === "video" && ["src", "poster"].includes(name) || ["source", "iframe"].includes(tag) && name === "src")) {
|
|
9541
|
+
edits.push({
|
|
9542
|
+
start: child.initializer.getStart(source),
|
|
9543
|
+
end: child.initializer.getEnd(),
|
|
9544
|
+
text: tag === "source" || tag === "iframe" || tag === "video" && name === "src" ? `{migratedVideo(${hookName})}` : `{migratedImage(${hookName})}`
|
|
9545
|
+
});
|
|
9546
|
+
return;
|
|
9547
|
+
}
|
|
9548
|
+
if (child.initializer && imageTag && name === "alt") {
|
|
9549
|
+
edits.push({
|
|
9550
|
+
start: child.initializer.getStart(source),
|
|
9551
|
+
end: child.initializer.getEnd(),
|
|
9552
|
+
text: `{migratedText(${hookName}, "imageAlt")}`
|
|
9553
|
+
});
|
|
9554
|
+
return;
|
|
9555
|
+
}
|
|
9556
|
+
if (child.initializer && tag === "a" && name === "href") {
|
|
9557
|
+
edits.push({
|
|
9558
|
+
start: child.initializer.getStart(source),
|
|
9559
|
+
end: child.initializer.getEnd(),
|
|
9560
|
+
text: `{migratedLink(${hookName})}`
|
|
9561
|
+
});
|
|
9562
|
+
return;
|
|
9563
|
+
}
|
|
9564
|
+
}
|
|
9565
|
+
ts.forEachChild(child, adapt);
|
|
9566
|
+
}
|
|
9567
|
+
adapt(node.body);
|
|
9568
|
+
}
|
|
9569
|
+
function visit(node) {
|
|
9570
|
+
if (options.unwrapDocumentTags && ts.isJsxElement(node)) {
|
|
9571
|
+
const tag = node.openingElement.tagName.getText(source).toLowerCase();
|
|
9572
|
+
if (tag === "html" || tag === "body") {
|
|
9573
|
+
edits.push({
|
|
9574
|
+
start: node.openingElement.getStart(source),
|
|
9575
|
+
end: node.openingElement.getEnd(),
|
|
9576
|
+
text: "<>"
|
|
9577
|
+
});
|
|
9578
|
+
edits.push({
|
|
9579
|
+
start: node.closingElement.getStart(source),
|
|
9580
|
+
end: node.closingElement.getEnd(),
|
|
9581
|
+
text: "</>"
|
|
9582
|
+
});
|
|
9583
|
+
}
|
|
9584
|
+
}
|
|
9585
|
+
if (contentByComponent.size && ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && /^(?:translations?|messages?|dictionary|locales?)$/i.test(node.name.text) && node.initializer && ts.isObjectLiteralExpression(node.initializer)) {
|
|
9586
|
+
edits.push({
|
|
9587
|
+
start: node.initializer.getStart(source),
|
|
9588
|
+
end: node.initializer.getEnd(),
|
|
9589
|
+
text: "new Proxy({} as any, { get: () => new Proxy({}, { get: () => \" \" }) })"
|
|
9590
|
+
});
|
|
9591
|
+
return;
|
|
9592
|
+
}
|
|
9593
|
+
if (ts.isJsxSelfClosingElement(node) || ts.isJsxElement(node)) {
|
|
9594
|
+
const tagName = ts.isJsxElement(node) ? node.openingElement.tagName.getText(source) : node.tagName.getText(source);
|
|
9595
|
+
if (removedComponents.has(tagName)) {
|
|
9596
|
+
edits.push({
|
|
9597
|
+
start: node.getStart(source),
|
|
9598
|
+
end: node.getEnd(),
|
|
9599
|
+
text: "{null}"
|
|
9600
|
+
});
|
|
9601
|
+
return;
|
|
9602
|
+
}
|
|
9603
|
+
}
|
|
9604
|
+
if (ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node)) {
|
|
9605
|
+
const name = componentName(node);
|
|
9606
|
+
const adaptation = name ? contentByComponent.get(name) : void 0;
|
|
9607
|
+
if (adaptation) adaptFunction(node, adaptation);
|
|
9608
|
+
}
|
|
9609
|
+
const literal = moduleLiteral(node);
|
|
9610
|
+
if (literal) {
|
|
9611
|
+
const dependency = dependencyBySpecifier.get(literal.text);
|
|
9612
|
+
if (ts.isImportDeclaration(node) && literal.text === "next/image" && options.nextImageAdapterFile) {
|
|
9613
|
+
const replacement = relativeImport(destinationFile, options.nextImageAdapterFile);
|
|
9614
|
+
edits.push({
|
|
9615
|
+
start: literal.getStart(source) + 1,
|
|
9616
|
+
end: literal.getEnd() - 1,
|
|
9617
|
+
text: replacement
|
|
9618
|
+
});
|
|
9619
|
+
} else if (dependency?.resolvedFile && ts.isImportDeclaration(node) && !node.importClause && /(?<!\.module)\.(?:css|scss|sass|less)$/i.test(dependency.resolvedFile)) edits.push({
|
|
9620
|
+
start: node.getFullStart(),
|
|
9621
|
+
end: node.getEnd(),
|
|
9622
|
+
text: ""
|
|
9623
|
+
});
|
|
9624
|
+
else if (dependency?.resolvedFile) {
|
|
9625
|
+
const target = destinationBySource.get(path.resolve(dependency.resolvedFile));
|
|
9626
|
+
if (target) {
|
|
9627
|
+
const replacement = relativeImport(destinationFile, target);
|
|
9628
|
+
edits.push({
|
|
9629
|
+
start: literal.getStart(source) + 1,
|
|
9630
|
+
end: literal.getEnd() - 1,
|
|
9631
|
+
text: replacement
|
|
9632
|
+
});
|
|
9633
|
+
}
|
|
9634
|
+
}
|
|
9635
|
+
}
|
|
9636
|
+
if (ts.isJsxAttribute(node) && !contentByComponent.size && ["src", "poster"].includes(node.name.getText(source)) && node.initializer && ts.isStringLiteral(node.initializer) && node.initializer.text.startsWith("/")) {
|
|
9637
|
+
const suffix = `${path.sep}public${node.initializer.text.split("/").join(path.sep)}`;
|
|
9638
|
+
const target = [...destinationBySource.entries()].find(([sourceFile]) => sourceFile.endsWith(suffix))?.[1];
|
|
9639
|
+
if (target) edits.push({
|
|
9640
|
+
start: node.initializer.getStart(source),
|
|
9641
|
+
end: node.initializer.getEnd(),
|
|
9642
|
+
text: `{new URL(${JSON.stringify(relativeImport(destinationFile, target))}, import.meta.url).href}`
|
|
9643
|
+
});
|
|
9644
|
+
}
|
|
9645
|
+
ts.forEachChild(node, visit);
|
|
9646
|
+
}
|
|
9647
|
+
visit(source);
|
|
9648
|
+
if (contentByComponent.size && options.contentAdapterFile) {
|
|
9649
|
+
const adapterImport = relativeImport(destinationFile, options.contentAdapterFile);
|
|
9650
|
+
edits.push({
|
|
9651
|
+
start: 0,
|
|
9652
|
+
end: 0,
|
|
9653
|
+
text: `import { MigratedContactFields, migratedImage, migratedItems, migratedLink, migratedText, migratedVideo, useMigratedContactForm, useMigratedSection } from ${JSON.stringify(adapterImport)};\n`
|
|
9654
|
+
});
|
|
9655
|
+
}
|
|
9656
|
+
return applyEdits(content, edits);
|
|
9657
|
+
}
|
|
9658
|
+
function exportedNames(source) {
|
|
9659
|
+
const values = /* @__PURE__ */ new Set();
|
|
9660
|
+
const types = /* @__PURE__ */ new Set();
|
|
9661
|
+
let hasDefault = false;
|
|
9662
|
+
for (const statement of source.statements) {
|
|
9663
|
+
const modifiers = "modifiers" in statement ? statement.modifiers : void 0;
|
|
9664
|
+
const exported = modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? false;
|
|
9665
|
+
const isDefault = modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword) ?? false;
|
|
9666
|
+
if (ts.isExportAssignment(statement)) hasDefault = true;
|
|
9667
|
+
if (isDefault) hasDefault = true;
|
|
9668
|
+
if (!exported) continue;
|
|
9669
|
+
if (ts.isVariableStatement(statement)) {
|
|
9670
|
+
for (const declaration of statement.declarationList.declarations) if (ts.isIdentifier(declaration.name)) values.add(declaration.name.text);
|
|
9671
|
+
} else if (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement)) {
|
|
9672
|
+
if (statement.name) values.add(statement.name.text);
|
|
9673
|
+
} else if (ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement)) types.add(statement.name.text);
|
|
9674
|
+
}
|
|
9675
|
+
for (const statement of source.statements.filter(ts.isExportDeclaration)) {
|
|
9676
|
+
if (!statement.exportClause || !ts.isNamedExports(statement.exportClause)) continue;
|
|
9677
|
+
for (const element of statement.exportClause.elements) values.add(element.name.text);
|
|
9678
|
+
}
|
|
9679
|
+
return {
|
|
9680
|
+
values,
|
|
9681
|
+
types,
|
|
9682
|
+
hasDefault
|
|
9683
|
+
};
|
|
9684
|
+
}
|
|
9685
|
+
function businessModuleStub(file, content) {
|
|
9686
|
+
const exported = exportedNames(ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true, scriptKind(file)));
|
|
9687
|
+
const lines = [
|
|
9688
|
+
"/* Adaptador temporário: regra de negócio da aplicação original isolada da Fidelity Pass. */",
|
|
9689
|
+
...[...exported.types].map((name) => `export type ${name} = any;`),
|
|
9690
|
+
...[...exported.values].map((name) => `export const ${name}: any = (..._args: any[]) => undefined;`)
|
|
9691
|
+
];
|
|
9692
|
+
if (exported.hasDefault) lines.push("const migratedBusinessDefault: any = (..._args: any[]) => undefined;", "export default migratedBusinessDefault;");
|
|
9693
|
+
if (!exported.hasDefault && !exported.values.size && !exported.types.size) lines.push("export {};");
|
|
9694
|
+
return `${lines.join("\n")}\n`;
|
|
9695
|
+
}
|
|
9696
|
+
//#endregion
|
|
9697
|
+
//#region src/migrate/generation/fidelity-pass.ts
|
|
9698
|
+
function destinationFor(directory, sourceFile) {
|
|
9699
|
+
return path.join(directory, "src", "migrated", "source", sourceFile);
|
|
9700
|
+
}
|
|
9701
|
+
function importPath(fromDirectory, target) {
|
|
9702
|
+
let relative = path.relative(fromDirectory, target).split(path.sep).join("/");
|
|
9703
|
+
relative = relative.replace(/\.(?:tsx?|jsx?|mts|cts)$/i, "");
|
|
9704
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
9705
|
+
}
|
|
9706
|
+
function sourceModule(plan, relativeFile) {
|
|
9707
|
+
return plan.analysis.sourceGraph.modules.find((module) => module.file === relativeFile);
|
|
9708
|
+
}
|
|
9709
|
+
function contentAdaptations(plan) {
|
|
9710
|
+
const result = /* @__PURE__ */ new Map();
|
|
9711
|
+
const modules = new Map(plan.analysis.sourceGraph.modules.map((module) => [path.resolve(module.absolutePath), module]));
|
|
9712
|
+
const componentsByFile = /* @__PURE__ */ new Map();
|
|
9713
|
+
for (const component of plan.analysis.components) {
|
|
9714
|
+
const components = componentsByFile.get(component.file) ?? [];
|
|
9715
|
+
components.push(component);
|
|
9716
|
+
componentsByFile.set(component.file, components);
|
|
9717
|
+
}
|
|
9718
|
+
const roots = [...plan.contentBindings.map((binding) => ({ binding }))];
|
|
9719
|
+
if (plan.selected.HEADER) roots.push({
|
|
9720
|
+
binding: {
|
|
9721
|
+
id: "__header",
|
|
9722
|
+
file: plan.selected.HEADER.component.file,
|
|
9723
|
+
component: plan.selected.HEADER.component.name
|
|
9724
|
+
},
|
|
9725
|
+
special: true
|
|
9726
|
+
});
|
|
9727
|
+
if (plan.selected.FOOTER) roots.push({
|
|
9728
|
+
binding: {
|
|
9729
|
+
id: "__footer",
|
|
9730
|
+
file: plan.selected.FOOTER.component.file,
|
|
9731
|
+
component: plan.selected.FOOTER.component.name
|
|
9732
|
+
},
|
|
9733
|
+
special: true
|
|
9734
|
+
});
|
|
9735
|
+
const rootFiles = new Set(roots.map(({ binding }) => binding.file));
|
|
9736
|
+
const claimed = /* @__PURE__ */ new Map();
|
|
9737
|
+
for (const { binding } of roots) {
|
|
9738
|
+
const current = result.get(binding.file) ?? [];
|
|
9739
|
+
if (!current.some((item) => item.componentName === binding.component)) {
|
|
9740
|
+
current.push({
|
|
9741
|
+
componentName: binding.component,
|
|
9742
|
+
bindingId: binding.id,
|
|
9743
|
+
componentKey: binding.componentKey
|
|
9744
|
+
});
|
|
9745
|
+
result.set(binding.file, current);
|
|
9746
|
+
}
|
|
9747
|
+
}
|
|
9748
|
+
const explicitRoots = new Set(roots.map(({ binding }) => `${binding.file}#${binding.component}`));
|
|
9749
|
+
for (const { binding } of roots) {
|
|
9750
|
+
const localComponents = componentsByFile.get(binding.file) ?? [];
|
|
9751
|
+
const localByName = new Map(localComponents.map((component) => [component.name, component]));
|
|
9752
|
+
const rootComponent = localByName.get(binding.component);
|
|
9753
|
+
if (!rootComponent) continue;
|
|
9754
|
+
const pending = [rootComponent];
|
|
9755
|
+
const visited = /* @__PURE__ */ new Set([rootComponent.name]);
|
|
9756
|
+
while (pending.length) {
|
|
9757
|
+
const owner = pending.shift();
|
|
9758
|
+
for (const node of owner.jsx) {
|
|
9759
|
+
const childName = node.tag.split(".")[0];
|
|
9760
|
+
const child = localByName.get(childName);
|
|
9761
|
+
if (!child || visited.has(child.name)) continue;
|
|
9762
|
+
visited.add(child.name);
|
|
9763
|
+
if (explicitRoots.has(`${binding.file}#${child.name}`)) continue;
|
|
9764
|
+
const current = result.get(binding.file) ?? [];
|
|
9765
|
+
if (!current.some((item) => item.componentName === child.name)) {
|
|
9766
|
+
current.push({
|
|
9767
|
+
componentName: child.name,
|
|
9768
|
+
bindingId: binding.id,
|
|
9769
|
+
componentKey: binding.componentKey
|
|
9770
|
+
});
|
|
9771
|
+
result.set(binding.file, current);
|
|
9772
|
+
pending.push(child);
|
|
9773
|
+
}
|
|
9774
|
+
}
|
|
9775
|
+
}
|
|
9776
|
+
}
|
|
9777
|
+
for (const { binding } of roots) {
|
|
9778
|
+
const root = plan.analysis.sourceGraph.modules.find((module) => module.file === binding.file);
|
|
9779
|
+
if (!root) continue;
|
|
9780
|
+
const queue = [root];
|
|
9781
|
+
const visited = /* @__PURE__ */ new Set();
|
|
9782
|
+
while (queue.length) {
|
|
9783
|
+
const module = queue.shift();
|
|
9784
|
+
if (visited.has(module.file)) continue;
|
|
9785
|
+
visited.add(module.file);
|
|
9786
|
+
if (module.file !== binding.file && rootFiles.has(module.file)) continue;
|
|
9787
|
+
const previousOwner = claimed.get(module.file);
|
|
9788
|
+
if (previousOwner && previousOwner !== binding.id) continue;
|
|
9789
|
+
claimed.set(module.file, binding.id);
|
|
9790
|
+
for (const component of module.file === binding.file ? [] : componentsByFile.get(module.file) ?? []) {
|
|
9791
|
+
const current = result.get(module.file) ?? [];
|
|
9792
|
+
if (!current.some((item) => item.componentName === component.name)) {
|
|
9793
|
+
current.push({
|
|
9794
|
+
componentName: component.name,
|
|
9795
|
+
bindingId: binding.id,
|
|
9796
|
+
componentKey: binding.componentKey
|
|
9797
|
+
});
|
|
9798
|
+
result.set(module.file, current);
|
|
9799
|
+
}
|
|
9800
|
+
}
|
|
9801
|
+
for (const dependency of module.dependencies) {
|
|
9802
|
+
if (!dependency.resolvedFile || dependency.type === "BUSINESS") continue;
|
|
9803
|
+
const target = modules.get(path.resolve(dependency.resolvedFile));
|
|
9804
|
+
if (target?.kind === "SOURCE") queue.push(target);
|
|
9805
|
+
}
|
|
9806
|
+
}
|
|
9807
|
+
}
|
|
9808
|
+
return result;
|
|
9809
|
+
}
|
|
9810
|
+
async function runFidelityPass(plan, directory) {
|
|
9811
|
+
const graph = plan.analysis.sourceGraph;
|
|
9812
|
+
const adaptations = contentAdaptations(plan);
|
|
9813
|
+
const destinationBySource = /* @__PURE__ */ new Map();
|
|
9814
|
+
const bootstrap = graph.entrypoint?.bootstrapFile;
|
|
9815
|
+
const modules = graph.modules.filter((module) => module.file !== bootstrap);
|
|
9816
|
+
for (const module of modules) destinationBySource.set(path.resolve(module.absolutePath), destinationFor(directory, module.file));
|
|
9817
|
+
const extraAssets = [];
|
|
9818
|
+
for (const asset of plan.assets.filter((candidate) => !destinationBySource.has(path.resolve(candidate.absolutePath)))) try {
|
|
9819
|
+
if ((await stat(asset.absolutePath)).isFile()) extraAssets.push(asset);
|
|
9820
|
+
else plan.warnings.push(`Asset não encontrado e ignorado: ${asset.file}`);
|
|
9821
|
+
} catch {
|
|
9822
|
+
plan.warnings.push(`Asset não encontrado e ignorado: ${asset.file}`);
|
|
9823
|
+
}
|
|
9824
|
+
for (const asset of extraAssets) destinationBySource.set(path.resolve(asset.absolutePath), destinationFor(directory, asset.file));
|
|
9825
|
+
const adaptedBusinessFiles = [];
|
|
9826
|
+
for (const module of modules) {
|
|
9827
|
+
const destination = destinationBySource.get(path.resolve(module.absolutePath));
|
|
9828
|
+
await mkdir(path.dirname(destination), { recursive: true });
|
|
9829
|
+
if (module.kind !== "SOURCE") {
|
|
9830
|
+
await writeFile(destination, await readFile(module.absolutePath));
|
|
9831
|
+
continue;
|
|
9832
|
+
}
|
|
9833
|
+
const content = await readFile(module.absolutePath, "utf8");
|
|
9834
|
+
const unwrapDocumentTags = graph.entrypoint?.layoutFiles.includes(module.file) ?? false;
|
|
9835
|
+
if (unwrapDocumentTags && /<(?:html|body)\b/i.test(content)) plan.warnings.push(`${module.file}: wrappers <html>/<body> do Next.js adaptados para o runtime do tema.`);
|
|
9836
|
+
const transformed = module.business && !module.visual ? businessModuleStub(module.absolutePath, content) : transformMigratedSource(module, content, graph, destination, destinationBySource, {
|
|
9837
|
+
contentAdapterFile: path.join(directory, "src", "migrated-content.tsx"),
|
|
9838
|
+
nextImageAdapterFile: path.join(directory, "src", "migrated-next-image.tsx"),
|
|
9839
|
+
content: adaptations.get(module.file),
|
|
9840
|
+
unwrapDocumentTags,
|
|
9841
|
+
removeComponents: module.file === graph.entrypoint?.pageFile ? plan.analysis.components.filter((component) => /(whatsapp|floating|float|chat|popup)/i.test(component.name)).map((component) => component.name) : []
|
|
9842
|
+
});
|
|
9843
|
+
if (module.business && !module.visual) adaptedBusinessFiles.push(module.file);
|
|
9844
|
+
await writeFile(destination, module.business && !module.visual ? transformed : `// @ts-nocheck -- código preservado pela Nuvler Fidelity Pass\n${transformed}`, "utf8");
|
|
9845
|
+
}
|
|
9846
|
+
for (const asset of extraAssets) {
|
|
9847
|
+
const destination = destinationBySource.get(path.resolve(asset.absolutePath));
|
|
9848
|
+
await mkdir(path.dirname(destination), { recursive: true });
|
|
9849
|
+
await writeFile(destination, await readFile(asset.absolutePath));
|
|
9850
|
+
}
|
|
9851
|
+
const homeDirectory = path.join(directory, "src", "sections");
|
|
9852
|
+
const entry = graph.entrypoint;
|
|
9853
|
+
const page = entry ? sourceModule(plan, entry.pageFile) : void 0;
|
|
9854
|
+
const pageDestination = page ? destinationBySource.get(path.resolve(page.absolutePath)) : void 0;
|
|
9855
|
+
const layoutImports = entry?.layoutFiles.flatMap((file) => {
|
|
9856
|
+
const layout = sourceModule(plan, file);
|
|
9857
|
+
const destination = layout ? destinationBySource.get(path.resolve(layout.absolutePath)) : void 0;
|
|
9858
|
+
if (!layout || !destination) return [];
|
|
9859
|
+
return [{
|
|
9860
|
+
importPath: importPath(homeDirectory, destination),
|
|
9861
|
+
exportName: "default",
|
|
9862
|
+
defaultExport: true
|
|
9863
|
+
}];
|
|
9864
|
+
}) ?? [];
|
|
9865
|
+
return {
|
|
9866
|
+
copiedFiles: modules.length + extraAssets.length,
|
|
9867
|
+
copiedAssets: modules.filter((module) => module.kind === "ASSET").length + extraAssets.length,
|
|
9868
|
+
entryImportPath: pageDestination ? importPath(homeDirectory, pageDestination) : null,
|
|
9869
|
+
entryExportName: entry?.exportName ?? null,
|
|
9870
|
+
entryDefaultExport: entry?.defaultExport ?? true,
|
|
9871
|
+
layoutImports,
|
|
9872
|
+
adaptedBusinessFiles
|
|
9873
|
+
};
|
|
9874
|
+
}
|
|
9875
|
+
async function mergeFidelityDependencies(plan, directory) {
|
|
9876
|
+
const packageFile = path.join(directory, "package.json");
|
|
9877
|
+
const generated = JSON.parse(await readFile(packageFile, "utf8"));
|
|
9878
|
+
const dependencies = { ...generated.dependencies };
|
|
9879
|
+
const skipped = /* @__PURE__ */ new Set([
|
|
9880
|
+
"react",
|
|
9881
|
+
"react-dom",
|
|
9882
|
+
"vite",
|
|
9883
|
+
"typescript",
|
|
9884
|
+
"@vitejs/plugin-react",
|
|
9885
|
+
"tailwindcss",
|
|
9886
|
+
"@tailwindcss/vite"
|
|
9887
|
+
]);
|
|
9888
|
+
for (const dependency of plan.analysis.sourceGraph.dependencies) {
|
|
9889
|
+
const name = dependency.packageName;
|
|
9890
|
+
if (!name || skipped.has(name)) continue;
|
|
9891
|
+
const version = plan.analysis.dependencies[name];
|
|
9892
|
+
if (version) dependencies[name] = version;
|
|
9893
|
+
else plan.warnings.push(`Dependência ${name} alcançada pela Home, mas sem versão declarada no projeto original.`);
|
|
9894
|
+
}
|
|
9895
|
+
const companions = /* @__PURE__ */ new Map([["@mui/icons-material", [
|
|
9896
|
+
"@mui/material",
|
|
9897
|
+
"@emotion/react",
|
|
9898
|
+
"@emotion/styled"
|
|
9899
|
+
]], ["@mui/material", ["@emotion/react", "@emotion/styled"]]]);
|
|
9900
|
+
for (const name of Object.keys(dependencies)) for (const companion of companions.get(name) ?? []) {
|
|
9901
|
+
const version = plan.analysis.dependencies[companion];
|
|
9902
|
+
if (version) dependencies[companion] = version;
|
|
9903
|
+
}
|
|
9904
|
+
generated.dependencies = dependencies;
|
|
9905
|
+
await writeFile(packageFile, `${JSON.stringify(generated, null, 2)}\n`, "utf8");
|
|
9906
|
+
const configFile = path.join(directory, "tsconfig.json");
|
|
9907
|
+
const config = JSON.parse(await readFile(configFile, "utf8"));
|
|
9908
|
+
config.compilerOptions = {
|
|
9909
|
+
...config.compilerOptions,
|
|
9910
|
+
module: "ESNext",
|
|
9911
|
+
moduleResolution: "Bundler",
|
|
9912
|
+
allowJs: true,
|
|
9913
|
+
noEmit: true
|
|
9914
|
+
};
|
|
9915
|
+
await writeFile(configFile, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
9916
|
+
}
|
|
9917
|
+
//#endregion
|
|
9918
|
+
//#region src/migrate/generator.ts
|
|
9919
|
+
function portable(file) {
|
|
9920
|
+
return file.split(path.sep).join("/");
|
|
9921
|
+
}
|
|
9922
|
+
function classes(base, source = "") {
|
|
9923
|
+
return JSON.stringify([base, source].filter(Boolean).join(" "));
|
|
9924
|
+
}
|
|
9925
|
+
function profile(plan, role) {
|
|
9926
|
+
return plan.selected[role]?.classes ?? {
|
|
9927
|
+
root: "",
|
|
9928
|
+
brand: "",
|
|
9929
|
+
navigation: "",
|
|
9930
|
+
title: "",
|
|
9931
|
+
text: "",
|
|
9932
|
+
action: "",
|
|
9933
|
+
media: "",
|
|
9934
|
+
grid: "",
|
|
9935
|
+
card: "",
|
|
9936
|
+
content: ""
|
|
9937
|
+
};
|
|
9938
|
+
}
|
|
9939
|
+
function headerSource(plan) {
|
|
9940
|
+
const style = profile(plan, "HEADER");
|
|
9941
|
+
return `import type { HeaderProps } from "@nuvler/theme-sdk";
|
|
9942
|
+
|
|
9943
|
+
export function Header({ site, categories, pages }: HeaderProps) {
|
|
9944
|
+
const name = site.settings?.siteName || site.tenant.name;
|
|
9945
|
+
return <header className=${classes("nuvler-migrated-header", style.root)}>
|
|
9946
|
+
<div className=${classes("nuvler-migrated-header-inner", style.content)}>
|
|
9947
|
+
<a className=${classes("nuvler-migrated-brand", style.brand)} href="/">
|
|
9948
|
+
{site.settings?.logo?.url ? <img src={site.settings.logo.url} alt={site.settings.logo.alt || name} /> : <span>{name}</span>}
|
|
9949
|
+
</a>
|
|
9950
|
+
<nav className=${classes("nuvler-migrated-nav", style.navigation)} aria-label="Navegação principal">
|
|
9951
|
+
<a href="/">Início</a>
|
|
9952
|
+
{site.modules.includes("PRODUCTS") && <a href="/produtos">Produtos</a>}
|
|
9953
|
+
{categories.slice(0, 6).map((category) => <a href={\`/\${category.slug}\`} key={category.slug}>{category.name}</a>)}
|
|
9954
|
+
{pages.slice(0, 4).map((page) => <a href={\`/\${page.slug}\`} key={page.slug}>{page.title}</a>)}
|
|
9955
|
+
</nav>
|
|
9956
|
+
{site.modules.includes("PRODUCTS") && <form className="nuvler-migrated-search" action="/produtos">
|
|
9957
|
+
<input name="busca" type="search" placeholder="Buscar produtos" />
|
|
9958
|
+
<button className=${classes("nuvler-migrated-action", style.action)} type="submit">Buscar</button>
|
|
9959
|
+
</form>}
|
|
9960
|
+
</div>
|
|
9961
|
+
</header>;
|
|
9962
|
+
}
|
|
9963
|
+
`;
|
|
9964
|
+
}
|
|
9965
|
+
function footerSource(plan) {
|
|
9966
|
+
const style = profile(plan, "FOOTER");
|
|
9967
|
+
return `import type { FooterProps } from "@nuvler/theme-sdk";
|
|
9968
|
+
|
|
9969
|
+
export function Footer({ site, pages, template }: FooterProps) {
|
|
9970
|
+
const name = site.settings?.siteName || site.tenant.name;
|
|
9971
|
+
return <footer className=${classes("nuvler-migrated-footer", style.root)}>
|
|
9972
|
+
<div className=${classes("nuvler-migrated-footer-inner", style.content)}>
|
|
9973
|
+
<div><strong className=${classes("nuvler-migrated-footer-brand", style.brand)}>{name}</strong>{site.settings?.description && <p className=${classes("nuvler-migrated-copy", style.text)}>{site.settings.description}</p>}</div>
|
|
9974
|
+
<nav className=${classes("nuvler-migrated-footer-nav", style.navigation)} aria-label={template.footerNavigationLabel}>
|
|
9975
|
+
<a href="/">Início</a>
|
|
9976
|
+
{site.modules.includes("PRODUCTS") && <a href="/produtos">Produtos</a>}
|
|
9977
|
+
{pages.map((page) => <a href={\`/\${page.slug}\`} key={page.slug}>{page.title}</a>)}
|
|
9978
|
+
</nav>
|
|
9979
|
+
<div className="nuvler-migrated-contact">
|
|
9980
|
+
{site.settings?.contact.phone && <a href={\`tel:\${site.settings.contact.phone}\`}>{site.settings.contact.phone}</a>}
|
|
9981
|
+
{site.settings?.contact.email && <a href={\`mailto:\${site.settings.contact.email}\`}>{site.settings.contact.email}</a>}
|
|
9982
|
+
</div>
|
|
9983
|
+
</div>
|
|
9984
|
+
{template.footerNote && <small>{template.footerNote}</small>}
|
|
9985
|
+
</footer>;
|
|
9986
|
+
}
|
|
9987
|
+
`;
|
|
9988
|
+
}
|
|
9989
|
+
function productCardSource(plan) {
|
|
9990
|
+
const style = profile(plan, "PRODUCT_CARD");
|
|
8764
9991
|
return `import { productUrl, type ThemeProduct } from "@nuvler/theme-sdk";
|
|
8765
9992
|
|
|
8766
9993
|
function money(value: number | null): string {
|
|
@@ -8818,192 +10045,1581 @@ export function ProductDetail({ product, descriptionContent, onAddToCart }: Prod
|
|
|
8818
10045
|
</div>
|
|
8819
10046
|
</article>;
|
|
8820
10047
|
}
|
|
8821
|
-
`;
|
|
10048
|
+
`;
|
|
10049
|
+
}
|
|
10050
|
+
function fidelityHomeSource(fidelity) {
|
|
10051
|
+
if (!fidelity.entryImportPath || !fidelity.entryExportName) return null;
|
|
10052
|
+
return `import type { HomeProps } from "@nuvler/theme-sdk";
|
|
10053
|
+
import { MigratedContentProvider } from "../migrated-content.js";
|
|
10054
|
+
${fidelity.entryDefaultExport ? `import MigratedPage from ${JSON.stringify(fidelity.entryImportPath)};` : `import { ${fidelity.entryExportName} as MigratedPage } from ${JSON.stringify(fidelity.entryImportPath)};`}
|
|
10055
|
+
${fidelity.layoutImports.map((layout, index) => layout.defaultExport ? `import MigratedLayout${index} from ${JSON.stringify(layout.importPath)};` : `import { ${layout.exportName} as MigratedLayout${index} } from ${JSON.stringify(layout.importPath)};`).join("\n")}
|
|
10056
|
+
|
|
10057
|
+
/** Fidelity Pass: a árvore original permanece ativa; somente o conteúdo é fornecido pelo Nuvler. */
|
|
10058
|
+
export function Home(props: HomeProps) {
|
|
10059
|
+
return <MigratedContentProvider {...props}>${fidelity.layoutImports.reduceRight((child, _layout, index) => `<MigratedLayout${index}>${child}</MigratedLayout${index}>`, "<MigratedPage />")}</MigratedContentProvider>;
|
|
10060
|
+
}
|
|
10061
|
+
`;
|
|
10062
|
+
}
|
|
10063
|
+
function homeSource(plan, fidelity) {
|
|
10064
|
+
const preserved = fidelityHomeSource(fidelity);
|
|
10065
|
+
if (preserved) return preserved;
|
|
10066
|
+
const home = profile(plan, "HOME");
|
|
10067
|
+
profile(plan, "SECTION");
|
|
10068
|
+
const bindings = plan.contentBindings.map(({ id, type, order, componentKey, classes: bindingClasses }) => ({
|
|
10069
|
+
id,
|
|
10070
|
+
type,
|
|
10071
|
+
order,
|
|
10072
|
+
componentKey,
|
|
10073
|
+
classes: bindingClasses
|
|
10074
|
+
}));
|
|
10075
|
+
return `import { useState, type FormEvent } from "react";
|
|
10076
|
+
import type { HomeProps, ThemeContactSubmissionInput, ThemeEditorialItem, ThemeHomeSection } from "@nuvler/theme-sdk";
|
|
10077
|
+
import { ProductGrid } from "../components/ProductGrid.js";
|
|
10078
|
+
|
|
10079
|
+
type Binding = {
|
|
10080
|
+
id: string;
|
|
10081
|
+
type: ThemeHomeSection["type"];
|
|
10082
|
+
order: number;
|
|
10083
|
+
componentKey?: string;
|
|
10084
|
+
classes: Record<"root" | "brand" | "navigation" | "title" | "text" | "action" | "media" | "grid" | "card" | "content", string>;
|
|
10085
|
+
};
|
|
10086
|
+
|
|
10087
|
+
const migratedBindings: Binding[] = ${JSON.stringify(bindings, null, 2)};
|
|
10088
|
+
|
|
10089
|
+
function cx(...values: Array<string | undefined>): string {
|
|
10090
|
+
return values.filter(Boolean).join(" ");
|
|
10091
|
+
}
|
|
10092
|
+
|
|
10093
|
+
function value(data: Record<string, unknown>, key: string): string {
|
|
10094
|
+
const candidate = data[key];
|
|
10095
|
+
return typeof candidate === "string" ? candidate : "";
|
|
10096
|
+
}
|
|
10097
|
+
|
|
10098
|
+
function limit(data: Record<string, unknown>): number {
|
|
10099
|
+
const candidate = data.limit;
|
|
10100
|
+
return typeof candidate === "number" && candidate > 0 ? Math.min(candidate, 24) : 8;
|
|
10101
|
+
}
|
|
10102
|
+
|
|
10103
|
+
function record(value: unknown): Record<string, unknown> | null {
|
|
10104
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : null;
|
|
10105
|
+
}
|
|
10106
|
+
|
|
10107
|
+
function media(data: Record<string, unknown>): { url: string; alt: string } | null {
|
|
10108
|
+
const image = record(data.image);
|
|
10109
|
+
const url = image ? value(image, "url") : value(data, "imageUrl");
|
|
10110
|
+
if (!url) return null;
|
|
10111
|
+
return { url, alt: (image ? value(image, "alt") : "") || value(data, "imageAlt") };
|
|
10112
|
+
}
|
|
10113
|
+
|
|
10114
|
+
function bindingFor(section: ThemeHomeSection, index: number, sections: ThemeHomeSection[]): Binding | undefined {
|
|
10115
|
+
if (section.id) {
|
|
10116
|
+
const exact = migratedBindings.find((binding) => binding.id === section.id);
|
|
10117
|
+
if (exact) return exact;
|
|
10118
|
+
}
|
|
10119
|
+
if (section.type === "theme-component" && typeof section.data.componentKey === "string") {
|
|
10120
|
+
const custom = migratedBindings.find((binding) => binding.componentKey === section.data.componentKey);
|
|
10121
|
+
if (custom) return custom;
|
|
10122
|
+
}
|
|
10123
|
+
const occurrence = sections.slice(0, index).filter((candidate) => candidate.type === section.type).length;
|
|
10124
|
+
return migratedBindings.filter((binding) => binding.type === section.type)[occurrence]
|
|
10125
|
+
?? migratedBindings[index];
|
|
10126
|
+
}
|
|
10127
|
+
|
|
10128
|
+
function heading(section: ThemeHomeSection, binding: Binding | undefined) {
|
|
10129
|
+
const eyebrow = value(section.data, "eyebrow");
|
|
10130
|
+
const title = value(section.data, "title");
|
|
10131
|
+
if (!eyebrow && !title) return null;
|
|
10132
|
+
return <header className="nuvler-migrated-section-heading">
|
|
10133
|
+
{eyebrow && <span>{eyebrow}</span>}
|
|
10134
|
+
{title && <h2 className={cx("nuvler-migrated-section-title", binding?.classes.title)}>{title}</h2>}
|
|
10135
|
+
</header>;
|
|
10136
|
+
}
|
|
10137
|
+
|
|
10138
|
+
function TextSection({ section, binding }: { section: ThemeHomeSection; binding?: Binding }) {
|
|
10139
|
+
const eyebrow = value(section.data, "eyebrow");
|
|
10140
|
+
const title = value(section.data, "title");
|
|
10141
|
+
const description = value(section.data, "description") || value(section.data, "text") || value(section.data, "content");
|
|
10142
|
+
const buttonLabel = value(section.data, "buttonLabel");
|
|
10143
|
+
const buttonUrl = value(section.data, "buttonUrl");
|
|
10144
|
+
const image = media(section.data);
|
|
10145
|
+
if (!eyebrow && !title && !description && !image && !(buttonLabel && buttonUrl)) return null;
|
|
10146
|
+
const hero = section.type === "hero";
|
|
10147
|
+
return <section className={cx(hero ? "nuvler-migrated-hero" : "nuvler-migrated-section nuvler-migrated-generic", binding?.classes.root)} data-image-position={value(section.data, "imagePosition") || undefined}>
|
|
10148
|
+
<div className={cx(hero ? "nuvler-migrated-hero-content" : "nuvler-migrated-section-content", binding?.classes.content)}>
|
|
10149
|
+
{eyebrow && <span>{eyebrow}</span>}
|
|
10150
|
+
{title && (hero
|
|
10151
|
+
? <h1 className={cx("nuvler-migrated-hero-title", binding?.classes.title)}>{title}</h1>
|
|
10152
|
+
: <h2 className={cx("nuvler-migrated-section-title", binding?.classes.title)}>{title}</h2>)}
|
|
10153
|
+
{description && <p className={cx("nuvler-migrated-copy", binding?.classes.text)}>{description}</p>}
|
|
10154
|
+
{buttonLabel && buttonUrl && <a className={cx("nuvler-migrated-action", binding?.classes.action)} href={buttonUrl}>{buttonLabel}</a>}
|
|
10155
|
+
</div>
|
|
10156
|
+
{image && <div className={cx(hero ? "nuvler-migrated-hero-media" : "nuvler-migrated-section-media", binding?.classes.media)}><img src={image.url} alt={image.alt || title} /></div>}
|
|
10157
|
+
</section>;
|
|
10158
|
+
}
|
|
10159
|
+
|
|
10160
|
+
function ThemeComponent({ section, binding, submitContact }: { section: ThemeHomeSection; binding?: Binding; submitContact?: HomeProps["submitContact"] }) {
|
|
10161
|
+
const props = record(section.data.props) ?? {};
|
|
10162
|
+
const componentKey = value(section.data, "componentKey");
|
|
10163
|
+
if (componentKey === "video") return <section className={cx("nuvler-migrated-section", binding?.classes.root)}><div className={binding?.classes.content}>{value(props, "eyebrow") && <span>{value(props, "eyebrow")}</span>}{value(props, "title") && <h2>{value(props, "title")}</h2>}{value(props, "description") && <p>{value(props, "description")}</p>}{value(props, "videoUrl") && <video className="nuvler-migrated-video" controls playsInline poster={value(props, "posterImageUrl") || undefined} src={value(props, "videoUrl")} />}</div></section>;
|
|
10164
|
+
if (componentKey !== "contact-form") return <TextSection section={{ ...section, data: props }} binding={binding} />;
|
|
10165
|
+
const configuredFields = Array.isArray(props.fields)
|
|
10166
|
+
? props.fields.map(record).filter((field): field is Record<string, unknown> => Boolean(field))
|
|
10167
|
+
: [];
|
|
10168
|
+
const fields = configuredFields.length ? configuredFields : [
|
|
10169
|
+
{ key: "name", label: "Nome", type: "text", required: true },
|
|
10170
|
+
{ key: "email", label: "E-mail", type: "email", required: true },
|
|
10171
|
+
{ key: "phone", label: "Telefone", type: "tel", required: false },
|
|
10172
|
+
{ key: "message", label: "Mensagem", type: "textarea", required: true },
|
|
10173
|
+
];
|
|
10174
|
+
const [status, setStatus] = useState<"idle" | "sending" | "success" | "error">("idle");
|
|
10175
|
+
const [error, setError] = useState("");
|
|
10176
|
+
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
10177
|
+
event.preventDefault();
|
|
10178
|
+
if (!submitContact) { setStatus("error"); setError("O envio de contatos ainda não está disponível."); return; }
|
|
10179
|
+
const element = event.currentTarget;
|
|
10180
|
+
const form = new FormData(element);
|
|
10181
|
+
const values: ThemeContactSubmissionInput["values"] = {};
|
|
10182
|
+
fields.forEach((field) => {
|
|
10183
|
+
const key = value(field, "key");
|
|
10184
|
+
if (!key) return;
|
|
10185
|
+
if (value(field, "type") === "checkbox") { values[key] = form.has(key); return; }
|
|
10186
|
+
const entries = form.getAll(key).map(String);
|
|
10187
|
+
values[key] = entries.length > 1 ? entries : entries[0] ?? "";
|
|
10188
|
+
});
|
|
10189
|
+
setStatus("sending"); setError("");
|
|
10190
|
+
try {
|
|
10191
|
+
await submitContact({ formKey: componentKey, sectionId: section.id, values, pathname: typeof window === "undefined" ? undefined : window.location.pathname });
|
|
10192
|
+
element.reset(); setStatus("success");
|
|
10193
|
+
} catch (cause) {
|
|
10194
|
+
setStatus("error"); setError(cause instanceof Error ? cause.message : "Não foi possível enviar o contato.");
|
|
10195
|
+
}
|
|
10196
|
+
};
|
|
10197
|
+
return <section className={cx("nuvler-migrated-section nuvler-migrated-contact-form-section", binding?.classes.root)}>
|
|
10198
|
+
<div className="nuvler-migrated-contact-form-copy">{value(props, "eyebrow") && <span>{value(props, "eyebrow")}</span>}<h2>{value(props, "title") || "Fale com nossa equipe"}</h2>{value(props, "description") && <p>{value(props, "description")}</p>}</div>
|
|
10199
|
+
<form className="nuvler-migrated-contact-form" onSubmit={(event) => void submit(event)}>{fields.map((field) => {
|
|
10200
|
+
const key = value(field, "key"); const type = value(field, "type") || "text"; const label = value(field, "label") || key; const required = field.required === true;
|
|
10201
|
+
if (!key) return null;
|
|
10202
|
+
if (type === "checkbox") return <label className="nuvler-migrated-form-wide nuvler-migrated-checkbox" key={key}><input name={key} required={required} type="checkbox" value="true" /><span>{label}</span></label>;
|
|
10203
|
+
if (type === "select") { const options = Array.isArray(field.options) ? field.options.map(record).filter((item): item is Record<string, unknown> => Boolean(item)) : []; return <label key={key}><span>{label}</span><select name={key} required={required}>{options.map((option) => <option key={value(option, "value")} value={value(option, "value")}>{value(option, "label") || value(option, "value")}</option>)}</select></label>; }
|
|
10204
|
+
return <label className={type === "textarea" ? "nuvler-migrated-form-wide" : ""} key={key}><span>{label}</span>{type === "textarea" ? <textarea name={key} placeholder={value(field, "placeholder")} required={required} rows={5} /> : <input name={key} placeholder={value(field, "placeholder")} required={required} type={["email", "tel", "url", "number"].includes(type) ? type : "text"} />}</label>;
|
|
10205
|
+
})}<div className="nuvler-migrated-form-wide"><button className="nuvler-migrated-action" disabled={status === "sending"} type="submit">{status === "sending" ? "Enviando…" : value(props, "submitLabel") || "Enviar contato"}</button>{status === "success" && <p role="status">{value(props, "successMessage") || "Contato enviado com sucesso."}</p>}{status === "error" && <p role="alert">{error}</p>}</div></form>
|
|
10206
|
+
</section>;
|
|
10207
|
+
}
|
|
10208
|
+
|
|
10209
|
+
function Banners({ section, binding }: { section: ThemeHomeSection; binding?: Binding }) {
|
|
10210
|
+
const banners = Array.isArray(section.data.banners)
|
|
10211
|
+
? section.data.banners.map(record).filter((item): item is Record<string, unknown> => Boolean(item))
|
|
10212
|
+
: [];
|
|
10213
|
+
const configured = banners.map((banner) => ({ banner, image: media(banner) })).filter(({ image }) => Boolean(image));
|
|
10214
|
+
if (!configured.length) return null;
|
|
10215
|
+
return <section className={cx("nuvler-migrated-banners", binding?.classes.root)}>
|
|
10216
|
+
{configured.map(({ banner, image }, index) => <article className={cx("nuvler-migrated-banner", binding?.classes.card)} key={value(banner, "id") || index}>
|
|
10217
|
+
<img className={cx("nuvler-migrated-banner-media", binding?.classes.media)} src={image!.url} alt={image!.alt || value(banner, "title")} />
|
|
10218
|
+
<div className={cx("nuvler-migrated-banner-content", binding?.classes.content)}>
|
|
10219
|
+
{value(banner, "title") && <h2 className={binding?.classes.title}>{value(banner, "title")}</h2>}
|
|
10220
|
+
{value(banner, "description") && <p className={binding?.classes.text}>{value(banner, "description")}</p>}
|
|
10221
|
+
{value(banner, "buttonLabel") && value(banner, "buttonUrl") && <a className={cx("nuvler-migrated-action", binding?.classes.action)} href={value(banner, "buttonUrl")}>{value(banner, "buttonLabel")}</a>}
|
|
10222
|
+
</div>
|
|
10223
|
+
</article>)}
|
|
10224
|
+
</section>;
|
|
10225
|
+
}
|
|
10226
|
+
|
|
10227
|
+
function Products({ section, binding, products, site }: { section: ThemeHomeSection; binding?: Binding; products: HomeProps["products"]; site: HomeProps["site"] }) {
|
|
10228
|
+
const category = value(section.data, "categorySlug");
|
|
10229
|
+
const visible = products.filter((product) => !category || product.categories.some((item) => item.slug === category) || product.categoryPath?.includes(category)).slice(0, limit(section.data));
|
|
10230
|
+
if (!visible.length) return null;
|
|
10231
|
+
return <section className={cx("nuvler-migrated-section", binding?.classes.root)}>
|
|
10232
|
+
{heading(section, binding)}
|
|
10233
|
+
<div className={binding?.classes.grid}><ProductGrid products={visible} columns={site.settings?.catalog?.desktopColumns || 3} showCategory={site.settings?.catalog?.showCategory} showDescription={site.settings?.catalog?.showDescription} /></div>
|
|
10234
|
+
</section>;
|
|
10235
|
+
}
|
|
10236
|
+
|
|
10237
|
+
function EditorialCards({ section, binding, items, basePath }: { section: ThemeHomeSection; binding?: Binding; items: ThemeEditorialItem[]; basePath: string }) {
|
|
10238
|
+
const visible = items.slice(0, limit(section.data));
|
|
10239
|
+
if (!visible.length) return null;
|
|
10240
|
+
return <section className={cx("nuvler-migrated-section", binding?.classes.root)}>
|
|
10241
|
+
{heading(section, binding)}
|
|
10242
|
+
<div className={cx("nuvler-migrated-editorial-grid", binding?.classes.grid)}>{visible.map((item) => {
|
|
10243
|
+
const image = item.image ?? item.thumbnail ?? item.coverImage;
|
|
10244
|
+
return <article className={cx("nuvler-migrated-editorial-card", binding?.classes.card)} key={item.slug}>
|
|
10245
|
+
{image?.url && <a className={binding?.classes.media} href={\`\${basePath}/\${item.slug}\`}><img src={image.url} alt={image.alt || item.title} /></a>}
|
|
10246
|
+
<div className={binding?.classes.content}><h3 className={binding?.classes.title}><a href={\`\${basePath}/\${item.slug}\`}>{item.title}</a></h3>{item.description && <p className={binding?.classes.text}>{item.description}</p>}</div>
|
|
10247
|
+
</article>;
|
|
10248
|
+
})}</div>
|
|
10249
|
+
</section>;
|
|
10250
|
+
}
|
|
10251
|
+
|
|
10252
|
+
function ConfiguredSection({ section, binding, products, posts, services, cases, site, submitContact }: { section: ThemeHomeSection; binding?: Binding } & Pick<HomeProps, "products" | "posts" | "services" | "cases" | "site" | "submitContact">) {
|
|
10253
|
+
if (section.type === "theme-component") return <ThemeComponent section={section} binding={binding} submitContact={submitContact} />;
|
|
10254
|
+
if (section.type === "banner-carousel") return <Banners section={section} binding={binding} />;
|
|
10255
|
+
if (section.type === "products-grid" || section.type === "products-carousel") return <Products section={section} binding={binding} products={products} site={site} />;
|
|
10256
|
+
if (section.type === "services-grid") return <EditorialCards section={section} binding={binding} items={services} basePath="/servicos" />;
|
|
10257
|
+
if (section.type === "blog-grid") return <EditorialCards section={section} binding={binding} items={posts} basePath="/blog" />;
|
|
10258
|
+
if (section.type === "cases-grid") return <EditorialCards section={section} binding={binding} items={cases} basePath="/cases" />;
|
|
10259
|
+
return <TextSection section={section} binding={binding} />;
|
|
10260
|
+
}
|
|
10261
|
+
|
|
10262
|
+
export function Home({ sections, products, posts, services, cases, site, submitContact }: HomeProps) {
|
|
10263
|
+
const enabled = sections.filter((item) => item.enabled).sort((left, right) => left.order - right.order);
|
|
10264
|
+
return <main className=${classes("nuvler-migrated-home", home.root)}>
|
|
10265
|
+
{enabled.map((item, index) => <ConfiguredSection section={item} binding={bindingFor(item, index, enabled)} products={products} posts={posts} services={services} cases={cases} site={site} submitContact={submitContact} key={item.id || \`\${item.type}-\${item.order}\`} />)}
|
|
10266
|
+
</main>;
|
|
10267
|
+
}
|
|
10268
|
+
`;
|
|
10269
|
+
}
|
|
10270
|
+
function migratedContentSource(plan) {
|
|
10271
|
+
const metadata = plan.contentBindings.map(({ id, type, order, componentKey }) => ({
|
|
10272
|
+
id,
|
|
10273
|
+
type,
|
|
10274
|
+
order,
|
|
10275
|
+
componentKey
|
|
10276
|
+
}));
|
|
10277
|
+
return `import { createContext, useContext, type FormEvent, type ReactNode } from "react";
|
|
10278
|
+
import type { HomeProps, ThemeHomeSection } from "@nuvler/theme-sdk";
|
|
10279
|
+
|
|
10280
|
+
const MigratedContentContext = createContext<HomeProps | null>(null);
|
|
10281
|
+
const bindingMetadata: ReadonlyArray<{ id: string; type: ThemeHomeSection["type"]; order: number; componentKey?: string }> = ${JSON.stringify(metadata, null, 2)};
|
|
10282
|
+
|
|
10283
|
+
export function MigratedContentProvider({ children, ...props }: HomeProps & { children: ReactNode }) {
|
|
10284
|
+
return <MigratedContentContext.Provider value={props}>{children}</MigratedContentContext.Provider>;
|
|
10285
|
+
}
|
|
10286
|
+
|
|
10287
|
+
function configuredSection(id: string, sections: ThemeHomeSection[]): ThemeHomeSection | undefined {
|
|
10288
|
+
const exact = sections.find((section) => section.id === id);
|
|
10289
|
+
if (exact) return exact;
|
|
10290
|
+
const binding = bindingMetadata.find((candidate) => candidate.id === id);
|
|
10291
|
+
if (!binding) return undefined;
|
|
10292
|
+
if (binding.type === "theme-component" && binding.componentKey) {
|
|
10293
|
+
const custom = sections.find((section) => section.enabled
|
|
10294
|
+
&& section.type === "theme-component"
|
|
10295
|
+
&& section.data.componentKey === binding.componentKey);
|
|
10296
|
+
if (custom) return custom;
|
|
10297
|
+
}
|
|
10298
|
+
const occurrence = bindingMetadata.filter((candidate) => candidate.type === binding.type && candidate.order < binding.order).length;
|
|
10299
|
+
return sections.filter((section) => section.enabled && section.type === binding.type).sort((left, right) => left.order - right.order)[occurrence];
|
|
10300
|
+
}
|
|
10301
|
+
|
|
10302
|
+
export function useMigratedSection(id: string): Record<string, unknown> {
|
|
10303
|
+
const context = useContext(MigratedContentContext);
|
|
10304
|
+
if (!context) return {};
|
|
10305
|
+
if (id === "__header" || id === "__footer") {
|
|
10306
|
+
const name = context.site.settings?.siteName || context.site.tenant.name;
|
|
10307
|
+
return {
|
|
10308
|
+
title: name,
|
|
10309
|
+
description: context.site.settings?.description || "",
|
|
10310
|
+
image: context.site.settings?.logo || null,
|
|
10311
|
+
imageUrl: context.site.settings?.logo?.url || "",
|
|
10312
|
+
imageAlt: context.site.settings?.logo?.alt || name,
|
|
10313
|
+
buttonLabel: "",
|
|
10314
|
+
buttonUrl: "",
|
|
10315
|
+
};
|
|
10316
|
+
}
|
|
10317
|
+
const section = configuredSection(id, context.sections);
|
|
10318
|
+
if (!section) return {};
|
|
10319
|
+
if (section.type === "theme-component") {
|
|
10320
|
+
const props = section.data.props;
|
|
10321
|
+
return props && typeof props === "object" && !Array.isArray(props)
|
|
10322
|
+
? props as Record<string, unknown>
|
|
10323
|
+
: {};
|
|
10324
|
+
}
|
|
10325
|
+
return section.data;
|
|
10326
|
+
}
|
|
10327
|
+
|
|
10328
|
+
export function useMigratedContactForm(id: string) {
|
|
10329
|
+
const context = useContext(MigratedContentContext);
|
|
10330
|
+
return async (event: FormEvent<HTMLFormElement>): Promise<void> => {
|
|
10331
|
+
event.preventDefault();
|
|
10332
|
+
const element = event.currentTarget;
|
|
10333
|
+
if (!context?.submitContact) {
|
|
10334
|
+
element.dataset.nuvlerStatus = "unavailable";
|
|
10335
|
+
element.dispatchEvent(new CustomEvent("nuvler:contact-error", { detail: { message: "Envio de contatos indisponível." } }));
|
|
10336
|
+
return;
|
|
10337
|
+
}
|
|
10338
|
+
const section = configuredSection(id, context.sections);
|
|
10339
|
+
const form = new FormData(element);
|
|
10340
|
+
const values: Record<string, string | boolean | string[]> = {};
|
|
10341
|
+
const configuredFields = section?.type === "theme-component" && section.data.props && typeof section.data.props === "object" && !Array.isArray(section.data.props)
|
|
10342
|
+
? migratedItems(section.data.props as Record<string, unknown>, "fields")
|
|
10343
|
+
: [];
|
|
10344
|
+
for (const field of configuredFields) {
|
|
10345
|
+
const key = stringValue(field, "key");
|
|
10346
|
+
if (key && stringValue(field, "type") === "checkbox") values[key] = form.has(key);
|
|
10347
|
+
}
|
|
10348
|
+
for (const key of new Set([...form.keys()])) {
|
|
10349
|
+
const entries = form.getAll(key).filter((value): value is string => typeof value === "string");
|
|
10350
|
+
values[key] = entries.length > 1 ? entries : entries[0] ?? "";
|
|
10351
|
+
}
|
|
10352
|
+
element.dataset.nuvlerStatus = "sending";
|
|
10353
|
+
try {
|
|
10354
|
+
const result = await context.submitContact({
|
|
10355
|
+
formKey: section?.type === "theme-component" && typeof section.data.componentKey === "string" ? section.data.componentKey : "contact-form",
|
|
10356
|
+
sectionId: section?.id,
|
|
10357
|
+
values,
|
|
10358
|
+
pathname: typeof window === "undefined" ? undefined : window.location.pathname,
|
|
10359
|
+
});
|
|
10360
|
+
element.reset();
|
|
10361
|
+
element.dataset.nuvlerStatus = "success";
|
|
10362
|
+
element.dispatchEvent(new CustomEvent("nuvler:contact-success", { detail: result }));
|
|
10363
|
+
} catch (cause) {
|
|
10364
|
+
const message = cause instanceof Error ? cause.message : "Não foi possível enviar o contato.";
|
|
10365
|
+
element.dataset.nuvlerStatus = "error";
|
|
10366
|
+
element.dispatchEvent(new CustomEvent("nuvler:contact-error", { detail: { message } }));
|
|
10367
|
+
}
|
|
10368
|
+
};
|
|
10369
|
+
}
|
|
10370
|
+
|
|
10371
|
+
export function migratedItems(data: Record<string, unknown>, field = "items"): Record<string, unknown>[] {
|
|
10372
|
+
const value = data[field];
|
|
10373
|
+
return Array.isArray(value)
|
|
10374
|
+
? value.filter((item): item is Record<string, unknown> => Boolean(item) && typeof item === "object" && !Array.isArray(item))
|
|
10375
|
+
: [];
|
|
10376
|
+
}
|
|
10377
|
+
|
|
10378
|
+
export function MigratedContactFields({ data }: { data: Record<string, unknown> }) {
|
|
10379
|
+
const configured = migratedItems(data, "fields");
|
|
10380
|
+
const fields = configured.length ? configured : [
|
|
10381
|
+
{ key: "name", label: "Nome", type: "text", required: true },
|
|
10382
|
+
{ key: "email", label: "E-mail", type: "email", required: true },
|
|
10383
|
+
{ key: "phone", label: "Telefone", type: "tel", required: false },
|
|
10384
|
+
{ key: "message", label: "Mensagem", type: "textarea", required: true },
|
|
10385
|
+
];
|
|
10386
|
+
return <>
|
|
10387
|
+
{fields.map((field) => {
|
|
10388
|
+
const key = stringValue(field, "key");
|
|
10389
|
+
const type = stringValue(field, "type") || "text";
|
|
10390
|
+
if (!key) return null;
|
|
10391
|
+
if (type === "checkbox") return <label className="nuvler-migrated-form-wide nuvler-migrated-checkbox" data-field-key={key} key={key}>
|
|
10392
|
+
<input name={key} required={field.required === true} type="checkbox" value="true" />
|
|
10393
|
+
<span>{stringValue(field, "label") || key}{field.required === true ? " *" : ""}</span>
|
|
10394
|
+
</label>;
|
|
10395
|
+
if (type === "select") return <label data-field-key={key} key={key}>
|
|
10396
|
+
<span>{stringValue(field, "label") || key}{field.required === true ? " *" : ""}</span>
|
|
10397
|
+
<select name={key} required={field.required === true}>{migratedItems(field, "options").map((option) => <option key={stringValue(option, "value")} value={stringValue(option, "value")}>{stringValue(option, "label") || stringValue(option, "value")}</option>)}</select>
|
|
10398
|
+
</label>;
|
|
10399
|
+
return <label data-field-key={key} key={key}>
|
|
10400
|
+
<span>{stringValue(field, "label") || key}{field.required === true ? " *" : ""}</span>
|
|
10401
|
+
{type === "textarea"
|
|
10402
|
+
? <textarea name={key} placeholder={stringValue(field, "placeholder")} required={field.required === true} rows={5} />
|
|
10403
|
+
: <input name={key} placeholder={stringValue(field, "placeholder")} required={field.required === true} type={["email", "tel", "url", "number"].includes(type) ? type : "text"} />}
|
|
10404
|
+
</label>;
|
|
10405
|
+
})}
|
|
10406
|
+
<button type="submit">{stringValue(data, "submitLabel") || "Enviar contato"}</button>
|
|
10407
|
+
</>;
|
|
10408
|
+
}
|
|
10409
|
+
|
|
10410
|
+
function stringValue(data: Record<string, unknown>, key: string): string {
|
|
10411
|
+
const candidate = data[key];
|
|
10412
|
+
return typeof candidate === "string" ? candidate : "";
|
|
10413
|
+
}
|
|
10414
|
+
|
|
10415
|
+
export function migratedText(data: Record<string, unknown>, field: string): string {
|
|
10416
|
+
if (field === "description") return stringValue(data, "description") || stringValue(data, "text") || stringValue(data, "content");
|
|
10417
|
+
return stringValue(data, field);
|
|
10418
|
+
}
|
|
10419
|
+
|
|
10420
|
+
export function migratedImage(data: Record<string, unknown>): string | undefined {
|
|
10421
|
+
const image = data.image && typeof data.image === "object" && !Array.isArray(data.image)
|
|
10422
|
+
? data.image as Record<string, unknown>
|
|
10423
|
+
: null;
|
|
10424
|
+
return (image ? stringValue(image, "url") : "") || stringValue(data, "imageUrl") || stringValue(data, "posterImageUrl") || undefined;
|
|
10425
|
+
}
|
|
10426
|
+
|
|
10427
|
+
export function migratedVideo(data: Record<string, unknown>): string | undefined {
|
|
10428
|
+
return stringValue(data, "videoUrl") || undefined;
|
|
10429
|
+
}
|
|
10430
|
+
|
|
10431
|
+
export function migratedLink(data: Record<string, unknown>): string | undefined {
|
|
10432
|
+
return stringValue(data, "buttonUrl") || undefined;
|
|
10433
|
+
}
|
|
10434
|
+
`;
|
|
10435
|
+
}
|
|
10436
|
+
function migratedNextImageSource() {
|
|
10437
|
+
return `import type { CSSProperties, ImgHTMLAttributes } from "react";
|
|
10438
|
+
|
|
10439
|
+
type StaticImage = { src: string; width?: number; height?: number };
|
|
10440
|
+
type MigratedNextImageProps = Omit<ImgHTMLAttributes<HTMLImageElement>, "src"> & {
|
|
10441
|
+
src: string | StaticImage;
|
|
10442
|
+
alt: string;
|
|
10443
|
+
fill?: boolean;
|
|
10444
|
+
priority?: boolean;
|
|
10445
|
+
quality?: number;
|
|
10446
|
+
placeholder?: string;
|
|
10447
|
+
blurDataURL?: string;
|
|
10448
|
+
onLoadingComplete?: (image: HTMLImageElement) => void;
|
|
10449
|
+
};
|
|
10450
|
+
|
|
10451
|
+
/** Adaptador browser-safe para projetos Next.js executados no preview Vite. */
|
|
10452
|
+
export default function MigratedNextImage({
|
|
10453
|
+
src, alt, fill, priority, quality: _quality, placeholder: _placeholder,
|
|
10454
|
+
blurDataURL: _blurDataURL, onLoadingComplete, style, ...props
|
|
10455
|
+
}: MigratedNextImageProps) {
|
|
10456
|
+
const url = typeof src === "string" ? src : src?.src;
|
|
10457
|
+
if (!url) return null;
|
|
10458
|
+
const fillStyle: CSSProperties | undefined = fill
|
|
10459
|
+
? { position: "absolute", inset: 0, width: "100%", height: "100%", ...style }
|
|
10460
|
+
: style;
|
|
10461
|
+
return <img
|
|
10462
|
+
{...props}
|
|
10463
|
+
src={url}
|
|
10464
|
+
alt={alt || ""}
|
|
10465
|
+
loading={priority ? "eager" : props.loading}
|
|
10466
|
+
style={fillStyle}
|
|
10467
|
+
onLoad={onLoadingComplete ? (event) => onLoadingComplete(event.currentTarget) : props.onLoad}
|
|
10468
|
+
/>;
|
|
10469
|
+
}
|
|
10470
|
+
`;
|
|
10471
|
+
}
|
|
10472
|
+
function definitionSource(plan) {
|
|
10473
|
+
const tokens = plan.tokens;
|
|
10474
|
+
const fallbackSections = plan.contentBindings.map((binding) => ({
|
|
10475
|
+
id: binding.id,
|
|
10476
|
+
type: binding.type,
|
|
10477
|
+
enabled: true,
|
|
10478
|
+
order: binding.order,
|
|
10479
|
+
data: blankBindingData(binding)
|
|
10480
|
+
}));
|
|
10481
|
+
return `import manifestData from "../nuvler.theme.json" with { type: "json" };
|
|
10482
|
+
import { defineTheme, type ThemeHomeSection, type ThemeManifest } from "@nuvler/theme-sdk";
|
|
10483
|
+
import { Footer } from "./components/Footer.js";
|
|
10484
|
+
import { Header } from "./components/Header.js";
|
|
10485
|
+
import { ProductDetail } from "./components/ProductDetail.js";
|
|
10486
|
+
import { ProductGrid } from "./components/ProductGrid.js";
|
|
10487
|
+
import { Home } from "./sections/Home.js";
|
|
10488
|
+
|
|
10489
|
+
const migratedSections: ThemeHomeSection[] = ${JSON.stringify(fallbackSections, null, 2)};
|
|
10490
|
+
|
|
10491
|
+
export const manifest = manifestData as ThemeManifest;
|
|
10492
|
+
export const themeDefinition = defineTheme({
|
|
10493
|
+
manifest,
|
|
10494
|
+
tokens: {
|
|
10495
|
+
colors: ${JSON.stringify({
|
|
10496
|
+
primary: tokens.primary,
|
|
10497
|
+
primaryText: tokens.primaryText,
|
|
10498
|
+
secondary: tokens.secondary,
|
|
10499
|
+
secondaryText: tokens.secondaryText,
|
|
10500
|
+
accent: tokens.accent,
|
|
10501
|
+
background: tokens.background,
|
|
10502
|
+
surface: tokens.surface,
|
|
10503
|
+
surfaceAlt: tokens.surfaceAlt,
|
|
10504
|
+
text: tokens.text,
|
|
10505
|
+
textMuted: tokens.textMuted,
|
|
10506
|
+
border: tokens.border,
|
|
10507
|
+
headerBackground: tokens.headerBackground,
|
|
10508
|
+
headerText: tokens.headerText,
|
|
10509
|
+
footerBackground: tokens.footerBackground,
|
|
10510
|
+
footerText: tokens.footerText
|
|
10511
|
+
})},
|
|
10512
|
+
layout: ${JSON.stringify({
|
|
10513
|
+
containerWidth: tokens.containerWidth,
|
|
10514
|
+
borderRadius: tokens.borderRadius
|
|
10515
|
+
})},
|
|
10516
|
+
},
|
|
10517
|
+
template: {
|
|
10518
|
+
announcement: "",
|
|
10519
|
+
footerTagline: "",
|
|
10520
|
+
footerNavigationLabel: "Navegação",
|
|
10521
|
+
footerNote: "",
|
|
10522
|
+
socialLabel: "Redes sociais",
|
|
10523
|
+
benefits: [],
|
|
10524
|
+
fallbackSections: () => migratedSections.map((section) => ({ ...section, data: { ...section.data } })),
|
|
10525
|
+
primaryAction: (modules) => modules.includes("PRODUCTS") ? { label: "Ver produtos", href: "/produtos" } : { label: "Saiba mais", href: "/" },
|
|
10526
|
+
},
|
|
10527
|
+
components: { Header, Footer, Home, ProductGrid, ProductDetail },
|
|
10528
|
+
});
|
|
10529
|
+
`;
|
|
10530
|
+
}
|
|
10531
|
+
function catalogPageSource() {
|
|
10532
|
+
return `import type { ThemeRoute, ThemeSite } from "@nuvler/theme-sdk";
|
|
10533
|
+
import { ProductGrid } from "../components/ProductGrid.js";
|
|
10534
|
+
|
|
10535
|
+
type CatalogRoute = Extract<ThemeRoute, { type: "catalog" }>;
|
|
10536
|
+
|
|
10537
|
+
export function CatalogPage({ route, site }: { route: CatalogRoute; site: ThemeSite }) {
|
|
10538
|
+
return <main className="nuvler-migrated-section nuvler-migrated-catalog">
|
|
10539
|
+
<header><span>Catálogo</span><h1>{route.search ? \`Busca: \${route.search}\` : "Produtos"}</h1><p>{route.pagination.total} produto(s)</p></header>
|
|
10540
|
+
<ProductGrid products={route.products} columns={site.settings?.catalog?.desktopColumns || 3} showCategory={site.settings?.catalog?.showCategory} showDescription={site.settings?.catalog?.showDescription} />
|
|
10541
|
+
</main>;
|
|
10542
|
+
}
|
|
10543
|
+
`;
|
|
10544
|
+
}
|
|
10545
|
+
function productPageSource() {
|
|
10546
|
+
return `import type { ThemeRoute, ThemeRuntimeSdk, ThemeSite } from "@nuvler/theme-sdk";
|
|
10547
|
+
import { ProductDetail } from "../components/ProductDetail.js";
|
|
10548
|
+
|
|
10549
|
+
type ProductRoute = Extract<ThemeRoute, { type: "product" }>;
|
|
10550
|
+
|
|
10551
|
+
export function ProductPage({ route, site, cart }: { route: ProductRoute; site: ThemeSite; cart?: ThemeRuntimeSdk["cart"] }) {
|
|
10552
|
+
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>;
|
|
10553
|
+
}
|
|
10554
|
+
`;
|
|
10555
|
+
}
|
|
10556
|
+
function editorialPageSource() {
|
|
10557
|
+
return `import type { ThemeRoute } from "@nuvler/theme-sdk";
|
|
10558
|
+
|
|
10559
|
+
type EditorialRoute = Extract<ThemeRoute, { type: "editorial-list" | "editorial-detail" }>;
|
|
10560
|
+
|
|
10561
|
+
export function EditorialPage({ route }: { route: EditorialRoute }) {
|
|
10562
|
+
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>;
|
|
10563
|
+
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>;
|
|
10564
|
+
}
|
|
10565
|
+
`;
|
|
10566
|
+
}
|
|
10567
|
+
function statePageSource() {
|
|
10568
|
+
return `export function StatePage({ title, pathname }: { title: string; pathname?: string }) {
|
|
10569
|
+
return <main className="nuvler-migrated-section nuvler-migrated-state"><span>{pathname || "Nuvler"}</span><h1>{title}</h1></main>;
|
|
10570
|
+
}
|
|
10571
|
+
`;
|
|
10572
|
+
}
|
|
10573
|
+
function themeSource(hasFidelityHome) {
|
|
10574
|
+
return `import type { CSSProperties } from "react";
|
|
10575
|
+
import type { NuvlerThemeProps, ThemeSite } from "@nuvler/theme-sdk";
|
|
10576
|
+
import { themeDefinition } from "./definition.js";
|
|
10577
|
+
import { CatalogPage } from "./pages/CatalogPage.js";
|
|
10578
|
+
import { EditorialPage } from "./pages/EditorialPage.js";
|
|
10579
|
+
import { ProductPage } from "./pages/ProductPage.js";
|
|
10580
|
+
import { StatePage } from "./pages/StatePage.js";
|
|
10581
|
+
import "./styles/theme.css";
|
|
10582
|
+
|
|
10583
|
+
export { manifest, themeDefinition } from "./definition.js";
|
|
10584
|
+
|
|
10585
|
+
export default function Theme({ context, route = { type: "home" }, sdk }: NuvlerThemeProps) {
|
|
10586
|
+
const { Header, Footer, Home } = themeDefinition.components;
|
|
10587
|
+
const site: ThemeSite = { tenant: context.store, ...context.site };
|
|
10588
|
+
const configured = site.settings?.theme;
|
|
10589
|
+
const tokens = {
|
|
10590
|
+
colors: { ...themeDefinition.tokens.colors, ...configured?.colors },
|
|
10591
|
+
layout: { ...themeDefinition.tokens.layout, ...configured?.layout },
|
|
10592
|
+
};
|
|
10593
|
+
const style = {
|
|
10594
|
+
"--theme-primary": tokens.colors.primary,
|
|
10595
|
+
"--theme-primary-text": tokens.colors.primaryText,
|
|
10596
|
+
"--theme-secondary": tokens.colors.secondary,
|
|
10597
|
+
"--theme-secondary-text": tokens.colors.secondaryText,
|
|
10598
|
+
"--theme-accent": tokens.colors.accent,
|
|
10599
|
+
"--theme-background": tokens.colors.background,
|
|
10600
|
+
"--theme-surface": tokens.colors.surface,
|
|
10601
|
+
"--theme-surface-alt": tokens.colors.surfaceAlt,
|
|
10602
|
+
"--theme-text": tokens.colors.text,
|
|
10603
|
+
"--theme-text-muted": tokens.colors.textMuted,
|
|
10604
|
+
"--theme-border": tokens.colors.border,
|
|
10605
|
+
"--theme-header-background": tokens.colors.headerBackground,
|
|
10606
|
+
"--theme-header-text": tokens.colors.headerText,
|
|
10607
|
+
"--theme-footer-background": tokens.colors.footerBackground,
|
|
10608
|
+
"--theme-footer-text": tokens.colors.footerText,
|
|
10609
|
+
"--theme-radius": \`\${tokens.layout.borderRadius}px\`,
|
|
10610
|
+
"--theme-container": \`\${tokens.layout.containerWidth}px\`,
|
|
10611
|
+
} as CSSProperties;
|
|
10612
|
+
const homeSections = context.home.content.sections.length
|
|
10613
|
+
? context.home.content.sections
|
|
10614
|
+
: themeDefinition.template.fallbackSections();
|
|
10615
|
+
let content;
|
|
10616
|
+
if (route.type === "home") content = <Home sections={homeSections} products={context.catalog.products} posts={context.editorial.posts} services={context.editorial.services} cases={context.editorial.cases} site={site} submitContact={sdk?.contact?.submit} template={themeDefinition.template} />;
|
|
10617
|
+
else if (route.type === "catalog") content = <CatalogPage route={route} site={site} />;
|
|
10618
|
+
else if (route.type === "product") content = <ProductPage route={route} site={site} cart={sdk?.cart} />;
|
|
10619
|
+
else if (route.type === "editorial-list" || route.type === "editorial-detail") content = <EditorialPage route={route} />;
|
|
10620
|
+
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} />;
|
|
10621
|
+
if (${JSON.stringify(hasFidelityHome)} && route.type === "home") {
|
|
10622
|
+
return <div className="nuvler-migrated-theme nuvler-migrated-fidelity" style={style}>{content}</div>;
|
|
10623
|
+
}
|
|
10624
|
+
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>;
|
|
10625
|
+
}
|
|
10626
|
+
`;
|
|
10627
|
+
}
|
|
10628
|
+
function blankSectionData(type) {
|
|
10629
|
+
if (type === "banner-carousel") return {
|
|
10630
|
+
banners: [],
|
|
10631
|
+
autoplay: true
|
|
10632
|
+
};
|
|
10633
|
+
if (type === "hero") return {
|
|
10634
|
+
eyebrow: "",
|
|
10635
|
+
title: "",
|
|
10636
|
+
description: "",
|
|
10637
|
+
imageId: "",
|
|
10638
|
+
imageUrl: "",
|
|
10639
|
+
imageAlt: "",
|
|
10640
|
+
buttonLabel: "",
|
|
10641
|
+
buttonUrl: ""
|
|
10642
|
+
};
|
|
10643
|
+
if (type === "image-text") return {
|
|
10644
|
+
eyebrow: "",
|
|
10645
|
+
title: "",
|
|
10646
|
+
description: "",
|
|
10647
|
+
imageId: "",
|
|
10648
|
+
imageUrl: "",
|
|
10649
|
+
imageAlt: "",
|
|
10650
|
+
imagePosition: "left"
|
|
10651
|
+
};
|
|
10652
|
+
if (type === "rich-text") return {
|
|
10653
|
+
eyebrow: "",
|
|
10654
|
+
title: "",
|
|
10655
|
+
text: ""
|
|
10656
|
+
};
|
|
10657
|
+
if (type === "cta") return {
|
|
10658
|
+
eyebrow: "",
|
|
10659
|
+
title: "",
|
|
10660
|
+
description: "",
|
|
10661
|
+
buttonLabel: "",
|
|
10662
|
+
buttonUrl: ""
|
|
10663
|
+
};
|
|
10664
|
+
if (type === "products-grid" || type === "products-carousel") return {
|
|
10665
|
+
eyebrow: "",
|
|
10666
|
+
title: "",
|
|
10667
|
+
limit: 6,
|
|
10668
|
+
categorySlug: ""
|
|
10669
|
+
};
|
|
10670
|
+
if (type === "theme-component") return {
|
|
10671
|
+
componentKey: "custom-component",
|
|
10672
|
+
schemaVersion: 1,
|
|
10673
|
+
props: {}
|
|
10674
|
+
};
|
|
10675
|
+
return {
|
|
10676
|
+
eyebrow: "",
|
|
10677
|
+
title: "",
|
|
10678
|
+
limit: 6
|
|
10679
|
+
};
|
|
10680
|
+
}
|
|
10681
|
+
function blankBindingData(binding) {
|
|
10682
|
+
if (binding.type !== "theme-component" || !binding.componentDefinition || !binding.componentKey) return blankSectionData(binding.type);
|
|
10683
|
+
const props = {};
|
|
10684
|
+
for (const field of binding.componentDefinition.fields) if (field.defaultValue !== void 0) props[field.key] = field.defaultValue;
|
|
10685
|
+
else if (field.control === "repeater") props[field.key] = [];
|
|
10686
|
+
else if (field.control === "contact-fields") props[field.key] = [
|
|
10687
|
+
{
|
|
10688
|
+
key: "name",
|
|
10689
|
+
label: "Nome",
|
|
10690
|
+
type: "text",
|
|
10691
|
+
required: true
|
|
10692
|
+
},
|
|
10693
|
+
{
|
|
10694
|
+
key: "email",
|
|
10695
|
+
label: "E-mail",
|
|
10696
|
+
type: "email",
|
|
10697
|
+
required: true
|
|
10698
|
+
},
|
|
10699
|
+
{
|
|
10700
|
+
key: "phone",
|
|
10701
|
+
label: "Telefone",
|
|
10702
|
+
type: "tel",
|
|
10703
|
+
required: false
|
|
10704
|
+
},
|
|
10705
|
+
{
|
|
10706
|
+
key: "message",
|
|
10707
|
+
label: "Mensagem",
|
|
10708
|
+
type: "textarea",
|
|
10709
|
+
required: true
|
|
10710
|
+
}
|
|
10711
|
+
];
|
|
10712
|
+
else if (field.control === "boolean") props[field.key] = false;
|
|
10713
|
+
else if (field.control === "number") props[field.key] = field.min ?? 0;
|
|
10714
|
+
else props[field.key] = "";
|
|
10715
|
+
return {
|
|
10716
|
+
componentKey: binding.componentKey,
|
|
10717
|
+
schemaVersion: binding.componentDefinition.schemaVersion,
|
|
10718
|
+
props
|
|
10719
|
+
};
|
|
10720
|
+
}
|
|
10721
|
+
/** Mirrors the labels shown by the Gestão Home builder. */
|
|
10722
|
+
var PANEL_SECTION_DEFINITIONS = {
|
|
10723
|
+
hero: {
|
|
10724
|
+
name: "Banner principal",
|
|
10725
|
+
category: "Destaques",
|
|
10726
|
+
description: "Uma abertura marcante com imagem, texto e botão.",
|
|
10727
|
+
controls: [
|
|
10728
|
+
{
|
|
10729
|
+
label: "Imagem do banner principal",
|
|
10730
|
+
fields: [
|
|
10731
|
+
"imageId",
|
|
10732
|
+
"imageUrl",
|
|
10733
|
+
"imageAlt"
|
|
10734
|
+
],
|
|
10735
|
+
note: "Ao escolher a imagem, URL e texto alternativo são preenchidos pelo painel."
|
|
10736
|
+
},
|
|
10737
|
+
{
|
|
10738
|
+
label: "Chamada pequena",
|
|
10739
|
+
fields: ["eyebrow"]
|
|
10740
|
+
},
|
|
10741
|
+
{
|
|
10742
|
+
label: "Título da seção",
|
|
10743
|
+
fields: ["title"]
|
|
10744
|
+
},
|
|
10745
|
+
{
|
|
10746
|
+
label: "Descrição",
|
|
10747
|
+
fields: ["description"]
|
|
10748
|
+
},
|
|
10749
|
+
{
|
|
10750
|
+
label: "Texto do botão",
|
|
10751
|
+
fields: ["buttonLabel"]
|
|
10752
|
+
},
|
|
10753
|
+
{
|
|
10754
|
+
label: "Destino do botão",
|
|
10755
|
+
fields: ["buttonUrl"]
|
|
10756
|
+
}
|
|
10757
|
+
]
|
|
10758
|
+
},
|
|
10759
|
+
"banner-carousel": {
|
|
10760
|
+
name: "Carrossel de banners",
|
|
10761
|
+
category: "Destaques",
|
|
10762
|
+
description: "Vários destaques alternando no topo da página.",
|
|
10763
|
+
controls: [{
|
|
10764
|
+
label: "Troca automática",
|
|
10765
|
+
fields: ["autoplay"]
|
|
10766
|
+
}, {
|
|
10767
|
+
label: "Banner 1, Banner 2…",
|
|
10768
|
+
fields: ["banners"],
|
|
10769
|
+
note: "Em cada banner: Imagem, Título, Descrição, Texto do botão e Destino do botão."
|
|
10770
|
+
}]
|
|
10771
|
+
},
|
|
10772
|
+
"image-text": {
|
|
10773
|
+
name: "Imagem e texto",
|
|
10774
|
+
category: "Conteúdo",
|
|
10775
|
+
description: "Apresente uma história com conteúdo lado a lado.",
|
|
10776
|
+
controls: [
|
|
10777
|
+
{
|
|
10778
|
+
label: "Imagem da seção",
|
|
10779
|
+
fields: [
|
|
10780
|
+
"imageId",
|
|
10781
|
+
"imageUrl",
|
|
10782
|
+
"imageAlt"
|
|
10783
|
+
],
|
|
10784
|
+
note: "Ao escolher a imagem, URL e texto alternativo são preenchidos pelo painel."
|
|
10785
|
+
},
|
|
10786
|
+
{
|
|
10787
|
+
label: "Chamada pequena",
|
|
10788
|
+
fields: ["eyebrow"]
|
|
10789
|
+
},
|
|
10790
|
+
{
|
|
10791
|
+
label: "Título da seção",
|
|
10792
|
+
fields: ["title"]
|
|
10793
|
+
},
|
|
10794
|
+
{
|
|
10795
|
+
label: "Texto",
|
|
10796
|
+
fields: ["description"]
|
|
10797
|
+
},
|
|
10798
|
+
{
|
|
10799
|
+
label: "Posição da imagem",
|
|
10800
|
+
fields: ["imagePosition"]
|
|
10801
|
+
}
|
|
10802
|
+
]
|
|
10803
|
+
},
|
|
10804
|
+
"rich-text": {
|
|
10805
|
+
name: "Bloco de texto",
|
|
10806
|
+
category: "Conteúdo",
|
|
10807
|
+
description: "Um título e texto livre para explicar o que quiser.",
|
|
10808
|
+
controls: [
|
|
10809
|
+
{
|
|
10810
|
+
label: "Chamada pequena",
|
|
10811
|
+
fields: ["eyebrow"]
|
|
10812
|
+
},
|
|
10813
|
+
{
|
|
10814
|
+
label: "Título da seção",
|
|
10815
|
+
fields: ["title"]
|
|
10816
|
+
},
|
|
10817
|
+
{
|
|
10818
|
+
label: "Conteúdo",
|
|
10819
|
+
fields: ["text"]
|
|
10820
|
+
}
|
|
10821
|
+
]
|
|
10822
|
+
},
|
|
10823
|
+
cta: {
|
|
10824
|
+
name: "Chamada para ação",
|
|
10825
|
+
category: "Conteúdo",
|
|
10826
|
+
description: "Convide a pessoa a dar o próximo passo.",
|
|
10827
|
+
controls: [
|
|
10828
|
+
{
|
|
10829
|
+
label: "Chamada pequena",
|
|
10830
|
+
fields: ["eyebrow"]
|
|
10831
|
+
},
|
|
10832
|
+
{
|
|
10833
|
+
label: "Título da seção",
|
|
10834
|
+
fields: ["title"]
|
|
10835
|
+
},
|
|
10836
|
+
{
|
|
10837
|
+
label: "Descrição",
|
|
10838
|
+
fields: ["description"]
|
|
10839
|
+
},
|
|
10840
|
+
{
|
|
10841
|
+
label: "Texto do botão",
|
|
10842
|
+
fields: ["buttonLabel"]
|
|
10843
|
+
},
|
|
10844
|
+
{
|
|
10845
|
+
label: "Destino do botão",
|
|
10846
|
+
fields: ["buttonUrl"]
|
|
10847
|
+
}
|
|
10848
|
+
]
|
|
10849
|
+
},
|
|
10850
|
+
"services-grid": {
|
|
10851
|
+
name: "Grade de serviços",
|
|
10852
|
+
category: "Conteúdo automático",
|
|
10853
|
+
description: "Mostra automaticamente os serviços cadastrados.",
|
|
10854
|
+
controls: [
|
|
10855
|
+
{
|
|
10856
|
+
label: "Chamada pequena",
|
|
10857
|
+
fields: ["eyebrow"]
|
|
10858
|
+
},
|
|
10859
|
+
{
|
|
10860
|
+
label: "Título da seção",
|
|
10861
|
+
fields: ["title"]
|
|
10862
|
+
},
|
|
10863
|
+
{
|
|
10864
|
+
label: "Quantidade de itens",
|
|
10865
|
+
fields: ["limit"]
|
|
10866
|
+
}
|
|
10867
|
+
],
|
|
10868
|
+
contentSource: {
|
|
10869
|
+
location: "Serviços → Lista de serviços",
|
|
10870
|
+
description: "Os cards, textos e imagens da grade vêm dos serviços cadastrados."
|
|
10871
|
+
}
|
|
10872
|
+
},
|
|
10873
|
+
"blog-grid": {
|
|
10874
|
+
name: "Últimos do blog",
|
|
10875
|
+
category: "Conteúdo automático",
|
|
10876
|
+
description: "Mantém as publicações recentes em evidência.",
|
|
10877
|
+
controls: [
|
|
10878
|
+
{
|
|
10879
|
+
label: "Chamada pequena",
|
|
10880
|
+
fields: ["eyebrow"]
|
|
10881
|
+
},
|
|
10882
|
+
{
|
|
10883
|
+
label: "Título da seção",
|
|
10884
|
+
fields: ["title"]
|
|
10885
|
+
},
|
|
10886
|
+
{
|
|
10887
|
+
label: "Quantidade de itens",
|
|
10888
|
+
fields: ["limit"]
|
|
10889
|
+
}
|
|
10890
|
+
],
|
|
10891
|
+
contentSource: {
|
|
10892
|
+
location: "Blog → Postagens",
|
|
10893
|
+
description: "Os cards, textos e imagens da grade vêm das postagens publicadas."
|
|
10894
|
+
}
|
|
10895
|
+
},
|
|
10896
|
+
"cases-grid": {
|
|
10897
|
+
name: "Cases de sucesso",
|
|
10898
|
+
category: "Conteúdo automático",
|
|
10899
|
+
description: "Exibe projetos e resultados já cadastrados.",
|
|
10900
|
+
controls: [
|
|
10901
|
+
{
|
|
10902
|
+
label: "Chamada pequena",
|
|
10903
|
+
fields: ["eyebrow"]
|
|
10904
|
+
},
|
|
10905
|
+
{
|
|
10906
|
+
label: "Título da seção",
|
|
10907
|
+
fields: ["title"]
|
|
10908
|
+
},
|
|
10909
|
+
{
|
|
10910
|
+
label: "Quantidade de itens",
|
|
10911
|
+
fields: ["limit"]
|
|
10912
|
+
}
|
|
10913
|
+
],
|
|
10914
|
+
contentSource: {
|
|
10915
|
+
location: "Cases → Cases",
|
|
10916
|
+
description: "Os cards, textos e imagens da grade vêm dos cases publicados."
|
|
10917
|
+
}
|
|
10918
|
+
},
|
|
10919
|
+
"products-grid": {
|
|
10920
|
+
name: "Grade de produtos",
|
|
10921
|
+
category: "Conteúdo automático",
|
|
10922
|
+
description: "Uma vitrine organizada de produtos cadastrados.",
|
|
10923
|
+
controls: [
|
|
10924
|
+
{
|
|
10925
|
+
label: "Chamada pequena",
|
|
10926
|
+
fields: ["eyebrow"]
|
|
10927
|
+
},
|
|
10928
|
+
{
|
|
10929
|
+
label: "Título da seção",
|
|
10930
|
+
fields: ["title"]
|
|
10931
|
+
},
|
|
10932
|
+
{
|
|
10933
|
+
label: "Quantidade de itens",
|
|
10934
|
+
fields: ["limit"]
|
|
10935
|
+
},
|
|
10936
|
+
{
|
|
10937
|
+
label: "Categoria de produtos",
|
|
10938
|
+
fields: ["categorySlug"]
|
|
10939
|
+
}
|
|
10940
|
+
],
|
|
10941
|
+
contentSource: {
|
|
10942
|
+
location: "Produtos → Produtos",
|
|
10943
|
+
description: "Os cards, textos e imagens da grade vêm dos produtos cadastrados."
|
|
10944
|
+
}
|
|
10945
|
+
},
|
|
10946
|
+
"products-carousel": {
|
|
10947
|
+
name: "Carrossel de produtos",
|
|
10948
|
+
category: "Conteúdo automático",
|
|
10949
|
+
description: "Uma vitrine compacta para navegar pelos produtos.",
|
|
10950
|
+
controls: [
|
|
10951
|
+
{
|
|
10952
|
+
label: "Chamada pequena",
|
|
10953
|
+
fields: ["eyebrow"]
|
|
10954
|
+
},
|
|
10955
|
+
{
|
|
10956
|
+
label: "Título da seção",
|
|
10957
|
+
fields: ["title"]
|
|
10958
|
+
},
|
|
10959
|
+
{
|
|
10960
|
+
label: "Quantidade de itens",
|
|
10961
|
+
fields: ["limit"]
|
|
10962
|
+
},
|
|
10963
|
+
{
|
|
10964
|
+
label: "Categoria de produtos",
|
|
10965
|
+
fields: ["categorySlug"]
|
|
10966
|
+
}
|
|
10967
|
+
],
|
|
10968
|
+
contentSource: {
|
|
10969
|
+
location: "Produtos → Produtos",
|
|
10970
|
+
description: "Os cards, textos e imagens do carrossel vêm dos produtos cadastrados."
|
|
10971
|
+
}
|
|
10972
|
+
},
|
|
10973
|
+
"theme-component": {
|
|
10974
|
+
name: "Componente do tema",
|
|
10975
|
+
category: "Conteúdo",
|
|
10976
|
+
description: "Componente configurável declarado pelo tema ativo.",
|
|
10977
|
+
controls: []
|
|
10978
|
+
}
|
|
10979
|
+
};
|
|
10980
|
+
function panelDefinition(binding) {
|
|
10981
|
+
const custom = binding.componentDefinition;
|
|
10982
|
+
if (!custom) return PANEL_SECTION_DEFINITIONS[binding.type];
|
|
10983
|
+
return {
|
|
10984
|
+
name: custom.name,
|
|
10985
|
+
category: custom.category,
|
|
10986
|
+
description: custom.description,
|
|
10987
|
+
controls: custom.fields.map((field) => ({
|
|
10988
|
+
label: field.label,
|
|
10989
|
+
fields: [field.key],
|
|
10990
|
+
note: field.control === "repeater" ? "Lista repetível controlada pelo cliente no Gestão." : field.control === "contact-fields" ? "Permite escolher, ordenar e tornar obrigatórios os campos do formulário." : void 0
|
|
10991
|
+
}))
|
|
10992
|
+
};
|
|
10993
|
+
}
|
|
10994
|
+
function panelCompatibility(binding) {
|
|
10995
|
+
if (binding.type === "theme-component") return {
|
|
10996
|
+
level: "direct",
|
|
10997
|
+
label: "Direto",
|
|
10998
|
+
note: "O tema declara este componente e seus campos editáveis para o Construtor da Home."
|
|
10999
|
+
};
|
|
11000
|
+
if (binding.type !== "rich-text") return {
|
|
11001
|
+
level: "direct",
|
|
11002
|
+
label: "Direto",
|
|
11003
|
+
note: "Existe um bloco equivalente no Construtor da Home."
|
|
11004
|
+
};
|
|
11005
|
+
const component = binding.component.toLowerCase();
|
|
11006
|
+
if (/(video|faq|form|benefit|number|stat|metric|feature|evaluation|avali|app|forwhom|quem)/.test(component)) return {
|
|
11007
|
+
level: "v1-fallback",
|
|
11008
|
+
label: "Fallback V1",
|
|
11009
|
+
note: "O Gestão ainda não possui um bloco nativo para esta estrutura; na V1 apenas título e texto ficam configuráveis como Bloco de texto."
|
|
11010
|
+
};
|
|
11011
|
+
return {
|
|
11012
|
+
level: "direct",
|
|
11013
|
+
label: "Direto",
|
|
11014
|
+
note: "O conteúdo textual pode ser configurado diretamente como Bloco de texto."
|
|
11015
|
+
};
|
|
11016
|
+
}
|
|
11017
|
+
function sourceKind(file) {
|
|
11018
|
+
const extension = path.extname(file).toLowerCase();
|
|
11019
|
+
if (extension === ".tsx") return ts.ScriptKind.TSX;
|
|
11020
|
+
if (extension === ".jsx") return ts.ScriptKind.JSX;
|
|
11021
|
+
if ([
|
|
11022
|
+
".js",
|
|
11023
|
+
".mjs",
|
|
11024
|
+
".cjs"
|
|
11025
|
+
].includes(extension)) return ts.ScriptKind.JS;
|
|
11026
|
+
return ts.ScriptKind.TS;
|
|
11027
|
+
}
|
|
11028
|
+
function unwrappedExpression(expression) {
|
|
11029
|
+
if (ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression) || ts.isParenthesizedExpression(expression)) return unwrappedExpression(expression.expression);
|
|
11030
|
+
return expression;
|
|
11031
|
+
}
|
|
11032
|
+
function propertyKey(property) {
|
|
11033
|
+
if (!(ts.isPropertyAssignment(property) || ts.isShorthandPropertyAssignment(property))) return null;
|
|
11034
|
+
const name = property.name;
|
|
11035
|
+
return ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name) ? name.text : null;
|
|
11036
|
+
}
|
|
11037
|
+
function propertyValue(object, key) {
|
|
11038
|
+
const property = object.properties.find((candidate) => propertyKey(candidate) === key);
|
|
11039
|
+
return property && ts.isPropertyAssignment(property) ? property.initializer : null;
|
|
11040
|
+
}
|
|
11041
|
+
function flattenStringObject(object, prefix = "", result = /* @__PURE__ */ new Map()) {
|
|
11042
|
+
for (const property of object.properties) {
|
|
11043
|
+
if (!ts.isPropertyAssignment(property)) continue;
|
|
11044
|
+
const key = propertyKey(property);
|
|
11045
|
+
if (!key) continue;
|
|
11046
|
+
const compound = prefix ? `${prefix}.${key}` : key;
|
|
11047
|
+
const value = unwrappedExpression(property.initializer);
|
|
11048
|
+
if (ts.isStringLiteralLike(value) || ts.isNoSubstitutionTemplateLiteral(value)) result.set(compound, value.text);
|
|
11049
|
+
else if (ts.isObjectLiteralExpression(value)) flattenStringObject(value, compound, result);
|
|
11050
|
+
}
|
|
11051
|
+
return result;
|
|
11052
|
+
}
|
|
11053
|
+
function translationValues(source) {
|
|
11054
|
+
const result = /* @__PURE__ */ new Map();
|
|
11055
|
+
function visit(node) {
|
|
11056
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && /^(?:translations?|messages?|dictionary|locales?)$/i.test(node.name.text) && node.initializer) {
|
|
11057
|
+
const initializer = unwrappedExpression(node.initializer);
|
|
11058
|
+
if (ts.isObjectLiteralExpression(initializer)) {
|
|
11059
|
+
const locale = [
|
|
11060
|
+
"pt",
|
|
11061
|
+
"pt-BR",
|
|
11062
|
+
"pt_BR",
|
|
11063
|
+
"default"
|
|
11064
|
+
].map((key) => propertyValue(initializer, key)).find((value) => Boolean(value));
|
|
11065
|
+
const selected = locale ? unwrappedExpression(locale) : initializer;
|
|
11066
|
+
if (ts.isObjectLiteralExpression(selected)) for (const [key, value] of flattenStringObject(selected)) result.set(key, value);
|
|
11067
|
+
}
|
|
11068
|
+
}
|
|
11069
|
+
ts.forEachChild(node, visit);
|
|
11070
|
+
}
|
|
11071
|
+
visit(source);
|
|
11072
|
+
return result;
|
|
11073
|
+
}
|
|
11074
|
+
function contentField(key) {
|
|
11075
|
+
const normalized = key.toLowerCase();
|
|
11076
|
+
const last = normalized.split(".").at(-1) ?? normalized;
|
|
11077
|
+
if (/^(?:eyebrow|overline|kicker)$/.test(last)) return "eyebrow";
|
|
11078
|
+
if (/^(?:title|headline|heading)$/.test(last)) return "title";
|
|
11079
|
+
if (/^(?:subtitle|subheadline|description|desc|text|content)$/.test(last)) return "description";
|
|
11080
|
+
if (/(?:^|\.)(?:cta|button|action)(?:\.|$)/.test(normalized) || /^(?:cta|button|label)$/.test(last)) return "buttonLabel";
|
|
11081
|
+
}
|
|
11082
|
+
function jsxTagForText(node) {
|
|
11083
|
+
const parent = node.parent;
|
|
11084
|
+
return ts.isJsxElement(parent) ? parent.openingElement.tagName.getText() : "text";
|
|
11085
|
+
}
|
|
11086
|
+
function fieldForTag(tag) {
|
|
11087
|
+
if (/^h[1-6]$/i.test(tag)) return "title";
|
|
11088
|
+
if (/^(?:p|blockquote)$/i.test(tag)) return "description";
|
|
11089
|
+
if (/^(?:a|button)$/i.test(tag)) return "buttonLabel";
|
|
11090
|
+
if (/^(?:span|small)$/i.test(tag)) return "eyebrow";
|
|
11091
|
+
}
|
|
11092
|
+
function markdownCell(value) {
|
|
11093
|
+
return value.replace(/\|/g, "\\|").replace(/\r?\n/g, "<br>");
|
|
11094
|
+
}
|
|
11095
|
+
async function extractContentCatalog(plan) {
|
|
11096
|
+
const sources = /* @__PURE__ */ new Map();
|
|
11097
|
+
const translations = /* @__PURE__ */ new Map();
|
|
11098
|
+
const constantNodes = /* @__PURE__ */ new Map();
|
|
11099
|
+
const constants = /* @__PURE__ */ new Map();
|
|
11100
|
+
for (const module of plan.analysis.sourceGraph.modules.filter(({ kind }) => kind === "SOURCE")) {
|
|
11101
|
+
const content = await readFile(module.absolutePath, "utf8");
|
|
11102
|
+
const source = ts.createSourceFile(module.absolutePath, content, ts.ScriptTarget.Latest, true, sourceKind(module.absolutePath));
|
|
11103
|
+
sources.set(module.file, {
|
|
11104
|
+
source,
|
|
11105
|
+
content
|
|
11106
|
+
});
|
|
11107
|
+
for (const [key, value] of translationValues(source)) translations.set(key, value);
|
|
11108
|
+
function collectConstants(node) {
|
|
11109
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer) constantNodes.set(node.name.text, node.initializer);
|
|
11110
|
+
ts.forEachChild(node, collectConstants);
|
|
11111
|
+
}
|
|
11112
|
+
collectConstants(source);
|
|
11113
|
+
}
|
|
11114
|
+
function resolvedString(expression, stack = /* @__PURE__ */ new Set()) {
|
|
11115
|
+
const value = unwrappedExpression(expression);
|
|
11116
|
+
if (ts.isStringLiteralLike(value) || ts.isNoSubstitutionTemplateLiteral(value)) return value.text;
|
|
11117
|
+
if (ts.isIdentifier(value)) {
|
|
11118
|
+
if (constants.has(value.text)) return constants.get(value.text);
|
|
11119
|
+
if (stack.has(value.text)) return null;
|
|
11120
|
+
const initializer = constantNodes.get(value.text);
|
|
11121
|
+
if (!initializer) return null;
|
|
11122
|
+
const resolved = resolvedString(initializer, new Set(stack).add(value.text));
|
|
11123
|
+
if (resolved !== null) constants.set(value.text, resolved);
|
|
11124
|
+
return resolved;
|
|
11125
|
+
}
|
|
11126
|
+
if (ts.isTemplateExpression(value)) {
|
|
11127
|
+
let output = value.head.text;
|
|
11128
|
+
for (const span of value.templateSpans) {
|
|
11129
|
+
const resolved = resolvedString(span.expression, stack);
|
|
11130
|
+
if (resolved === null) return null;
|
|
11131
|
+
output += resolved + span.literal.text;
|
|
11132
|
+
}
|
|
11133
|
+
return output;
|
|
11134
|
+
}
|
|
11135
|
+
if (ts.isBinaryExpression(value) && value.operatorToken.kind === ts.SyntaxKind.PlusToken) {
|
|
11136
|
+
const left = resolvedString(value.left, stack);
|
|
11137
|
+
const right = resolvedString(value.right, stack);
|
|
11138
|
+
return left === null || right === null ? null : left + right;
|
|
11139
|
+
}
|
|
11140
|
+
return null;
|
|
11141
|
+
}
|
|
11142
|
+
for (const [name, expression] of constantNodes) {
|
|
11143
|
+
const value = resolvedString(expression);
|
|
11144
|
+
if (value !== null) constants.set(name, value);
|
|
11145
|
+
}
|
|
11146
|
+
const sections = plan.contentBindings.map((binding) => {
|
|
11147
|
+
const parsed = sources.get(binding.file);
|
|
11148
|
+
const values = [];
|
|
11149
|
+
const formFields = [];
|
|
11150
|
+
const seen = /* @__PURE__ */ new Set();
|
|
11151
|
+
const counters = /* @__PURE__ */ new Map();
|
|
11152
|
+
const importedAssets = /* @__PURE__ */ new Map();
|
|
11153
|
+
const add = (candidate) => {
|
|
11154
|
+
const value = candidate.value.trim().replace(/\s+/g, " ");
|
|
11155
|
+
if (!value || seen.has(`${candidate.kind}:${candidate.key}:${value}`)) return;
|
|
11156
|
+
seen.add(`${candidate.kind}:${candidate.key}:${value}`);
|
|
11157
|
+
values.push({
|
|
11158
|
+
...candidate,
|
|
11159
|
+
value
|
|
11160
|
+
});
|
|
11161
|
+
};
|
|
11162
|
+
if (parsed) {
|
|
11163
|
+
const source = parsed.source;
|
|
11164
|
+
const attributeValue = (attributes, name) => {
|
|
11165
|
+
const attribute = attributes.properties.find((candidate) => ts.isJsxAttribute(candidate) && candidate.name.getText(source) === name);
|
|
11166
|
+
if (!attribute?.initializer) return null;
|
|
11167
|
+
if (ts.isStringLiteral(attribute.initializer)) return attribute.initializer.text;
|
|
11168
|
+
if (ts.isJsxExpression(attribute.initializer) && attribute.initializer.expression) return resolvedString(attribute.initializer.expression);
|
|
11169
|
+
return null;
|
|
11170
|
+
};
|
|
11171
|
+
const hasAttribute = (attributes, name) => attributes.properties.some((candidate) => ts.isJsxAttribute(candidate) && candidate.name.getText(source) === name);
|
|
11172
|
+
const nodeText = (node) => {
|
|
11173
|
+
const chunks = [];
|
|
11174
|
+
const collect = (candidate) => {
|
|
11175
|
+
if (ts.isJsxText(candidate) && candidate.text.trim()) chunks.push(candidate.text);
|
|
11176
|
+
else if (ts.isJsxExpression(candidate) && candidate.expression) {
|
|
11177
|
+
const value = resolvedString(candidate.expression);
|
|
11178
|
+
if (value) chunks.push(value);
|
|
11179
|
+
}
|
|
11180
|
+
ts.forEachChild(candidate, collect);
|
|
11181
|
+
};
|
|
11182
|
+
collect(node);
|
|
11183
|
+
return chunks.join(" ").trim().replace(/\s+/g, " ");
|
|
11184
|
+
};
|
|
11185
|
+
const fieldLabelText = (node) => {
|
|
11186
|
+
const chunks = [];
|
|
11187
|
+
const collect = (candidate) => {
|
|
11188
|
+
if (ts.isJsxElement(candidate) || ts.isJsxSelfClosingElement(candidate)) {
|
|
11189
|
+
const tag = (ts.isJsxElement(candidate) ? candidate.openingElement.tagName : candidate.tagName).getText(source).toLowerCase();
|
|
11190
|
+
if ([
|
|
11191
|
+
"input",
|
|
11192
|
+
"textarea",
|
|
11193
|
+
"select",
|
|
11194
|
+
"option"
|
|
11195
|
+
].includes(tag)) return;
|
|
11196
|
+
}
|
|
11197
|
+
if (ts.isJsxText(candidate) && candidate.text.trim()) chunks.push(candidate.text);
|
|
11198
|
+
else if (ts.isJsxExpression(candidate) && candidate.expression) {
|
|
11199
|
+
const value = resolvedString(candidate.expression);
|
|
11200
|
+
if (value) chunks.push(value);
|
|
11201
|
+
}
|
|
11202
|
+
ts.forEachChild(candidate, collect);
|
|
11203
|
+
};
|
|
11204
|
+
collect(node);
|
|
11205
|
+
return chunks.join(" ").trim().replace(/\s+/g, " ");
|
|
11206
|
+
};
|
|
11207
|
+
const nearbyFieldLabel = (node, type) => {
|
|
11208
|
+
let ancestor = node.parent;
|
|
11209
|
+
while (ancestor && !ts.isFunctionLike(ancestor)) {
|
|
11210
|
+
if (ts.isJsxElement(ancestor) && ancestor.openingElement.tagName.getText(source).toLowerCase() === "label") {
|
|
11211
|
+
const label = fieldLabelText(ancestor);
|
|
11212
|
+
if (label) return label;
|
|
11213
|
+
}
|
|
11214
|
+
if (ts.isJsxElement(ancestor)) {
|
|
11215
|
+
const index = ancestor.children.findIndex((child) => child === node || child.pos <= node.pos && child.end >= node.end);
|
|
11216
|
+
if (index >= 0) {
|
|
11217
|
+
const before = ancestor.children.slice(0, index).reverse();
|
|
11218
|
+
const after = ancestor.children.slice(index + 1);
|
|
11219
|
+
const siblings = type === "checkbox" ? [...after, ...before] : [...before, ...after];
|
|
11220
|
+
for (const sibling of siblings) {
|
|
11221
|
+
if (!sibling) continue;
|
|
11222
|
+
const label = fieldLabelText(sibling);
|
|
11223
|
+
if (label) return label;
|
|
11224
|
+
}
|
|
11225
|
+
}
|
|
11226
|
+
}
|
|
11227
|
+
ancestor = ancestor.parent;
|
|
11228
|
+
}
|
|
11229
|
+
return "";
|
|
11230
|
+
};
|
|
11231
|
+
const collectFormField = (node) => {
|
|
11232
|
+
if (binding.componentKey !== "contact-form") return;
|
|
11233
|
+
const opening = ts.isJsxElement(node) ? node.openingElement : node;
|
|
11234
|
+
const tag = opening.tagName.getText(source).toLowerCase();
|
|
11235
|
+
if (![
|
|
11236
|
+
"input",
|
|
11237
|
+
"textarea",
|
|
11238
|
+
"select"
|
|
11239
|
+
].includes(tag)) return;
|
|
11240
|
+
const key = attributeValue(opening.attributes, "name")?.trim();
|
|
11241
|
+
if (!key || formFields.some((field) => field.key === key)) return;
|
|
11242
|
+
const rawType = tag === "textarea" ? "textarea" : tag === "select" ? "select" : attributeValue(opening.attributes, "type") ?? "text";
|
|
11243
|
+
const type = [
|
|
11244
|
+
"text",
|
|
11245
|
+
"email",
|
|
11246
|
+
"tel",
|
|
11247
|
+
"url",
|
|
11248
|
+
"number",
|
|
11249
|
+
"textarea",
|
|
11250
|
+
"select",
|
|
11251
|
+
"checkbox"
|
|
11252
|
+
].includes(rawType) ? rawType : "text";
|
|
11253
|
+
const field = {
|
|
11254
|
+
key,
|
|
11255
|
+
label: nearbyFieldLabel(node, type) || key,
|
|
11256
|
+
type,
|
|
11257
|
+
required: hasAttribute(opening.attributes, "required")
|
|
11258
|
+
};
|
|
11259
|
+
const placeholder = attributeValue(opening.attributes, "placeholder")?.trim();
|
|
11260
|
+
if (placeholder) field.placeholder = placeholder;
|
|
11261
|
+
if (tag === "select" && ts.isJsxElement(node)) {
|
|
11262
|
+
const options = [];
|
|
11263
|
+
const visitOption = (candidate) => {
|
|
11264
|
+
if (ts.isJsxElement(candidate) && candidate.openingElement.tagName.getText(source).toLowerCase() === "option") {
|
|
11265
|
+
const optionLabel = nodeText(candidate);
|
|
11266
|
+
const optionValue = attributeValue(candidate.openingElement.attributes, "value") ?? optionLabel;
|
|
11267
|
+
if (optionLabel) options.push({
|
|
11268
|
+
label: optionLabel,
|
|
11269
|
+
value: optionValue
|
|
11270
|
+
});
|
|
11271
|
+
return;
|
|
11272
|
+
}
|
|
11273
|
+
ts.forEachChild(candidate, visitOption);
|
|
11274
|
+
};
|
|
11275
|
+
visitOption(node);
|
|
11276
|
+
if (options.length) field.options = options;
|
|
11277
|
+
}
|
|
11278
|
+
formFields.push(field);
|
|
11279
|
+
};
|
|
11280
|
+
for (const statement of source.statements.filter(ts.isImportDeclaration)) {
|
|
11281
|
+
const specifier = statement.moduleSpecifier;
|
|
11282
|
+
if (!ts.isStringLiteralLike(specifier) || !statement.importClause) continue;
|
|
11283
|
+
const extension = path.extname(specifier.text).toLowerCase();
|
|
11284
|
+
if (!/[.](?:avif|gif|jpe?g|png|svg|webp|mp4|webm|ogg)$/i.test(extension)) continue;
|
|
11285
|
+
const assetReference = specifier.text.startsWith(".") ? portable(path.normalize(path.join(path.dirname(binding.file), specifier.text))) : specifier.text;
|
|
11286
|
+
if (statement.importClause.name) importedAssets.set(statement.importClause.name.text, assetReference);
|
|
11287
|
+
if (statement.importClause.namedBindings && ts.isNamedImports(statement.importClause.namedBindings)) for (const item of statement.importClause.namedBindings.elements) importedAssets.set(item.name.text, assetReference);
|
|
11288
|
+
}
|
|
11289
|
+
function componentName(node) {
|
|
11290
|
+
if ("name" in node && node.name && ts.isIdentifier(node.name)) return node.name.text;
|
|
11291
|
+
const parent = node.parent;
|
|
11292
|
+
return ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name) ? parent.name.text : null;
|
|
11293
|
+
}
|
|
11294
|
+
function visitContent(node) {
|
|
11295
|
+
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) collectFormField(node);
|
|
11296
|
+
if (binding.componentKey === "feature-list" && ts.isArrayLiteralExpression(node)) for (const element of node.elements) {
|
|
11297
|
+
const item = resolvedString(element);
|
|
11298
|
+
if (item) add({
|
|
11299
|
+
key: "data.item",
|
|
11300
|
+
value: item,
|
|
11301
|
+
kind: "text"
|
|
11302
|
+
});
|
|
11303
|
+
}
|
|
11304
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "t" && node.arguments[0] && ts.isStringLiteralLike(node.arguments[0])) {
|
|
11305
|
+
const key = node.arguments[0].text;
|
|
11306
|
+
add({
|
|
11307
|
+
key,
|
|
11308
|
+
value: translations.get(key) ?? `[tradução não localizada: ${key}]`,
|
|
11309
|
+
kind: "text",
|
|
11310
|
+
field: contentField(key)
|
|
11311
|
+
});
|
|
11312
|
+
return;
|
|
11313
|
+
}
|
|
11314
|
+
if (ts.isJsxText(node) && node.text.trim()) {
|
|
11315
|
+
const tag = jsxTagForText(node);
|
|
11316
|
+
const count = (counters.get(tag) ?? 0) + 1;
|
|
11317
|
+
counters.set(tag, count);
|
|
11318
|
+
add({
|
|
11319
|
+
key: `jsx.${tag}.${count}`,
|
|
11320
|
+
value: node.text,
|
|
11321
|
+
kind: "text",
|
|
11322
|
+
field: fieldForTag(tag)
|
|
11323
|
+
});
|
|
11324
|
+
return;
|
|
11325
|
+
}
|
|
11326
|
+
if (ts.isPropertyAssignment(node)) {
|
|
11327
|
+
const key = propertyKey(node);
|
|
11328
|
+
const value = resolvedString(node.initializer);
|
|
11329
|
+
if (key && value !== null && /^(?:title|headline|heading|subtitle|description|desc|text|content|label|cta|price|period|badge|question|answer|q|a|name|value|number|metric|num|role|email|phone|tel)$/i.test(key)) add({
|
|
11330
|
+
key: `data.${key}`,
|
|
11331
|
+
value,
|
|
11332
|
+
kind: "text",
|
|
11333
|
+
field: contentField(key)
|
|
11334
|
+
});
|
|
11335
|
+
}
|
|
11336
|
+
if (ts.isJsxAttribute(node) && node.initializer) {
|
|
11337
|
+
const name = node.name.getText(source);
|
|
11338
|
+
const tag = node.parent.parent.tagName.getText(source).toLowerCase();
|
|
11339
|
+
let expression = null;
|
|
11340
|
+
if (ts.isStringLiteral(node.initializer)) expression = node.initializer;
|
|
11341
|
+
else if (ts.isJsxExpression(node.initializer) && node.initializer.expression) expression = node.initializer.expression;
|
|
11342
|
+
const literal = expression ? resolvedString(expression) : null;
|
|
11343
|
+
const imported = expression && ts.isIdentifier(expression) ? importedAssets.get(expression.text) : void 0;
|
|
11344
|
+
const value = literal ?? imported ?? null;
|
|
11345
|
+
if (value && name === "href" && (tag === "a" || tag === "button")) add({
|
|
11346
|
+
key: `${tag}.href`,
|
|
11347
|
+
value,
|
|
11348
|
+
kind: "link",
|
|
11349
|
+
field: "buttonUrl"
|
|
11350
|
+
});
|
|
11351
|
+
if (value && ["src", "poster"].includes(name) && [
|
|
11352
|
+
"img",
|
|
11353
|
+
"image",
|
|
11354
|
+
"video",
|
|
11355
|
+
"source",
|
|
11356
|
+
"iframe"
|
|
11357
|
+
].includes(tag)) {
|
|
11358
|
+
const field = name === "poster" ? "posterImageUrl" : binding.componentKey === "video" && (tag === "video" || tag === "source" || tag === "iframe") ? "videoUrl" : "imageUrl";
|
|
11359
|
+
add({
|
|
11360
|
+
key: `${tag}.${name}`,
|
|
11361
|
+
value,
|
|
11362
|
+
kind: "media",
|
|
11363
|
+
field
|
|
11364
|
+
});
|
|
11365
|
+
}
|
|
11366
|
+
if (value && name === "alt" && ["img", "image"].includes(tag)) add({
|
|
11367
|
+
key: `${tag}.alt`,
|
|
11368
|
+
value,
|
|
11369
|
+
kind: "text",
|
|
11370
|
+
field: "imageAlt"
|
|
11371
|
+
});
|
|
11372
|
+
}
|
|
11373
|
+
ts.forEachChild(node, visitContent);
|
|
11374
|
+
}
|
|
11375
|
+
function findComponent(node) {
|
|
11376
|
+
if ((ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node)) && componentName(node) === binding.component && node.body) {
|
|
11377
|
+
visitContent(node.body);
|
|
11378
|
+
return;
|
|
11379
|
+
}
|
|
11380
|
+
ts.forEachChild(node, findComponent);
|
|
11381
|
+
}
|
|
11382
|
+
findComponent(source);
|
|
11383
|
+
}
|
|
11384
|
+
const sectionData = blankBindingData(binding);
|
|
11385
|
+
const data = binding.type === "theme-component" ? sectionData.props : sectionData;
|
|
11386
|
+
const availableFields = new Set(binding.fields);
|
|
11387
|
+
const selected = /* @__PURE__ */ new Set();
|
|
11388
|
+
const assign = (field, candidate) => {
|
|
11389
|
+
if (!candidate || !availableFields.has(field)) return;
|
|
11390
|
+
data[field] = candidate.kind === "media" ? "" : candidate.value;
|
|
11391
|
+
selected.add(candidate.key);
|
|
11392
|
+
};
|
|
11393
|
+
const rank = (field, item) => {
|
|
11394
|
+
if (field === "title" && /^jsx\.h[1-6]\./.test(item.key)) return 0;
|
|
11395
|
+
if (field === "description" && /^jsx\.(?:p|blockquote)\./.test(item.key)) return 0;
|
|
11396
|
+
if (field === "buttonLabel" && /^jsx\.(?:button|a)\./.test(item.key)) return 0;
|
|
11397
|
+
if (field === "eyebrow" && /^jsx\.(?:span|small)\./.test(item.key)) return 0;
|
|
11398
|
+
if (item.key.startsWith("jsx.")) return 1;
|
|
11399
|
+
if (item.key.startsWith("data.")) return 3;
|
|
11400
|
+
return 2;
|
|
11401
|
+
};
|
|
11402
|
+
const ranked = (field) => values.filter((item) => item.field === field && !(field === "eyebrow" && /(?:lgpd|consent|privacidade|tratamento dos meus dados|autorizo)/i.test(item.value))).sort((left, right) => rank(field, left) - rank(field, right) || left.key.split(".").length - right.key.split(".").length)[0];
|
|
11403
|
+
assign("eyebrow", ranked("eyebrow") ?? values.find((item) => /^jsx\.div\./.test(item.key) && item.value.length <= 100 && item.value === item.value.toLocaleUpperCase("pt-BR") && /[A-ZÀ-Ü]/.test(item.value) && !/(?:lgpd|consent|privacidade|tratamento dos meus dados|autorizo)/i.test(item.value)));
|
|
11404
|
+
assign("title", ranked("title"));
|
|
11405
|
+
const description = ranked("description");
|
|
11406
|
+
assign(availableFields.has("description") ? "description" : "text", description);
|
|
11407
|
+
assign("buttonLabel", ranked("buttonLabel"));
|
|
11408
|
+
assign("buttonUrl", ranked("buttonUrl"));
|
|
11409
|
+
assign("imageAlt", ranked("imageAlt"));
|
|
11410
|
+
assign("videoUrl", ranked("videoUrl"));
|
|
11411
|
+
assign("posterImageUrl", ranked("posterImageUrl"));
|
|
11412
|
+
if (binding.componentKey === "contact-form" && formFields.length && availableFields.has("fields")) data.fields = formFields;
|
|
11413
|
+
const media = ranked("imageUrl");
|
|
11414
|
+
if (media && availableFields.has("imageUrl")) selected.add(media.key);
|
|
11415
|
+
if (availableFields.has("text") && !data.text) data.text = values.filter(({ kind, key }) => kind === "text" && !selected.has(key) && !key.includes("tradução não localizada")).map(({ value }) => value).join("\n\n");
|
|
11416
|
+
if (binding.type === "theme-component" && availableFields.has("items")) {
|
|
11417
|
+
const properties = values.filter(({ key, kind }) => key.startsWith("data.") && kind === "text");
|
|
11418
|
+
const items = [];
|
|
11419
|
+
if (binding.componentKey === "faq") for (let index = 0; index < properties.length; index += 1) {
|
|
11420
|
+
const question = properties[index];
|
|
11421
|
+
if (!/(?:question|q)$/.test(question.key.toLowerCase())) continue;
|
|
11422
|
+
const answer = properties.slice(index + 1).find(({ key }) => /(?:answer|a)$/.test(key.toLowerCase()));
|
|
11423
|
+
items.push({
|
|
11424
|
+
question: question.value,
|
|
11425
|
+
answer: answer?.value ?? ""
|
|
11426
|
+
});
|
|
11427
|
+
}
|
|
11428
|
+
else if (binding.componentKey === "metrics") {
|
|
11429
|
+
let current = {};
|
|
11430
|
+
for (const property of properties) {
|
|
11431
|
+
const key = property.key.toLowerCase();
|
|
11432
|
+
if (/(?:value|number|metric)$/.test(key)) {
|
|
11433
|
+
if (Object.keys(current).length) items.push(current);
|
|
11434
|
+
current = { value: property.value };
|
|
11435
|
+
} else if (/(?:title|label|name)$/.test(key) && !current.title) current.title = property.value;
|
|
11436
|
+
else if (/(?:description|desc|text)$/.test(key) && !current.description) current.description = property.value;
|
|
11437
|
+
}
|
|
11438
|
+
if (Object.keys(current).length) items.push(current);
|
|
11439
|
+
} else if (binding.componentKey === "steps") {
|
|
11440
|
+
let current = {};
|
|
11441
|
+
for (const property of properties) {
|
|
11442
|
+
const key = property.key.toLowerCase();
|
|
11443
|
+
if (/(?:num|number|value)$/.test(key)) {
|
|
11444
|
+
if (Object.keys(current).length) items.push(current);
|
|
11445
|
+
current = { num: property.value };
|
|
11446
|
+
} else if (/(?:title|label|name)$/.test(key)) current.title = property.value;
|
|
11447
|
+
else if (/(?:description|desc|text)$/.test(key)) current.desc = property.value;
|
|
11448
|
+
}
|
|
11449
|
+
if (Object.keys(current).length) items.push(current);
|
|
11450
|
+
} else if (binding.componentKey === "contacts") {
|
|
11451
|
+
let current = {};
|
|
11452
|
+
for (const property of properties) {
|
|
11453
|
+
const key = property.key.toLowerCase();
|
|
11454
|
+
if (/(?:role)$/.test(key)) {
|
|
11455
|
+
if (Object.keys(current).length) items.push(current);
|
|
11456
|
+
current = { role: property.value };
|
|
11457
|
+
} else if (/(?:name)$/.test(key)) current.name = property.value;
|
|
11458
|
+
else if (/(?:email)$/.test(key)) current.email = property.value;
|
|
11459
|
+
else if (/(?:phone|tel)$/.test(key)) current.phone = property.value;
|
|
11460
|
+
}
|
|
11461
|
+
if (Object.keys(current).length) items.push(current);
|
|
11462
|
+
} else if (binding.componentKey === "feature-list") items.push(...values.filter(({ key }) => key === "data.item").map(({ value }) => ({ title: value })));
|
|
11463
|
+
else {
|
|
11464
|
+
let current = {};
|
|
11465
|
+
for (const property of properties) {
|
|
11466
|
+
const key = property.key.toLowerCase();
|
|
11467
|
+
if (/(?:title|label|name)$/.test(key)) {
|
|
11468
|
+
if (current.title) items.push(current);
|
|
11469
|
+
current = { title: property.value };
|
|
11470
|
+
} else if (/(?:description|desc|text)$/.test(key) && current.title && !current.description) current.description = property.value;
|
|
11471
|
+
}
|
|
11472
|
+
if (Object.keys(current).length) items.push(current);
|
|
11473
|
+
}
|
|
11474
|
+
data.items = items;
|
|
11475
|
+
}
|
|
11476
|
+
return {
|
|
11477
|
+
id: binding.id,
|
|
11478
|
+
component: binding.component,
|
|
11479
|
+
file: binding.file,
|
|
11480
|
+
type: binding.type,
|
|
11481
|
+
order: binding.order,
|
|
11482
|
+
data: sectionData,
|
|
11483
|
+
sourceContent: values
|
|
11484
|
+
};
|
|
11485
|
+
});
|
|
11486
|
+
return {
|
|
11487
|
+
version: 1,
|
|
11488
|
+
locale: translations.size ? "pt" : "original",
|
|
11489
|
+
note: "Conteúdo de referência extraído do projeto original. Cadastre-o no painel; este arquivo não é carregado pelo tema em runtime.",
|
|
11490
|
+
sections
|
|
11491
|
+
};
|
|
11492
|
+
}
|
|
11493
|
+
function homeConfiguration(plan) {
|
|
11494
|
+
return `${JSON.stringify({
|
|
11495
|
+
version: 1,
|
|
11496
|
+
sections: plan.contentBindings.map((binding) => ({
|
|
11497
|
+
id: binding.id,
|
|
11498
|
+
type: binding.type,
|
|
11499
|
+
enabled: true,
|
|
11500
|
+
order: binding.order,
|
|
11501
|
+
data: blankBindingData(binding)
|
|
11502
|
+
}))
|
|
11503
|
+
}, null, 2)}\n`;
|
|
8822
11504
|
}
|
|
8823
|
-
function
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
11505
|
+
function contentMap(plan, catalog) {
|
|
11506
|
+
return `${JSON.stringify({
|
|
11507
|
+
version: 1,
|
|
11508
|
+
sourceProject: plan.analysis.projectName,
|
|
11509
|
+
note: "Preencha estes campos no painel Nuvler. Os valores extraídos estão em migration-content-seed.json; o tema não os publica hardcoded.",
|
|
11510
|
+
management: {
|
|
11511
|
+
location: "Home → Construtor",
|
|
11512
|
+
mode: "Montar",
|
|
11513
|
+
finalAction: "Salvar rascunho e Publicar"
|
|
11514
|
+
},
|
|
11515
|
+
sections: plan.contentBindings.map((binding) => {
|
|
11516
|
+
const serializableBinding = {
|
|
11517
|
+
id: binding.id,
|
|
11518
|
+
component: binding.component,
|
|
11519
|
+
file: binding.file,
|
|
11520
|
+
type: binding.type,
|
|
11521
|
+
order: binding.order,
|
|
11522
|
+
fields: binding.fields,
|
|
11523
|
+
componentKey: binding.componentKey,
|
|
11524
|
+
componentDefinition: binding.componentDefinition
|
|
11525
|
+
};
|
|
11526
|
+
const definition = panelDefinition(binding);
|
|
11527
|
+
const compatibility = panelCompatibility(binding);
|
|
11528
|
+
return {
|
|
11529
|
+
...serializableBinding,
|
|
11530
|
+
visualLink: `${binding.component} → ${definition.name} → ${binding.type}`,
|
|
11531
|
+
panel: {
|
|
11532
|
+
location: "Home → Construtor → Montar",
|
|
11533
|
+
category: definition.category,
|
|
11534
|
+
name: definition.name,
|
|
11535
|
+
description: definition.description,
|
|
11536
|
+
sectionId: binding.id,
|
|
11537
|
+
type: binding.type,
|
|
11538
|
+
order: binding.order,
|
|
11539
|
+
compatibility,
|
|
11540
|
+
controls: definition.controls,
|
|
11541
|
+
contentSource: definition.contentSource ?? null,
|
|
11542
|
+
data: blankBindingData(binding)
|
|
11543
|
+
},
|
|
11544
|
+
template: {
|
|
11545
|
+
hook: `useMigratedSection(${JSON.stringify(binding.id)})`,
|
|
11546
|
+
reads: binding.fields.map((field) => ({
|
|
11547
|
+
field,
|
|
11548
|
+
accessor: binding.type === "theme-component" ? `section.data.props.${field}` : `section.data.${field}`
|
|
11549
|
+
}))
|
|
11550
|
+
},
|
|
11551
|
+
extractedContent: catalog.sections.find(({ id }) => id === binding.id)?.sourceContent ?? []
|
|
11552
|
+
};
|
|
11553
|
+
})
|
|
11554
|
+
}, null, 2)}\n`;
|
|
11555
|
+
}
|
|
11556
|
+
function contentGuide(plan, catalog) {
|
|
11557
|
+
const rows = plan.contentBindings.map((binding) => {
|
|
11558
|
+
const definition = panelDefinition(binding);
|
|
11559
|
+
const compatibility = panelCompatibility(binding);
|
|
11560
|
+
const source = definition.contentSource?.location ?? "Nesta própria seção";
|
|
11561
|
+
return `| ${binding.order + 1} | ${binding.component} | **${definition.name}** | \`${binding.type}\` | ${compatibility.label} | ${source} |`;
|
|
11562
|
+
}).join("\n");
|
|
11563
|
+
const details = catalog.sections.map((section) => {
|
|
11564
|
+
const binding = plan.contentBindings.find(({ id }) => id === section.id);
|
|
11565
|
+
const definition = binding ? panelDefinition(binding) : PANEL_SECTION_DEFINITIONS[section.type];
|
|
11566
|
+
const compatibility = binding ? panelCompatibility(binding) : null;
|
|
11567
|
+
const populatedData = Object.fromEntries(Object.entries(section.data).filter(([, value]) => value !== ""));
|
|
11568
|
+
const detected = section.sourceContent.map(({ key, value, kind, field }) => `| \`${markdownCell(key)}\` | ${markdownCell(value)} | ${kind === "media" ? "mídia: faça upload no painel" : field ? `\`${field}\`` : "conteúdo adicional"} |`).join("\n");
|
|
11569
|
+
const controls = definition.controls.map((control) => `| ${control.label} | ${control.fields.map((field) => `\`${field}\``).join(", ")} | ${control.note ?? "-"} |`).join("\n");
|
|
11570
|
+
const contentSource = definition.contentSource ? `\n**Conteúdo dos itens:** abra **${definition.contentSource.location}**. ${definition.contentSource.description}\n` : "";
|
|
11571
|
+
return `## ${section.order + 1}. ${section.component} → ${definition.name}
|
|
8831
11572
|
|
|
8832
|
-
|
|
11573
|
+
No Gestão: **Home → Construtor → Montar → ${definition.category} → ${definition.name}**.
|
|
11574
|
+
O nome técnico enviado pela API é \`${section.type}\`.
|
|
11575
|
+
${compatibility ? `\n**Compatibilidade:** ${compatibility.label}. ${compatibility.note}\n` : ""}
|
|
11576
|
+
${contentSource}
|
|
11577
|
+
| Rótulo que aparece no Gestão | Chave na API | Observação |
|
|
11578
|
+
| --- | --- | --- |
|
|
11579
|
+
${controls}
|
|
8833
11580
|
|
|
8834
|
-
|
|
8835
|
-
const candidate = section?.data[key];
|
|
8836
|
-
return typeof candidate === "string" ? candidate : "";
|
|
8837
|
-
}
|
|
11581
|
+
Valores encontrados no projeto original para copiar no painel:
|
|
8838
11582
|
|
|
8839
|
-
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
const productSection = enabled.find((item) => item.type === "products-grid" || item.type === "products-carousel");
|
|
8843
|
-
const name = site.settings?.siteName || site.tenant.name;
|
|
8844
|
-
const action = template.primaryAction(site.modules);
|
|
8845
|
-
return <main className=${classes("nuvler-migrated-home", home.root)}>
|
|
8846
|
-
<section className=${classes("nuvler-migrated-hero", hero.root || home.content)}>
|
|
8847
|
-
<div className=${classes("nuvler-migrated-hero-content", hero.content)}>
|
|
8848
|
-
<span>{${JSON.stringify(heroText)}}</span>
|
|
8849
|
-
<h1 className=${classes("nuvler-migrated-hero-title", hero.title)}>{value(heroSection, "title") || name}</h1>
|
|
8850
|
-
<p className=${classes("nuvler-migrated-copy", hero.text)}>{value(heroSection, "description") || site.settings?.description || "Conheça nossos produtos e soluções."}</p>
|
|
8851
|
-
<a className=${classes("nuvler-migrated-action", hero.action)} href={value(heroSection, "buttonUrl") || action.href}>{value(heroSection, "buttonLabel") || action.label}</a>
|
|
8852
|
-
</div>
|
|
8853
|
-
{migratedHeroAsset && <div className=${classes("nuvler-migrated-hero-media", hero.media)}><img src={migratedHeroAsset} alt="" /></div>}
|
|
8854
|
-
</section>
|
|
8855
|
-
{site.modules.includes("PRODUCTS") && <section className=${classes("nuvler-migrated-section", section.root)}>
|
|
8856
|
-
<header><span>Destaques</span><h2 className=${classes("nuvler-migrated-section-title", section.title)}>{value(productSection, "title") || "Produtos em destaque"}</h2></header>
|
|
8857
|
-
<ProductGrid products={products} columns={site.settings?.catalog?.desktopColumns || 3} showCategory={site.settings?.catalog?.showCategory} showDescription={site.settings?.catalog?.showDescription} />
|
|
8858
|
-
</section>}
|
|
8859
|
-
{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>)}
|
|
8860
|
-
</main>;
|
|
8861
|
-
}
|
|
8862
|
-
`;
|
|
8863
|
-
}
|
|
8864
|
-
function definitionSource(plan) {
|
|
8865
|
-
const tokens = plan.tokens;
|
|
8866
|
-
return `import manifestData from "../nuvler.theme.json" with { type: "json" };
|
|
8867
|
-
import { defineTheme, type ThemeHomeSection, type ThemeManifest } from "@nuvler/theme-sdk";
|
|
8868
|
-
import { Footer } from "./components/Footer.js";
|
|
8869
|
-
import { Header } from "./components/Header.js";
|
|
8870
|
-
import { ProductDetail } from "./components/ProductDetail.js";
|
|
8871
|
-
import { ProductGrid } from "./components/ProductGrid.js";
|
|
8872
|
-
import { Home } from "./sections/Home.js";
|
|
11583
|
+
\`\`\`json
|
|
11584
|
+
${JSON.stringify(populatedData, null, 2)}
|
|
11585
|
+
\`\`\`
|
|
8873
11586
|
|
|
8874
|
-
|
|
8875
|
-
return { id, type, enabled: true, order, data: {} };
|
|
8876
|
-
}
|
|
11587
|
+
Conteúdo encontrado no projeto original:
|
|
8877
11588
|
|
|
8878
|
-
|
|
8879
|
-
|
|
8880
|
-
|
|
8881
|
-
tokens: {
|
|
8882
|
-
colors: ${JSON.stringify({
|
|
8883
|
-
primary: tokens.primary,
|
|
8884
|
-
primaryText: tokens.primaryText,
|
|
8885
|
-
secondary: tokens.secondary,
|
|
8886
|
-
secondaryText: tokens.secondaryText,
|
|
8887
|
-
accent: tokens.accent,
|
|
8888
|
-
background: tokens.background,
|
|
8889
|
-
surface: tokens.surface,
|
|
8890
|
-
surfaceAlt: tokens.surfaceAlt,
|
|
8891
|
-
text: tokens.text,
|
|
8892
|
-
textMuted: tokens.textMuted,
|
|
8893
|
-
border: tokens.border,
|
|
8894
|
-
headerBackground: tokens.headerBackground,
|
|
8895
|
-
headerText: tokens.headerText,
|
|
8896
|
-
footerBackground: tokens.footerBackground,
|
|
8897
|
-
footerText: tokens.footerText
|
|
8898
|
-
})},
|
|
8899
|
-
layout: ${JSON.stringify({
|
|
8900
|
-
containerWidth: tokens.containerWidth,
|
|
8901
|
-
borderRadius: tokens.borderRadius
|
|
8902
|
-
})},
|
|
8903
|
-
},
|
|
8904
|
-
template: {
|
|
8905
|
-
announcement: ${JSON.stringify(plan.themeName)},
|
|
8906
|
-
footerTagline: "Experiência visual migrada para a plataforma Nuvler.",
|
|
8907
|
-
footerNavigationLabel: "Navegação",
|
|
8908
|
-
footerNote: ${JSON.stringify(plan.themeName)},
|
|
8909
|
-
socialLabel: "Redes sociais",
|
|
8910
|
-
benefits: [],
|
|
8911
|
-
fallbackSections: () => [section("migrated-hero", "hero", 0), section("migrated-products", "products-grid", 1)],
|
|
8912
|
-
primaryAction: (modules) => modules.includes("PRODUCTS") ? { label: "Ver produtos", href: "/produtos" } : { label: "Saiba mais", href: "/" },
|
|
8913
|
-
},
|
|
8914
|
-
components: { Header, Footer, Home, ProductGrid, ProductDetail },
|
|
8915
|
-
});
|
|
11589
|
+
| Origem | Valor original | Destino sugerido |
|
|
11590
|
+
| --- | --- | --- |
|
|
11591
|
+
${detected || "| - | Nenhum valor literal localizado | revise o componente original |"}
|
|
8916
11592
|
`;
|
|
8917
|
-
}
|
|
8918
|
-
|
|
8919
|
-
return `import type { ThemeRoute, ThemeSite } from "@nuvler/theme-sdk";
|
|
8920
|
-
import { ProductGrid } from "../components/ProductGrid.js";
|
|
11593
|
+
}).join("\n");
|
|
11594
|
+
return `# Configuração de conteúdo no Nuvler
|
|
8921
11595
|
|
|
8922
|
-
|
|
8923
|
-
|
|
8924
|
-
export function CatalogPage({ route, site }: { route: CatalogRoute; site: ThemeSite }) {
|
|
8925
|
-
return <main className="nuvler-migrated-section nuvler-migrated-catalog">
|
|
8926
|
-
<header><span>Catálogo</span><h1>{route.search ? \`Busca: \${route.search}\` : "Produtos"}</h1><p>{route.pagination.total} produto(s)</p></header>
|
|
8927
|
-
<ProductGrid products={route.products} columns={site.settings?.catalog?.desktopColumns || 3} showCategory={site.settings?.catalog?.showCategory} showDescription={site.settings?.catalog?.showDescription} />
|
|
8928
|
-
</main>;
|
|
8929
|
-
}
|
|
8930
|
-
`;
|
|
8931
|
-
}
|
|
8932
|
-
function productPageSource() {
|
|
8933
|
-
return `import type { ThemeRoute, ThemeRuntimeSdk, ThemeSite } from "@nuvler/theme-sdk";
|
|
8934
|
-
import { ProductDetail } from "../components/ProductDetail.js";
|
|
11596
|
+
Este tema mantém os componentes e a estilização do projeto original. Textos,
|
|
11597
|
+
imagens e links são lidos das seções configuradas em **Home** no painel Nuvler.
|
|
8935
11598
|
|
|
8936
|
-
|
|
11599
|
+
No Gestão, abra **Home → Construtor**, mantenha o modo **Montar** e escolha os
|
|
11600
|
+
blocos pelos nomes da coluna **Bloco no Gestão**. Depois use **Salvar rascunho**
|
|
11601
|
+
e **Publicar**. Não procure por nomes técnicos como \`hero\`: na tela ele aparece
|
|
11602
|
+
como **Banner principal**.
|
|
8937
11603
|
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
|
|
8941
|
-
`;
|
|
8942
|
-
}
|
|
8943
|
-
function editorialPageSource() {
|
|
8944
|
-
return `import type { ThemeRoute } from "@nuvler/theme-sdk";
|
|
11604
|
+
Crie as seções abaixo na mesma ordem. O tema prioriza o ID descrito em
|
|
11605
|
+
\`nuvler.home.json\`; quando o painel gerar outro ID, ele associa por tipo e
|
|
11606
|
+
ocorrência na ordem da Home.
|
|
8945
11607
|
|
|
8946
|
-
|
|
11608
|
+
| Ordem | Componente no projeto | Bloco no Gestão | Tipo técnico/API | Compatibilidade | Onde cadastrar os itens |
|
|
11609
|
+
| ---: | --- | --- | --- | --- | --- |
|
|
11610
|
+
${rows || "| - | Nenhuma seção detectada | - | - | - | - |"}
|
|
8947
11611
|
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
8951
|
-
|
|
8952
|
-
`;
|
|
8953
|
-
}
|
|
8954
|
-
function statePageSource() {
|
|
8955
|
-
return `export function StatePage({ title, pathname }: { title: string; pathname?: string }) {
|
|
8956
|
-
return <main className="nuvler-migrated-section nuvler-migrated-state"><span>{pathname || "Nuvler"}</span><h1>{title}</h1></main>;
|
|
8957
|
-
}
|
|
8958
|
-
`;
|
|
8959
|
-
}
|
|
8960
|
-
function themeSource() {
|
|
8961
|
-
return `import type { CSSProperties } from "react";
|
|
8962
|
-
import type { NuvlerThemeProps, ThemeSite } from "@nuvler/theme-sdk";
|
|
8963
|
-
import { themeDefinition } from "./definition.js";
|
|
8964
|
-
import { CatalogPage } from "./pages/CatalogPage.js";
|
|
8965
|
-
import { EditorialPage } from "./pages/EditorialPage.js";
|
|
8966
|
-
import { ProductPage } from "./pages/ProductPage.js";
|
|
8967
|
-
import { StatePage } from "./pages/StatePage.js";
|
|
8968
|
-
import "./styles/theme.css";
|
|
11612
|
+
O arquivo \`nuvler.home.json\` é o blueprint vazio usado para conferir a estrutura.
|
|
11613
|
+
\`migration-content-seed.json\` guarda os valores extraídos para cadastro no painel,
|
|
11614
|
+
sem incluí-los no runtime do tema. \`migration-content-map.json\` documenta a ligação
|
|
11615
|
+
entre o componente, o painel e o template.
|
|
8969
11616
|
|
|
8970
|
-
|
|
11617
|
+
Referências de mídia apontam para o arquivo do projeto original. Faça o upload no
|
|
11618
|
+
painel e use a URL ou o ID retornado pelo Nuvler. Conteúdos adicionais sem campo
|
|
11619
|
+
equivalente ficam documentados abaixo; repeaters e schemas customizados continuam
|
|
11620
|
+
fora da V1.
|
|
8971
11621
|
|
|
8972
|
-
|
|
8973
|
-
const { Header, Footer, Home } = themeDefinition.components;
|
|
8974
|
-
const site: ThemeSite = { tenant: context.store, ...context.site };
|
|
8975
|
-
const configured = site.settings?.theme;
|
|
8976
|
-
const tokens = {
|
|
8977
|
-
colors: { ...themeDefinition.tokens.colors, ...configured?.colors },
|
|
8978
|
-
layout: { ...themeDefinition.tokens.layout, ...configured?.layout },
|
|
8979
|
-
};
|
|
8980
|
-
const style = {
|
|
8981
|
-
"--theme-primary": tokens.colors.primary,
|
|
8982
|
-
"--theme-primary-text": tokens.colors.primaryText,
|
|
8983
|
-
"--theme-secondary": tokens.colors.secondary,
|
|
8984
|
-
"--theme-secondary-text": tokens.colors.secondaryText,
|
|
8985
|
-
"--theme-accent": tokens.colors.accent,
|
|
8986
|
-
"--theme-background": tokens.colors.background,
|
|
8987
|
-
"--theme-surface": tokens.colors.surface,
|
|
8988
|
-
"--theme-surface-alt": tokens.colors.surfaceAlt,
|
|
8989
|
-
"--theme-text": tokens.colors.text,
|
|
8990
|
-
"--theme-text-muted": tokens.colors.textMuted,
|
|
8991
|
-
"--theme-border": tokens.colors.border,
|
|
8992
|
-
"--theme-header-background": tokens.colors.headerBackground,
|
|
8993
|
-
"--theme-header-text": tokens.colors.headerText,
|
|
8994
|
-
"--theme-footer-background": tokens.colors.footerBackground,
|
|
8995
|
-
"--theme-footer-text": tokens.colors.footerText,
|
|
8996
|
-
"--theme-radius": \`\${tokens.layout.borderRadius}px\`,
|
|
8997
|
-
"--theme-container": \`\${tokens.layout.containerWidth}px\`,
|
|
8998
|
-
} as CSSProperties;
|
|
8999
|
-
let content;
|
|
9000
|
-
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} />;
|
|
9001
|
-
else if (route.type === "catalog") content = <CatalogPage route={route} site={site} />;
|
|
9002
|
-
else if (route.type === "product") content = <ProductPage route={route} site={site} cart={sdk?.cart} />;
|
|
9003
|
-
else if (route.type === "editorial-list" || route.type === "editorial-detail") content = <EditorialPage route={route} />;
|
|
9004
|
-
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} />;
|
|
9005
|
-
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>;
|
|
9006
|
-
}
|
|
11622
|
+
${details}
|
|
9007
11623
|
`;
|
|
9008
11624
|
}
|
|
9009
11625
|
function baseCss(plan) {
|
|
@@ -9025,6 +11641,16 @@ body { margin: 0; }
|
|
|
9025
11641
|
.nuvler-migrated-hero-media, .nuvler-migrated-product-media, .nuvler-migrated-detail-media { overflow: hidden; border-radius: var(--theme-radius); }
|
|
9026
11642
|
.nuvler-migrated-hero-media img, .nuvler-migrated-product-media img, .nuvler-migrated-detail-media img { display: block; width: 100%; height: 100%; object-fit: cover; }
|
|
9027
11643
|
.nuvler-migrated-section { padding-block: 56px; }
|
|
11644
|
+
.nuvler-migrated-contact-form-section { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); align-items: start; gap: 48px; }
|
|
11645
|
+
.nuvler-migrated-contact-form-copy h2 { margin-block: 10px; }
|
|
11646
|
+
.nuvler-migrated-contact-form-copy p { color: var(--theme-text-muted); line-height: 1.7; }
|
|
11647
|
+
.nuvler-migrated-contact-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; border: 1px solid var(--theme-border); border-radius: var(--theme-radius); background: var(--theme-surface); padding: 24px; }
|
|
11648
|
+
.nuvler-migrated-contact-form label { display: grid; gap: 7px; }
|
|
11649
|
+
.nuvler-migrated-contact-form input, .nuvler-migrated-contact-form textarea, .nuvler-migrated-contact-form select { width: 100%; border: 1px solid var(--theme-border); border-radius: var(--theme-radius); background: var(--theme-background); color: var(--theme-text); padding: 12px 14px; font: inherit; }
|
|
11650
|
+
.nuvler-migrated-form-wide { grid-column: 1 / -1; }
|
|
11651
|
+
.nuvler-migrated-contact-form .nuvler-migrated-checkbox { display: flex; flex-direction: row; align-items: flex-start; gap: 10px; line-height: 1.55; }
|
|
11652
|
+
.nuvler-migrated-contact-form .nuvler-migrated-checkbox input { width: 18px; height: 18px; margin-top: 2px; padding: 0; accent-color: var(--theme-primary); }
|
|
11653
|
+
.nuvler-migrated-video { display: block; width: 100%; max-height: 720px; margin-top: 24px; border-radius: var(--theme-radius); background: #000; }
|
|
9028
11654
|
.nuvler-migrated-product-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
|
|
9029
11655
|
.nuvler-migrated-product-grid[data-columns="4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
|
9030
11656
|
.nuvler-migrated-product-card { overflow: hidden; border: 1px solid var(--theme-border); border-radius: var(--theme-radius); background: var(--theme-surface); }
|
|
@@ -9036,7 +11662,7 @@ body { margin: 0; }
|
|
|
9036
11662
|
.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)); }
|
|
9037
11663
|
.nuvler-migrated-footer-inner { width: 100%; display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 40px; }
|
|
9038
11664
|
.nuvler-migrated-footer-nav, .nuvler-migrated-contact { display: grid; gap: 8px; }
|
|
9039
|
-
@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; } }
|
|
11665
|
+
@media (max-width: 850px) { .nuvler-migrated-header-inner, .nuvler-migrated-hero, .nuvler-migrated-contact-form-section, .nuvler-migrated-contact-form { grid-template-columns: 1fr; flex-direction: column; align-items: stretch; } .nuvler-migrated-form-wide { grid-column: auto; } .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; } }
|
|
9040
11666
|
|
|
9041
11667
|
:root {
|
|
9042
11668
|
--theme-primary: ${plan.tokens.primary};
|
|
@@ -9073,6 +11699,8 @@ function preservedCss(plan, copied) {
|
|
|
9073
11699
|
content = content.replace(/:global\(([^)]+)\)/g, "$1");
|
|
9074
11700
|
content = content.replace(/url\(\s*(["']?)([^)'"\s]+)\1\s*\)/gi, (full, _quote, reference) => {
|
|
9075
11701
|
if (/^(?:data:|https?:|#)/i.test(reference)) return full;
|
|
11702
|
+
const sourceAsset = sourceAssetFor(style, reference, plan);
|
|
11703
|
+
if (sourceAsset && sourceAsset.kind !== "font") return "none";
|
|
9076
11704
|
const asset = copiedAssetFor(style, reference, plan, copied);
|
|
9077
11705
|
if (!asset) return full;
|
|
9078
11706
|
const output = portable(asset.outputFile);
|
|
@@ -9083,6 +11711,14 @@ function preservedCss(plan, copied) {
|
|
|
9083
11711
|
return `/* Origem: ${style.file}${style.module ? " (CSS Module convertido para CSS comum)" : ""} */\n${content}`;
|
|
9084
11712
|
}).join("\n\n");
|
|
9085
11713
|
}
|
|
11714
|
+
function sourceAssetFor(style, reference, plan) {
|
|
11715
|
+
const absolute = reference.startsWith("/") ? path.join(plan.analysis.sourceDirectory, "public", reference.replace(/^\/+/, "")) : path.resolve(path.dirname(style.absolutePath), reference);
|
|
11716
|
+
return plan.assets.find((asset) => path.resolve(asset.absolutePath) === path.resolve(absolute));
|
|
11717
|
+
}
|
|
11718
|
+
function classCatalog(plan) {
|
|
11719
|
+
const classNames = plan.analysis.components.flatMap((component) => component.jsx.flatMap((node) => node.classes)).filter((className) => !className.includes("url("));
|
|
11720
|
+
return `/** Classes observadas no projeto original. Mantém utilitários visuais sem copiar conteúdo. */\nexport const migratedClassCatalog = ${JSON.stringify([...new Set(classNames)].join(" "))};\n`;
|
|
11721
|
+
}
|
|
9086
11722
|
function externalCssImports(plan) {
|
|
9087
11723
|
const imports = plan.styles.flatMap(({ content }) => [...content.matchAll(/@import\s+(?:url\(\s*)?(["'])(?:https?:\/\/[^"']+)\1\s*\)?[^;]*;?/gi)].map((match) => match[0].trim()));
|
|
9088
11724
|
return [...new Set(imports)].join("\n");
|
|
@@ -9099,7 +11735,7 @@ async function configureTailwind(plan, directory) {
|
|
|
9099
11735
|
metadata.devDependencies["@tailwindcss/postcss"] = plan.analysis.dependencies["@tailwindcss/postcss"] || "^4.0.0";
|
|
9100
11736
|
await writeFile(path.join(directory, "postcss.config.mjs"), "export default { plugins: { \"@tailwindcss/postcss\": {} } };\n", "utf8");
|
|
9101
11737
|
await writeFile(packageFile, `${JSON.stringify(metadata, null, 2)}\n`, "utf8");
|
|
9102
|
-
return "@import \"tailwindcss\";\n";
|
|
11738
|
+
return "@import \"tailwindcss\";\n@source \"../**/*.{ts,tsx,js,jsx}\";\n";
|
|
9103
11739
|
}
|
|
9104
11740
|
metadata.devDependencies.autoprefixer = plan.analysis.dependencies.autoprefixer || "^10.4.0";
|
|
9105
11741
|
const migratedColors = JSON.stringify(plan.analysis.tailwind.colors);
|
|
@@ -9126,26 +11762,53 @@ async function generateMigratedTheme(plan, directory) {
|
|
|
9126
11762
|
mkdir(path.join(directory, "src", "styles"), { recursive: true }),
|
|
9127
11763
|
mkdir(path.join(directory, "src", "pages"), { recursive: true })
|
|
9128
11764
|
]);
|
|
9129
|
-
const
|
|
11765
|
+
const fidelityEnabled = Boolean(plan.analysis.sourceGraph.entrypoint);
|
|
11766
|
+
const styleFiles = new Set(plan.styles.map((style) => style.file));
|
|
11767
|
+
const copiedAssets = await copyMigrationAssets(plan, directory, fidelityEnabled ? plan.assets.filter((asset) => asset.kind === "font" && asset.referencedBy.some((file) => styleFiles.has(file))) : plan.assets);
|
|
11768
|
+
const fidelity = await runFidelityPass(plan, directory);
|
|
11769
|
+
await mergeFidelityDependencies(plan, directory);
|
|
11770
|
+
for (const file of fidelity.adaptedBusinessFiles) plan.warnings.push(`${file}: regra de negócio isolada pela Nuvler Adaptation Pass; apresentação dependente preservada.`);
|
|
9130
11771
|
const tailwindHeader = await configureTailwind(plan, directory);
|
|
11772
|
+
const extractedContent = await extractContentCatalog(plan);
|
|
9131
11773
|
await Promise.all([
|
|
9132
11774
|
writeFile(path.join(directory, "src/components/Header.tsx"), headerSource(plan), "utf8"),
|
|
9133
11775
|
writeFile(path.join(directory, "src/components/Footer.tsx"), footerSource(plan), "utf8"),
|
|
9134
11776
|
writeFile(path.join(directory, "src/components/ProductCard.tsx"), productCardSource(plan), "utf8"),
|
|
9135
11777
|
writeFile(path.join(directory, "src/components/ProductGrid.tsx"), productGridSource(plan), "utf8"),
|
|
9136
11778
|
writeFile(path.join(directory, "src/components/ProductDetail.tsx"), productDetailSource(plan), "utf8"),
|
|
9137
|
-
writeFile(path.join(directory, "src/sections/Home.tsx"), homeSource(plan,
|
|
11779
|
+
writeFile(path.join(directory, "src/sections/Home.tsx"), homeSource(plan, fidelity), "utf8"),
|
|
9138
11780
|
writeFile(path.join(directory, "src/pages/CatalogPage.tsx"), catalogPageSource(), "utf8"),
|
|
9139
11781
|
writeFile(path.join(directory, "src/pages/ProductPage.tsx"), productPageSource(), "utf8"),
|
|
9140
11782
|
writeFile(path.join(directory, "src/pages/EditorialPage.tsx"), editorialPageSource(), "utf8"),
|
|
9141
11783
|
writeFile(path.join(directory, "src/pages/StatePage.tsx"), statePageSource(), "utf8"),
|
|
9142
11784
|
writeFile(path.join(directory, "src/definition.tsx"), definitionSource(plan), "utf8"),
|
|
9143
|
-
writeFile(path.join(directory, "src/theme.tsx"), themeSource(), "utf8"),
|
|
9144
|
-
writeFile(path.join(directory, "src/
|
|
9145
|
-
writeFile(path.join(directory, "src/
|
|
11785
|
+
writeFile(path.join(directory, "src/theme.tsx"), themeSource(Boolean(fidelity.entryImportPath)), "utf8"),
|
|
11786
|
+
writeFile(path.join(directory, "src/migrated-content.tsx"), migratedContentSource(plan), "utf8"),
|
|
11787
|
+
writeFile(path.join(directory, "src/migrated-next-image.tsx"), migratedNextImageSource(), "utf8"),
|
|
11788
|
+
writeFile(path.join(directory, "src/migrated-class-catalog.ts"), classCatalog(plan), "utf8"),
|
|
11789
|
+
writeFile(path.join(directory, "nuvler.home.json"), homeConfiguration(plan), "utf8"),
|
|
11790
|
+
writeFile(path.join(directory, "migration-content-seed.json"), `${JSON.stringify(extractedContent, null, 2)}\n`, "utf8"),
|
|
11791
|
+
writeFile(path.join(directory, "migration-content-map.json"), contentMap(plan, extractedContent), "utf8"),
|
|
11792
|
+
writeFile(path.join(directory, "CONTENT_SETUP.md"), contentGuide(plan, extractedContent), "utf8"),
|
|
11793
|
+
writeFile(path.join(directory, "src/styles/theme.css"), `${externalCssImports(plan)}\n${tailwindHeader}${baseCss(plan)}\n${preservedCss(plan, copiedAssets)}\n`, "utf8"),
|
|
11794
|
+
writeFile(path.join(directory, "src/styles.d.ts"), `declare module "*.module.css" { const classes: Record<string, string>; export default classes; }
|
|
11795
|
+
declare module "*.css";
|
|
11796
|
+
declare module "*.scss";
|
|
11797
|
+
declare module "*.sass";
|
|
11798
|
+
declare module "*.less";
|
|
11799
|
+
declare module "*.svg" { const url: string; export default url; }
|
|
11800
|
+
declare module "*.png" { const url: string; export default url; }
|
|
11801
|
+
declare module "*.jpg" { const url: string; export default url; }
|
|
11802
|
+
declare module "*.jpeg" { const url: string; export default url; }
|
|
11803
|
+
declare module "*.webp" { const url: string; export default url; }
|
|
11804
|
+
declare module "*.gif" { const url: string; export default url; }
|
|
11805
|
+
declare module "*.mp4" { const url: string; export default url; }
|
|
11806
|
+
declare module "*.webm" { const url: string; export default url; }
|
|
11807
|
+
`, "utf8")
|
|
9146
11808
|
]);
|
|
9147
11809
|
const manifestFile = path.join(directory, "nuvler.theme.json");
|
|
9148
11810
|
const manifest = JSON.parse(await readFile(manifestFile, "utf8"));
|
|
11811
|
+
const homeComponents = [...new Map(plan.contentBindings.flatMap((binding) => binding.componentDefinition ? [[binding.componentDefinition.key, binding.componentDefinition]] : [])).values()];
|
|
9149
11812
|
manifest.entry = "src/theme.tsx";
|
|
9150
11813
|
manifest.styles = ["src/styles/theme.css"];
|
|
9151
11814
|
manifest.presentation = {
|
|
@@ -9171,7 +11834,8 @@ async function generateMigratedTheme(plan, directory) {
|
|
|
9171
11834
|
layout: {
|
|
9172
11835
|
containerWidth: plan.tokens.containerWidth,
|
|
9173
11836
|
borderRadius: plan.tokens.borderRadius
|
|
9174
|
-
}
|
|
11837
|
+
},
|
|
11838
|
+
...homeComponents.length ? { homeComponents } : {}
|
|
9175
11839
|
};
|
|
9176
11840
|
await writeFile(manifestFile, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
|
|
9177
11841
|
const selectedComponents = {};
|
|
@@ -9186,8 +11850,12 @@ async function generateMigratedTheme(plan, directory) {
|
|
|
9186
11850
|
sourceRoots: plan.analysis.sourceRoots,
|
|
9187
11851
|
componentsAnalyzed: plan.analysis.components.length,
|
|
9188
11852
|
selectedComponents,
|
|
9189
|
-
|
|
9190
|
-
|
|
11853
|
+
contentBindings: plan.contentBindings.map(({ classes: _classes, ...binding }) => binding),
|
|
11854
|
+
assetsCopied: fidelity.copiedAssets + copiedAssets.length,
|
|
11855
|
+
styleFilesPreserved: (/* @__PURE__ */ new Set([...plan.styles.map((style) => style.file), ...plan.analysis.sourceGraph.modules.filter((module) => module.kind === "STYLE").map((module) => module.file)])).size,
|
|
11856
|
+
sourceFilesPreserved: fidelity.copiedFiles,
|
|
11857
|
+
entrypoint: plan.analysis.sourceGraph.entrypoint,
|
|
11858
|
+
dependencies: plan.analysis.sourceGraph.dependencies,
|
|
9191
11859
|
tailwind: plan.analysis.tailwind,
|
|
9192
11860
|
ignoredFiles: plan.analysis.ignoredFiles,
|
|
9193
11861
|
warnings: [...new Set(plan.warnings)],
|
|
@@ -9539,6 +12207,433 @@ function safeThemeId(value) {
|
|
|
9539
12207
|
function themeName(value) {
|
|
9540
12208
|
return value.replace(/^@[^/]+\//, "").split(/[-_\s]+/).filter(Boolean).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ").slice(0, 120) || "Tema Migrado";
|
|
9541
12209
|
}
|
|
12210
|
+
var CONTENT_FIELDS = {
|
|
12211
|
+
hero: [
|
|
12212
|
+
"eyebrow",
|
|
12213
|
+
"title",
|
|
12214
|
+
"description",
|
|
12215
|
+
"imageId",
|
|
12216
|
+
"imageUrl",
|
|
12217
|
+
"imageAlt",
|
|
12218
|
+
"buttonLabel",
|
|
12219
|
+
"buttonUrl"
|
|
12220
|
+
],
|
|
12221
|
+
"banner-carousel": ["banners"],
|
|
12222
|
+
"image-text": [
|
|
12223
|
+
"eyebrow",
|
|
12224
|
+
"title",
|
|
12225
|
+
"description",
|
|
12226
|
+
"imageId",
|
|
12227
|
+
"imageUrl",
|
|
12228
|
+
"imageAlt",
|
|
12229
|
+
"imagePosition"
|
|
12230
|
+
],
|
|
12231
|
+
"rich-text": [
|
|
12232
|
+
"eyebrow",
|
|
12233
|
+
"title",
|
|
12234
|
+
"text"
|
|
12235
|
+
],
|
|
12236
|
+
cta: [
|
|
12237
|
+
"eyebrow",
|
|
12238
|
+
"title",
|
|
12239
|
+
"description",
|
|
12240
|
+
"buttonLabel",
|
|
12241
|
+
"buttonUrl"
|
|
12242
|
+
],
|
|
12243
|
+
"services-grid": [
|
|
12244
|
+
"eyebrow",
|
|
12245
|
+
"title",
|
|
12246
|
+
"limit"
|
|
12247
|
+
],
|
|
12248
|
+
"blog-grid": [
|
|
12249
|
+
"eyebrow",
|
|
12250
|
+
"title",
|
|
12251
|
+
"limit"
|
|
12252
|
+
],
|
|
12253
|
+
"cases-grid": [
|
|
12254
|
+
"eyebrow",
|
|
12255
|
+
"title",
|
|
12256
|
+
"limit"
|
|
12257
|
+
],
|
|
12258
|
+
"products-grid": [
|
|
12259
|
+
"eyebrow",
|
|
12260
|
+
"title",
|
|
12261
|
+
"limit",
|
|
12262
|
+
"categorySlug"
|
|
12263
|
+
],
|
|
12264
|
+
"products-carousel": [
|
|
12265
|
+
"eyebrow",
|
|
12266
|
+
"title",
|
|
12267
|
+
"limit",
|
|
12268
|
+
"categorySlug"
|
|
12269
|
+
],
|
|
12270
|
+
"theme-component": [
|
|
12271
|
+
"eyebrow",
|
|
12272
|
+
"title",
|
|
12273
|
+
"description",
|
|
12274
|
+
"items",
|
|
12275
|
+
"fields",
|
|
12276
|
+
"submitLabel",
|
|
12277
|
+
"successMessage",
|
|
12278
|
+
"videoUrl",
|
|
12279
|
+
"posterImageId",
|
|
12280
|
+
"posterImageUrl",
|
|
12281
|
+
"posterImageAlt"
|
|
12282
|
+
]
|
|
12283
|
+
};
|
|
12284
|
+
function customComponentKind(component) {
|
|
12285
|
+
const name = normalized(component.name);
|
|
12286
|
+
const tags = new Set(component.jsx.map(({ tag }) => tag.toLowerCase()));
|
|
12287
|
+
if (/(form|formulario)/.test(name) || [
|
|
12288
|
+
"form",
|
|
12289
|
+
"input",
|
|
12290
|
+
"textarea",
|
|
12291
|
+
"select"
|
|
12292
|
+
].some((tag) => tags.has(tag))) return "contact-form";
|
|
12293
|
+
if (/(faq|frequent|pergunta)/.test(name)) return "faq";
|
|
12294
|
+
if (/(evaluation|avaliacao|process|etapa|steps)/.test(name)) return "steps";
|
|
12295
|
+
if (/(number|numero|stat|metric|indicador)/.test(name)) return "metrics";
|
|
12296
|
+
if (/(benefit|beneficio|feature|vantagem)/.test(name)) return "benefits";
|
|
12297
|
+
if (/(video)/.test(name) || tags.has("video") || tags.has("iframe")) return "video";
|
|
12298
|
+
if (/(forwhom|paraquem|audience|publico)/.test(name)) return "audience";
|
|
12299
|
+
if (/(Contacts|Contatos|ContactList)/.test(component.name) || /(contact|contato)/.test(name) && component.jsx.filter(({ tag }) => tag.toLowerCase() === "a").length >= 2 && component.text.some((text) => /contatos?/i.test(text))) return "contacts";
|
|
12300
|
+
if (/(appsection|monitoring|monitoramento)/.test(name)) return "feature-list";
|
|
12301
|
+
return null;
|
|
12302
|
+
}
|
|
12303
|
+
function listComponentDefinition(kind) {
|
|
12304
|
+
const definition = {
|
|
12305
|
+
faq: {
|
|
12306
|
+
name: "Perguntas frequentes",
|
|
12307
|
+
description: "Lista editável de perguntas e respostas.",
|
|
12308
|
+
itemFields: [{
|
|
12309
|
+
key: "question",
|
|
12310
|
+
label: "Pergunta",
|
|
12311
|
+
control: "text",
|
|
12312
|
+
required: true
|
|
12313
|
+
}, {
|
|
12314
|
+
key: "answer",
|
|
12315
|
+
label: "Resposta",
|
|
12316
|
+
control: "textarea",
|
|
12317
|
+
required: true
|
|
12318
|
+
}]
|
|
12319
|
+
},
|
|
12320
|
+
metrics: {
|
|
12321
|
+
name: "Métricas e números",
|
|
12322
|
+
description: "Indicadores, números e pequenos destaques.",
|
|
12323
|
+
itemFields: [
|
|
12324
|
+
{
|
|
12325
|
+
key: "value",
|
|
12326
|
+
label: "Valor",
|
|
12327
|
+
control: "text",
|
|
12328
|
+
required: true
|
|
12329
|
+
},
|
|
12330
|
+
{
|
|
12331
|
+
key: "title",
|
|
12332
|
+
label: "Rótulo",
|
|
12333
|
+
control: "text",
|
|
12334
|
+
required: true
|
|
12335
|
+
},
|
|
12336
|
+
{
|
|
12337
|
+
key: "description",
|
|
12338
|
+
label: "Descrição",
|
|
12339
|
+
control: "textarea"
|
|
12340
|
+
}
|
|
12341
|
+
]
|
|
12342
|
+
},
|
|
12343
|
+
benefits: {
|
|
12344
|
+
name: "Lista de benefícios",
|
|
12345
|
+
description: "Benefícios ou diferenciais apresentados em cards.",
|
|
12346
|
+
itemFields: [{
|
|
12347
|
+
key: "title",
|
|
12348
|
+
label: "Título",
|
|
12349
|
+
control: "text",
|
|
12350
|
+
required: true
|
|
12351
|
+
}, {
|
|
12352
|
+
key: "description",
|
|
12353
|
+
label: "Descrição",
|
|
12354
|
+
control: "textarea"
|
|
12355
|
+
}]
|
|
12356
|
+
},
|
|
12357
|
+
audience: {
|
|
12358
|
+
name: "Para quem é",
|
|
12359
|
+
description: "Públicos, perfis ou cenários atendidos.",
|
|
12360
|
+
itemFields: [{
|
|
12361
|
+
key: "title",
|
|
12362
|
+
label: "Público",
|
|
12363
|
+
control: "text",
|
|
12364
|
+
required: true
|
|
12365
|
+
}, {
|
|
12366
|
+
key: "description",
|
|
12367
|
+
label: "Descrição",
|
|
12368
|
+
control: "textarea"
|
|
12369
|
+
}]
|
|
12370
|
+
},
|
|
12371
|
+
steps: {
|
|
12372
|
+
name: "Etapas do processo",
|
|
12373
|
+
description: "Etapas numeradas de uma avaliação ou processo.",
|
|
12374
|
+
itemFields: [
|
|
12375
|
+
{
|
|
12376
|
+
key: "num",
|
|
12377
|
+
label: "Número",
|
|
12378
|
+
control: "text"
|
|
12379
|
+
},
|
|
12380
|
+
{
|
|
12381
|
+
key: "title",
|
|
12382
|
+
label: "Título",
|
|
12383
|
+
control: "text",
|
|
12384
|
+
required: true
|
|
12385
|
+
},
|
|
12386
|
+
{
|
|
12387
|
+
key: "desc",
|
|
12388
|
+
label: "Descrição",
|
|
12389
|
+
control: "textarea"
|
|
12390
|
+
}
|
|
12391
|
+
]
|
|
12392
|
+
},
|
|
12393
|
+
contacts: {
|
|
12394
|
+
name: "Lista de contatos",
|
|
12395
|
+
description: "Pessoas e canais de atendimento exibidos na Home.",
|
|
12396
|
+
itemFields: [
|
|
12397
|
+
{
|
|
12398
|
+
key: "role",
|
|
12399
|
+
label: "Função",
|
|
12400
|
+
control: "text"
|
|
12401
|
+
},
|
|
12402
|
+
{
|
|
12403
|
+
key: "name",
|
|
12404
|
+
label: "Nome",
|
|
12405
|
+
control: "text",
|
|
12406
|
+
required: true
|
|
12407
|
+
},
|
|
12408
|
+
{
|
|
12409
|
+
key: "email",
|
|
12410
|
+
label: "E-mail",
|
|
12411
|
+
control: "text"
|
|
12412
|
+
},
|
|
12413
|
+
{
|
|
12414
|
+
key: "phone",
|
|
12415
|
+
label: "Telefone",
|
|
12416
|
+
control: "text"
|
|
12417
|
+
}
|
|
12418
|
+
]
|
|
12419
|
+
},
|
|
12420
|
+
"feature-list": {
|
|
12421
|
+
name: "Lista de recursos",
|
|
12422
|
+
description: "Recursos ou funcionalidades apresentados em uma seção.",
|
|
12423
|
+
itemFields: [{
|
|
12424
|
+
key: "title",
|
|
12425
|
+
label: "Recurso",
|
|
12426
|
+
control: "text",
|
|
12427
|
+
required: true
|
|
12428
|
+
}]
|
|
12429
|
+
}
|
|
12430
|
+
}[kind];
|
|
12431
|
+
return {
|
|
12432
|
+
key: kind,
|
|
12433
|
+
name: definition.name,
|
|
12434
|
+
description: definition.description,
|
|
12435
|
+
category: "Listas",
|
|
12436
|
+
schemaVersion: 1,
|
|
12437
|
+
fields: [
|
|
12438
|
+
{
|
|
12439
|
+
key: "eyebrow",
|
|
12440
|
+
label: "Chamada pequena",
|
|
12441
|
+
control: "text"
|
|
12442
|
+
},
|
|
12443
|
+
{
|
|
12444
|
+
key: "title",
|
|
12445
|
+
label: "Título da seção",
|
|
12446
|
+
control: "text",
|
|
12447
|
+
required: true
|
|
12448
|
+
},
|
|
12449
|
+
{
|
|
12450
|
+
key: "description",
|
|
12451
|
+
label: "Descrição",
|
|
12452
|
+
control: "textarea"
|
|
12453
|
+
},
|
|
12454
|
+
{
|
|
12455
|
+
key: "items",
|
|
12456
|
+
label: definition.name,
|
|
12457
|
+
control: "repeater",
|
|
12458
|
+
maxItems: 30,
|
|
12459
|
+
itemFields: [...definition.itemFields]
|
|
12460
|
+
}
|
|
12461
|
+
]
|
|
12462
|
+
};
|
|
12463
|
+
}
|
|
12464
|
+
function customComponentDefinition(kind) {
|
|
12465
|
+
if (kind === "contact-form") return {
|
|
12466
|
+
key: kind,
|
|
12467
|
+
name: "Formulário de contato",
|
|
12468
|
+
description: "Formulário configurável com envios salvos em Contatos.",
|
|
12469
|
+
category: "Formulários",
|
|
12470
|
+
schemaVersion: 1,
|
|
12471
|
+
fields: [
|
|
12472
|
+
{
|
|
12473
|
+
key: "eyebrow",
|
|
12474
|
+
label: "Chamada pequena",
|
|
12475
|
+
control: "text"
|
|
12476
|
+
},
|
|
12477
|
+
{
|
|
12478
|
+
key: "title",
|
|
12479
|
+
label: "Título da seção",
|
|
12480
|
+
control: "text",
|
|
12481
|
+
required: true
|
|
12482
|
+
},
|
|
12483
|
+
{
|
|
12484
|
+
key: "description",
|
|
12485
|
+
label: "Descrição",
|
|
12486
|
+
control: "textarea"
|
|
12487
|
+
},
|
|
12488
|
+
{
|
|
12489
|
+
key: "fields",
|
|
12490
|
+
label: "Campos do formulário",
|
|
12491
|
+
control: "contact-fields",
|
|
12492
|
+
required: true
|
|
12493
|
+
},
|
|
12494
|
+
{
|
|
12495
|
+
key: "submitLabel",
|
|
12496
|
+
label: "Texto do botão",
|
|
12497
|
+
control: "text",
|
|
12498
|
+
defaultValue: "Enviar contato"
|
|
12499
|
+
},
|
|
12500
|
+
{
|
|
12501
|
+
key: "successMessage",
|
|
12502
|
+
label: "Mensagem de sucesso",
|
|
12503
|
+
control: "text",
|
|
12504
|
+
defaultValue: "Contato enviado com sucesso."
|
|
12505
|
+
}
|
|
12506
|
+
],
|
|
12507
|
+
action: {
|
|
12508
|
+
type: "contact.submit",
|
|
12509
|
+
formKey: kind
|
|
12510
|
+
}
|
|
12511
|
+
};
|
|
12512
|
+
if (kind === "video") return {
|
|
12513
|
+
key: kind,
|
|
12514
|
+
name: "Vídeo",
|
|
12515
|
+
description: "Vídeo com título, descrição e imagem de capa.",
|
|
12516
|
+
category: "Mídia",
|
|
12517
|
+
schemaVersion: 1,
|
|
12518
|
+
fields: [
|
|
12519
|
+
{
|
|
12520
|
+
key: "eyebrow",
|
|
12521
|
+
label: "Chamada pequena",
|
|
12522
|
+
control: "text"
|
|
12523
|
+
},
|
|
12524
|
+
{
|
|
12525
|
+
key: "title",
|
|
12526
|
+
label: "Título da seção",
|
|
12527
|
+
control: "text",
|
|
12528
|
+
required: true
|
|
12529
|
+
},
|
|
12530
|
+
{
|
|
12531
|
+
key: "description",
|
|
12532
|
+
label: "Descrição",
|
|
12533
|
+
control: "textarea"
|
|
12534
|
+
},
|
|
12535
|
+
{
|
|
12536
|
+
key: "videoUrl",
|
|
12537
|
+
label: "URL do vídeo",
|
|
12538
|
+
control: "video",
|
|
12539
|
+
required: true
|
|
12540
|
+
},
|
|
12541
|
+
{
|
|
12542
|
+
key: "posterImageId",
|
|
12543
|
+
label: "Imagem de capa",
|
|
12544
|
+
control: "image"
|
|
12545
|
+
}
|
|
12546
|
+
]
|
|
12547
|
+
};
|
|
12548
|
+
return listComponentDefinition(kind);
|
|
12549
|
+
}
|
|
12550
|
+
function contentType(component) {
|
|
12551
|
+
const name = normalized(component.name);
|
|
12552
|
+
const hasRole = (role) => component.roles.some((candidate) => candidate.role === role);
|
|
12553
|
+
const hasEditorialImage = component.jsx.some(({ tag }) => [
|
|
12554
|
+
"img",
|
|
12555
|
+
"image",
|
|
12556
|
+
"picture"
|
|
12557
|
+
].includes(tag.toLowerCase()));
|
|
12558
|
+
if (name.includes("carousel") && /(product|produto|catalog)/.test(name)) return "products-carousel";
|
|
12559
|
+
if (hasRole("PRODUCT_GRID") || /(product|produto|catalog|vitrine)/.test(name)) return "products-grid";
|
|
12560
|
+
if (/(service|servico)/.test(name)) return "services-grid";
|
|
12561
|
+
if (/(blog|post|article|artigo)/.test(name)) return "blog-grid";
|
|
12562
|
+
if (/(case|project|projeto|portfolio|testimonial|depoimento)/.test(name)) return "cases-grid";
|
|
12563
|
+
if (name.includes("banner") && /(carousel|slider|slide)/.test(name)) return "banner-carousel";
|
|
12564
|
+
if (/(hero|banner|masthead)/.test(name)) return "hero";
|
|
12565
|
+
if (customComponentKind(component)) return "theme-component";
|
|
12566
|
+
if (/(cta|calltoaction|contact|contato|newsletter|final)/.test(name)) return "cta";
|
|
12567
|
+
if (/(image|imagem|showcase|dashboard|integration|integracao|widget|media|about|sobre)/.test(name)) return "image-text";
|
|
12568
|
+
if (hasEditorialImage) return "image-text";
|
|
12569
|
+
return "rich-text";
|
|
12570
|
+
}
|
|
12571
|
+
function contentBindings(analysis, selected) {
|
|
12572
|
+
const home = selected.HOME?.component;
|
|
12573
|
+
const excluded = new Set([
|
|
12574
|
+
selected.HEADER?.component.id,
|
|
12575
|
+
selected.FOOTER?.component.id,
|
|
12576
|
+
selected.PRODUCT_DETAIL?.component.id
|
|
12577
|
+
].filter((id) => Boolean(id)));
|
|
12578
|
+
if (selected.PRODUCT_CARD?.component.id !== selected.PRODUCT_GRID?.component.id) excluded.add(selected.PRODUCT_CARD?.component.id ?? "");
|
|
12579
|
+
const byName = new Map(analysis.components.map((component) => [normalized(component.name), component]));
|
|
12580
|
+
const candidates = [];
|
|
12581
|
+
const add = (component) => {
|
|
12582
|
+
if (!component || excluded.has(component.id) || candidates.some((candidate) => candidate.id === component.id)) return;
|
|
12583
|
+
candidates.push(component);
|
|
12584
|
+
};
|
|
12585
|
+
if (home) for (const node of home.jsx) {
|
|
12586
|
+
const componentName = node.tag.split(".")[0];
|
|
12587
|
+
const component = byName.get(normalized(componentName));
|
|
12588
|
+
if (!component || component.id === home.id) continue;
|
|
12589
|
+
const name = normalized(component.name);
|
|
12590
|
+
if (/^(suspense|fragment|provider|layout|router|route|link|image)$/.test(name)) continue;
|
|
12591
|
+
if (/(whatsapp|floating|modal|dialog|toast|tooltip|provider|deferred|fallback|skeleton|boundary|loader)/.test(name)) continue;
|
|
12592
|
+
add(component);
|
|
12593
|
+
}
|
|
12594
|
+
const reachableFiles = /* @__PURE__ */ new Set();
|
|
12595
|
+
const modulesByFile = new Map(analysis.sourceGraph.modules.map((module) => [module.file, module]));
|
|
12596
|
+
const pendingFiles = analysis.sourceGraph.entrypoint?.pageFile ? [analysis.sourceGraph.entrypoint.pageFile] : home ? [home.file] : [];
|
|
12597
|
+
while (pendingFiles.length) {
|
|
12598
|
+
const file = pendingFiles.shift();
|
|
12599
|
+
if (reachableFiles.has(file)) continue;
|
|
12600
|
+
reachableFiles.add(file);
|
|
12601
|
+
const module = modulesByFile.get(file);
|
|
12602
|
+
for (const dependency of module?.dependencies ?? []) {
|
|
12603
|
+
if (!dependency.resolvedFile || dependency.type === "BUSINESS") continue;
|
|
12604
|
+
const target = analysis.sourceGraph.modules.find((candidate) => path.resolve(candidate.absolutePath) === path.resolve(dependency.resolvedFile));
|
|
12605
|
+
if (target?.kind === "SOURCE" && !reachableFiles.has(target.file)) pendingFiles.push(target.file);
|
|
12606
|
+
}
|
|
12607
|
+
}
|
|
12608
|
+
for (const component of analysis.components) {
|
|
12609
|
+
if (!reachableFiles.has(component.file) || component.id === home?.id) continue;
|
|
12610
|
+
if (!component.jsx.some(({ tag }) => tag.toLowerCase() === "section")) continue;
|
|
12611
|
+
add(component);
|
|
12612
|
+
}
|
|
12613
|
+
if (!candidates.length) {
|
|
12614
|
+
add(selected.HERO?.component);
|
|
12615
|
+
add(selected.PRODUCT_GRID?.component);
|
|
12616
|
+
add(selected.SECTION?.component);
|
|
12617
|
+
}
|
|
12618
|
+
if (!candidates.length && home) add(home);
|
|
12619
|
+
return candidates.map((component, order) => {
|
|
12620
|
+
const type = contentType(component);
|
|
12621
|
+
const slug = safeThemeId(component.name);
|
|
12622
|
+
const customKind = type === "theme-component" ? customComponentKind(component) : null;
|
|
12623
|
+
const componentDefinition = customKind ? customComponentDefinition(customKind) : void 0;
|
|
12624
|
+
return {
|
|
12625
|
+
id: `migrated-${slug}-${order + 1}`,
|
|
12626
|
+
component: component.name,
|
|
12627
|
+
file: component.file,
|
|
12628
|
+
type,
|
|
12629
|
+
order,
|
|
12630
|
+
fields: componentDefinition?.fields.map(({ key }) => key) ?? CONTENT_FIELDS[type],
|
|
12631
|
+
classes: classProfile(component),
|
|
12632
|
+
componentKey: componentDefinition?.key,
|
|
12633
|
+
componentDefinition
|
|
12634
|
+
};
|
|
12635
|
+
});
|
|
12636
|
+
}
|
|
9542
12637
|
function createMigrationPlan(analysis, options) {
|
|
9543
12638
|
const selected = {};
|
|
9544
12639
|
for (const role of ROLES) {
|
|
@@ -9559,12 +12654,15 @@ function createMigrationPlan(analysis, options) {
|
|
|
9559
12654
|
if (!selected.PRODUCT_CARD) warnings.push("ProductCard não identificado; será usado o card do tema base.");
|
|
9560
12655
|
if (analysis.tailwind.detected) warnings.push("Tailwind detectado: classes observadas serão preservadas e recompiladas no tema gerado.");
|
|
9561
12656
|
const outputName = path.basename(path.resolve(options.outputDirectory));
|
|
12657
|
+
const bindings = contentBindings(analysis, selected);
|
|
12658
|
+
if (bindings.length) warnings.push(`${bindings.length} seção(ões) visual(is) convertida(s) para conteúdo configurável pelo painel Nuvler; textos e imagens originais não serão publicados como dados do tema.`);
|
|
9562
12659
|
return {
|
|
9563
12660
|
analysis,
|
|
9564
12661
|
themeId: safeThemeId(options.id?.trim() || outputName),
|
|
9565
12662
|
themeName: options.name?.trim() || themeName(analysis.projectName),
|
|
9566
12663
|
selected,
|
|
9567
|
-
|
|
12664
|
+
contentBindings: bindings,
|
|
12665
|
+
styles: analysis.styles.filter(({ imported, file, module }) => imported && file.endsWith(".css") && (!analysis.sourceGraph.entrypoint || !module)),
|
|
9568
12666
|
assets: analysis.assets,
|
|
9569
12667
|
tokens: inferredTokens(analysis, selected),
|
|
9570
12668
|
warnings: [...new Set(warnings)]
|
|
@@ -9658,6 +12756,9 @@ function printReport(report, outputDirectory) {
|
|
|
9658
12756
|
for (const [role, label] of Object.entries(ROLE_LABELS)) if (report.selectedComponents[role]) console.log(`✓ ${label}`);
|
|
9659
12757
|
console.log(`✓ ${report.assetsCopied} asset(s) copiado(s)`);
|
|
9660
12758
|
console.log(`✓ ${report.styleFilesPreserved} arquivo(s) de estilo preservado(s)`);
|
|
12759
|
+
if (report.entrypoint) console.log(`✓ Árvore visual preservada a partir de ${report.entrypoint.pageFile}`);
|
|
12760
|
+
if (report.sourceFilesPreserved) console.log(`✓ ${report.sourceFilesPreserved} arquivo(s) fonte preservado(s)`);
|
|
12761
|
+
if (report.contentBindings.length) console.log(`✓ ${report.contentBindings.length} seção(ões) preparada(s) para o painel Nuvler`);
|
|
9661
12762
|
if (report.tailwind.detected) console.log("✓ Tailwind detectado e configurado");
|
|
9662
12763
|
for (const ignored of report.ignoredFiles) console.log(`⚠ ${ignored.file} ignorado: ${ignored.reason}`);
|
|
9663
12764
|
for (const warning of report.warnings) console.log(`⚠ ${warning}`);
|
|
@@ -9665,6 +12766,7 @@ function printReport(report, outputDirectory) {
|
|
|
9665
12766
|
console.log("✓ Manifesto Nuvler validado");
|
|
9666
12767
|
if (report.validation.typecheck) console.log("✓ Typecheck concluído");
|
|
9667
12768
|
if (report.validation.build) console.log("✓ Build do tema concluído");
|
|
12769
|
+
console.log("✓ Conteúdo extraído em CONTENT_SETUP.md e migration-content-seed.json");
|
|
9668
12770
|
console.log(`✓ Tema Nuvler gerado em ${outputDirectory}`);
|
|
9669
12771
|
console.log("");
|
|
9670
12772
|
}
|
|
@@ -10025,7 +13127,7 @@ async function authLogout() {
|
|
|
10025
13127
|
//#endregion
|
|
10026
13128
|
//#region src/index.ts
|
|
10027
13129
|
var program = new Command();
|
|
10028
|
-
program.name("nuvler").description("Nuvler Theme Development CLI").version("0.
|
|
13130
|
+
program.name("nuvler").description("Nuvler Theme Development CLI").version("0.5.0");
|
|
10029
13131
|
var theme = program.command("theme").description("Manage Nuvler themes");
|
|
10030
13132
|
var auth = program.command("auth").description("Manage developer authentication");
|
|
10031
13133
|
auth.command("login").requiredOption("--token <token>", "Developer token").option("--api-url <url>", "Nuvler API base URL (or use NUVLER_API_URL)").action(async (options) => {
|