diff --git a/src/hooks/constants.ts b/src/hooks/constants.ts new file mode 100644 index 000000000..d12c5461e --- /dev/null +++ b/src/hooks/constants.ts @@ -0,0 +1,4 @@ +import { join } from "node:path"; +export const vscodeSchemasRoot = + "https://raw.githubusercontent.com/wraith13/vscode-schemas/master/en/latest/schemas/"; +export const repoRoot = join(__dirname, "../.."); diff --git a/src/hooks/generateThemes.ts b/src/hooks/generateThemes.ts index 6a1b24f30..3f622ff44 100644 --- a/src/hooks/generateThemes.ts +++ b/src/hooks/generateThemes.ts @@ -1,11 +1,11 @@ -import * as fs from "fs/promises"; -import * as path from "path"; +import { mkdir, writeFile } from "node:fs/promises"; +import { join } from "node:path"; import { variants } from "@catppuccin/palette"; import { compileTheme, defaultOptions } from "@/theme"; import type { CatppuccinFlavor } from "@/types"; +import { repoRoot } from "./constants"; -const themeDir = path.join(__dirname, "../../themes"); const flavors = Object.keys(variants) as CatppuccinFlavor[]; // options can also be passed as a JSON string @@ -14,9 +14,9 @@ const options = process.argv[2] ? JSON.parse(process.argv[2]) : {}; flavors.map((flavor) => { const theme = compileTheme(flavor, { ...defaultOptions, ...options }); // ignore error if directory exists - fs.mkdir(themeDir, { recursive: true }).then(() => { - fs.writeFile( - path.join(themeDir, `${flavor}.json`), + mkdir(join(repoRoot, "themes"), { recursive: true }).then(() => { + writeFile( + join(repoRoot, `themes/${flavor}.json`), JSON.stringify(theme, null, 2), ); }); diff --git a/src/hooks/updateSchemas.ts b/src/hooks/updateSchemas.ts index ef9a6531b..a02ece5e3 100644 --- a/src/hooks/updateSchemas.ts +++ b/src/hooks/updateSchemas.ts @@ -1,74 +1,172 @@ -import * as path from "path"; -import { writeFileSync } from "fs"; +import { readFile, writeFile } from "node:fs/promises"; +import { join } from "node:path"; import fetch from "node-fetch"; -const vscodeSchemasRoot = - "https://raw.githubusercontent.com/wraith13/vscode-schemas/master/en/latest/schemas/"; +import { repoRoot, vscodeSchemasRoot } from "./constants"; + +const accents = [ + "rosewater", + "flamingo", + "pink", + "mauve", + "red", + "maroon", + "peach", + "yellow", + "green", + "teal", + "sky", + "sapphire", + "blue", + "lavender", +]; + +const customUiColorsSchema = (workbenchColors: any) => { + const validColors = [...accents, "accent"]; + return { + $schema: "http://json-schema.org/draft-07/schema#", + type: "object", + additionalProperties: false, + required: [], + properties: { + all: { $ref: "#/$defs/catppuccinWorkbenchColors" }, + latte: { $ref: "#/$defs/catppuccinWorkbenchColors" }, + frappe: { $ref: "#/$defs/catppuccinWorkbenchColors" }, + macchiato: { $ref: "#/$defs/catppuccinWorkbenchColors" }, + mocha: { $ref: "#/$defs/catppuccinWorkbenchColors" }, + }, + $defs: { + catppuccinColor: { + anyOf: [ + // allow plain color names, + { enum: validColors }, + // custom hex codes, + { format: "color-hex" }, + // and plain color names + opacity + { + type: "string", + pattern: `^(${validColors.join("|")})\\s\\d\\.\\d+$`, + }, + ], + }, + catppuccinWorkbenchColors: { + type: "object", + additionalProperties: false, + required: [], + properties: workbenchColors, + }, + }, + }; +}; + +const configuration = (version: string) => { + return { + title: "Catppuccin", + properties: { + "catppuccin.boldKeywords": { + type: "boolean", + default: true, + markdownDescription: "Controls whether to use **bold** for keywords.", + }, + "catppuccin.italicComments": { + type: "boolean", + default: true, + markdownDescription: "Controls whether to use *italics* for comments.", + }, + "catppuccin.italicKeywords": { + type: "boolean", + default: true, + markdownDescription: "Controls whether to use *italics* for keywords.", + }, + "catppuccin.colorOverrides": { + type: "object", + default: {}, + markdownDescription: + "Custom color overrides. Assign your own hex codes to palette colors. See [the docs](https://github.com/catppuccin/vscode#override-palette-colors) for reference.", + $ref: `https://cdn.jsdelivr.net/gh/catppuccin/vscode@v${version}/schemas/colorOverrides.schema.json`, + }, + "catppuccin.customUIColors": { + type: "object", + default: {}, + markdownDescription: + "Customize UI colors. Map `workbench.colorCustomizations` to palette colors. See [the docs](https://github.com/catppuccin/vscode#use-palette-colors-on-workbench-elements-ui) for reference.", + $ref: `https://cdn.jsdelivr.net/gh/catppuccin/vscode@v${version}/schemas/customUIColors.schema.json`, + }, + "catppuccin.accentColor": { + type: "string", + default: "mauve", + description: "Controls which accent color to use.", + enum: accents, + }, + "catppuccin.workbenchMode": { + type: "string", + default: "default", + description: "Controls how the workbench should be styled.", + enum: ["default", "flat", "minimal"], + enumDescriptions: [ + "The default look, using 3 shades of the base color.", + "A more flat look, using 2 shades of the base color.", + "A minimal look, using 1 shade of the base color.", + ], + }, + "catppuccin.bracketMode": { + type: "string", + default: "rainbow", + description: "Controls how bracket pairs should be themed", + enum: ["rainbow", "dimmed", "monochromatic", "neovim"], + enumDescriptions: [ + "Uses 6 rainbow colors for matching bracket pairs.", + "Uses the same 6 rainbow colors as `rainbow`, but has a dimmed appearance.", + "A monochromatic, grey appearance for matching bracket pairs.", + "Uses the same bracket pair colors as our neovim port.", + ], + }, + "catppuccin.extraBordersEnabled": { + type: "boolean", + default: false, + description: + "Controls whether borders should be enabled on some additional UI elements.", + }, + }, + }; +}; fetch(vscodeSchemasRoot + "workbench-colors.json") .then((data) => data.json()) .then((data) => { - const extracted = Object.entries(data.properties).reduce( - (acc, [name, { type, description }]) => { - acc[name] = { - type, - description, - anyOf: [{ format: "color-hex" }, { $ref: "#/$defs/catppuccinColor" }], - }; - return acc; - }, - {} as any, + const schema = customUiColorsSchema( + Object.entries(data.properties).reduce( + (acc, [name, { description }]) => { + acc[name] = { + description, + $ref: "#/$defs/catppuccinColor", + }; + return acc; + }, + {} as any, + ), ); + writeFile( + join(repoRoot, "schemas/customUIColors.schema.json"), + JSON.stringify(schema, null, 2), + "utf-8", + ); + }); - const schema = { - $schema: "http://json-schema.org/draft-07/schema#", - type: "object", - additionalProperties: false, - required: [], - properties: { - all: { - $ref: "#/$defs/catppuccinWorkbenchColors", - }, - latte: { - $ref: "#/$defs/catppuccinWorkbenchColors", - }, - frappe: { - $ref: "#/$defs/catppuccinWorkbenchColors", - }, - macchiato: { - $ref: "#/$defs/catppuccinWorkbenchColors", - }, - mocha: { - $ref: "#/$defs/catppuccinWorkbenchColors", - }, - }, - $defs: { - catppuccinColor: { - enum: [ - "accent", - "rosewater", - "flamingo", - "pink", - "mauve", - "red", - "maroon", - "peach", - "yellow", - "green", - "teal", - "sky", - "sapphire", - "blue", - "lavender", - ], - }, - catppuccinWorkbenchColors: { - type: "object", - additionalProperties: false, - required: [], - properties: extracted, - }, +readFile(join(repoRoot, "package.json"), "utf-8") + .then((data) => JSON.parse(data)) + .then((data) => { + return { + ...data, + contributes: { + ...data.contributes, + configuration: configuration(data.version), }, }; - const fp = path.join(__dirname, "../../schemas/customUIColors.schema.json"); - writeFileSync(fp, JSON.stringify(schema, null, 2), "utf-8"); - }); + }) + .then((data) => + writeFile( + join(repoRoot, "package.json"), + JSON.stringify(data, null, 2), + "utf-8", + ), + ); diff --git a/src/hooks/updateVSCtypes.ts b/src/hooks/updateVSCtypes.ts index 876554795..4f3b30840 100644 --- a/src/hooks/updateVSCtypes.ts +++ b/src/hooks/updateVSCtypes.ts @@ -1,11 +1,9 @@ -import * as path from "path"; -import { writeFileSync } from "fs"; +import { join } from "node:path"; +import { writeFileSync } from "node:fs"; import { compile, JSONSchema } from "json-schema-to-typescript"; +import { repoRoot, vscodeSchemasRoot } from "./constants"; import fetch from "node-fetch"; -const tag = process.argv[2] ?? "latest"; -const vscodeSchemasRoot = `https://raw.githubusercontent.com/wraith13/vscode-schemas/master/en/${tag}/schemas/`; - const bannerComment = `/* eslint-disable */ /** * This file was automatically generated. @@ -71,10 +69,9 @@ for (const { schema, name, fname, kind } of mappings) { throw new Error(`Unknown kind: ${kind}`); } }) - .then((typeDefs) => { - const fp = path.join(__dirname, `../types/${fname}`); - writeFileSync(fp, typeDefs, "utf-8"); - }); + .then((typeDefs) => + writeFileSync(join(repoRoot, fname), typeDefs, "utf-8"), + ); } const fromVSIXColors = (interfaceName: string, data: any) => {