@nuvler/cli 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +25 -2
  2. package/dist/commands/theme/create.js +2 -2
  3. package/dist/commands/theme/validate.js +21 -0
  4. package/dist/commands/theme/validate.js.map +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/migrate/generator.js +49 -8
  7. package/dist/migrate/generator.js.map +1 -1
  8. package/dist/migrate/transformer.js +20 -4
  9. package/dist/migrate/transformer.js.map +1 -1
  10. package/dist/nuvler.js +279 -47
  11. package/dist/nuvler.js.map +1 -1
  12. package/dist/templates/nuvler-atelier/nuvler.theme.json +10 -3
  13. package/dist/templates/nuvler-atelier/package.json +3 -3
  14. package/dist/templates/nuvler-atelier/src/definition.tsx +11 -1
  15. package/dist/templates/nuvler-atelier/src/theme.css +26 -26
  16. package/dist/templates/nuvler-atelier/src/theme.tsx +12 -1
  17. package/dist/templates/nuvler-default/README.md +50 -4
  18. package/dist/templates/nuvler-default/nuvler.theme.json +10 -3
  19. package/dist/templates/nuvler-default/package.json +36 -4
  20. package/dist/templates/nuvler-default/src/banner-carousel.tsx +42 -12
  21. package/dist/templates/nuvler-default/src/carousel-frame.tsx +58 -0
  22. package/dist/templates/nuvler-default/src/definition.ts +9 -48
  23. package/dist/templates/nuvler-default/src/footer.tsx +7 -2
  24. package/dist/templates/nuvler-default/src/header-interactions.tsx +1 -1
  25. package/dist/templates/nuvler-default/src/header.tsx +3 -3
  26. package/dist/templates/nuvler-default/src/home.tsx +41 -17
  27. package/dist/templates/nuvler-default/src/index.ts +1 -0
  28. package/dist/templates/nuvler-default/src/product-carousel.tsx +13 -7
  29. package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +230 -0
  30. package/dist/templates/nuvler-default/src/product-detail.tsx +80 -55
  31. package/dist/templates/nuvler-default/src/products.tsx +6 -5
  32. package/dist/templates/nuvler-default/src/server-shell.tsx +88 -0
  33. package/dist/templates/nuvler-default/src/shared.tsx +25 -9
  34. package/dist/templates/nuvler-default/src/theme-component.tsx +11 -0
  35. package/dist/templates/nuvler-default/src/theme-config.ts +63 -0
  36. package/dist/templates/nuvler-default/src/theme.css +48 -17
  37. package/dist/templates/starter/nuvler.theme.json +9 -2
  38. package/dist/templates/starter/package.json +2 -2
  39. package/dist/templates/starter/src/definition.tsx +8 -1
  40. package/dist/templates/starter/src/theme.css +10 -10
  41. package/dist/templates/starter/src/theme.tsx +11 -0
  42. package/dist/theme/performance.js +126 -0
  43. package/dist/theme/performance.js.map +1 -0
  44. package/package.json +3 -3
  45. package/preview-host/index.html +1 -0
  46. package/preview-host/package.json +1 -1
  47. package/preview-host/public/nuvler-icon.ico +0 -0
  48. package/preview-host/public/nuvler-logo-white.png +0 -0
  49. package/preview-host/src/app/globals.css +28 -0
  50. package/preview-host/src/main.tsx +11 -1
  51. package/preview-host/vendor/theme-runtime/default-theme.tsx +24 -2
package/dist/nuvler.js CHANGED
@@ -14,6 +14,7 @@ import os, { tmpdir } from "node:os";
14
14
  import { spawn } from "node:child_process";
15
15
  import { create } from "tar";
16
16
  import ts from "typescript";
17
+ import { gzipSync } from "node:zlib";
17
18
  //#region \0rolldown/runtime.js
18
19
  var __defProp = Object.defineProperty;
