diff --git a/nix/default.nix b/nix/default.nix index 4d2868736..c3ba1fed2 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -46,7 +46,7 @@ extension = pkgs.stdenvNoCC.mkDerivation { inherit name version pname src; - buildInputs = [pkgs.nodejs pkgs.vsce pkgs.yarn]; + buildInputs = [pkgs.nodejs pkgs.vsce]; # check in the ./themes/.flag so it doesn't prompt for initial rebuilds patchPhase = '' @@ -55,13 +55,15 @@ runHook postPatch ''; + env.CATPPUCCIN_OPTIONS = builtins.toJSON options; + buildPhase = '' runHook preBuild mkdir -p themes dist cp -r ${builder}/* dist/ touch ./themes/.flag - node dist/hooks/generateThemes.js '${builtins.toJSON options}' - vsce package --allow-star-activation --yarn + node dist/hooks/generateThemes.js + vsce package --yarn runHook postBuild ''; diff --git a/package.json b/package.json index 53883016f..74a9bd8db 100644 --- a/package.json +++ b/package.json @@ -194,14 +194,13 @@ "*.{ts,json,md}": "prettier --write" }, "scripts": { - "build": "yarn hooks && yarn compile", + "build": "tsup", "build-storybook": "storybook build", + "build:ads": "tsup --env.BUILD_TARGET AZURE_DATA_STUDIO", "chromatic": "chromatic --exit-zero-on-changes --exit-once-uploaded --project-token chpt_e3cba49738d7554", - "compile": "tsup", - "dev": "yarn compile:theme && yarn compile --env.NODE_ENV development", - "hooks": "tsx src/hooks/index.ts", + "dev": "tsup --env.NODE_ENV development", "lint": "eslint . --ext .ts", - "package": "vsce package --allow-star-activation --yarn", + "package": "vsce package --yarn", "prepare": "husky install", "storybook": "storybook dev -p 6006", "update-types": "tsx src/hooks/updateVSCtypes.ts" diff --git a/src/hooks/generateThemes.ts b/src/hooks/generateThemes.ts index 3f622ff44..0eb0a5936 100644 --- a/src/hooks/generateThemes.ts +++ b/src/hooks/generateThemes.ts @@ -8,16 +8,21 @@ import { repoRoot } from "./constants"; const flavors = Object.keys(variants) as CatppuccinFlavor[]; -// options can also be passed as a JSON string -const options = process.argv[2] ? JSON.parse(process.argv[2]) : {}; +// options can also be passed as a JSON string as an environment variable +const optEnvVar = process.env.CATPPUCCIN_OPTIONS; +const options = optEnvVar ? JSON.parse(optEnvVar) : {}; -flavors.map((flavor) => { - const theme = compileTheme(flavor, { ...defaultOptions, ...options }); - // ignore error if directory exists - mkdir(join(repoRoot, "themes"), { recursive: true }).then(() => { - writeFile( - join(repoRoot, `themes/${flavor}.json`), - JSON.stringify(theme, null, 2), - ); +const main = async () => { + flavors.map((flavor) => { + const theme = compileTheme(flavor, { ...defaultOptions, ...options }); + // ignore error if directory exists + mkdir(join(repoRoot, "themes"), { recursive: true }).then(() => { + writeFile( + join(repoRoot, `themes/${flavor}.json`), + JSON.stringify(theme, null, 2), + ); + }); }); -}); +}; + +export default main; diff --git a/src/hooks/index.ts b/src/hooks/index.ts index b8394bb96..2181fe9a1 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -1,2 +1,7 @@ -import "./generateThemes"; -import "./updateSchemas"; +import generateThemes from "./generateThemes"; +import updateSchemas from "./updateSchemas"; + +export const run = async () => { + await generateThemes(); + await updateSchemas(); +}; diff --git a/src/hooks/updateSchemas.ts b/src/hooks/updateSchemas.ts index 510942d12..253c856e0 100644 --- a/src/hooks/updateSchemas.ts +++ b/src/hooks/updateSchemas.ts @@ -129,43 +129,52 @@ const configuration = (version: string) => { }; }; -fetch(vscodeSchemasRoot + "workbench-colors.json") - .then((data) => data.json()) - .then((data: any) => { - const schema = customUiColorsSchema( - Object.entries(data.properties).reduce( - (acc, [name, { description }]) => { - acc[name] = { - description, - $ref: "#/$defs/catppuccinColor", - }; - return acc; +const main = async () => { + const buildForADS = process.env.BUILD_TARGET === "AZURE_DATA_STUDIO"; + + await fetch(vscodeSchemasRoot + "workbench-colors.json") + .then((data) => data.json()) + .then((data: 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) + "\n", + "utf-8", + ); + }); + + await readFile(join(repoRoot, "package.json"), "utf-8") + .then((data) => JSON.parse(data)) + .then((data) => { + const productName = buildForADS ? "Azure Data Studio" : "VSCode"; + return { + ...data, + displayName: `Catppuccin for ${productName}`, + description: `🦌 Soothing pastel theme for ${productName}`, + contributes: { + ...data.contributes, + configuration: configuration(data.version), }, - {} as any, + }; + }) + .then((data) => + writeFile( + join(repoRoot, "package.json"), + JSON.stringify(data, null, 2) + "\n", + "utf-8", ), ); - writeFile( - join(repoRoot, "schemas/customUIColors.schema.json"), - JSON.stringify(schema, null, 2) + "\n", - "utf-8", - ); - }); +}; -readFile(join(repoRoot, "package.json"), "utf-8") - .then((data) => JSON.parse(data)) - .then((data) => { - return { - ...data, - contributes: { - ...data.contributes, - configuration: configuration(data.version), - }, - }; - }) - .then((data) => - writeFile( - join(repoRoot, "package.json"), - JSON.stringify(data, null, 2) + "\n", - "utf-8", - ), - ); +export default main; diff --git a/src/theme/ui/azureDataStudio.ts b/src/theme/ui/azureDataStudio.ts new file mode 100644 index 000000000..dca01a8d4 --- /dev/null +++ b/src/theme/ui/azureDataStudio.ts @@ -0,0 +1,19 @@ +import type { ThemeContext } from "@/types"; + +/** + * Contains extra keys used in Azure Data Studio that might be missing or + * deprecated in VSCode. + */ +const azureDataStudio = (context: ThemeContext): Record => { + const { options, palette } = context; + const accent = palette[options.accent]; + + return { + "button.secondaryBorder": accent, + "table.headerBackground": palette.surface0, + "table.headerForeground": palette.text, + "list.focusAndSelectionBackground": palette.surface1, + }; +}; + +export default azureDataStudio; diff --git a/src/theme/ui/index.ts b/src/theme/ui/index.ts index dc8485673..42ce82369 100644 --- a/src/theme/ui/index.ts +++ b/src/theme/ui/index.ts @@ -1,4 +1,6 @@ import { ThemeContext } from "@/types"; + +import azureDataStudio from "./azureDataStudio"; import brackets from "./brackets"; import workbench from "./workbench"; @@ -9,6 +11,7 @@ const uiCustomizations = (context: ThemeContext) => { ...brackets(context), ...workbench(context), ...customNamedColors(context), + ...azureDataStudio(context), }; }; diff --git a/tsup.config.ts b/tsup.config.ts index a473e6ddf..2d6319a95 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,13 +1,18 @@ import { defineConfig } from "tsup"; +import { run as runHooks } from "./src/hooks"; -const dev = process.env.NODE_ENV === "development"; +export default defineConfig(async (options) => { + const dev = options.env?.NODE_ENV === "development"; + process.env = { ...process.env, ...options.env }; + await runHooks(); -export default defineConfig({ - entry: ["src/browser.ts", "src/main.ts", "src/hooks/generateThemes.ts"], - external: ["vscode"], - sourcemap: dev, - minify: !dev, - target: "node16", - clean: true, - splitting: true, + return { + entry: ["src/browser.ts", "src/main.ts", "src/hooks/generateThemes.ts"], + external: ["vscode"], + sourcemap: dev, + minify: !dev, + target: "node16", + clean: true, + splitting: true, + }; });