Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// auto-generated by package/src/common/create-deno-config.ts
// see dev-docs/update-deno_jsonc.md
{
"compilerOptions": {
"noErrorTruncation": true
},
"lint": {
"include": ["src/"],
"exclude": [
Expand Down
7 changes: 6 additions & 1 deletion package/src/common/create-schema-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import {
generateJsonSchemasFromSchemas,
} from "../../../src/core/schema/json-schema-from-schema.ts";

import {
generateZodTypesFromSchemas,
} from "../../../src/core/schema/zod-types-from-schema.ts";

await generateTypesFromSchemas(Deno.args[0]);
await generateSchemaTypes(Deno.args[0]);
await generateJsonSchemasFromSchemas(Deno.args[0]);
await generateJsonSchemasFromSchemas(Deno.args[0]);
await generateZodTypesFromSchemas(Deno.args[0]);
12 changes: 4 additions & 8 deletions src/command/render/pandoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,7 @@ import {
MarkdownPipelineHandler,
} from "../../core/markdown-pipeline.ts";
import { getenv } from "../../core/env.ts";
import {
BrandFontBunny,
BrandFontFile,
BrandFontGoogle,
} from "../../resources/types/schema-types.ts";
import { Zod } from "../../resources/types/zod/schema-types.ts";
import { kFieldCategories } from "../../project/types/website/listing/website-listing-shared.ts";
import { isWindows } from "../../deno_ral/platform.ts";
import { appendToCombinedLuaProfile } from "../../core/performance/perfetto-utils.ts";
Expand Down Expand Up @@ -1480,19 +1476,19 @@ async function resolveExtras(
// deno-lint-ignore no-explicit-any
const source: string = (_font as any).source ?? "google";
if (source === "file") {
const font = _font as BrandFontFile;
const font = Zod.BrandFontFile.parse(_font);
for (const file of font.files || []) {
const path = typeof file === "object" ? file.path : file;
fontdirs.add(dirname(join(brand.brandDir, path)));
}
} else if (source === "bunny") {
const font = _font as BrandFontBunny;
const font = Zod.BrandFontBunny.parse(_font);
console.log(
"Font bunny is not yet supported for Typst, skipping",
font.family,
);
} else if (source === "google" /* || font.source === "bunny" */) {
const font = _font as BrandFontGoogle;
const font = Zod.BrandFontGoogle.parse(_font);
let { family, style, weight } = font;
const parts = [family!];
if (style) {
Expand Down
8 changes: 5 additions & 3 deletions src/command/render/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import { Format } from "../../config/types.ts";
import { fileExecutionEngine } from "../../execute/engine.ts";
import { projectContextForDirectory } from "../../project/project-context.ts";
import { ProjectType } from "../../project/types/types.ts";
import { ProjectConfig as ProjectConfig_Project } from "../../resources/types/schema-types.ts";
import { Zod } from "../../resources/types/zod/schema-types.ts";

const noMutationValidations = (
projType: ProjectType,
Expand Down Expand Up @@ -255,9 +255,11 @@ const mergeExtensionMetadata = async (
context.isSingleFile ? undefined : context.dir,
{ builtIn: false },
);
const projectMetadata = extensions.map((extension) =>
const projectMetadata = extensions.filter((extension) =>
extension.contributes.metadata?.project
).filter((project) => project) as ProjectConfig_Project[];
).map((extension) => {
return Zod.ProjectConfig.parse(extension.contributes.metadata!.project);
});
context.config.project = mergeProjectMetadata(
context.config.project,
...projectMetadata,
Expand Down
19 changes: 13 additions & 6 deletions src/core/brand/brand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
BrandTypography,
BrandTypographyOptionsBase,
BrandTypographyOptionsHeadings,
} from "../../resources/types/schema-types.ts";
Zod,
} from "../../resources/types/zod/schema-types.ts";
import { InternalError } from "../lib/error.ts";

import { join, relative } from "../../deno_ral/path.ts";
Expand Down Expand Up @@ -67,11 +68,15 @@ export class Brand {
projectDir: string;
processedData: ProcessedBrandData;

constructor(readonly brand: BrandJson, brandDir: string, projectDir: string) {
this.data = brand;
constructor(
readonly brand: unknown,
brandDir: string,
projectDir: string,
) {
this.data = Zod.Brand.parse(brand);
this.brandDir = brandDir;
this.projectDir = projectDir;
this.processedData = this.processData(brand);
this.processedData = this.processData(this.data);
}

processData(data: BrandJson): ProcessedBrandData {
Expand Down Expand Up @@ -261,8 +266,10 @@ export class Brand {
if (typeof entry === "string") {
return { path: join(pathPrefix, entry) };
}
entry.path = join(pathPrefix, entry.path);
return entry;
return {
...entry,
path: join(pathPrefix, entry.path),
};
}

getLogo(name: "small" | "medium" | "large"): CanonicalLogoInfo | undefined {
Expand Down
38 changes: 21 additions & 17 deletions src/core/sass/brand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import {
import { ProjectContext } from "../../project/types.ts";
import {
BrandFont,
BrandFontBunny,
// BrandFontBunny,
BrandFontCommon,
BrandFontGoogle,
BrandFontWeight,
} from "../../resources/types/schema-types.ts";
Zod,
} from "../../resources/types/zod/schema-types.ts";
import { Brand } from "../brand/brand.ts";
import { darkModeDefault } from "../../format/html/format-html-info.ts";

Expand Down Expand Up @@ -323,10 +324,11 @@ const brandTypographyLayer = (
): string | undefined => {
let googleFamily = "";
for (const _resolvedFont of font) {
const resolvedFont = _resolvedFont as (BrandFontGoogle | BrandFontBunny);
if (resolvedFont.source !== "google") {
const safeResolvedFont = Zod.BrandFontGoogle.safeParse(_resolvedFont);
if (!safeResolvedFont.success) {
return undefined;
}
const resolvedFont = safeResolvedFont.data;
const thisFamily = resolvedFont.family;
if (!thisFamily) {
continue;
Expand All @@ -351,17 +353,15 @@ const brandTypographyLayer = (
): string | undefined => {
let googleFamily = "";
for (const _resolvedFont of font) {
const resolvedFont =
_resolvedFont as (BrandFont | BrandFontGoogle | BrandFontBunny);
const safeResolvedFont = Zod.BrandFontBunny.safeParse(_resolvedFont);
if (!safeResolvedFont.success) {
return undefined;
}
const resolvedFont = safeResolvedFont.data;
// Typescript's type checker doesn't understand that it's ok to attempt
// to access a property that might not exist on a type when you're
// only testing for its existence.

// deno-lint-ignore no-explicit-any
const source = (resolvedFont as any).source;
if (source && source !== "bunny") {
return undefined;
}
const thisFamily = resolvedFont.family;
if (!thisFamily) {
continue;
Expand All @@ -384,6 +384,7 @@ const brandTypographyLayer = (
type HTMLFontInformation = { [key: string]: unknown };

type FontKind =
| "link"
| "base"
| "headings"
| "monospace"
Expand All @@ -398,9 +399,14 @@ const brandTypographyLayer = (
} else if (typeof resolvedFontOptions === "string") {
resolvedFontOptions = { family: resolvedFontOptions };
}
const family = resolvedFontOptions.family;
const font = getFontFamilies(family);
const result: HTMLFontInformation = {};
// This is an ugly hack:
// resolvedFontOptions doesn't always have 'family', but at this
// point in the code we know resolvedFontOptions is an object
// that we can attempt to extract the family from.
const family =
(resolvedFontOptions as Record<string, string | undefined>).family;
const font = getFontFamilies(family);
result.family = resolveGoogleFontFamily(font) ??
resolveBunnyFontFamily(font) ??
// resolveFilesFontFamily(font) ??
Expand Down Expand Up @@ -524,11 +530,9 @@ const brandTypographyLayer = (
"monospace",
"headings",
"base",
]
] as const
) {
const fontInformation = resolveHTMLFontInformation(
kind as FontKind,
);
const fontInformation = resolveHTMLFontInformation(kind);
if (!fontInformation) {
continue;
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/schema/build-schema-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { kLangCommentChars } from "../lib/partition-cell-options.ts";
import { generateTypesFromSchemas } from "./types-from-schema.ts";
import { generateJsonSchemasFromSchemas } from "./json-schema-from-schema.ts";
import { InternalError } from "../lib/error.ts";
import { generateZodTypesFromSchemas } from "./zod-types-from-schema.ts";

////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -90,6 +91,7 @@ export async function buildIntelligenceResources() {
await Promise.all([
generateTypesFromSchemas(path),
generateJsonSchemasFromSchemas(path),
generateZodTypesFromSchemas(path),
]);
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/schema/types-from-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ export function typeNameFromSchemaName(schemaName: string) {
return capitalize(toCapitalizationCase(schemaName.replaceAll("/", "-")));
}

function fmtSource(source: string) {
export function fmtSource(source: string) {
return new Deno.Command(Deno.execPath(), {
args: ["fmt", source],
}).output();
}

export const generatedSrcMessage =
`// This file is automatically generated by \`quarto build-js\`! Do not edit.",
`// This file is automatically generated by \`quarto dev-call build-artifacts\`! Do not edit.",
//
// If you find yourself trying to rebuild types and \`quarto build-js\` won't run because
// If you find yourself trying to rebuild types and \`quarto dev-call build-artifacts\` won't run because
// of bad type definitions, run the following:
// $ cd $QUARTO_ROOT
// $ ./package/dist/bin/tools/deno run --importmap=./src/import_map.json --allow-all ./package/src/common/create-schema-types.ts ./src/resources
Expand Down Expand Up @@ -104,7 +104,7 @@ export async function generateTypesFromSchemas(resourcePath: string) {
await fmtSource(join(resourcePath, "/types/schema-types.ts"));
}

function yamlToTypeScriptKey(key: string) {
export function yamlToTypeScriptKey(key: string) {
// if the key isn't a valid typescript identifier, quote it
if (!/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(key)) {
return JSON.stringify(key);
Expand Down
Loading
Loading