19
20
  var __exportAll = (all, no_symbols) => {
@@ -29,8 +30,8 @@ var __exportAll = (all, no_symbols) => {
29
30
  //#region src/commands/theme/create.ts
30
31
  var THEME_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
31
32
  var NEW_THEME_VERSION = "0.1.0";
32
- var CLI_VERSION_RANGE = "^0.4.0";
33
- var SDK_VERSION_RANGE = "^1.1.0";
33
+ var CLI_VERSION_RANGE = "^0.4.2";
34
+ var SDK_VERSION_RANGE = "^1.2.0";
34
35
  var THEME_TEMPLATES = [
35
36
  {
36
37
  id: "starter",
@@ -6620,15 +6621,28 @@ config(en_default());
6620
6621
  //#endregion
6621
6622
  //#region ../theme-schema/dist/index.js
6622
6623
  var relativeThemeFileSchema = string$1().trim().min(1).max(240).refine((value) => !value.startsWith("/") && !value.startsWith("\\"), { message: "Use um caminho relativo à pasta do tema" }).refine((value) => !value.split(/[\\/]+/).includes(".."), { message: "O caminho não pode sair da pasta do tema" });
6624
+ var hexColorSchema = string$1().regex(/^#[0-9a-f]{6}$/i, "Use uma cor hexadecimal no formato #RRGGBB");
6625
+ var ThemeSiteColorsSchema = object({
6626
+ primary: hexColorSchema,
6627
+ secondary: hexColorSchema,
6628
+ background: hexColorSchema,
6629
+ text: hexColorSchema,
6630
+ primaryText: hexColorSchema.optional(),
6631
+ secondaryText: hexColorSchema.optional(),
6632
+ accent: hexColorSchema.optional(),
6633
+ surface: hexColorSchema.optional(),
6634
+ surfaceAlt: hexColorSchema.optional(),
6635
+ textMuted: hexColorSchema.optional(),
6636
+ border: hexColorSchema.optional(),
6637
+ headerBackground: hexColorSchema.optional(),
6638
+ headerText: hexColorSchema.optional(),
6639
+ footerBackground: hexColorSchema.optional(),
6640
+ footerText: hexColorSchema.optional()
6641
+ }).strict();
6623
6642
  var ThemePresentationSchema = object({
6624
6643
  description: string$1().trim().min(1).max(500),
6625
6644
  templateId: string$1().trim().min(1).max(80).optional(),
6626
- colors: object({
6627
- primary: string$1().regex(/^#[0-9a-f]{6}$/i),
6628
- secondary: string$1().regex(/^#[0-9a-f]{6}$/i),
6629
- background: string$1().regex(/^#[0-9a-f]{6}$/i),
6630
- text: string$1().regex(/^#[0-9a-f]{6}$/i)
6631
- }).strict(),
6645
+ colors: ThemeSiteColorsSchema,
6632
6646
  layout: object({
6633
6647
  containerWidth: number$1().int().min(960).max(1600),
6634
6648
  borderRadius: number$1().int().min(0).max(32)
@@ -6646,7 +6660,6 @@ var ThemeManifestSchema = object({
6646
6660
  presentation: ThemePresentationSchema.optional()
6647
6661
  }).strict();
6648
6662
  var nullableStringSchema = string$1().nullable();
6649
- var hexColorSchema = string$1().regex(/^#[0-9a-f]{6}$/i, "Use uma cor hexadecimal no formato #RRGGBB");
6650
6663
  var ThemeImageSchema = object({
6651
6664
  url: nullableStringSchema,
6652
6665
  alt: nullableStringSchema,
@@ -6695,12 +6708,7 @@ var ThemeSiteSchema = object({
6695
6708
  }).strict().optional(),
6696
6709
  theme: object({
6697
6710
  id: string$1().trim().min(1).optional(),
6698
- colors: object({
6699
- primary: hexColorSchema,
6700
- secondary: hexColorSchema,
6701
- background: hexColorSchema,
6702
- text: hexColorSchema
6703
- }).strict(),
6711
+ colors: ThemeSiteColorsSchema,
6704
6712
  layout: object({
6705
6713
  containerWidth: number$1().int().min(960).max(1600),
6706
6714
  borderRadius: number$1().int().min(0).max(32)
@@ -7894,7 +7902,7 @@ async function themePublish(options) {
7894
7902
  }
7895
7903
  //#endregion
7896
7904
  //#region src/migrate/analyzer.ts
7897
- var IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
7905
+ var IGNORED_DIRECTORIES$1 = /* @__PURE__ */ new Set([
7898
7906
  ".git",
7899
7907
  ".next",
7900
7908
  ".nuxt",
@@ -7947,7 +7955,7 @@ async function walk(directory) {
7947
7955
  const entries = await readdir(current, { withFileTypes: true });
7948
7956
  for (const entry of entries) {
7949
7957
  if (entry.isSymbolicLink()) continue;
7950
- if (entry.isDirectory() && IGNORED_DIRECTORIES.has(entry.name)) continue;
7958
+ if (entry.isDirectory() && IGNORED_DIRECTORIES$1.has(entry.name)) continue;
7951
7959
  const absolute = path.join(current, entry.name);
7952
7960
  if (entry.isDirectory()) await visit(absolute);
7953
7961
  else if (entry.isFile()) files.push(absolute);
@@ -8765,9 +8773,20 @@ export const themeDefinition = defineTheme({
8765
8773
  tokens: {
8766
8774
  colors: ${JSON.stringify({
8767
8775
  primary: tokens.primary,
8776
+ primaryText: tokens.primaryText,
8768
8777
  secondary: tokens.secondary,
8778
+ secondaryText: tokens.secondaryText,
8779
+ accent: tokens.accent,
8769
8780
  background: tokens.background,
8770
- text: tokens.text
8781
+ surface: tokens.surface,
8782
+ surfaceAlt: tokens.surfaceAlt,
8783
+ text: tokens.text,
8784
+ textMuted: tokens.textMuted,
8785
+ border: tokens.border,
8786
+ headerBackground: tokens.headerBackground,
8787
+ headerText: tokens.headerText,
8788
+ footerBackground: tokens.footerBackground,
8789
+ footerText: tokens.footerText
8771
8790
  })},
8772
8791
  layout: ${JSON.stringify({
8773
8792
  containerWidth: tokens.containerWidth,
@@ -8852,9 +8871,20 @@ export default function Theme({ context, route = { type: "home" }, sdk }: Nuvler
8852
8871
  };
8853
8872
  const style = {
8854
8873
  "--theme-primary": tokens.colors.primary,
8874
+ "--theme-primary-text": tokens.colors.primaryText,
8855
8875
  "--theme-secondary": tokens.colors.secondary,
8876
+ "--theme-secondary-text": tokens.colors.secondaryText,
8877
+ "--theme-accent": tokens.colors.accent,
8856
8878
  "--theme-background": tokens.colors.background,
8879
+ "--theme-surface": tokens.colors.surface,
8880
+ "--theme-surface-alt": tokens.colors.surfaceAlt,
8857
8881
  "--theme-text": tokens.colors.text,
8882
+ "--theme-text-muted": tokens.colors.textMuted,
8883
+ "--theme-border": tokens.colors.border,
8884
+ "--theme-header-background": tokens.colors.headerBackground,
8885
+ "--theme-header-text": tokens.colors.headerText,
8886
+ "--theme-footer-background": tokens.colors.footerBackground,
8887
+ "--theme-footer-text": tokens.colors.footerText,
8858
8888
  "--theme-radius": \`\${tokens.layout.borderRadius}px\`,
8859
8889
  "--theme-container": \`\${tokens.layout.containerWidth}px\`,
8860
8890
  } as CSSProperties;
@@ -8874,13 +8904,14 @@ function baseCss(plan) {
8874
8904
  body { margin: 0; }
8875
8905
  .nuvler-migrated-theme { min-height: 100vh; background: var(--theme-background); color: var(--theme-text); font-family: Inter, system-ui, sans-serif; }
8876
8906
  .nuvler-migrated-header-inner, .nuvler-migrated-footer-inner, .nuvler-migrated-section, .nuvler-migrated-hero { width: min(calc(100% - 32px), var(--theme-container)); margin-inline: auto; }
8907
+ .nuvler-migrated-header { background: var(--theme-header-background); color: var(--theme-header-text); }
8877
8908
  .nuvler-migrated-header-inner { min-height: 72px; display: flex; align-items: center; gap: 24px; justify-content: space-between; }
8878
8909
  .nuvler-migrated-brand img { display: block; width: auto; max-width: 200px; max-height: 56px; }
8879
8910
  .nuvler-migrated-nav { display: flex; flex-wrap: wrap; gap: 18px; }
8880
8911
  .nuvler-migrated-nav a, .nuvler-migrated-brand, .nuvler-migrated-footer a { color: inherit; text-decoration: none; }
8881
8912
  .nuvler-migrated-search { display: flex; gap: 8px; }
8882
- .nuvler-migrated-search input { min-width: 220px; border: 1px solid color-mix(in srgb, var(--theme-text), transparent 78%); border-radius: var(--theme-radius); padding: 10px 13px; }
8883
- .nuvler-migrated-action { display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: var(--theme-radius); background: var(--theme-primary); color: #fff; padding: 12px 18px; text-decoration: none; cursor: pointer; }
8913
+ .nuvler-migrated-search input { min-width: 220px; border: 1px solid var(--theme-border); border-radius: var(--theme-radius); background: var(--theme-surface); color: var(--theme-header-text); padding: 10px 13px; }
8914
+ .nuvler-migrated-action { display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: var(--theme-radius); background: var(--theme-primary); color: var(--theme-primary-text); padding: 12px 18px; text-decoration: none; cursor: pointer; }
8884
8915
  .nuvler-migrated-hero { display: grid; min-height: 520px; grid-template-columns: minmax(0, 1fr) minmax(320px, .9fr); align-items: center; gap: 40px; padding-block: 64px; }
8885
8916
  .nuvler-migrated-hero-title { margin: 12px 0; font-size: clamp(42px, 7vw, 82px); line-height: .98; }
8886
8917
  .nuvler-migrated-hero-media, .nuvler-migrated-product-media, .nuvler-migrated-detail-media { overflow: hidden; border-radius: var(--theme-radius); }
@@ -8888,22 +8919,33 @@ body { margin: 0; }
8888
8919
  .nuvler-migrated-section { padding-block: 56px; }
8889
8920
  .nuvler-migrated-product-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
8890
8921
  .nuvler-migrated-product-grid[data-columns="4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
8891
- .nuvler-migrated-product-card { overflow: hidden; border: 1px solid color-mix(in srgb, var(--theme-text), transparent 85%); border-radius: var(--theme-radius); background: #fff; }
8892
- .nuvler-migrated-product-media { display: block; aspect-ratio: 1; }
8922
+ .nuvler-migrated-product-card { overflow: hidden; border: 1px solid var(--theme-border); border-radius: var(--theme-radius); background: var(--theme-surface); }
8923
+ .nuvler-migrated-product-media { display: block; aspect-ratio: 1; background: var(--theme-surface-alt); }
8893
8924
  .nuvler-migrated-product-content { display: grid; gap: 12px; padding: 20px; }
8894
- .nuvler-migrated-product-content p { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
8925
+ .nuvler-migrated-product-content p { overflow: hidden; display: -webkit-box; color: var(--theme-text-muted); -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
8895
8926
  .nuvler-migrated-product-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, .8fr); gap: 48px; }
8896
- .nuvler-migrated-price { display: block; margin-block: 18px; font-size: 28px; }
8897
- .nuvler-migrated-footer { margin-top: 64px; background: var(--theme-text); color: var(--theme-background); padding: 56px max(16px, calc((100% - var(--theme-container)) / 2)); }
8927
+ .nuvler-migrated-price { display: block; margin-block: 18px; color: var(--theme-accent); font-size: 28px; }
8928
+ .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)); }
8898
8929
  .nuvler-migrated-footer-inner { width: 100%; display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 40px; }
8899
8930
  .nuvler-migrated-footer-nav, .nuvler-migrated-contact { display: grid; gap: 8px; }
8900
8931
  @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; } }
8901
8932
 
8902
8933
  :root {
8903
8934
  --theme-primary: ${plan.tokens.primary};
8935
+ --theme-primary-text: ${plan.tokens.primaryText};
8904
8936
  --theme-secondary: ${plan.tokens.secondary};
8937
+ --theme-secondary-text: ${plan.tokens.secondaryText};
8938
+ --theme-accent: ${plan.tokens.accent};
8905
8939
  --theme-background: ${plan.tokens.background};
8940
+ --theme-surface: ${plan.tokens.surface};
8941
+ --theme-surface-alt: ${plan.tokens.surfaceAlt};
8906
8942
  --theme-text: ${plan.tokens.text};
8943
+ --theme-text-muted: ${plan.tokens.textMuted};
8944
+ --theme-border: ${plan.tokens.border};
8945
+ --theme-header-background: ${plan.tokens.headerBackground};
8946
+ --theme-header-text: ${plan.tokens.headerText};
8947
+ --theme-footer-background: ${plan.tokens.footerBackground};
8948
+ --theme-footer-text: ${plan.tokens.footerText};
8907
8949
  --theme-radius: ${plan.tokens.borderRadius}px;
8908
8950
  --theme-container: ${plan.tokens.containerWidth}px;
8909
8951
  }
@@ -8997,9 +9039,20 @@ async function generateMigratedTheme(plan, directory) {
8997
9039
  templateId: "starter",
8998
9040
  colors: {
8999
9041
  primary: plan.tokens.primary,
9042
+ primaryText: plan.tokens.primaryText,
9000
9043
  secondary: plan.tokens.secondary,
9044
+ secondaryText: plan.tokens.secondaryText,
9045
+ accent: plan.tokens.accent,
9001
9046
  background: plan.tokens.background,
9002
- text: plan.tokens.text
9047
+ surface: plan.tokens.surface,
9048
+ surfaceAlt: plan.tokens.surfaceAlt,
9049
+ text: plan.tokens.text,
9050
+ textMuted: plan.tokens.textMuted,
9051
+ border: plan.tokens.border,
9052
+ headerBackground: plan.tokens.headerBackground,
9053
+ headerText: plan.tokens.headerText,
9054
+ footerBackground: plan.tokens.footerBackground,
9055
+ footerText: plan.tokens.footerText
9003
9056
  },
9004
9057
  layout: {
9005
9058
  containerWidth: plan.tokens.containerWidth,
@@ -9155,27 +9208,55 @@ function inferredTokens(analysis) {
9155
9208
  ].includes(color));
9156
9209
  const widths = [...css.matchAll(/max-width\s*:\s*(\d{3,4})px/gi)].map((match) => Number(match[1])).filter((value) => value >= 960 && value <= 1600);
9157
9210
  const radii = [...css.matchAll(/border-radius\s*:\s*(\d{1,2})px/gi)].map((match) => Number(match[1])).filter((value) => value >= 0 && value <= 32);
9211
+ const primary = customProperty(css, [
9212
+ "primary",
9213
+ "brand",
9214
+ "principal"
9215
+ ]) ?? nonNeutral[0] ?? "#1d4ed8";
9216
+ const secondary = customProperty(css, ["secondary", "destaque"]) ?? nonNeutral[1] ?? "#f59e0b";
9217
+ const background = customProperty(css, [
9218
+ "background",
9219
+ "fundo",
9220
+ "bg"
9221
+ ]) ?? "#f8fafc";
9222
+ const text = customProperty(css, [
9223
+ "foreground",
9224
+ "text",
9225
+ "texto"
9226
+ ]) ?? "#0f172a";
9227
+ const surface = customProperty(css, [
9228
+ "surface",
9229
+ "card",
9230
+ "panel"
9231
+ ]) ?? "#ffffff";
9158
9232
  return {
9159
- primary: customProperty(css, [
9160
- "primary",
9161
- "brand",
9162
- "principal"
9163
- ]) ?? nonNeutral[0] ?? "#1d4ed8",
9164
- secondary: customProperty(css, [
9165
- "secondary",
9166
- "accent",
9167
- "destaque"
9168
- ]) ?? nonNeutral[1] ?? "#f59e0b",
9169
- background: customProperty(css, [
9170
- "background",
9171
- "fundo",
9172
- "bg"
9173
- ]) ?? "#f8fafc",
9174
- text: customProperty(css, [
9175
- "foreground",
9176
- "text",
9177
- "texto"
9178
- ]) ?? "#0f172a",
9233
+ primary,
9234
+ primaryText: customProperty(css, ["on-primary", "primary-text"]) ?? "#ffffff",
9235
+ secondary,
9236
+ secondaryText: customProperty(css, ["on-secondary", "secondary-text"]) ?? text,
9237
+ accent: customProperty(css, ["accent", "destaque"]) ?? secondary,
9238
+ background,
9239
+ surface,
9240
+ surfaceAlt: customProperty(css, [
9241
+ "surface-alt",
9242
+ "surface-muted",
9243
+ "subtle"
9244
+ ]) ?? background,
9245
+ text,
9246
+ textMuted: customProperty(css, [
9247
+ "muted",
9248
+ "text-secondary",
9249
+ "subtle-text"
9250
+ ]) ?? "#64748b",
9251
+ border: customProperty(css, [
9252
+ "border",
9253
+ "line",
9254
+ "divider"
9255
+ ]) ?? "#e2e8f0",
9256
+ headerBackground: customProperty(css, ["header-background", "header-bg"]) ?? surface,
9257
+ headerText: customProperty(css, ["header-text", "header-foreground"]) ?? text,
9258
+ footerBackground: customProperty(css, ["footer-background", "footer-bg"]) ?? text,
9259
+ footerText: customProperty(css, ["footer-text", "footer-foreground"]) ?? background,
9179
9260
  containerWidth: widths[0] ?? 1200,
9180
9261
  borderRadius: radii[0] ?? 16
9181
9262
  };
@@ -9350,9 +9431,142 @@ async function themeMigrate(options) {
9350
9431
  }
9351
9432
  }
9352
9433
  //#endregion
9434
+ //#region src/theme/performance.ts
9435
+ var SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
9436
+ ".js",
9437
+ ".jsx",
9438
+ ".mjs",
9439
+ ".cjs",
9440
+ ".ts",
9441
+ ".tsx"
9442
+ ]);
9443
+ var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([
9444
+ ".avif",
9445
+ ".gif",
9446
+ ".jpeg",
9447
+ ".jpg",
9448
+ ".png",
9449
+ ".svg",
9450
+ ".webp"
9451
+ ]);
9452
+ var FONT_EXTENSIONS = /* @__PURE__ */ new Set([
9453
+ ".eot",
9454
+ ".otf",
9455
+ ".ttf",
9456
+ ".woff",
9457
+ ".woff2"
9458
+ ]);
9459
+ var IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
9460
+ ".git",
9461
+ ".nuvler",
9462
+ ".next",
9463
+ ".vite",
9464
+ "artifacts",
9465
+ "dist",
9466
+ "node_modules"
9467
+ ]);
9468
+ var DEFAULT_THEME_PERFORMANCE_BUDGET = {
9469
+ cssGzipBytes: 51200,
9470
+ clientJavaScriptGzipBytes: 122880,
9471
+ imageTotalBytes: 5242880,
9472
+ imageMaxBytes: 524288,
9473
+ fontTotalBytes: 409600,
9474
+ fontFiles: 4,
9475
+ clientComponents: 8
9476
+ };
9477
+ async function listProjectFiles(directory) {
9478
+ const files = [];
9479
+ async function visit(currentDirectory) {
9480
+ const entries = await readdir(currentDirectory, { withFileTypes: true });
9481
+ await Promise.all(entries.map(async (entry) => {
9482
+ if (entry.isSymbolicLink()) return;
9483
+ const absolutePath = path.join(currentDirectory, entry.name);
9484
+ if (entry.isDirectory()) {
9485
+ if (!IGNORED_DIRECTORIES.has(entry.name)) await visit(absolutePath);
9486
+ return;
9487
+ }
9488
+ if (entry.isFile()) files.push(absolutePath);
9489
+ }));
9490
+ }
9491
+ await visit(directory);
9492
+ return files.sort();
9493
+ }
9494
+ function hasUseClientDirective(source, filePath) {
9495
+ const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, false, filePath.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
9496
+ for (const statement of sourceFile.statements) {
9497
+ if (ts.isExpressionStatement(statement) && ts.isStringLiteral(statement.expression)) {
9498
+ if (statement.expression.text === "use client") return true;
9499
+ continue;
9500
+ }
9501
+ break;
9502
+ }
9503
+ return false;
9504
+ }
9505
+ async function totalSize(files) {
9506
+ return (await Promise.all(files.map(async (file) => (await stat(file)).size))).reduce((total, size) => total + size, 0);
9507
+ }
9508
+ async function gzipFiles(files) {
9509
+ if (!files.length) return 0;
9510
+ const contents = await Promise.all(files.map((file) => readFile(file)));
9511
+ return gzipSync(Buffer.concat(contents), { level: 9 }).byteLength;
9512
+ }
9513
+ function metric(key, label, value, unit, available = true, detail) {
9514
+ return {
9515
+ key,
9516
+ label,
9517
+ value,
9518
+ limit: DEFAULT_THEME_PERFORMANCE_BUDGET[key],
9519
+ unit,
9520
+ available,
9521
+ detail
9522
+ };
9523
+ }
9524
+ async function analyzeThemePerformance(project) {
9525
+ const projectFiles = await listProjectFiles(project.directory);
9526
+ const css = projectFiles.filter((file) => path.extname(file).toLowerCase() === ".css");
9527
+ const images = projectFiles.filter((file) => IMAGE_EXTENSIONS.has(path.extname(file).toLowerCase()));
9528
+ const fonts = projectFiles.filter((file) => FONT_EXTENSIONS.has(path.extname(file).toLowerCase()));
9529
+ const sourceFiles = projectFiles.filter((file) => SOURCE_EXTENSIONS.has(path.extname(file).toLowerCase()));
9530
+ const clientComponents = (await Promise.all(sourceFiles.map(async (file) => ({
9531
+ file,
9532
+ client: hasUseClientDirective(await readFile(file, "utf8"), file)
9533
+ })))).filter(({ client }) => client).map(({ file }) => file);
9534
+ const imageSizes = await Promise.all(images.map(async (file) => (await stat(file)).size));
9535
+ const clientBundle = path.join(project.directory, "dist", "theme.js");
9536
+ const hasClientBundle = await stat(clientBundle).then((details) => details.isFile()).catch(() => false);
9537
+ const clientJavaScriptGzipBytes = hasClientBundle ? gzipSync(await readFile(clientBundle), { level: 9 }).byteLength : 0;
9538
+ const metrics = [
9539
+ metric("cssGzipBytes", "CSS gzip", await gzipFiles(css), "bytes", true, `${css.length} arquivo(s)`),
9540
+ metric("clientJavaScriptGzipBytes", "JS client gzip", clientJavaScriptGzipBytes, "bytes", hasClientBundle, hasClientBundle ? "dist/theme.js" : "execute nuvler theme build para medir"),
9541
+ metric("imageTotalBytes", "Imagens (total)", imageSizes.reduce((total, size) => total + size, 0), "bytes", true, `${images.length} arquivo(s)`),
9542
+ metric("imageMaxBytes", "Maior imagem", Math.max(0, ...imageSizes), "bytes"),
9543
+ metric("fontTotalBytes", "Fontes (total)", await totalSize(fonts), "bytes", true, `${fonts.length} arquivo(s)`),
9544
+ metric("fontFiles", "Arquivos de fonte", fonts.length, "count"),
9545
+ metric("clientComponents", "Client Components", clientComponents.length, "count")
9546
+ ];
9547
+ return {
9548
+ metrics,
9549
+ files: {
9550
+ css: css.map((file) => path.relative(project.directory, file)),
9551
+ images: images.map((file) => path.relative(project.directory, file)),
9552
+ fonts: fonts.map((file) => path.relative(project.directory, file)),
9553
+ clientComponents: clientComponents.map((file) => path.relative(project.directory, file)),
9554
+ clientBundle: hasClientBundle ? path.relative(project.directory, clientBundle) : void 0
9555
+ },
9556
+ warnings: metrics.filter(({ available, value, limit }) => available && value > limit)
9557
+ };
9558
+ }
9559
+ function formatPerformanceValue(metric) {
9560
+ if (metric.unit === "count") return String(metric.value);
9561
+ if (metric.value < 1024) return `${metric.value} B`;
9562
+ if (metric.value < 1048576) return `${(metric.value / 1024).toFixed(1)} KiB`;
9563
+ return `${(metric.value / 1024 / 1024).toFixed(2)} MiB`;
9564
+ }
9565
+ //#endregion
9353
9566
  //#region src/commands/theme/validate.ts
9354
9567
  async function themeValidate(options) {
9355
9568
  const project = await loadThemeProject(options.themeDirectory);
9569
+ const performance = await analyzeThemePerformance(project);
9356
9570
  console.log("");
9357
9571
  console.log("✓ Manifesto válido");
9358
9572
  console.log(`✓ Tema: ${project.manifest.name} (${project.manifest.id})`);
@@ -9362,6 +9576,24 @@ async function themeValidate(options) {
9362
9576
  console.log(`✓ Entrada: ${project.manifest.entry}`);
9363
9577
  console.log(`✓ Estilos: ${project.stylePaths.length}`);
9364
9578
  console.log("");
9579
+ console.log("Performance (informativo)");
9580
+ for (const metric of performance.metrics) {
9581
+ if (!metric.available) {
9582
+ console.log(`○ ${metric.label}: não medido (${metric.detail})`);
9583
+ continue;
9584
+ }
9585
+ const marker = metric.value > metric.limit ? "⚠" : "✓";
9586
+ const details = metric.detail ? ` · ${metric.detail}` : "";
9587
+ const limit = formatPerformanceValue({
9588
+ ...metric,
9589
+ value: metric.limit
9590
+ });
9591
+ console.log(`${marker} ${metric.label}: ${formatPerformanceValue(metric)} / ${limit}${details}`);
9592
+ }
9593
+ if (performance.warnings.length) console.log(`⚠ ${performance.warnings.length} limite(s) excedido(s); publicação ainda não é bloqueada.`);
9594
+ else console.log("✓ Performance dentro do budget medido.");
9595
+ console.log("");
9596
+ return performance;
9365
9597
  }
9366
9598
  //#endregion
9367
9599
  //#region src/commands/auth.ts
@@ -9392,7 +9624,7 @@ async function authLogout() {
9392
9624
  //#endregion
9393
9625
  //#region src/index.ts
9394
9626
  var program = new Command();
9395
- program.name("nuvler").description("Nuvler Theme Development CLI").version("0.4.0");
9627
+ program.name("nuvler").description("Nuvler Theme Development CLI").version("0.4.2");
9396
9628
  var theme = program.command("theme").description("Manage Nuvler themes");
9397
9629
  var auth = program.command("auth").description("Manage developer authentication");
9398
9630
  auth.command("login").requiredOption("--token <token>", "Developer token").option("--api-url <url>", "Nuvler API base URL (or use NUVLER_API_URL)").action(async (options) => {