@nuvler/cli 0.4.4 → 0.4.5
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 +2 -2
- package/dist/commands/theme/create.js +1 -1
- package/dist/index.js +1 -1
- package/dist/migrate/analyzer.js +6 -5
- package/dist/migrate/analyzer.js.map +1 -1
- package/dist/migrate/classifier.js +4 -0
- package/dist/migrate/classifier.js.map +1 -1
- package/dist/migrate/generator.js +9 -3
- package/dist/migrate/generator.js.map +1 -1
- package/dist/migrate/transformer.js +25 -10
- package/dist/migrate/transformer.js.map +1 -1
- package/dist/nuvler.js +40 -18
- package/dist/nuvler.js.map +1 -1
- package/dist/templates/nuvler-atelier/package.json +1 -1
- package/dist/templates/starter/package.json +1 -1
- package/package.json +1 -1
package/dist/nuvler.js
CHANGED
|
@@ -30,7 +30,7 @@ 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.
|
|
33
|
+
var CLI_VERSION_RANGE = "^0.4.5";
|
|
34
34
|
var SDK_VERSION_RANGE = "^1.2.2";
|
|
35
35
|
var THEME_TEMPLATES = [
|
|
36
36
|
{
|
|
@@ -8202,15 +8202,16 @@ function importsOf(source) {
|
|
|
8202
8202
|
}
|
|
8203
8203
|
function businessSignals(source, imports) {
|
|
8204
8204
|
const signals = /* @__PURE__ */ new Set();
|
|
8205
|
+
const moduleBoundary = (module, term) => new RegExp(`(?:^|[/@._-])${term}(?:$|[/._-])`).test(module);
|
|
8205
8206
|
for (const item of imports) {
|
|
8206
8207
|
const module = item.module.toLowerCase();
|
|
8207
8208
|
if (module.includes("axios")) signals.add("Axios/API externa");
|
|
8208
8209
|
if (module.includes("react-router")) signals.add("React Router");
|
|
8209
8210
|
if (module.includes("redux")) signals.add("Redux/store própria");
|
|
8210
8211
|
if (module.includes("zustand")) signals.add("Zustand/store própria");
|
|
8211
|
-
if (module
|
|
8212
|
-
if (module
|
|
8213
|
-
if (module
|
|
8212
|
+
if (moduleBoundary(module, "auth") || moduleBoundary(module, "authentication")) signals.add("autenticação");
|
|
8213
|
+
if (moduleBoundary(module, "checkout")) signals.add("checkout próprio");
|
|
8214
|
+
if (moduleBoundary(module, "cart") || moduleBoundary(module, "carrinho")) signals.add("carrinho próprio");
|
|
8214
8215
|
}
|
|
8215
8216
|
function visit(node) {
|
|
8216
8217
|
if (ts.isCallExpression(node)) {
|
|
@@ -8218,8 +8219,8 @@ function businessSignals(source, imports) {
|
|
|
8218
8219
|
if (name === "fetch" || name.endsWith(".fetch")) signals.add("fetch/API externa");
|
|
8219
8220
|
if (name.includes("useselector") || name.includes("usedispatch")) signals.add("Redux/store própria");
|
|
8220
8221
|
if (name.includes("usestore")) signals.add("store própria");
|
|
8221
|
-
if (
|
|
8222
|
-
if (
|
|
8222
|
+
if (/(?:^|\.)useauth(?:entication)?(?:<|\()/.test(name)) signals.add("autenticação");
|
|
8223
|
+
if (/(?:^|\.)use(?:cart|carrinho)(?:<|\()/.test(name)) signals.add("carrinho próprio");
|
|
8223
8224
|
}
|
|
8224
8225
|
ts.forEachChild(node, visit);
|
|
8225
8226
|
}
|
|
@@ -8620,6 +8621,10 @@ function roleScore(component, rule) {
|
|
|
8620
8621
|
reasons.push("possui chamada textual de destaque");
|
|
8621
8622
|
}
|
|
8622
8623
|
}
|
|
8624
|
+
if (/(^|\/)(?:ui|primitives)\//.test(file)) {
|
|
8625
|
+
score -= 8;
|
|
8626
|
+
reasons.push("componente primitivo de UI");
|
|
8627
|
+
}
|
|
8623
8628
|
if (component.defaultExport) score += 1;
|
|
8624
8629
|
return {
|
|
8625
8630
|
role: rule.role,
|
|
@@ -9061,9 +9066,10 @@ function copiedAssetFor(style, reference, plan, copied) {
|
|
|
9061
9066
|
function preservedCss(plan, copied) {
|
|
9062
9067
|
return plan.styles.map((style) => {
|
|
9063
9068
|
let content = style.content;
|
|
9064
|
-
content = content.replace(/@import\s+(["'])(
|
|
9069
|
+
content = content.replace(/@import\s+(?:url\(\s*)?(["'])(?:https?:\/\/[^"']+)\1\s*\)?[^;]*;?/gi, "");
|
|
9070
|
+
content = content.replace(/@import\s+(?:url\(\s*)?(["'])(?!https?:)(?!tailwindcss)([^"']+)\1\s*\)?[^;\r\n]*(?:;|$)/gim, "");
|
|
9065
9071
|
content = content.replace(/@tailwind\s+(?:base|components|utilities)\s*;?/gi, "");
|
|
9066
|
-
content = content.replace(/@import\s+["']tailwindcss["']\s
|
|
9072
|
+
content = content.replace(/@import\s+(?:url\(\s*)?["']tailwindcss["']\s*\)?[^;\r\n]*(?:;|$)/gim, "");
|
|
9067
9073
|
content = content.replace(/:global\(([^)]+)\)/g, "$1");
|
|
9068
9074
|
content = content.replace(/url\(\s*(["']?)([^)'"\s]+)\1\s*\)/gi, (full, _quote, reference) => {
|
|
9069
9075
|
if (/^(?:data:|https?:|#)/i.test(reference)) return full;
|
|
@@ -9077,6 +9083,10 @@ function preservedCss(plan, copied) {
|
|
|
9077
9083
|
return `/* Origem: ${style.file}${style.module ? " (CSS Module convertido para CSS comum)" : ""} */\n${content}`;
|
|
9078
9084
|
}).join("\n\n");
|
|
9079
9085
|
}
|
|
9086
|
+
function externalCssImports(plan) {
|
|
9087
|
+
const imports = plan.styles.flatMap(({ content }) => [...content.matchAll(/@import\s+(?:url\(\s*)?(["'])(?:https?:\/\/[^"']+)\1\s*\)?[^;]*;?/gi)].map((match) => match[0].trim()));
|
|
9088
|
+
return [...new Set(imports)].join("\n");
|
|
9089
|
+
}
|
|
9080
9090
|
async function configureTailwind(plan, directory) {
|
|
9081
9091
|
if (!plan.analysis.tailwind.detected) return "";
|
|
9082
9092
|
const packageFile = path.join(directory, "package.json");
|
|
@@ -9131,7 +9141,7 @@ async function generateMigratedTheme(plan, directory) {
|
|
|
9131
9141
|
writeFile(path.join(directory, "src/pages/StatePage.tsx"), statePageSource(), "utf8"),
|
|
9132
9142
|
writeFile(path.join(directory, "src/definition.tsx"), definitionSource(plan), "utf8"),
|
|
9133
9143
|
writeFile(path.join(directory, "src/theme.tsx"), themeSource(), "utf8"),
|
|
9134
|
-
writeFile(path.join(directory, "src/styles/theme.css"), `${tailwindHeader}${baseCss(plan)}\n${preservedCss(plan, copiedAssets)}\n`, "utf8"),
|
|
9144
|
+
writeFile(path.join(directory, "src/styles/theme.css"), `${tailwindHeader}${externalCssImports(plan)}\n${baseCss(plan)}\n${preservedCss(plan, copiedAssets)}\n`, "utf8"),
|
|
9135
9145
|
writeFile(path.join(directory, "src/styles.d.ts"), "declare module \"*.css\";\ndeclare module \"*.svg\";\n", "utf8")
|
|
9136
9146
|
]);
|
|
9137
9147
|
const manifestFile = path.join(directory, "nuvler.theme.json");
|
|
@@ -9357,12 +9367,18 @@ function cssVariables(css) {
|
|
|
9357
9367
|
return variables;
|
|
9358
9368
|
}
|
|
9359
9369
|
function customProperty(css, terms, variables) {
|
|
9370
|
+
const candidates = [];
|
|
9360
9371
|
for (const match of css.matchAll(/--([\w-]+)\s*:\s*([^;}]+)/gi)) {
|
|
9361
9372
|
const name = normalized(match[1]);
|
|
9362
9373
|
const color = normalizedColor(match[2], variables);
|
|
9363
|
-
if (color
|
|
9374
|
+
if (!color) continue;
|
|
9375
|
+
const score = Math.max(...terms.map((term) => name === term ? 100 : name.startsWith(`${term}-`) || name.endsWith(`-${term}`) ? 60 : name.includes(term) ? 20 : 0));
|
|
9376
|
+
if (score) candidates.push({
|
|
9377
|
+
color,
|
|
9378
|
+
score
|
|
9379
|
+
});
|
|
9364
9380
|
}
|
|
9365
|
-
return null;
|
|
9381
|
+
return candidates.sort((left, right) => right.score - left.score)[0]?.color ?? null;
|
|
9366
9382
|
}
|
|
9367
9383
|
function frequentColors(css, literals, variables) {
|
|
9368
9384
|
const counts = /* @__PURE__ */ new Map();
|
|
@@ -9415,22 +9431,28 @@ var TAILWIND_COLORS = {
|
|
|
9415
9431
|
"purple-500": "#a855f7",
|
|
9416
9432
|
"pink-500": "#ec4899"
|
|
9417
9433
|
};
|
|
9418
|
-
function
|
|
9419
|
-
if (!component) return null;
|
|
9434
|
+
function tailwindNodeColor(analysis, nodes, prefix) {
|
|
9420
9435
|
const palette = {
|
|
9421
9436
|
...TAILWIND_COLORS,
|
|
9422
9437
|
...analysis.tailwind.colors
|
|
9423
9438
|
};
|
|
9424
|
-
for (const original of
|
|
9439
|
+
for (const original of nodes.flatMap((node) => node.classes)) {
|
|
9425
9440
|
const utility = original.split(":").at(-1) ?? original;
|
|
9426
9441
|
if (!utility.startsWith(`${prefix}-`)) continue;
|
|
9427
9442
|
const name = utility.slice(prefix.length + 1);
|
|
9428
|
-
const arbitrary = name.match(/^\[(.+)\]
|
|
9443
|
+
const arbitrary = name.match(/^\[(.+)\](?:\/.+)?$/)?.[1]?.replaceAll("_", " ");
|
|
9429
9444
|
const color = arbitrary ? normalizedColor(arbitrary) : normalizedColor(palette[name] ?? "");
|
|
9430
9445
|
if (color) return color;
|
|
9431
9446
|
}
|
|
9432
9447
|
return null;
|
|
9433
9448
|
}
|
|
9449
|
+
function tailwindColor(analysis, component, prefix) {
|
|
9450
|
+
return component ? tailwindNodeColor(analysis, component.jsx, prefix) : null;
|
|
9451
|
+
}
|
|
9452
|
+
function actionColor(analysis, component, prefix) {
|
|
9453
|
+
if (!component) return null;
|
|
9454
|
+
return tailwindNodeColor(analysis, component.jsx.filter(({ tag }) => ["a", "button"].includes(normalized(tag))), prefix);
|
|
9455
|
+
}
|
|
9434
9456
|
function contrastColor(background) {
|
|
9435
9457
|
const channels = [
|
|
9436
9458
|
background.slice(1, 3),
|
|
@@ -9453,7 +9475,7 @@ function inferredTokens(analysis, selected) {
|
|
|
9453
9475
|
const widths = [...css.matchAll(/max-width\s*:\s*(\d{3,4})px/gi)].map((match) => Number(match[1])).filter((value) => value >= 960 && value <= 1600);
|
|
9454
9476
|
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
9477
|
const component = (role) => selected[role]?.component;
|
|
9456
|
-
const primary = customProperty(css, [
|
|
9478
|
+
const primary = actionColor(analysis, component("HERO"), "bg") ?? actionColor(analysis, component("HEADER"), "bg") ?? customProperty(css, [
|
|
9457
9479
|
"primary",
|
|
9458
9480
|
"brand",
|
|
9459
9481
|
"principal"
|
|
@@ -9480,7 +9502,7 @@ function inferredTokens(analysis, selected) {
|
|
|
9480
9502
|
const footerText = customProperty(css, ["footer-text", "footer-foreground"], variables) ?? ruleColor(css, component("FOOTER"), "color", variables) ?? tailwindColor(analysis, component("FOOTER"), "text") ?? background;
|
|
9481
9503
|
return {
|
|
9482
9504
|
primary,
|
|
9483
|
-
primaryText: customProperty(css, ["on-primary", "primary-text"], variables) ?? ruleColor(css, component("PRODUCT_CARD"), "color", variables) ?? contrastColor(primary),
|
|
9505
|
+
primaryText: actionColor(analysis, component("HERO"), "text") ?? actionColor(analysis, component("HEADER"), "text") ?? customProperty(css, ["on-primary", "primary-text"], variables) ?? ruleColor(css, component("PRODUCT_CARD"), "color", variables) ?? contrastColor(primary),
|
|
9484
9506
|
secondary,
|
|
9485
9507
|
secondaryText: customProperty(css, ["on-secondary", "secondary-text"], variables) ?? contrastColor(secondary),
|
|
9486
9508
|
accent: customProperty(css, ["accent", "destaque"], variables) ?? secondary,
|
|
@@ -10003,7 +10025,7 @@ async function authLogout() {
|
|
|
10003
10025
|
//#endregion
|
|
10004
10026
|
//#region src/index.ts
|
|
10005
10027
|
var program = new Command();
|
|
10006
|
-
program.name("nuvler").description("Nuvler Theme Development CLI").version("0.4.
|
|
10028
|
+
program.name("nuvler").description("Nuvler Theme Development CLI").version("0.4.5");
|
|
10007
10029
|
var theme = program.command("theme").description("Manage Nuvler themes");
|
|
10008
10030
|
var auth = program.command("auth").description("Manage developer authentication");
|
|
10009
10031
|
auth.command("login").requiredOption("--token <token>", "Developer token").option("--api-url <url>", "Nuvler API base URL (or use NUVLER_API_URL)").action(async (options) => {
|