@nuvler/cli 0.4.2 → 0.4.4
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 +225 -0
- package/dist/commands/theme/create.js +6 -4
- package/dist/commands/theme/create.js.map +1 -1
- package/dist/commands/theme/upgrade.js +128 -0
- package/dist/commands/theme/upgrade.js.map +1 -0
- package/dist/index.js +39 -1
- package/dist/index.js.map +1 -1
- package/dist/migrate/analyzer.js +147 -11
- package/dist/migrate/analyzer.js.map +1 -1
- package/dist/migrate/classifier.js +10 -6
- package/dist/migrate/classifier.js.map +1 -1
- package/dist/migrate/generator.js +8 -6
- package/dist/migrate/generator.js.map +1 -1
- package/dist/migrate/transformer.js +150 -27
- package/dist/migrate/transformer.js.map +1 -1
- package/dist/nuvler.js +462 -58
- package/dist/nuvler.js.map +1 -1
- package/dist/templates/nuvler-atelier/README.md +1 -1
- package/dist/templates/nuvler-atelier/nuvler.theme.json +2 -2
- package/dist/templates/nuvler-atelier/package.json +4 -3
- package/dist/templates/nuvler-atelier/src/definition.tsx +10 -9
- package/dist/templates/nuvler-atelier/src/theme.tsx +2 -2
- package/dist/templates/nuvler-default/README.md +2 -2
- package/dist/templates/nuvler-default/nuvler.theme.json +2 -2
- package/dist/templates/nuvler-default/package.json +3 -3
- package/dist/templates/nuvler-default/src/header-interactions.tsx +113 -11
- package/dist/templates/nuvler-default/src/header.tsx +6 -4
- package/dist/templates/nuvler-default/src/home.tsx +22 -5
- package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +32 -1
- package/dist/templates/nuvler-default/src/products.tsx +4 -2
- package/dist/templates/nuvler-default/src/server-shell.tsx +4 -1
- package/dist/templates/nuvler-default/src/shared.tsx +3 -7
- package/dist/templates/nuvler-default/src/theme-component.tsx +6 -5
- package/dist/templates/nuvler-default/src/theme.css +138 -2
- package/dist/templates/starter/nuvler.theme.json +1 -1
- package/dist/templates/starter/package.json +3 -2
- package/dist/templates/starter/src/definition.tsx +3 -2
- package/package.json +2 -2
- package/preview-host/package.json +1 -1
- package/preview-host/vendor/theme-runtime/default-theme.tsx +13 -12
package/dist/nuvler.js
CHANGED
|
@@ -7,7 +7,7 @@ import { fileURLToPath } from "node:url";
|
|
|
7
7
|
import { createHash, randomUUID } from "node:crypto";
|
|
8
8
|
import { build, normalizePath } from "vite";
|
|
9
9
|
import { THEME_API_VERSION, THEME_RUNTIME_VERSION, THEME_SCHEMA_VERSION, THEME_SCHEMA_VERSION as THEME_SCHEMA_VERSION$1 } from "@nuvler/theme-sdk";
|
|
10
|
-
import { satisfies, validRange } from "semver";
|
|
10
|
+
import { gt, inc, minVersion, satisfies, valid, validRange } from "semver";
|
|
11
11
|
import { createInterface } from "node:readline/promises";
|
|
12
12
|
import { stdin, stdout } from "node:process";
|
|
13
13
|
import os, { tmpdir } from "node:os";
|
|
@@ -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.4.
|
|
34
|
-
var SDK_VERSION_RANGE = "^1.2.
|
|
33
|
+
var CLI_VERSION_RANGE = "^0.4.4";
|
|
34
|
+
var SDK_VERSION_RANGE = "^1.2.2";
|
|
35
35
|
var THEME_TEMPLATES = [
|
|
36
36
|
{
|
|
37
37
|
id: "starter",
|
|
@@ -110,6 +110,7 @@ async function customizeTemplate(directory, id, name, template) {
|
|
|
110
110
|
build: "nuvler theme build --theme .",
|
|
111
111
|
pack: "nuvler theme pack --theme .",
|
|
112
112
|
publish: "nuvler theme publish --theme .",
|
|
113
|
+
upgrade: "nuvler theme upgrade --theme .",
|
|
113
114
|
typecheck: "tsc -p tsconfig.json --noEmit"
|
|
114
115
|
};
|
|
115
116
|
packageMetadata.dependencies = {
|
|
@@ -161,6 +162,7 @@ async function customizeTemplate(directory, id, name, template) {
|
|
|
161
162
|
"| `npm run build` | Gera `dist/theme.js`, CSS e assets |",
|
|
162
163
|
"| `npm run pack` | Gera o artefato `.nuvler-theme.tgz` |",
|
|
163
164
|
"| `npm run publish` | Compila e envia ao Theme Registry |",
|
|
165
|
+
"| `npm run upgrade` | Atualiza o Theme SDK e o CLI local |",
|
|
164
166
|
"",
|
|
165
167
|
"As opções completas estão em `npx nuvler theme <comando> --help`.",
|
|
166
168
|
"",
|
|
@@ -174,8 +176,8 @@ async function customizeTemplate(directory, id, name, template) {
|
|
|
174
176
|
"```",
|
|
175
177
|
"",
|
|
176
178
|
`O artefato será gerado em \`artifacts/${id}-${NEW_THEME_VERSION}.nuvler-theme.tgz\`.`,
|
|
177
|
-
"Antes de publicar outra versão,
|
|
178
|
-
"
|
|
179
|
+
"Antes de publicar outra versão, execute `npx nuvler theme version patch`,",
|
|
180
|
+
"pois versões publicadas são imutáveis.",
|
|
179
181
|
"",
|
|
180
182
|
"Por padrão, um projeto configurado publica um tema privado do tenant.",
|
|
181
183
|
"Use `npx nuvler theme publish --visibility unlisted` ou",
|
|
@@ -7965,7 +7967,7 @@ async function walk(directory) {
|
|
|
7965
7967
|
await visit(directory);
|
|
7966
7968
|
return files;
|
|
7967
7969
|
}
|
|
7968
|
-
async function jsonFile(file) {
|
|
7970
|
+
async function jsonFile$1(file) {
|
|
7969
7971
|
try {
|
|
7970
7972
|
return JSON.parse(await readFile(file, "utf8"));
|
|
7971
7973
|
} catch (error) {
|
|
@@ -8017,11 +8019,11 @@ function assetKind(extension) {
|
|
|
8017
8019
|
return "image";
|
|
8018
8020
|
}
|
|
8019
8021
|
async function resolveImport(sourceFile, specifier, sourceDirectory) {
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
+
const bases = specifier.startsWith(".") ? [path.resolve(path.dirname(sourceFile), specifier)] : specifier.startsWith("@/") || specifier.startsWith("~/") ? [path.resolve(sourceDirectory, "src", specifier.slice(2)), path.resolve(sourceDirectory, specifier.slice(2))] : [];
|
|
8023
|
+
if (!bases.length) return null;
|
|
8022
8024
|
const candidates = [
|
|
8023
|
-
|
|
8024
|
-
...[
|
|
8025
|
+
...bases,
|
|
8026
|
+
...bases.flatMap((base) => [
|
|
8025
8027
|
".ts",
|
|
8026
8028
|
".tsx",
|
|
8027
8029
|
".js",
|
|
@@ -8031,14 +8033,14 @@ async function resolveImport(sourceFile, specifier, sourceDirectory) {
|
|
|
8031
8033
|
".sass",
|
|
8032
8034
|
".less",
|
|
8033
8035
|
...ASSET_EXTENSIONS
|
|
8034
|
-
].map((extension) => `${base}${extension}`),
|
|
8035
|
-
...[
|
|
8036
|
+
].map((extension) => `${base}${extension}`)),
|
|
8037
|
+
...bases.flatMap((base) => [
|
|
8036
8038
|
"index.ts",
|
|
8037
8039
|
"index.tsx",
|
|
8038
8040
|
"index.js",
|
|
8039
8041
|
"index.jsx",
|
|
8040
8042
|
"index.css"
|
|
8041
|
-
].map((entry) => path.join(base, entry))
|
|
8043
|
+
].map((entry) => path.join(base, entry)))
|
|
8042
8044
|
];
|
|
8043
8045
|
for (const candidate of candidates) {
|
|
8044
8046
|
if (!inside$1(sourceDirectory, candidate)) continue;
|
|
@@ -8052,10 +8054,19 @@ function expressionClasses(expression) {
|
|
|
8052
8054
|
if (ts.isStringLiteralLike(expression)) return expression.text.split(/\s+/).filter(Boolean);
|
|
8053
8055
|
if (ts.isNoSubstitutionTemplateLiteral(expression)) return expression.text.split(/\s+/).filter(Boolean);
|
|
8054
8056
|
if (ts.isPropertyAccessExpression(expression)) return [expression.name.text];
|
|
8057
|
+
if (ts.isElementAccessExpression(expression) && expression.argumentExpression && ts.isStringLiteralLike(expression.argumentExpression)) return [expression.argumentExpression.text];
|
|
8058
|
+
if (ts.isTemplateExpression(expression)) return [...expression.head.text.split(/\s+/), ...expression.templateSpans.flatMap((span) => [...expressionClasses(span.expression), ...span.literal.text.split(/\s+/)])].filter(Boolean);
|
|
8055
8059
|
if (ts.isCallExpression(expression)) return expression.arguments.flatMap(expressionClasses);
|
|
8056
8060
|
if (ts.isConditionalExpression(expression)) return [...expressionClasses(expression.whenTrue), ...expressionClasses(expression.whenFalse)];
|
|
8057
8061
|
if (ts.isBinaryExpression(expression)) return [...expressionClasses(expression.left), ...expressionClasses(expression.right)];
|
|
8058
8062
|
if (ts.isArrayLiteralExpression(expression)) return expression.elements.flatMap((item) => ts.isExpression(item) ? expressionClasses(item) : []);
|
|
8063
|
+
if (ts.isObjectLiteralExpression(expression)) return expression.properties.flatMap((property) => {
|
|
8064
|
+
if (ts.isPropertyAssignment(property) || ts.isShorthandPropertyAssignment(property)) {
|
|
8065
|
+
const name = property.name;
|
|
8066
|
+
return ts.isIdentifier(name) || ts.isStringLiteralLike(name) ? [name.text] : [];
|
|
8067
|
+
}
|
|
8068
|
+
return [];
|
|
8069
|
+
});
|
|
8059
8070
|
return [];
|
|
8060
8071
|
}
|
|
8061
8072
|
function jsxClasses(attributes) {
|
|
@@ -8113,7 +8124,40 @@ function containsJsx(node) {
|
|
|
8113
8124
|
function componentNodes(source) {
|
|
8114
8125
|
const result = [];
|
|
8115
8126
|
const defaultNames = /* @__PURE__ */ new Set();
|
|
8116
|
-
|
|
8127
|
+
function referencedIdentifiers(expression) {
|
|
8128
|
+
if (ts.isIdentifier(expression)) {
|
|
8129
|
+
defaultNames.add(expression.text);
|
|
8130
|
+
return;
|
|
8131
|
+
}
|
|
8132
|
+
if (ts.isParenthesizedExpression(expression)) referencedIdentifiers(expression.expression);
|
|
8133
|
+
if (ts.isCallExpression(expression)) {
|
|
8134
|
+
for (const argument of expression.arguments) if (ts.isIdentifier(argument) || ts.isParenthesizedExpression(argument) || ts.isCallExpression(argument)) referencedIdentifiers(argument);
|
|
8135
|
+
}
|
|
8136
|
+
}
|
|
8137
|
+
for (const statement of source.statements) if (ts.isExportAssignment(statement)) referencedIdentifiers(statement.expression);
|
|
8138
|
+
function wrappedFunction(expression) {
|
|
8139
|
+
if (ts.isArrowFunction(expression) || ts.isFunctionExpression(expression)) return expression;
|
|
8140
|
+
if (ts.isParenthesizedExpression(expression)) return wrappedFunction(expression.expression);
|
|
8141
|
+
if (ts.isCallExpression(expression)) for (const argument of expression.arguments) {
|
|
8142
|
+
if (!ts.isExpression(argument)) continue;
|
|
8143
|
+
const candidate = wrappedFunction(argument);
|
|
8144
|
+
if (candidate) return candidate;
|
|
8145
|
+
}
|
|
8146
|
+
return null;
|
|
8147
|
+
}
|
|
8148
|
+
for (const statement of source.statements) {
|
|
8149
|
+
if (!ts.isExportAssignment(statement) || ts.isIdentifier(statement.expression)) continue;
|
|
8150
|
+
const node = wrappedFunction(statement.expression);
|
|
8151
|
+
if (!node || !containsJsx(node)) continue;
|
|
8152
|
+
const fallback = path.basename(source.fileName, path.extname(source.fileName));
|
|
8153
|
+
const name = ts.isFunctionExpression(node) && node.name?.text ? node.name.text : fallback;
|
|
8154
|
+
result.push({
|
|
8155
|
+
name,
|
|
8156
|
+
node,
|
|
8157
|
+
exported: true,
|
|
8158
|
+
defaultExport: true
|
|
8159
|
+
});
|
|
8160
|
+
}
|
|
8117
8161
|
for (const statement of source.statements) {
|
|
8118
8162
|
if (ts.isFunctionDeclaration(statement) && statement.body && containsJsx(statement)) {
|
|
8119
8163
|
const modifiers = statement.modifiers ?? [];
|
|
@@ -8130,8 +8174,8 @@ function componentNodes(source) {
|
|
|
8130
8174
|
const exported = statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? false;
|
|
8131
8175
|
for (const declaration of statement.declarationList.declarations) {
|
|
8132
8176
|
if (!ts.isIdentifier(declaration.name) || !declaration.initializer) continue;
|
|
8133
|
-
const initializer = declaration.initializer;
|
|
8134
|
-
if (!
|
|
8177
|
+
const initializer = wrappedFunction(declaration.initializer);
|
|
8178
|
+
if (!initializer || !containsJsx(initializer)) continue;
|
|
8135
8179
|
result.push({
|
|
8136
8180
|
name: declaration.name.text,
|
|
8137
8181
|
node: initializer,
|
|
@@ -8250,6 +8294,34 @@ async function analyzeComponentFile(absoluteFile, sourceDirectory, framework) {
|
|
|
8250
8294
|
styles
|
|
8251
8295
|
};
|
|
8252
8296
|
}
|
|
8297
|
+
function propertyName(node) {
|
|
8298
|
+
if (ts.isIdentifier(node) || ts.isStringLiteralLike(node) || ts.isNumericLiteral(node)) return node.text;
|
|
8299
|
+
return null;
|
|
8300
|
+
}
|
|
8301
|
+
function tailwindColors(configFile) {
|
|
8302
|
+
if (!configFile) return {};
|
|
8303
|
+
const content = ts.sys.readFile(configFile);
|
|
8304
|
+
if (!content) return {};
|
|
8305
|
+
const source = ts.createSourceFile(configFile, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
8306
|
+
const colors = {};
|
|
8307
|
+
function collect(object, prefix = "") {
|
|
8308
|
+
for (const property of object.properties) {
|
|
8309
|
+
if (!ts.isPropertyAssignment(property)) continue;
|
|
8310
|
+
const name = propertyName(property.name);
|
|
8311
|
+
if (!name) continue;
|
|
8312
|
+
const key = name === "DEFAULT" ? prefix : prefix ? `${prefix}-${name}` : name;
|
|
8313
|
+
if (!key) continue;
|
|
8314
|
+
if (ts.isStringLiteralLike(property.initializer) && /^(?:#|rgb|hsl)/i.test(property.initializer.text)) colors[key] = property.initializer.text;
|
|
8315
|
+
else if (ts.isObjectLiteralExpression(property.initializer)) collect(property.initializer, key);
|
|
8316
|
+
}
|
|
8317
|
+
}
|
|
8318
|
+
function visit(node) {
|
|
8319
|
+
if (ts.isPropertyAssignment(node) && propertyName(node.name) === "colors" && ts.isObjectLiteralExpression(node.initializer)) collect(node.initializer);
|
|
8320
|
+
ts.forEachChild(node, visit);
|
|
8321
|
+
}
|
|
8322
|
+
visit(source);
|
|
8323
|
+
return colors;
|
|
8324
|
+
}
|
|
8253
8325
|
function tailwindAnalysis(files, dependencies, sourceDirectory) {
|
|
8254
8326
|
const version = dependencies.tailwindcss ?? null;
|
|
8255
8327
|
const match = version?.match(/(\d+)/);
|
|
@@ -8260,7 +8332,8 @@ function tailwindAnalysis(files, dependencies, sourceDirectory) {
|
|
|
8260
8332
|
version,
|
|
8261
8333
|
major: match ? Number(match[1]) : null,
|
|
8262
8334
|
configFile: config ? portable$2(path.relative(sourceDirectory, config)) : null,
|
|
8263
|
-
postcssFile: postcss ? portable$2(path.relative(sourceDirectory, postcss)) : null
|
|
8335
|
+
postcssFile: postcss ? portable$2(path.relative(sourceDirectory, postcss)) : null,
|
|
8336
|
+
colors: tailwindColors(config)
|
|
8264
8337
|
};
|
|
8265
8338
|
}
|
|
8266
8339
|
function addAsset(target, absolutePath, sourceDirectory, referencedBy) {
|
|
@@ -8281,6 +8354,12 @@ function addAsset(target, absolutePath, sourceDirectory, referencedBy) {
|
|
|
8281
8354
|
function cssAssetReferences(content) {
|
|
8282
8355
|
return [...content.matchAll(/url\(\s*(["']?)([^)'"\s]+)\1\s*\)/gi)].map((match) => match[2]).filter((value) => !/^(?:data:|https?:|#)/i.test(value));
|
|
8283
8356
|
}
|
|
8357
|
+
function colorLiterals(content) {
|
|
8358
|
+
return [...content.matchAll(/#[0-9a-f]{3,8}\b|(?:rgb|hsl)a?\([^)]*\)/gi)].map((match) => match[0]);
|
|
8359
|
+
}
|
|
8360
|
+
function cssImports(content) {
|
|
8361
|
+
return [...content.matchAll(/@import\s+(?:url\(\s*)?["']([^"']+)["']\s*\)?/gi)].map((match) => match[1]).filter((value) => !/^(?:https?:|data:|tailwindcss)/i.test(value));
|
|
8362
|
+
}
|
|
8284
8363
|
async function analyzeReactProject(inputDirectory) {
|
|
8285
8364
|
const sourceDirectory = path.resolve(inputDirectory);
|
|
8286
8365
|
let details;
|
|
@@ -8290,7 +8369,7 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8290
8369
|
throw new Error(`Projeto de origem não encontrado: ${sourceDirectory}`);
|
|
8291
8370
|
}
|
|
8292
8371
|
if (!details.isDirectory()) throw new Error(`A origem não é uma pasta: ${sourceDirectory}`);
|
|
8293
|
-
const packageJson = await jsonFile(path.join(sourceDirectory, "package.json"));
|
|
8372
|
+
const packageJson = await jsonFile$1(path.join(sourceDirectory, "package.json"));
|
|
8294
8373
|
const dependencies = dependenciesOf(packageJson);
|
|
8295
8374
|
if (!dependencies.react) throw new Error("O projeto não declara React nas dependências.");
|
|
8296
8375
|
const files = await walk(sourceDirectory);
|
|
@@ -8298,10 +8377,12 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8298
8377
|
const tsxFiles = files.filter((file) => file.endsWith(".tsx"));
|
|
8299
8378
|
if (!tsxFiles.length) throw new Error("Nenhum componente TSX foi encontrado. A V1 exige React com TypeScript.");
|
|
8300
8379
|
const components = [];
|
|
8380
|
+
const detectedColors = /* @__PURE__ */ new Set();
|
|
8301
8381
|
const ignoredFiles = [];
|
|
8302
8382
|
const referencedStyles = /* @__PURE__ */ new Set();
|
|
8303
8383
|
const assetMap = /* @__PURE__ */ new Map();
|
|
8304
8384
|
for (const file of tsxFiles) {
|
|
8385
|
+
colorLiterals(await readFile(file, "utf8")).forEach((color) => detectedColors.add(color));
|
|
8305
8386
|
const analyzed = await analyzeComponentFile(file, sourceDirectory, framework);
|
|
8306
8387
|
components.push(...analyzed.components);
|
|
8307
8388
|
analyzed.styles.forEach((style) => referencedStyles.add(path.resolve(style)));
|
|
@@ -8321,6 +8402,7 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8321
8402
|
const styles = [];
|
|
8322
8403
|
for (const file of files.filter((candidate) => STYLE_EXTENSIONS.has(path.extname(candidate).toLowerCase()))) {
|
|
8323
8404
|
const content = await readFile(file, "utf8");
|
|
8405
|
+
colorLiterals(content).forEach((color) => detectedColors.add(color));
|
|
8324
8406
|
const relativeFile = portable$2(path.relative(sourceDirectory, file));
|
|
8325
8407
|
styles.push({
|
|
8326
8408
|
file: relativeFile,
|
|
@@ -8331,6 +8413,19 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8331
8413
|
});
|
|
8332
8414
|
for (const reference of cssAssetReferences(content)) addAsset(assetMap, reference.startsWith("/") ? path.join(sourceDirectory, "public", reference.replace(/^\/+/, "")) : path.resolve(path.dirname(file), reference), sourceDirectory, relativeFile);
|
|
8333
8415
|
}
|
|
8416
|
+
const stylesByPath = new Map(styles.map((style) => [path.resolve(style.absolutePath), style]));
|
|
8417
|
+
let importsChanged = true;
|
|
8418
|
+
while (importsChanged) {
|
|
8419
|
+
importsChanged = false;
|
|
8420
|
+
for (const style of styles.filter(({ imported }) => imported)) for (const reference of cssImports(style.content)) {
|
|
8421
|
+
const extension = path.extname(reference) ? "" : ".css";
|
|
8422
|
+
const imported = stylesByPath.get(path.resolve(path.dirname(style.absolutePath), `${reference}${extension}`));
|
|
8423
|
+
if (imported && !imported.imported) {
|
|
8424
|
+
imported.imported = true;
|
|
8425
|
+
importsChanged = true;
|
|
8426
|
+
}
|
|
8427
|
+
}
|
|
8428
|
+
}
|
|
8334
8429
|
return {
|
|
8335
8430
|
sourceDirectory,
|
|
8336
8431
|
projectName: typeof packageJson.name === "string" && packageJson.name.trim() ? packageJson.name.trim() : path.basename(sourceDirectory),
|
|
@@ -8342,6 +8437,7 @@ async function analyzeReactProject(inputDirectory) {
|
|
|
8342
8437
|
styles,
|
|
8343
8438
|
assets: [...assetMap.values()],
|
|
8344
8439
|
tailwind: tailwindAnalysis(files, dependencies, sourceDirectory),
|
|
8440
|
+
colorLiterals: [...detectedColors],
|
|
8345
8441
|
ignoredFiles,
|
|
8346
8442
|
warnings: styles.some(({ file }) => /\.(?:scss|sass|less)$/.test(file)) ? ["A V1 detecta Sass/Less, mas preserva automaticamente apenas CSS e CSS Modules."] : []
|
|
8347
8443
|
};
|
|
@@ -8460,7 +8556,11 @@ function componentCorpus(component) {
|
|
|
8460
8556
|
component.name,
|
|
8461
8557
|
component.file,
|
|
8462
8558
|
...component.rootClasses,
|
|
8463
|
-
...component.jsx.flatMap(({ classes, text }) => [
|
|
8559
|
+
...component.jsx.flatMap(({ tag, classes, text }) => [
|
|
8560
|
+
tag,
|
|
8561
|
+
...classes,
|
|
8562
|
+
...text
|
|
8563
|
+
])
|
|
8464
8564
|
].join(" "));
|
|
8465
8565
|
}
|
|
8466
8566
|
function roleScore(component, rule) {
|
|
@@ -8482,9 +8582,9 @@ function roleScore(component, rule) {
|
|
|
8482
8582
|
reasons.push(`JSX/classes contêm "${keyword}"`);
|
|
8483
8583
|
}
|
|
8484
8584
|
}
|
|
8485
|
-
for (const tag of rule.tags ?? []) if (component.jsx.some((node) => normalized$1(node.tag) === tag)) {
|
|
8585
|
+
for (const tag of rule.tags ?? []) if (component.jsx.some((node) => node.depth === 0 && normalized$1(node.tag) === tag)) {
|
|
8486
8586
|
score += 6;
|
|
8487
|
-
reasons.push(`usa <${tag}>`);
|
|
8587
|
+
reasons.push(`raiz usa <${tag}>`);
|
|
8488
8588
|
}
|
|
8489
8589
|
if (component.page && rule.role === "HOME" && /(^|\/)(?:app\/)?page\.tsx$/.test(component.file)) {
|
|
8490
8590
|
score += 7;
|
|
@@ -8503,7 +8603,7 @@ function roleScore(component, rule) {
|
|
|
8503
8603
|
}
|
|
8504
8604
|
}
|
|
8505
8605
|
if (rule.role === "PRODUCT_GRID") {
|
|
8506
|
-
if (component.jsx.some(({ classes }) => classes.some((item) => /grid|list/.test(normalized$1(item))))) {
|
|
8606
|
+
if ((corpus.includes("product") || corpus.includes("produto") || corpus.includes("catalog")) && component.jsx.some(({ classes }) => classes.some((item) => /grid|list/.test(normalized$1(item))))) {
|
|
8507
8607
|
score += 5;
|
|
8508
8608
|
reasons.push("possui estrutura de grid/lista");
|
|
8509
8609
|
}
|
|
@@ -8515,8 +8615,10 @@ function roleScore(component, rule) {
|
|
|
8515
8615
|
}
|
|
8516
8616
|
}
|
|
8517
8617
|
if (rule.role === "HERO" && component.text.some((text) => text.length > 20)) {
|
|
8518
|
-
|
|
8519
|
-
|
|
8618
|
+
if (rule.keywords.some((keyword) => corpus.includes(normalized$1(keyword)))) {
|
|
8619
|
+
score += 2;
|
|
8620
|
+
reasons.push("possui chamada textual de destaque");
|
|
8621
|
+
}
|
|
8520
8622
|
}
|
|
8521
8623
|
if (component.defaultExport) score += 1;
|
|
8522
8624
|
return {
|
|
@@ -8616,7 +8718,7 @@ export function Header({ site, categories, pages }: HeaderProps) {
|
|
|
8616
8718
|
<nav className=${classes("nuvler-migrated-nav", style.navigation)} aria-label="Navegação principal">
|
|
8617
8719
|
<a href="/">Início</a>
|
|
8618
8720
|
{site.modules.includes("PRODUCTS") && <a href="/produtos">Produtos</a>}
|
|
8619
|
-
{categories.slice(0, 6).map((category) => <a href={
|
|
8721
|
+
{categories.slice(0, 6).map((category) => <a href={\`/\${category.slug}\`} key={category.slug}>{category.name}</a>)}
|
|
8620
8722
|
{pages.slice(0, 4).map((page) => <a href={\`/\${page.slug}\`} key={page.slug}>{page.title}</a>)}
|
|
8621
8723
|
</nav>
|
|
8622
8724
|
{site.modules.includes("PRODUCTS") && <form className="nuvler-migrated-search" action="/produtos">
|
|
@@ -8654,7 +8756,7 @@ export function Footer({ site, pages, template }: FooterProps) {
|
|
|
8654
8756
|
}
|
|
8655
8757
|
function productCardSource(plan) {
|
|
8656
8758
|
const style = profile(plan, "PRODUCT_CARD");
|
|
8657
|
-
return `import type
|
|
8759
|
+
return `import { productUrl, type ThemeProduct } from "@nuvler/theme-sdk";
|
|
8658
8760
|
|
|
8659
8761
|
function money(value: number | null): string {
|
|
8660
8762
|
return value === null ? "Consulte" : new Intl.NumberFormat("pt-BR", { style: "currency", currency: "BRL" }).format(value);
|
|
@@ -8662,16 +8764,17 @@ function money(value: number | null): string {
|
|
|
8662
8764
|
|
|
8663
8765
|
export function ProductCard({ product, showCategory = true, showDescription = true }: { product: ThemeProduct; showCategory?: boolean; showDescription?: boolean }) {
|
|
8664
8766
|
const price = product.promotionalPrice ?? product.price;
|
|
8767
|
+
const href = productUrl(product);
|
|
8665
8768
|
return <article className=${classes("nuvler-migrated-product-card", style.root || style.card)}>
|
|
8666
|
-
<a className=${classes("nuvler-migrated-product-media", style.media)} href={
|
|
8769
|
+
<a className=${classes("nuvler-migrated-product-media", style.media)} href={href}>
|
|
8667
8770
|
{product.image?.url ? <img src={product.image.url} alt={product.image.alt || product.title} /> : <span aria-hidden="true" />}
|
|
8668
8771
|
</a>
|
|
8669
8772
|
<div className=${classes("nuvler-migrated-product-content", style.content)}>
|
|
8670
8773
|
{showCategory && <small>{product.categories[0]?.name || product.brand || "Produto"}</small>}
|
|
8671
|
-
<h3 className=${classes("nuvler-migrated-product-title", style.title)}><a href={
|
|
8774
|
+
<h3 className=${classes("nuvler-migrated-product-title", style.title)}><a href={href}>{product.title}</a></h3>
|
|
8672
8775
|
{showDescription && product.description && <p className=${classes("nuvler-migrated-copy", style.text)}>{product.description}</p>}
|
|
8673
8776
|
<strong>{money(price)}</strong>
|
|
8674
|
-
<a className=${classes("nuvler-migrated-action", style.action)} href={
|
|
8777
|
+
<a className=${classes("nuvler-migrated-action", style.action)} href={href}>Ver produto</a>
|
|
8675
8778
|
</div>
|
|
8676
8779
|
</article>;
|
|
8677
8780
|
}
|
|
@@ -8989,7 +9092,8 @@ async function configureTailwind(plan, directory) {
|
|
|
8989
9092
|
return "@import \"tailwindcss\";\n";
|
|
8990
9093
|
}
|
|
8991
9094
|
metadata.devDependencies.autoprefixer = plan.analysis.dependencies.autoprefixer || "^10.4.0";
|
|
8992
|
-
|
|
9095
|
+
const migratedColors = JSON.stringify(plan.analysis.tailwind.colors);
|
|
9096
|
+
await writeFile(path.join(directory, "tailwind.config.cjs"), `module.exports = { content: ["./src/**/*.{ts,tsx}"], theme: { extend: { colors: ${migratedColors} } }, plugins: [] };\n`, "utf8");
|
|
8993
9097
|
await writeFile(path.join(directory, "postcss.config.cjs"), "module.exports = { plugins: { tailwindcss: {}, autoprefixer: {} } };\n", "utf8");
|
|
8994
9098
|
await writeFile(packageFile, `${JSON.stringify(metadata, null, 2)}\n`, "utf8");
|
|
8995
9099
|
return "@tailwind base;\n@tailwind components;\n@tailwind utilities;\n";
|
|
@@ -9127,7 +9231,8 @@ function classProfile(component) {
|
|
|
9127
9231
|
navigation: classesFor(component, [
|
|
9128
9232
|
"nav",
|
|
9129
9233
|
"menu",
|
|
9130
|
-
"navigation"
|
|
9234
|
+
"navigation",
|
|
9235
|
+
"links"
|
|
9131
9236
|
], "", ["nav"]),
|
|
9132
9237
|
title: classesFor(component, [
|
|
9133
9238
|
"title",
|
|
@@ -9171,7 +9276,9 @@ function classProfile(component) {
|
|
|
9171
9276
|
"body",
|
|
9172
9277
|
"inner",
|
|
9173
9278
|
"container",
|
|
9174
|
-
"wrapper"
|
|
9279
|
+
"wrapper",
|
|
9280
|
+
"shell",
|
|
9281
|
+
"layout"
|
|
9175
9282
|
])
|
|
9176
9283
|
};
|
|
9177
9284
|
}
|
|
@@ -9181,24 +9288,161 @@ function selectedFor(analysis, role) {
|
|
|
9181
9288
|
return (right.roles.find((candidate) => candidate.role === role)?.score ?? 0) - leftScore || Number(right.exported) - Number(left.exported);
|
|
9182
9289
|
})[0];
|
|
9183
9290
|
}
|
|
9184
|
-
function
|
|
9185
|
-
|
|
9291
|
+
function byte(value) {
|
|
9292
|
+
return Math.max(0, Math.min(255, Math.round(value))).toString(16).padStart(2, "0");
|
|
9293
|
+
}
|
|
9294
|
+
function normalizedColor(input, variables = /* @__PURE__ */ new Map()) {
|
|
9295
|
+
let value = input.trim().toLowerCase();
|
|
9296
|
+
const variable = value.match(/^var\(\s*(--[\w-]+)/);
|
|
9297
|
+
if (variable) {
|
|
9298
|
+
const resolved = variables.get(variable[1]);
|
|
9299
|
+
return resolved && resolved !== input ? normalizedColor(resolved, variables) : null;
|
|
9300
|
+
}
|
|
9301
|
+
const named = {
|
|
9302
|
+
black: "#000000",
|
|
9303
|
+
white: "#ffffff"
|
|
9304
|
+
};
|
|
9305
|
+
if (named[value]) return named[value];
|
|
9306
|
+
const hex = value.match(/^#([0-9a-f]{3,8})\b/i)?.[1];
|
|
9307
|
+
if (hex) {
|
|
9308
|
+
if (hex.length === 3 || hex.length === 4) return `#${hex.slice(0, 3).split("").map((part) => part + part).join("")}`;
|
|
9309
|
+
return `#${hex.slice(0, 6)}`;
|
|
9310
|
+
}
|
|
9311
|
+
const rgb = value.match(/^rgba?\(\s*([\d.]+)%?[,\s]+([\d.]+)%?[,\s]+([\d.]+)%?/);
|
|
9312
|
+
if (rgb) {
|
|
9313
|
+
const factor = value.slice(0, value.indexOf(")")).includes("%") ? 2.55 : 1;
|
|
9314
|
+
return `#${byte(Number(rgb[1]) * factor)}${byte(Number(rgb[2]) * factor)}${byte(Number(rgb[3]) * factor)}`;
|
|
9315
|
+
}
|
|
9316
|
+
const hsl = value.match(/^hsla?\(\s*([\d.]+)(?:deg)?[,\s]+([\d.]+)%[,\s]+([\d.]+)%/);
|
|
9317
|
+
if (hsl) {
|
|
9318
|
+
const hue = (Number(hsl[1]) % 360 + 360) % 360;
|
|
9319
|
+
const saturation = Number(hsl[2]) / 100;
|
|
9320
|
+
const lightness = Number(hsl[3]) / 100;
|
|
9321
|
+
const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
|
|
9322
|
+
const segment = hue / 60;
|
|
9323
|
+
const middle = chroma * (1 - Math.abs(segment % 2 - 1));
|
|
9324
|
+
const [red, green, blue] = segment < 1 ? [
|
|
9325
|
+
chroma,
|
|
9326
|
+
middle,
|
|
9327
|
+
0
|
|
9328
|
+
] : segment < 2 ? [
|
|
9329
|
+
middle,
|
|
9330
|
+
chroma,
|
|
9331
|
+
0
|
|
9332
|
+
] : segment < 3 ? [
|
|
9333
|
+
0,
|
|
9334
|
+
chroma,
|
|
9335
|
+
middle
|
|
9336
|
+
] : segment < 4 ? [
|
|
9337
|
+
0,
|
|
9338
|
+
middle,
|
|
9339
|
+
chroma
|
|
9340
|
+
] : segment < 5 ? [
|
|
9341
|
+
middle,
|
|
9342
|
+
0,
|
|
9343
|
+
chroma
|
|
9344
|
+
] : [
|
|
9345
|
+
chroma,
|
|
9346
|
+
0,
|
|
9347
|
+
middle
|
|
9348
|
+
];
|
|
9349
|
+
const offset = lightness - chroma / 2;
|
|
9350
|
+
return `#${byte((red + offset) * 255)}${byte((green + offset) * 255)}${byte((blue + offset) * 255)}`;
|
|
9351
|
+
}
|
|
9352
|
+
return null;
|
|
9353
|
+
}
|
|
9354
|
+
function cssVariables(css) {
|
|
9355
|
+
const variables = /* @__PURE__ */ new Map();
|
|
9356
|
+
for (const match of css.matchAll(/(--[\w-]+)\s*:\s*([^;}]+)/gi)) variables.set(match[1].toLowerCase(), match[2].trim());
|
|
9357
|
+
return variables;
|
|
9358
|
+
}
|
|
9359
|
+
function customProperty(css, terms, variables) {
|
|
9360
|
+
for (const match of css.matchAll(/--([\w-]+)\s*:\s*([^;}]+)/gi)) {
|
|
9186
9361
|
const name = normalized(match[1]);
|
|
9187
|
-
|
|
9362
|
+
const color = normalizedColor(match[2], variables);
|
|
9363
|
+
if (color && terms.some((term) => name.includes(term))) return color;
|
|
9188
9364
|
}
|
|
9189
9365
|
return null;
|
|
9190
9366
|
}
|
|
9191
|
-
function frequentColors(css) {
|
|
9367
|
+
function frequentColors(css, literals, variables) {
|
|
9192
9368
|
const counts = /* @__PURE__ */ new Map();
|
|
9193
|
-
|
|
9194
|
-
|
|
9369
|
+
const candidates = [...css.matchAll(/#[0-9a-f]{3,8}\b|(?:rgb|hsl)a?\([^)]*\)/gi)].map((match) => match[0]);
|
|
9370
|
+
for (const candidate of [...candidates, ...literals]) {
|
|
9371
|
+
const color = normalizedColor(candidate, variables);
|
|
9372
|
+
if (!color) continue;
|
|
9195
9373
|
counts.set(color, (counts.get(color) ?? 0) + 1);
|
|
9196
9374
|
}
|
|
9197
9375
|
return [...counts.entries()].sort((left, right) => right[1] - left[1]).map(([color]) => color);
|
|
9198
9376
|
}
|
|
9199
|
-
function
|
|
9377
|
+
function ruleColor(css, component, property, variables) {
|
|
9378
|
+
if (!component) return null;
|
|
9379
|
+
const classes = new Set(component.jsx.flatMap((node) => node.classes).filter((name) => /^[a-z_-][\w-]*$/i.test(name)));
|
|
9380
|
+
for (const match of css.matchAll(/([^{}]+)\{([^{}]+)\}/g)) {
|
|
9381
|
+
const selector = match[1];
|
|
9382
|
+
if (![...classes].some((name) => new RegExp(`\\.${name}(?![\\w-])`).test(selector))) continue;
|
|
9383
|
+
const declaration = [...match[2].matchAll(new RegExp(`(?:^|;)\\s*${property}\\s*:\\s*([^;!]+)`, "gi"))].at(-1);
|
|
9384
|
+
const color = declaration ? normalizedColor(declaration[1], variables) : null;
|
|
9385
|
+
if (color) return color;
|
|
9386
|
+
}
|
|
9387
|
+
return null;
|
|
9388
|
+
}
|
|
9389
|
+
var TAILWIND_COLORS = {
|
|
9390
|
+
black: "#000000",
|
|
9391
|
+
white: "#ffffff",
|
|
9392
|
+
"slate-50": "#f8fafc",
|
|
9393
|
+
"slate-200": "#e2e8f0",
|
|
9394
|
+
"slate-500": "#64748b",
|
|
9395
|
+
"slate-900": "#0f172a",
|
|
9396
|
+
"gray-50": "#f9fafb",
|
|
9397
|
+
"gray-200": "#e5e7eb",
|
|
9398
|
+
"gray-500": "#6b7280",
|
|
9399
|
+
"gray-900": "#111827",
|
|
9400
|
+
"red-500": "#ef4444",
|
|
9401
|
+
"red-600": "#dc2626",
|
|
9402
|
+
"orange-500": "#f97316",
|
|
9403
|
+
"amber-500": "#f59e0b",
|
|
9404
|
+
"yellow-500": "#eab308",
|
|
9405
|
+
"green-500": "#22c55e",
|
|
9406
|
+
"emerald-500": "#10b981",
|
|
9407
|
+
"teal-500": "#14b8a6",
|
|
9408
|
+
"cyan-500": "#06b6d4",
|
|
9409
|
+
"sky-500": "#0ea5e9",
|
|
9410
|
+
"blue-500": "#3b82f6",
|
|
9411
|
+
"blue-600": "#2563eb",
|
|
9412
|
+
"blue-900": "#1e3a8a",
|
|
9413
|
+
"indigo-500": "#6366f1",
|
|
9414
|
+
"violet-500": "#8b5cf6",
|
|
9415
|
+
"purple-500": "#a855f7",
|
|
9416
|
+
"pink-500": "#ec4899"
|
|
9417
|
+
};
|
|
9418
|
+
function tailwindColor(analysis, component, prefix) {
|
|
9419
|
+
if (!component) return null;
|
|
9420
|
+
const palette = {
|
|
9421
|
+
...TAILWIND_COLORS,
|
|
9422
|
+
...analysis.tailwind.colors
|
|
9423
|
+
};
|
|
9424
|
+
for (const original of component.jsx.flatMap((node) => node.classes)) {
|
|
9425
|
+
const utility = original.split(":").at(-1) ?? original;
|
|
9426
|
+
if (!utility.startsWith(`${prefix}-`)) continue;
|
|
9427
|
+
const name = utility.slice(prefix.length + 1);
|
|
9428
|
+
const arbitrary = name.match(/^\[(.+)\]$/)?.[1]?.replaceAll("_", " ");
|
|
9429
|
+
const color = arbitrary ? normalizedColor(arbitrary) : normalizedColor(palette[name] ?? "");
|
|
9430
|
+
if (color) return color;
|
|
9431
|
+
}
|
|
9432
|
+
return null;
|
|
9433
|
+
}
|
|
9434
|
+
function contrastColor(background) {
|
|
9435
|
+
const channels = [
|
|
9436
|
+
background.slice(1, 3),
|
|
9437
|
+
background.slice(3, 5),
|
|
9438
|
+
background.slice(5, 7)
|
|
9439
|
+
].map((channel) => Number.parseInt(channel, 16) / 255).map((channel) => channel <= .04045 ? channel / 12.92 : ((channel + .055) / 1.055) ** 2.4);
|
|
9440
|
+
return channels[0] * .2126 + channels[1] * .7152 + channels[2] * .0722 > .42 ? "#0f172a" : "#ffffff";
|
|
9441
|
+
}
|
|
9442
|
+
function inferredTokens(analysis, selected) {
|
|
9200
9443
|
const css = analysis.styles.filter(({ imported }) => imported).map(({ content }) => content).join("\n");
|
|
9201
|
-
const
|
|
9444
|
+
const variables = cssVariables(css);
|
|
9445
|
+
const nonNeutral = frequentColors(css, analysis.colorLiterals, variables).filter((color) => ![
|
|
9202
9446
|
"#ffffff",
|
|
9203
9447
|
"#000000",
|
|
9204
9448
|
"#f8fafc",
|
|
@@ -9208,55 +9452,60 @@ function inferredTokens(analysis) {
|
|
|
9208
9452
|
].includes(color));
|
|
9209
9453
|
const widths = [...css.matchAll(/max-width\s*:\s*(\d{3,4})px/gi)].map((match) => Number(match[1])).filter((value) => value >= 960 && value <= 1600);
|
|
9210
9454
|
const radii = [...css.matchAll(/border-radius\s*:\s*(\d{1,2})px/gi)].map((match) => Number(match[1])).filter((value) => value >= 0 && value <= 32);
|
|
9455
|
+
const component = (role) => selected[role]?.component;
|
|
9211
9456
|
const primary = customProperty(css, [
|
|
9212
9457
|
"primary",
|
|
9213
9458
|
"brand",
|
|
9214
9459
|
"principal"
|
|
9215
|
-
]) ?? nonNeutral[0] ?? "#1d4ed8";
|
|
9216
|
-
const secondary = customProperty(css, ["secondary", "destaque"]) ?? nonNeutral
|
|
9460
|
+
], variables) ?? ruleColor(css, component("PRODUCT_CARD"), "background(?:-color)?", variables) ?? tailwindColor(analysis, component("HERO"), "bg") ?? nonNeutral[0] ?? "#1d4ed8";
|
|
9461
|
+
const secondary = customProperty(css, ["secondary", "destaque"], variables) ?? nonNeutral.find((color) => color !== primary) ?? "#f59e0b";
|
|
9217
9462
|
const background = customProperty(css, [
|
|
9218
9463
|
"background",
|
|
9219
9464
|
"fundo",
|
|
9220
|
-
"bg"
|
|
9221
|
-
]) ?? "#f8fafc";
|
|
9465
|
+
"page-bg"
|
|
9466
|
+
], variables) ?? ruleColor(css, component("HOME"), "background(?:-color)?", variables) ?? tailwindColor(analysis, component("HOME"), "bg") ?? "#f8fafc";
|
|
9222
9467
|
const text = customProperty(css, [
|
|
9223
9468
|
"foreground",
|
|
9224
9469
|
"text",
|
|
9225
9470
|
"texto"
|
|
9226
|
-
]) ?? "#0f172a";
|
|
9471
|
+
], variables) ?? ruleColor(css, component("HOME"), "color", variables) ?? tailwindColor(analysis, component("HOME"), "text") ?? "#0f172a";
|
|
9227
9472
|
const surface = customProperty(css, [
|
|
9228
9473
|
"surface",
|
|
9229
9474
|
"card",
|
|
9230
9475
|
"panel"
|
|
9231
|
-
]) ?? "#ffffff";
|
|
9476
|
+
], variables) ?? ruleColor(css, component("PRODUCT_CARD"), "background(?:-color)?", variables) ?? "#ffffff";
|
|
9477
|
+
const headerBackground = customProperty(css, ["header-background", "header-bg"], variables) ?? ruleColor(css, component("HEADER"), "background(?:-color)?", variables) ?? tailwindColor(analysis, component("HEADER"), "bg") ?? surface;
|
|
9478
|
+
const headerText = customProperty(css, ["header-text", "header-foreground"], variables) ?? ruleColor(css, component("HEADER"), "color", variables) ?? tailwindColor(analysis, component("HEADER"), "text") ?? text;
|
|
9479
|
+
const footerBackground = customProperty(css, ["footer-background", "footer-bg"], variables) ?? ruleColor(css, component("FOOTER"), "background(?:-color)?", variables) ?? tailwindColor(analysis, component("FOOTER"), "bg") ?? text;
|
|
9480
|
+
const footerText = customProperty(css, ["footer-text", "footer-foreground"], variables) ?? ruleColor(css, component("FOOTER"), "color", variables) ?? tailwindColor(analysis, component("FOOTER"), "text") ?? background;
|
|
9232
9481
|
return {
|
|
9233
9482
|
primary,
|
|
9234
|
-
primaryText: customProperty(css, ["on-primary", "primary-text"]) ?? "
|
|
9483
|
+
primaryText: customProperty(css, ["on-primary", "primary-text"], variables) ?? ruleColor(css, component("PRODUCT_CARD"), "color", variables) ?? contrastColor(primary),
|
|
9235
9484
|
secondary,
|
|
9236
|
-
secondaryText: customProperty(css, ["on-secondary", "secondary-text"]) ??
|
|
9237
|
-
accent: customProperty(css, ["accent", "destaque"]) ?? secondary,
|
|
9485
|
+
secondaryText: customProperty(css, ["on-secondary", "secondary-text"], variables) ?? contrastColor(secondary),
|
|
9486
|
+
accent: customProperty(css, ["accent", "destaque"], variables) ?? secondary,
|
|
9238
9487
|
background,
|
|
9239
9488
|
surface,
|
|
9240
9489
|
surfaceAlt: customProperty(css, [
|
|
9241
9490
|
"surface-alt",
|
|
9242
9491
|
"surface-muted",
|
|
9243
9492
|
"subtle"
|
|
9244
|
-
]) ?? background,
|
|
9493
|
+
], variables) ?? background,
|
|
9245
9494
|
text,
|
|
9246
9495
|
textMuted: customProperty(css, [
|
|
9247
9496
|
"muted",
|
|
9248
9497
|
"text-secondary",
|
|
9249
9498
|
"subtle-text"
|
|
9250
|
-
]) ?? "#64748b",
|
|
9499
|
+
], variables) ?? "#64748b",
|
|
9251
9500
|
border: customProperty(css, [
|
|
9252
9501
|
"border",
|
|
9253
9502
|
"line",
|
|
9254
9503
|
"divider"
|
|
9255
|
-
]) ?? "#e2e8f0",
|
|
9256
|
-
headerBackground
|
|
9257
|
-
headerText
|
|
9258
|
-
footerBackground
|
|
9259
|
-
footerText
|
|
9504
|
+
], variables) ?? ruleColor(css, component("PRODUCT_CARD"), "border(?:-color)?", variables) ?? "#e2e8f0",
|
|
9505
|
+
headerBackground,
|
|
9506
|
+
headerText,
|
|
9507
|
+
footerBackground,
|
|
9508
|
+
footerText,
|
|
9260
9509
|
containerWidth: widths[0] ?? 1200,
|
|
9261
9510
|
borderRadius: radii[0] ?? 16
|
|
9262
9511
|
};
|
|
@@ -9295,7 +9544,7 @@ function createMigrationPlan(analysis, options) {
|
|
|
9295
9544
|
selected,
|
|
9296
9545
|
styles: analysis.styles.filter(({ imported, file }) => imported && file.endsWith(".css")),
|
|
9297
9546
|
assets: analysis.assets,
|
|
9298
|
-
tokens: inferredTokens(analysis),
|
|
9547
|
+
tokens: inferredTokens(analysis, selected),
|
|
9299
9548
|
warnings: [...new Set(warnings)]
|
|
9300
9549
|
};
|
|
9301
9550
|
}
|
|
@@ -9596,6 +9845,136 @@ async function themeValidate(options) {
|
|
|
9596
9845
|
return performance;
|
|
9597
9846
|
}
|
|
9598
9847
|
//#endregion
|
|
9848
|
+
//#region src/commands/theme/upgrade.ts
|
|
9849
|
+
async function jsonFile(file, label) {
|
|
9850
|
+
try {
|
|
9851
|
+
return JSON.parse(await readFile(file, "utf8"));
|
|
9852
|
+
} catch (error) {
|
|
9853
|
+
throw new Error(`${label} inválido ou não encontrado: ${file}`, { cause: error });
|
|
9854
|
+
}
|
|
9855
|
+
}
|
|
9856
|
+
async function writeJson(file, value) {
|
|
9857
|
+
await writeFile(file, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
9858
|
+
}
|
|
9859
|
+
function exactVersion(input, label) {
|
|
9860
|
+
const version = valid(input.trim());
|
|
9861
|
+
if (!version) throw new Error(`${label} deve ser "latest" ou uma versão SemVer exata.`);
|
|
9862
|
+
return version;
|
|
9863
|
+
}
|
|
9864
|
+
async function npmInstall(directory, dependency, development) {
|
|
9865
|
+
const args = [
|
|
9866
|
+
"install",
|
|
9867
|
+
development ? "--save-dev" : "--save",
|
|
9868
|
+
dependency,
|
|
9869
|
+
"--ignore-scripts",
|
|
9870
|
+
"--no-audit",
|
|
9871
|
+
"--no-fund"
|
|
9872
|
+
];
|
|
9873
|
+
await new Promise((resolve, reject) => {
|
|
9874
|
+
const child = spawn("npm", args, {
|
|
9875
|
+
cwd: directory,
|
|
9876
|
+
stdio: "inherit",
|
|
9877
|
+
shell: false
|
|
9878
|
+
});
|
|
9879
|
+
child.once("error", reject);
|
|
9880
|
+
child.once("exit", (code, signal) => {
|
|
9881
|
+
if (code === 0) resolve();
|
|
9882
|
+
else reject(/* @__PURE__ */ new Error(`npm install falhou${signal ? ` (${signal})` : ` com código ${code ?? "desconhecido"}`}.`));
|
|
9883
|
+
});
|
|
9884
|
+
});
|
|
9885
|
+
}
|
|
9886
|
+
function dependencyVersion(value, packageName) {
|
|
9887
|
+
const version = value ? minVersion(value)?.version : null;
|
|
9888
|
+
if (!version) throw new Error(`O npm não registrou uma versão válida para ${packageName}.`);
|
|
9889
|
+
return version;
|
|
9890
|
+
}
|
|
9891
|
+
function nextThemeVersion(current, release) {
|
|
9892
|
+
const requested = release.trim().toLowerCase();
|
|
9893
|
+
const next = [
|
|
9894
|
+
"patch",
|
|
9895
|
+
"minor",
|
|
9896
|
+
"major"
|
|
9897
|
+
].includes(requested) ? inc(current, requested) : valid(requested);
|
|
9898
|
+
if (!next) throw new Error("Versão inválida. Use patch, minor, major ou uma versão SemVer exata.");
|
|
9899
|
+
if (!gt(next, current)) throw new Error(`A nova versão (${next}) precisa ser maior que a atual (${current}).`);
|
|
9900
|
+
return next;
|
|
9901
|
+
}
|
|
9902
|
+
async function themeVersion(options) {
|
|
9903
|
+
const directory = path.resolve(options.themeDirectory);
|
|
9904
|
+
const manifestFile = path.join(directory, "nuvler.theme.json");
|
|
9905
|
+
const packageFile = path.join(directory, "package.json");
|
|
9906
|
+
const lockFile = path.join(directory, "package-lock.json");
|
|
9907
|
+
const manifest = ThemeManifestSchema.parse(await jsonFile(manifestFile, "Manifesto do tema"));
|
|
9908
|
+
const packageMetadata = await jsonFile(packageFile, "package.json");
|
|
9909
|
+
const version = nextThemeVersion(manifest.version, options.release);
|
|
9910
|
+
manifest.version = version;
|
|
9911
|
+
packageMetadata.version = version;
|
|
9912
|
+
let lockMetadata = null;
|
|
9913
|
+
try {
|
|
9914
|
+
lockMetadata = await jsonFile(lockFile, "package-lock.json");
|
|
9915
|
+
lockMetadata.version = version;
|
|
9916
|
+
if (lockMetadata.packages?.[""]) lockMetadata.packages[""].version = version;
|
|
9917
|
+
} catch (error) {
|
|
9918
|
+
if (error.cause && error.cause.code !== "ENOENT") throw error;
|
|
9919
|
+
}
|
|
9920
|
+
await Promise.all([
|
|
9921
|
+
writeJson(manifestFile, manifest),
|
|
9922
|
+
writeJson(packageFile, packageMetadata),
|
|
9923
|
+
...lockMetadata ? [writeJson(lockFile, lockMetadata)] : []
|
|
9924
|
+
]);
|
|
9925
|
+
console.log(`✓ Versão do tema: ${manifest.id}@${version}`);
|
|
9926
|
+
return version;
|
|
9927
|
+
}
|
|
9928
|
+
async function themeUpgrade(options) {
|
|
9929
|
+
const directory = path.resolve(options.themeDirectory);
|
|
9930
|
+
const manifestFile = path.join(directory, "nuvler.theme.json");
|
|
9931
|
+
const packageFile = path.join(directory, "package.json");
|
|
9932
|
+
const sdkTarget = options.sdk?.trim() || "latest";
|
|
9933
|
+
const cliTarget = options.cli?.trim() || "latest";
|
|
9934
|
+
const install = options.installDependencies !== false;
|
|
9935
|
+
const manifest = ThemeManifestSchema.parse(await jsonFile(manifestFile, "Manifesto do tema"));
|
|
9936
|
+
await jsonFile(packageFile, "package.json");
|
|
9937
|
+
if (!install && (sdkTarget === "latest" || cliTarget === "latest")) throw new Error("Com --skip-install, informe versões exatas em --sdk e --cli.");
|
|
9938
|
+
if (sdkTarget !== "latest") exactVersion(sdkTarget, "A versão do SDK");
|
|
9939
|
+
if (cliTarget !== "latest") exactVersion(cliTarget, "A versão do CLI");
|
|
9940
|
+
if (install) {
|
|
9941
|
+
await npmInstall(directory, `@nuvler/theme-sdk@${sdkTarget}`, false);
|
|
9942
|
+
await npmInstall(directory, `@nuvler/cli@${cliTarget}`, true);
|
|
9943
|
+
}
|
|
9944
|
+
const installedPackage = await jsonFile(packageFile, "package.json");
|
|
9945
|
+
const sdkVersion = install ? dependencyVersion(installedPackage.dependencies?.["@nuvler/theme-sdk"], "@nuvler/theme-sdk") : exactVersion(sdkTarget, "A versão do SDK");
|
|
9946
|
+
const cliVersion = install ? dependencyVersion(installedPackage.devDependencies?.["@nuvler/cli"], "@nuvler/cli") : exactVersion(cliTarget, "A versão do CLI");
|
|
9947
|
+
const sdkRange = `^${sdkVersion}`;
|
|
9948
|
+
const cliRange = `^${cliVersion}`;
|
|
9949
|
+
const updatedPackage = installedPackage;
|
|
9950
|
+
updatedPackage.dependencies = {
|
|
9951
|
+
...updatedPackage.dependencies,
|
|
9952
|
+
"@nuvler/theme-sdk": sdkRange
|
|
9953
|
+
};
|
|
9954
|
+
updatedPackage.devDependencies = {
|
|
9955
|
+
...updatedPackage.devDependencies,
|
|
9956
|
+
"@nuvler/cli": cliRange
|
|
9957
|
+
};
|
|
9958
|
+
manifest.sdkVersion = sdkRange;
|
|
9959
|
+
await Promise.all([writeJson(manifestFile, manifest), writeJson(packageFile, updatedPackage)]);
|
|
9960
|
+
let version = manifest.version;
|
|
9961
|
+
if (options.bump) version = await themeVersion({
|
|
9962
|
+
themeDirectory: directory,
|
|
9963
|
+
release: options.bump
|
|
9964
|
+
});
|
|
9965
|
+
console.log("");
|
|
9966
|
+
console.log(`✓ Theme SDK atualizado: ${sdkRange}`);
|
|
9967
|
+
console.log(`✓ CLI local atualizado: ${cliRange}`);
|
|
9968
|
+
console.log("✓ package.json e nuvler.theme.json sincronizados");
|
|
9969
|
+
if (!install) console.log("⚠ Instalação ignorada; regenere o lockfile com npm install.");
|
|
9970
|
+
console.log("");
|
|
9971
|
+
return {
|
|
9972
|
+
sdkVersion,
|
|
9973
|
+
cliVersion,
|
|
9974
|
+
themeVersion: version
|
|
9975
|
+
};
|
|
9976
|
+
}
|
|
9977
|
+
//#endregion
|
|
9599
9978
|
//#region src/commands/auth.ts
|
|
9600
9979
|
async function authLogin(options) {
|
|
9601
9980
|
const apiUrl = options.apiUrl?.trim() || process.env.NUVLER_API_URL?.trim();
|
|
@@ -9624,7 +10003,7 @@ async function authLogout() {
|
|
|
9624
10003
|
//#endregion
|
|
9625
10004
|
//#region src/index.ts
|
|
9626
10005
|
var program = new Command();
|
|
9627
|
-
program.name("nuvler").description("Nuvler Theme Development CLI").version("0.4.
|
|
10006
|
+
program.name("nuvler").description("Nuvler Theme Development CLI").version("0.4.4");
|
|
9628
10007
|
var theme = program.command("theme").description("Manage Nuvler themes");
|
|
9629
10008
|
var auth = program.command("auth").description("Manage developer authentication");
|
|
9630
10009
|
auth.command("login").requiredOption("--token <token>", "Developer token").option("--api-url <url>", "Nuvler API base URL (or use NUVLER_API_URL)").action(async (options) => {
|
|
@@ -9687,6 +10066,31 @@ theme.command("templates").description("List the templates available for theme c
|
|
|
9687
10066
|
for (const template of THEME_TEMPLATES) console.log(` ${template.id.padEnd(16)} ${template.description}`);
|
|
9688
10067
|
console.log("");
|
|
9689
10068
|
});
|
|
10069
|
+
theme.command("upgrade").description("Update the local Theme SDK and CLI and synchronize the manifest").option("--theme <directory>", "Theme directory", ".").option("--sdk <version>", "Theme SDK version or latest", "latest").option("--cli <version>", "Local CLI version or latest", "latest").option("--bump <release>", "Also bump theme version: patch, minor, major or exact").option("--skip-install", "Only update metadata; requires exact --sdk and --cli versions").action(async (options) => {
|
|
10070
|
+
try {
|
|
10071
|
+
await themeUpgrade({
|
|
10072
|
+
themeDirectory: options.theme,
|
|
10073
|
+
sdk: options.sdk,
|
|
10074
|
+
cli: options.cli,
|
|
10075
|
+
bump: options.bump,
|
|
10076
|
+
installDependencies: !options.skipInstall
|
|
10077
|
+
});
|
|
10078
|
+
} catch (error) {
|
|
10079
|
+
console.error(`Erro: ${error instanceof Error ? error.message : "Erro desconhecido."}`);
|
|
10080
|
+
process.exitCode = 1;
|
|
10081
|
+
}
|
|
10082
|
+
});
|
|
10083
|
+
theme.command("version").description("Bump and synchronize the published theme version").argument("<release>", "patch, minor, major or an exact SemVer version").option("--theme <directory>", "Theme directory", ".").action(async (release, options) => {
|
|
10084
|
+
try {
|
|
10085
|
+
await themeVersion({
|
|
10086
|
+
themeDirectory: options.theme,
|
|
10087
|
+
release
|
|
10088
|
+
});
|
|
10089
|
+
} catch (error) {
|
|
10090
|
+
console.error(`Erro: ${error instanceof Error ? error.message : "Erro desconhecido."}`);
|
|
10091
|
+
process.exitCode = 1;
|
|
10092
|
+
}
|
|
10093
|
+
});
|
|
9690
10094
|
theme.command("configure").description("Configure this theme project for an authorized tenant").option("--theme <directory>", "Theme directory", ".").option("--tenant <slug-or-id>", "Authorized tenant slug or ID").option("--key <connection-key>", "Nuvler connection key from the tenant panel").action(async (options) => {
|
|
9691
10095
|
try {
|
|
9692
10096
|
await themeConfigure({
|