From 9e032bde964b7adae320f890c0c9b69d684b3be2 Mon Sep 17 00:00:00 2001 From: s-ol Date: Mon, 4 Jan 2021 12:20:54 +0100 Subject: add SASS plugin --- .../sass/converts: text$moonscript -> table.moon | 55 ++++++++++++++++++++++ shell.nix | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 root/$mmm/plugins/sass/converts: text$moonscript -> table.moon diff --git a/root/$mmm/plugins/sass/converts: text$moonscript -> table.moon b/root/$mmm/plugins/sass/converts: text$moonscript -> table.moon new file mode 100644 index 0000000..e353c53 --- /dev/null +++ b/root/$mmm/plugins/sass/converts: text$moonscript -> table.moon @@ -0,0 +1,55 @@ +if MODE == 'CLIENT' + return {} + +posix = require 'posix' + +{ + { + inp: 'text/x-scss' + out: 'text/css' + cost: 1 + transform: (content) => + r0, w0 = posix.pipe! + r1, w1 = posix.pipe! + r2, w2 = posix.pipe! + + pid = assert posix.fork! + if pid == 0 + posix.close w0 + posix.close r1 + posix.close r2 + + posix.dup2 r0, posix.fileno io.stdin + posix.dup2 w1, posix.fileno io.stdout + posix.dup2 w2, posix.fileno io.stderr + + posix.close r0 + posix.close w1 + posix.close w2 + + err = assert posix.execp 'sassc', '-s' + posix._exit err + return + else + posix.close r0 + posix.close w1 + posix.close w2 + + posix.write w0, content + posix.close w0 + + _, _, status = posix.wait pid + + out = if status == 0 then r1 else r2 + out = assert posix.fdopen out, 'r' + out = out\read 'a' + + posix.close r1 + posix.close r2 + + if status == 0 + out + else + error out + } +} diff --git a/shell.nix b/shell.nix index 5131563..703f8b5 100644 --- a/shell.nix +++ b/shell.nix @@ -48,7 +48,7 @@ in pkgs.mkShell { name = "mmm-env"; buildInputs = with pkgs; [ tup sassc entr - (lua5_3.withPackages (p: with p; [ moonscript http cjson discount busted ])) + (lua5_3.withPackages (p: with p; [ moonscript http cjson discount busted luaposix ])) ]; shellHook = '' runServer () { -- cgit v1.2.3