Skip to content

Commit

Permalink
feat: blueprint plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Aylur committed Nov 3, 2024
1 parent 4b1e7da commit 198993b
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 10 deletions.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
// {
default = self.packages.${system}.ags;
ags = pkgs.callPackage ./src (with astal.packages.${system}; {
astal3 = astal3;
inherit astal3 astal4;
astal-io = io;
astal-gjs = "${gjs}/share/astal/gjs";
});
agsFull = pkgs.callPackage ./src (with astal.packages.${system}; {
astal3 = astal3;
inherit astal3 astal4;
astal-io = io;
astal-gjs = "${gjs}/share/astal/gjs";
extraPackages = builtins.attrValues (
Expand Down
1 change: 1 addition & 0 deletions result
5 changes: 5 additions & 0 deletions src/data/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ declare module "*.scss" {
export default content
}

declare module "*.blp" {
const content: string
export default content
}

declare module "*.css" {
const content: string
export default content
Expand Down
3 changes: 2 additions & 1 deletion src/data/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"experimentalDecorators": true,
"strict": true,
"target": "ES2023",
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "Bundler",
// "checkJs": true,
// "allowJs": true,
Expand Down
8 changes: 6 additions & 2 deletions src/default.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
astal3,
astal4,
gtk4-layer-shell,
astal-io,
astal-gjs,
lib,
writers,
buildGoModule,
wrapGAppsHook,
gobject-introspection,
gtk3,
glib,
gjs,
nodejs,
dart-sass,
blueprint-compiler,
extraPackages ? [],
}: let
inherit (builtins) replaceStrings readFile;
Expand All @@ -27,6 +29,7 @@
gjs
nodejs
dart-sass
blueprint-compiler
astal-io # FIXME: should not be needed after the astal commends are properly implemented using dbus in astal.go
];
in
Expand All @@ -44,9 +47,9 @@ in

buildInputs = extraPackages ++ [
glib
gtk3
astal-io
astal3
astal4
];

preFixup = ''
Expand All @@ -58,5 +61,6 @@ in

ldflags = [
"-X main.astalGjs=${astal-gjs}"
"-X main.gtk4LayerShell=${gtk4-layer-shell}/lib/libgtk4-layer-shell.so"
];
}
40 changes: 38 additions & 2 deletions src/esbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var inlinePlugin api.Plugin = api.Plugin{
var sassPlugin api.Plugin = api.Plugin{
Name: "sass",
Setup: func(build api.PluginBuild) {
build.OnResolve(api.OnResolveOptions{Filter: `.*\.(scss|sass)$`},
build.OnResolve(api.OnResolveOptions{Filter: `.*\.scss$`},
func(args api.OnResolveArgs) (api.OnResolveResult, error) {
return api.OnResolveResult{
Path: path.Join(
Expand All @@ -60,7 +60,7 @@ var sassPlugin api.Plugin = api.Plugin{
},
)

build.OnLoad(api.OnLoadOptions{Filter: `.*\.(scss|sass)$`, Namespace: "sass"},
build.OnLoad(api.OnLoadOptions{Filter: `.*\.scss$`, Namespace: "sass"},
func(args api.OnLoadArgs) (api.OnLoadResult, error) {
data, err := os.ReadFile(args.Path)
if err != nil {
Expand Down Expand Up @@ -91,6 +91,41 @@ var sassPlugin api.Plugin = api.Plugin{
},
}

var blpPlugin api.Plugin = api.Plugin{
Name: "blueprint",
Setup: func(build api.PluginBuild) {
build.OnResolve(api.OnResolveOptions{Filter: `.*\.blp$`},
func(args api.OnResolveArgs) (api.OnResolveResult, error) {
return api.OnResolveResult{
Path: path.Join(
args.ResolveDir,
args.Path,
),
Namespace: "blueprint",
}, nil
},
)

build.OnLoad(api.OnLoadOptions{Filter: `.*\.blp$`, Namespace: "blueprint"},
func(args api.OnLoadArgs) (api.OnLoadResult, error) {
blp := Exec("blueprint-compiler", "compile", args.Path)
blp.Stderr = os.Stderr

data, err := blp.Output()
if err != nil {
return api.OnLoadResult{}, err
}

content := strings.TrimSpace(string(data))
return api.OnLoadResult{
Contents: &content,
WatchFiles: []string{args.Path},
Loader: api.LoaderText,
}, nil
})
},
}

// TODO:
// svg loader
// other css preproceccors
Expand Down Expand Up @@ -124,6 +159,7 @@ func Build(infile, outfile string) {
Plugins: []api.Plugin{
inlinePlugin,
sassPlugin,
blpPlugin,
},
})

Expand Down
5 changes: 5 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"path/filepath"
)

var gtk4LayerShell = "/usr/lib/libgtk4-layer-shell.so"

func main() {
if *Opts.help {
PrintHelp()
Expand Down Expand Up @@ -107,6 +109,9 @@ func run() {

outfile := getOutfile()
Build(infile, outfile)

// TODO: gtk4 flag
// os.Setenv("LD_PRELOAD", gtk4LayerShell)
cmd := Exec("gjs", "-m", outfile)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down

0 comments on commit 198993b

Please sign in to comment.