feat(node): make function to make girs types and move it to lib

This commit is contained in:
matt1432 2024-09-24 16:12:57 -04:00
parent aa9723303b
commit 7a3ea83d40
7 changed files with 58 additions and 24 deletions

View file

@ -1,6 +1,7 @@
{
inputs ? {},
pkgs ? {},
self ? {},
}: let
lock = builtins.fromJSON (builtins.readFile ../flake.lock);
@ -9,11 +10,12 @@
sha256 = lock.nodes.nixpkgs.locked.narHash;
}}/lib";
inherit (lib) optionalAttrs;
inherit (lib) concatStringsSep optionalAttrs stringToCharacters substring tail toUpper;
mkVersion = src: "0.0.0+" + src.shortRev;
capitalise = str: (toUpper (substring 0 1 str) + (concatStringsSep "" (tail (stringToCharacters str))));
in
{inherit lib mkVersion;}
{inherit lib mkVersion capitalise;}
// (import ./inputs.nix lib lock)
// optionalAttrs (inputs != {}) (import ./flake-lib.nix inputs)
// optionalAttrs (pkgs != {}) (import ./pkgs.nix pkgs mkVersion)
// optionalAttrs (pkgs != {}) (import ./pkgs.nix pkgs mkVersion capitalise self)

1
lib/mk-types/.envrc Normal file
View file

@ -0,0 +1 @@
use flake $FLAKE#node

32
lib/mk-types/default.nix Normal file
View file

@ -0,0 +1,32 @@
{
lib,
pname,
withGirNames,
buildNpmPackage,
ts-for-gir-src,
...
}: let
inherit (lib) concatMapStringsSep;
in
buildNpmPackage {
pname = "${pname}-types";
version = "0.0.0";
npmDepsHash = "sha256-8De8tRUKzRhD1jyx0anYNPMhxZyIr2nI45HdK6nb8jI=";
src = ./.;
dontNpmBuild = true;
buildPhase = ''
npx @ts-for-gir/cli generate ${concatMapStringsSep " " (p: p.girName) withGirNames} \
${concatMapStringsSep "\n" (p: "-g ${p.package.dev}/share/gir-1.0 \\") withGirNames}
-g ${ts-for-gir-src}/girs \
--ignoreVersionConflicts \
--package \
-e gjs -o ./types
'';
installPhase = ''
cp -r ./types $out
'';
}

1204
lib/mk-types/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,5 @@
{
"dependencies": {
"@ts-for-gir/cli": "^3.3.0"
}
}

View file

@ -1,4 +1,4 @@
pkgs: mkVersion: {
pkgs: mkVersion: capitalise: self: {
buildPlugin = pname: src:
pkgs.vimUtils.buildVimPlugin {
inherit pname src;
@ -21,4 +21,29 @@ pkgs: mkVersion: {
dontNpmBuild = true;
}) {};
in "${pkg}/lib/node_modules/${pkg.pname}/node_modules";
buildNodeTypes = {
configPath,
packages,
pname,
}: let
inherit (pkgs.lib) concatMapStrings elemAt length map optionalString splitString toLower;
withGirNames =
map (package: {
inherit package;
girName =
if package.pname == "astal-wireplumber"
then "AstalWp-0.1"
else (concatMapStrings capitalise (splitString "-" package.pname)) + "-0.1";
})
packages;
in {
"${configPath}${optionalString (length packages == 1) "/${toLower (elemAt withGirNames 0).girName}"}".source =
pkgs.callPackage
./mk-types {
inherit (self.inputs) ts-for-gir-src;
inherit pname withGirNames;
};
};
}