@nuvler/cli 0.5.14 → 0.5.16
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 +6 -0
- package/dist/api/theme-context.js +53 -21
- package/dist/api/theme-context.js.map +1 -1
- package/dist/commands/theme/build.js +11 -6
- package/dist/commands/theme/build.js.map +1 -1
- package/dist/commands/theme/validate.js +69 -26
- package/dist/commands/theme/validate.js.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/nuvler.js +170 -41
- package/dist/nuvler.js.map +1 -1
- package/dist/templates/nuvler-default/nuvler.theme.json +15 -4
- package/dist/templates/nuvler-default/package.json +2 -2
- package/dist/templates/nuvler-default/src/custom-html-content.tsx +26 -0
- package/dist/templates/nuvler-default/src/theme-component.tsx +235 -72
- package/dist/templates/nuvler-default/src/theme.css +20 -2
- package/dist/templates/nuvler-default/test/editorial-content.test.mjs +47 -0
- package/dist/theme/artifact.js +3 -2
- package/dist/theme/artifact.js.map +1 -1
- package/package.json +3 -3
- package/preview-host/src/main.tsx +14 -0
- package/preview-host/vendor/theme-runtime/default-theme.tsx +1611 -336
package/dist/nuvler.js
CHANGED
|
@@ -273,6 +273,7 @@ function createArtifactManifest(project, build) {
|
|
|
273
273
|
sdkVersion: project.manifest.sdkVersion,
|
|
274
274
|
entry: "./theme.js",
|
|
275
275
|
style: build.stylePath ? "./theme.css" : void 0,
|
|
276
|
+
capabilities: project.manifest.capabilities,
|
|
276
277
|
presentation: project.manifest.presentation
|
|
277
278
|
};
|
|
278
279
|
}
|
|
@@ -6935,6 +6936,7 @@ var ThemeManifestSchema = object({
|
|
|
6935
6936
|
sdkVersion: string$1().trim().min(1).max(80),
|
|
6936
6937
|
entry: relativeThemeFileSchema.refine((value) => /\.(?:[cm]?[jt]sx?)$/i.test(value), { message: "A entrada deve ser um arquivo JavaScript ou TypeScript" }),
|
|
6937
6938
|
styles: array(relativeThemeFileSchema.refine((value) => /\.css$/i.test(value), { message: "Os estilos do manifesto devem ser arquivos CSS" })).max(10).optional(),
|
|
6939
|
+
capabilities: object({ pageListings: literal(1).optional() }).strict().optional(),
|
|
6938
6940
|
presentation: ThemePresentationSchema.optional()
|
|
6939
6941
|
}).strict();
|
|
6940
6942
|
var nullableStringSchema = string$1().nullable();
|
|
@@ -7050,7 +7052,7 @@ var ThemeMiniBannersDataSchema = object({
|
|
|
7050
7052
|
});
|
|
7051
7053
|
});
|
|
7052
7054
|
var ThemeHomeSectionSchema = object({
|
|
7053
|
-
id: string$1().optional(),
|
|
7055
|
+
id: string$1().trim().min(1).max(100).optional(),
|
|
7054
7056
|
reference: string$1().max(80).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).optional(),
|
|
7055
7057
|
type: _enum([
|
|
7056
7058
|
"hero",
|
|
@@ -7184,14 +7186,35 @@ var ThemeNavigationHeaderButtonSchema = object({
|
|
|
7184
7186
|
openInNewTab: boolean$1()
|
|
7185
7187
|
}).strict();
|
|
7186
7188
|
var ThemeEditorialItemSchema = object({
|
|
7189
|
+
href: string$1().regex(/^\/(?!\/)[^\\]*$/).optional(),
|
|
7187
7190
|
title: string$1(),
|
|
7188
7191
|
slug: string$1(),
|
|
7189
7192
|
description: string$1(),
|
|
7193
|
+
content: union([string$1(), object({
|
|
7194
|
+
schemaVersion: literal(1),
|
|
7195
|
+
time: number$1().optional(),
|
|
7196
|
+
version: string$1().optional(),
|
|
7197
|
+
blocks: array(object({
|
|
7198
|
+
id: string$1().optional(),
|
|
7199
|
+
type: string$1(),
|
|
7200
|
+
data: record(string$1(), unknown())
|
|
7201
|
+
}).strict())
|
|
7202
|
+
}).strict()]).nullable().optional(),
|
|
7190
7203
|
image: ThemeImageSchema.nullable(),
|
|
7191
7204
|
category: object({
|
|
7192
7205
|
title: string$1(),
|
|
7193
7206
|
slug: nullableStringSchema
|
|
7194
7207
|
}).strict().nullable(),
|
|
7208
|
+
author: object({
|
|
7209
|
+
name: string$1().optional(),
|
|
7210
|
+
slug: nullableStringSchema.optional()
|
|
7211
|
+
}).strict().nullable().optional(),
|
|
7212
|
+
tags: array(object({
|
|
7213
|
+
title: string$1().optional(),
|
|
7214
|
+
name: string$1().optional(),
|
|
7215
|
+
slug: nullableStringSchema.optional()
|
|
7216
|
+
}).strict()).optional(),
|
|
7217
|
+
updatedAt: nullableStringSchema.optional(),
|
|
7195
7218
|
publishedAt: nullableStringSchema
|
|
7196
7219
|
}).strict();
|
|
7197
7220
|
var ThemeTeamMemberSchema = object({
|
|
@@ -7207,7 +7230,12 @@ var ThemeContextSchema = object({
|
|
|
7207
7230
|
pages: array(ThemeNavigationPageSchema),
|
|
7208
7231
|
categories: array(ThemeCategorySchema),
|
|
7209
7232
|
menu: array(ThemeNavigationItemSchema).optional(),
|
|
7210
|
-
headerButton: ThemeNavigationHeaderButtonSchema.nullable().optional()
|
|
7233
|
+
headerButton: ThemeNavigationHeaderButtonSchema.nullable().optional(),
|
|
7234
|
+
pageMenu: object({
|
|
7235
|
+
enabled: boolean$1(),
|
|
7236
|
+
label: string$1().trim().min(1).max(80),
|
|
7237
|
+
pageSlugs: array(string$1()).max(50).refine((values) => new Set(values).size === values.length)
|
|
7238
|
+
}).strict().nullable().optional()
|
|
7211
7239
|
}).strict(),
|
|
7212
7240
|
home: ThemeHomeSchema,
|
|
7213
7241
|
catalog: object({
|
|
@@ -7327,8 +7355,8 @@ export default runtime;
|
|
|
7327
7355
|
}
|
|
7328
7356
|
async function themeBuild(options) {
|
|
7329
7357
|
const project = await loadThemeProject(options.themeDirectory);
|
|
7330
|
-
console.log("");
|
|
7331
|
-
console.log(`Compilando ${project.manifest.name} v${project.manifest.version}...`);
|
|
7358
|
+
if (!options.quiet) console.log("");
|
|
7359
|
+
if (!options.quiet) console.log(`Compilando ${project.manifest.name} v${project.manifest.version}...`);
|
|
7332
7360
|
const temporaryEntry = path.join(project.directory, `.nuvler-build-entry-${randomUUID()}.ts`);
|
|
7333
7361
|
await writeFile(temporaryEntry, buildEntrySource(project.entryPath, project.stylePaths, `${project.manifest.id}@${project.manifest.version}`), "utf8");
|
|
7334
7362
|
const previousNodeEnv = process.env.NODE_ENV;
|
|
@@ -7339,7 +7367,7 @@ async function themeBuild(options) {
|
|
|
7339
7367
|
mode: "production",
|
|
7340
7368
|
root: project.directory,
|
|
7341
7369
|
publicDir: false,
|
|
7342
|
-
logLevel: "warn",
|
|
7370
|
+
logLevel: options.quiet ? "silent" : "warn",
|
|
7343
7371
|
build: {
|
|
7344
7372
|
outDir: path.join(project.directory, "dist"),
|
|
7345
7373
|
emptyOutDir: true,
|
|
@@ -7361,9 +7389,9 @@ async function themeBuild(options) {
|
|
|
7361
7389
|
await rm(temporaryEntry, { force: true });
|
|
7362
7390
|
}
|
|
7363
7391
|
const output = await loadThemeBuild(project);
|
|
7364
|
-
console.log(`✓ JavaScript: ${path.relative(project.directory, output.entryPath)}`);
|
|
7365
|
-
console.log(`✓ CSS: ${output.stylePath ? path.relative(project.directory, output.stylePath) : "sem stylesheet"}`);
|
|
7366
|
-
console.log("");
|
|
7392
|
+
if (!options.quiet) console.log(`✓ JavaScript: ${path.relative(project.directory, output.entryPath)}`);
|
|
7393
|
+
if (!options.quiet) console.log(`✓ CSS: ${output.stylePath ? path.relative(project.directory, output.stylePath) : "sem stylesheet"}`);
|
|
7394
|
+
if (!options.quiet) console.log("");
|
|
7367
7395
|
return output;
|
|
7368
7396
|
}
|
|
7369
7397
|
//#endregion
|
|
@@ -7809,9 +7837,20 @@ function normalizeCategory(category) {
|
|
|
7809
7837
|
function normalizeEditorial(item) {
|
|
7810
7838
|
const categoryTitle = item.category?.title || item.category?.name;
|
|
7811
7839
|
return {
|
|
7840
|
+
author: item.author ? {
|
|
7841
|
+
name: item.author.name,
|
|
7842
|
+
slug: item.author.slug ?? null
|
|
7843
|
+
} : null,
|
|
7844
|
+
tags: (item.tags ?? []).map((tag) => ({
|
|
7845
|
+
title: tag.title,
|
|
7846
|
+
name: tag.name,
|
|
7847
|
+
slug: tag.slug ?? null
|
|
7848
|
+
})),
|
|
7849
|
+
updatedAt: item.updatedAt,
|
|
7812
7850
|
title: item.title,
|
|
7813
7851
|
slug: item.slug,
|
|
7814
7852
|
description: item.description || "",
|
|
7853
|
+
...item.content !== void 0 ? { content: item.content } : {},
|
|
7815
7854
|
image: normalizeImage(item.coverImage || item.image || item.thumbnail || null),
|
|
7816
7855
|
category: categoryTitle ? {
|
|
7817
7856
|
title: categoryTitle,
|
|
@@ -7912,14 +7951,16 @@ async function loadThemeContext({ store, apiUrl }) {
|
|
|
7912
7951
|
})),
|
|
7913
7952
|
categories: categories.map(normalizeCategory),
|
|
7914
7953
|
menu,
|
|
7915
|
-
headerButton: site.navigation?.headerButton ?? null
|
|
7954
|
+
headerButton: site.navigation?.headerButton ?? null,
|
|
7955
|
+
pageMenu: site.navigation?.pageMenu ?? null
|
|
7916
7956
|
},
|
|
7917
7957
|
home: {
|
|
7918
7958
|
title: home.title,
|
|
7919
7959
|
slug: home.slug,
|
|
7920
7960
|
content: {
|
|
7921
7961
|
version: home.content.version,
|
|
7922
|
-
sections: home.content.sections.map(({ type, reference, enabled, order, data }) => ({
|
|
7962
|
+
sections: home.content.sections.map(({ id, type, reference, enabled, order, data }) => ({
|
|
7963
|
+
id,
|
|
7923
7964
|
reference,
|
|
7924
7965
|
type,
|
|
7925
7966
|
enabled,
|
|
@@ -13130,7 +13171,7 @@ function diagnosticsMessage(diagnostics) {
|
|
|
13130
13171
|
getNewLine: () => "\n"
|
|
13131
13172
|
});
|
|
13132
13173
|
}
|
|
13133
|
-
async function typecheck(directory) {
|
|
13174
|
+
async function typecheck$1(directory) {
|
|
13134
13175
|
const configFile = path.join(directory, "tsconfig.json");
|
|
13135
13176
|
const config = ts.readConfigFile(configFile, ts.sys.readFile);
|
|
13136
13177
|
if (config.error) throw new Error(`tsconfig inválido:\n${diagnosticsMessage([config.error])}`);
|
|
@@ -13151,7 +13192,7 @@ async function validateMigratedTheme(directory, options) {
|
|
|
13151
13192
|
build: false
|
|
13152
13193
|
};
|
|
13153
13194
|
if (!options.runChecks) return result;
|
|
13154
|
-
await typecheck(directory);
|
|
13195
|
+
await typecheck$1(directory);
|
|
13155
13196
|
result.typecheck = true;
|
|
13156
13197
|
await themeBuild({ themeDirectory: directory });
|
|
13157
13198
|
result.build = true;
|
|
@@ -13390,36 +13431,119 @@ function formatPerformanceValue(metric) {
|
|
|
13390
13431
|
}
|
|
13391
13432
|
//#endregion
|
|
13392
13433
|
//#region src/commands/theme/validate.ts
|
|
13434
|
+
function typecheck(directory) {
|
|
13435
|
+
const configPath = ts.findConfigFile(directory, ts.sys.fileExists);
|
|
13436
|
+
if (!configPath || path.dirname(configPath) !== directory) return [{
|
|
13437
|
+
code: "TSCONFIG_NOT_FOUND",
|
|
13438
|
+
message: "Crie um tsconfig.json na raiz do tema para executar a checagem de tipos."
|
|
13439
|
+
}];
|
|
13440
|
+
const config = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
13441
|
+
const parsed = ts.parseJsonConfigFileContent(config.config ?? {}, ts.sys, directory);
|
|
13442
|
+
return (config.error ? [config.error] : [...parsed.errors, ...ts.getPreEmitDiagnostics(ts.createProgram(parsed.fileNames, {
|
|
13443
|
+
...parsed.options,
|
|
13444
|
+
noEmit: true,
|
|
13445
|
+
incremental: false,
|
|
13446
|
+
composite: false
|
|
13447
|
+
}))]).filter((item) => item.category === ts.DiagnosticCategory.Error).map((item) => {
|
|
13448
|
+
const position = item.file && item.start !== void 0 ? item.file.getLineAndCharacterOfPosition(item.start) : void 0;
|
|
13449
|
+
return {
|
|
13450
|
+
code: `TS${item.code}`,
|
|
13451
|
+
message: ts.flattenDiagnosticMessageText(item.messageText, "\n"),
|
|
13452
|
+
...item.file ? { file: path.relative(directory, item.file.fileName) } : {},
|
|
13453
|
+
...position ? {
|
|
13454
|
+
line: position.line + 1,
|
|
13455
|
+
column: position.character + 1
|
|
13456
|
+
} : {}
|
|
13457
|
+
};
|
|
13458
|
+
});
|
|
13459
|
+
}
|
|
13393
13460
|
async function themeValidate(options) {
|
|
13394
|
-
const
|
|
13395
|
-
|
|
13396
|
-
|
|
13397
|
-
|
|
13398
|
-
|
|
13399
|
-
|
|
13400
|
-
|
|
13401
|
-
|
|
13402
|
-
|
|
13403
|
-
|
|
13404
|
-
|
|
13405
|
-
|
|
13406
|
-
|
|
13407
|
-
|
|
13408
|
-
|
|
13409
|
-
|
|
13410
|
-
|
|
13411
|
-
|
|
13412
|
-
|
|
13413
|
-
|
|
13414
|
-
|
|
13415
|
-
|
|
13461
|
+
const report = {
|
|
13462
|
+
schemaVersion: 1,
|
|
13463
|
+
ok: false,
|
|
13464
|
+
checks: []
|
|
13465
|
+
};
|
|
13466
|
+
let stage = "manifest";
|
|
13467
|
+
try {
|
|
13468
|
+
const project = await loadThemeProject(options.themeDirectory);
|
|
13469
|
+
const { id, name, version, sdkVersion, runtimeVersion } = project.manifest;
|
|
13470
|
+
report.theme = {
|
|
13471
|
+
id,
|
|
13472
|
+
name,
|
|
13473
|
+
version,
|
|
13474
|
+
sdkVersion,
|
|
13475
|
+
runtimeVersion
|
|
13476
|
+
};
|
|
13477
|
+
report.checks.push({
|
|
13478
|
+
name: stage,
|
|
13479
|
+
status: "PASSED",
|
|
13480
|
+
issues: []
|
|
13481
|
+
});
|
|
13482
|
+
stage = "typecheck";
|
|
13483
|
+
const issues = options.checks ? typecheck(project.directory) : [];
|
|
13484
|
+
report.checks.push({
|
|
13485
|
+
name: stage,
|
|
13486
|
+
status: options.checks ? issues.length ? "FAILED" : "PASSED" : "SKIPPED",
|
|
13487
|
+
issues
|
|
13488
|
+
});
|
|
13489
|
+
stage = "build";
|
|
13490
|
+
if (options.checks && !issues.length) {
|
|
13491
|
+
await themeBuild({
|
|
13492
|
+
themeDirectory: project.directory,
|
|
13493
|
+
quiet: true
|
|
13494
|
+
});
|
|
13495
|
+
report.checks.push({
|
|
13496
|
+
name: stage,
|
|
13497
|
+
status: "PASSED",
|
|
13498
|
+
issues: []
|
|
13499
|
+
});
|
|
13500
|
+
} else report.checks.push({
|
|
13501
|
+
name: stage,
|
|
13502
|
+
status: "SKIPPED",
|
|
13503
|
+
issues: []
|
|
13504
|
+
});
|
|
13505
|
+
stage = "performance";
|
|
13506
|
+
const performance = await analyzeThemePerformance(project);
|
|
13507
|
+
report.performance = performance;
|
|
13508
|
+
const warnings = performance.warnings.map((metric) => ({
|
|
13509
|
+
code: `BUDGET_${metric.key}`,
|
|
13510
|
+
message: `${metric.label}: ${metric.value} excede ${metric.limit}`
|
|
13511
|
+
}));
|
|
13512
|
+
report.checks.push({
|
|
13513
|
+
name: stage,
|
|
13514
|
+
status: options.strictPerformance && warnings.length ? "FAILED" : "PASSED",
|
|
13515
|
+
issues: warnings
|
|
13516
|
+
});
|
|
13517
|
+
report.ok = !report.checks.some((check) => check.status === "FAILED");
|
|
13518
|
+
} catch (error) {
|
|
13519
|
+
report.checks.push({
|
|
13520
|
+
name: stage,
|
|
13521
|
+
status: "FAILED",
|
|
13522
|
+
issues: [{
|
|
13523
|
+
code: "THEME_VALIDATION_ERROR",
|
|
13524
|
+
message: error instanceof Error ? error.message : "Falha ao validar o tema."
|
|
13525
|
+
}]
|
|
13416
13526
|
});
|
|
13417
|
-
console.log(`${marker} ${metric.label}: ${formatPerformanceValue(metric)} / ${limit}${details}`);
|
|
13418
13527
|
}
|
|
13419
|
-
if (
|
|
13420
|
-
else
|
|
13421
|
-
|
|
13422
|
-
|
|
13528
|
+
if (options.json) process.stdout.write(`${JSON.stringify(report)}\n`);
|
|
13529
|
+
else {
|
|
13530
|
+
console.log("");
|
|
13531
|
+
if (report.theme) console.log(`${report.theme.name} v${report.theme.version} · Theme SDK ${report.theme.sdkVersion} (CLI ${THEME_API_VERSION})`);
|
|
13532
|
+
for (const check of report.checks) {
|
|
13533
|
+
console.log(`${check.status === "PASSED" ? "✓" : check.status === "FAILED" ? "✗" : "○"} ${check.name}: ${check.status}`);
|
|
13534
|
+
for (const issue of check.issues) console.log(` ${issue.file ? `${issue.file}:${issue.line}:${issue.column}: ` : ""}${issue.message}`);
|
|
13535
|
+
}
|
|
13536
|
+
if (report.performance) {
|
|
13537
|
+
console.log(options.strictPerformance ? "Performance (obrigatório)" : "Performance (informativo)");
|
|
13538
|
+
if (report.performance.warnings.length && !options.strictPerformance) console.log(`⚠ ${report.performance.warnings.length} limite(s) excedido(s); publicação ainda não é bloqueada.`);
|
|
13539
|
+
}
|
|
13540
|
+
for (const metric of report.performance?.metrics ?? []) console.log(`${metric.available ? formatPerformanceValue(metric) : "Não medido"} · ${metric.label}`);
|
|
13541
|
+
console.log("");
|
|
13542
|
+
}
|
|
13543
|
+
return {
|
|
13544
|
+
...report,
|
|
13545
|
+
...report.performance
|
|
13546
|
+
};
|
|
13423
13547
|
}
|
|
13424
13548
|
//#endregion
|
|
13425
13549
|
//#region src/commands/theme/upgrade.ts
|
|
@@ -13699,9 +13823,14 @@ theme.command("dev").description("Start the local theme development server").opt
|
|
|
13699
13823
|
process.exitCode = 1;
|
|
13700
13824
|
}
|
|
13701
13825
|
});
|
|
13702
|
-
theme.command("validate").description("Validate a local theme project").option("--theme <directory>", "Theme directory", ".").action(async (options) => {
|
|
13826
|
+
theme.command("validate").description("Validate a local theme project").option("--theme <directory>", "Theme directory", ".").option("--json", "Emit a machine-readable validation report").option("--checks", "Run TypeScript checking and a production build").option("--strict-performance", "Fail when a measured performance budget is exceeded").action(async (options) => {
|
|
13703
13827
|
try {
|
|
13704
|
-
await themeValidate({
|
|
13828
|
+
if (!(await themeValidate({
|
|
13829
|
+
themeDirectory: options.theme,
|
|
13830
|
+
json: options.json,
|
|
13831
|
+
checks: options.checks,
|
|
13832
|
+
strictPerformance: options.strictPerformance
|
|
13833
|
+
})).ok) process.exitCode = 1;
|
|
13705
13834
|
} catch (error) {
|
|
13706
13835
|
const message = error instanceof Error ? error.message : "Erro desconhecido.";
|
|
13707
13836
|
console.error(`Erro: ${message}`);
|