diff --git a/.envrc b/.envrc index 7b616241..f1e3a46d 100644 --- a/.envrc +++ b/.envrc @@ -1,2 +1,2 @@ -use nix +use nix ./nix/shell.nix layout node diff --git a/.yarnrc.yml b/.yarnrc.yml index 07a8a70b..020e50e8 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -12,4 +12,8 @@ plugins: path: .yarn/plugins/yarn-plugin-nixify.cjs spec: "https://raw.githubusercontent.com/stephank/yarn-plugin-nixify/main/dist/yarn-plugin-nixify.js" +# yarn-plugin-nixify options +generateDefaultNix: false +nixExprPath: nix/yarn-project.nix + yarnPath: .yarn/releases/yarn-4.0.2.cjs diff --git a/default.nix b/default.nix deleted file mode 100644 index 1b4daae1..00000000 --- a/default.nix +++ /dev/null @@ -1,57 +0,0 @@ -{ - pkgs ? import {}, - accentColor ? "mauve", - boldKeywords ? true, - italicComments ? true, - italicKeywords ? true, - extraBordersEnabled ? false, - workbenchMode ? "default", - bracketMode ? "rainbow", - colorOverrides ? {}, - customUIColors ? {}, -} @ inputs: let - inherit (pkgs) lib; - - packageJSON = builtins.fromJSON (builtins.readFile ./package.json); - properties = (builtins.head packageJSON.contributes.configuration).properties; - validAccents = properties."catppuccin.accentColor".enum; - validWorkbenchModes = properties."catppuccin.workbenchMode".enum; - validBracketModes = properties."catppuccin.bracketMode".enum; - - inherit (packageJSON) name version; - pname = "${name}-${version}"; - - options = builtins.removeAttrs inputs ["pkgs"]; - project = - (pkgs.callPackage ./yarn-project.nix {} { - src = pkgs.nix-gitignore.gitignoreSource [] ./.; - }) - .overrideAttrs (old: { - # check in the ./themes/.flag so it doesn't prompt for initial rebuilds - patchPhase = '' - printf "\n!themes/.flag\n" >> .vscodeignore - ''; - buildPhase = '' - yarn compile - yarn compile:theme '${builtins.toJSON options}' - touch ./themes/.flag - yarn package - ''; - installPhase = '' - mkdir -p $out - # rename the file extension to zip for the buildVSCodeMarketplaceExtension builder - mv catppuccin-vsc-*.vsix $out/catppuccin-vsc.zip - ''; - }); -in - (lib.checkListOfEnum "${pname}: accent" validAccents [accentColor]) - (lib.checkListOfEnum "${pname}: workbenchMode" validWorkbenchModes [workbenchMode]) - (lib.checkListOfEnum "${pname}: bracketMode" validBracketModes [bracketMode]) - pkgs.vscode-utils.buildVscodeMarketplaceExtension { - vsix = "${project.outPath}/catppuccin-vsc.zip"; - mktplcRef = { - # lowercase since it is used in the pname - publisher = "catppuccin"; - inherit name version; - }; - } diff --git a/flake.nix b/flake.nix index 9e76c7c8..b2f9e71b 100644 --- a/flake.nix +++ b/flake.nix @@ -9,7 +9,7 @@ pkgs = nixpkgs.legacyPackages.${system}; in rec { default = catppuccin-vsc; - catppuccin-vsc = pkgs.callPackage ./. {}; + catppuccin-vsc = pkgs.callPackage ./nix {}; }); overlays.default = final: prev: let @@ -32,7 +32,7 @@ devShells = forAllSystems (system: let pkgs = nixpkgs.legacyPackages.${system}; in { - default = import ./shell.nix {inherit pkgs;}; + default = import ./nix/shell.nix {inherit pkgs;}; }); }; } diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 00000000..73dbf0fd --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,87 @@ +{ + pkgs ? import {}, + accentColor ? "mauve", + boldKeywords ? true, + italicComments ? true, + italicKeywords ? true, + extraBordersEnabled ? false, + workbenchMode ? "default", + bracketMode ? "rainbow", + colorOverrides ? {}, + customUIColors ? {}, +} @ inputs: let + inherit (pkgs) lib; + + packageJSON = builtins.fromJSON (builtins.readFile ../package.json); + properties = (builtins.head packageJSON.contributes.configuration).properties; + validAccents = properties."catppuccin.accentColor".enum; + validWorkbenchModes = properties."catppuccin.workbenchMode".enum; + validBracketModes = properties."catppuccin.bracketMode".enum; + + inherit (packageJSON) name version; + pname = "${name}-${version}"; + + options = builtins.removeAttrs inputs ["pkgs"]; + src = pkgs.nix-gitignore.gitignoreSource [] ../.; + + builder = pkgs.callPackage ./yarn-project.nix {} { + inherit src; + overrideAttrs = { + pname = "${pname}-builder"; + + buildPhase = '' + runHook preBuild + yarn compile + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out + cp -r dist/* $out + runHook postInstall + ''; + }; + }; + + extension = pkgs.stdenvNoCC.mkDerivation { + inherit name version pname src; + buildInputs = [pkgs.nodejs pkgs.vsce pkgs.yarn]; + + # check in the ./themes/.flag so it doesn't prompt for initial rebuilds + patchPhase = '' + runHook prePatch + printf "\n!themes/.flag\n" >> .vscodeignore + runHook postPatch + ''; + + 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 + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out + # rename the file extension to zip for the buildVSCodeMarketplaceExtension builder + mv catppuccin-vsc-*.vsix $out/catppuccin-vsc.zip + runHook postInstall + ''; + }; +in + (lib.checkListOfEnum "${pname}: accent" validAccents [accentColor]) + (lib.checkListOfEnum "${pname}: workbenchMode" validWorkbenchModes [workbenchMode]) + (lib.checkListOfEnum "${pname}: bracketMode" validBracketModes [bracketMode]) + pkgs.vscode-utils.buildVscodeMarketplaceExtension { + vsix = "${extension.outPath}/catppuccin-vsc.zip"; + mktplcRef = { + # lowercase since it is used in the pname + publisher = "catppuccin"; + inherit name version; + }; + } diff --git a/shell.nix b/nix/shell.nix similarity index 82% rename from shell.nix rename to nix/shell.nix index 3e4c4eff..d2ab8c7c 100644 --- a/shell.nix +++ b/nix/shell.nix @@ -5,5 +5,7 @@ in buildInputs = [ nodejs (pkgs.yarn.override {inherit nodejs;}) + pkgs.alejandra + pkgs.nil ]; } diff --git a/yarn-project.nix b/nix/yarn-project.nix similarity index 99% rename from yarn-project.nix rename to nix/yarn-project.nix index b6aad9e3..6c731a2d 100644 --- a/yarn-project.nix +++ b/nix/yarn-project.nix @@ -6,10 +6,10 @@ let - yarnBin = ./.yarn/releases/yarn-4.0.2.cjs; + yarnBin = ../.yarn/releases/yarn-4.0.2.cjs; cacheFolder = ".yarn/cache"; - lockfile = ./yarn.lock; + lockfile = ../yarn.lock; # Call overrideAttrs on a derivation if a function is provided. optionalOverride = fn: drv: diff --git a/package.json b/package.json index d01a5722..cfc89ac6 100644 --- a/package.json +++ b/package.json @@ -201,7 +201,7 @@ "chromatic": "chromatic --exit-zero-on-changes --exit-once-uploaded --project-token chpt_e3cba49738d7554", "compile": "tsup", "compile:theme": "tsx src/hooks/generateThemes.ts", - "dev": "DEBUG=1 yarn build", + "dev": "yarn compile:theme && yarn compile --env.NODE_ENV development", "lint": "eslint . --ext .ts", "package": "vsce package --allow-star-activation --yarn", "postbuild": "prettier -w ./themes", diff --git a/tsup.config.ts b/tsup.config.ts index 96a7c98b..a473e6dd 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,9 +1,13 @@ import { defineConfig } from "tsup"; +const dev = process.env.NODE_ENV === "development"; + export default defineConfig({ - entry: ["src/browser.ts", "src/main.ts"], + entry: ["src/browser.ts", "src/main.ts", "src/hooks/generateThemes.ts"], external: ["vscode"], - sourcemap: true, + sourcemap: dev, + minify: !dev, target: "node16", clean: true, + splitting: true, });