mirror of
https://github.com/SebastianWendel/nixpkgs.git
synced 2024-09-20 04:19:00 +02:00
movim: minifyStaticFiles prop
This commit is contained in:
parent
fcc7c53e9c
commit
64b110589c
|
@ -44,11 +44,17 @@ let
|
||||||
|
|
||||||
package =
|
package =
|
||||||
let
|
let
|
||||||
p = cfg.package.override {
|
p = cfg.package.override
|
||||||
inherit phpCfg;
|
({
|
||||||
withPgsql = cfg.database.type == "pgsql";
|
inherit phpCfg;
|
||||||
withMysql = cfg.database.type == "mysql";
|
withPgsql = cfg.database.type == "pgsql";
|
||||||
};
|
withMysql = cfg.database.type == "mysql";
|
||||||
|
inherit (cfg) minifyStaticFiles;
|
||||||
|
} // lib.optionalAttrs (lib.isAttrs cfg.minifyStaticFiles) (with cfg.minifyStaticFiles; {
|
||||||
|
esbuild = esbuild.package;
|
||||||
|
lightningcss = lightningcss.package;
|
||||||
|
scour = scour.package;
|
||||||
|
}));
|
||||||
in
|
in
|
||||||
p.overrideAttrs (finalAttrs: prevAttrs:
|
p.overrideAttrs (finalAttrs: prevAttrs:
|
||||||
let
|
let
|
||||||
|
@ -177,6 +183,47 @@ in
|
||||||
description = "Verbose logs.";
|
description = "Verbose logs.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
minifyStaticFiles = mkOption {
|
||||||
|
type = with types; either bool (submodule {
|
||||||
|
options = {
|
||||||
|
script = mkOption {
|
||||||
|
type = types.submodule {
|
||||||
|
options = {
|
||||||
|
enable = mkEnableOption "Script minification";
|
||||||
|
package = mkPackageOption pkgs "esbuild" { };
|
||||||
|
target = mkOption {
|
||||||
|
type = with types; nullOr nonEmptyStr;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
style = mkOption {
|
||||||
|
type = types.submodule {
|
||||||
|
options = {
|
||||||
|
enable = mkEnableOption "Script minification";
|
||||||
|
package = mkPackageOption pkgs "lightningcss" { };
|
||||||
|
target = mkOption {
|
||||||
|
type = with types; nullOr nonEmptyStr;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
svg = mkOption {
|
||||||
|
type = types.submodule {
|
||||||
|
options = {
|
||||||
|
enable = mkEnableOption "SVG minification";
|
||||||
|
package = mkPackageOption pkgs "scour" { };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
default = true;
|
||||||
|
description = "Do minification on public static files";
|
||||||
|
};
|
||||||
|
|
||||||
podConfig = mkOption {
|
podConfig = mkOption {
|
||||||
type = types.submodule {
|
type = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
|
|
|
@ -6,9 +6,37 @@
|
||||||
, phpCfg ? null
|
, phpCfg ? null
|
||||||
, withPgsql ? true # “strongly recommended” according to docs
|
, withPgsql ? true # “strongly recommended” according to docs
|
||||||
, withMysql ? false
|
, withMysql ? false
|
||||||
|
, minifyStaticFiles ? false # default files are often not minified
|
||||||
|
, parallel
|
||||||
|
, esbuild
|
||||||
|
, lightningcss
|
||||||
|
, scour
|
||||||
, nixosTests
|
, nixosTests
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
let
|
||||||
|
defaultMinifyOpts = {
|
||||||
|
script = {
|
||||||
|
enable = false;
|
||||||
|
target = "es2021";
|
||||||
|
};
|
||||||
|
style = {
|
||||||
|
enable = false;
|
||||||
|
browserslist = "defaults, Firefox ESR, last 20 Firefox major versions, last 20 Chrome major versions, last 3 Safari major versions, last 1 KaiOS version, and supports css-variables";
|
||||||
|
};
|
||||||
|
svg = {
|
||||||
|
enable = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
minify = lib.recursiveUpdate defaultMinifyOpts
|
||||||
|
(if lib.isBool minifyStaticFiles && minifyStaticFiles then
|
||||||
|
{ script.enable = true; style.enable = true; svg.enable = true; }
|
||||||
|
else if lib.isAttrs minifyStaticFiles then
|
||||||
|
lib.filterAttrsRecursive (_: v: v != null) minifyStaticFiles
|
||||||
|
else
|
||||||
|
{ });
|
||||||
|
in
|
||||||
php.buildComposerProject (finalAttrs: {
|
php.buildComposerProject (finalAttrs: {
|
||||||
pname = "movim";
|
pname = "movim";
|
||||||
version = "0.23.0.20240328";
|
version = "0.23.0.20240328";
|
||||||
|
@ -31,6 +59,12 @@ php.buildComposerProject (finalAttrs: {
|
||||||
extraConfig = phpCfg;
|
extraConfig = phpCfg;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
nativeBuildInputs =
|
||||||
|
lib.optional (lib.any (x: x.enable) (lib.attrValues minify)) parallel
|
||||||
|
++ lib.optional minify.script.enable esbuild
|
||||||
|
++ lib.optional minify.style.enable lightningcss
|
||||||
|
++ lib.optional minify.svg.enable scour;
|
||||||
|
|
||||||
# no listed license
|
# no listed license
|
||||||
# pinned commonmark
|
# pinned commonmark
|
||||||
composerStrictValidation = false;
|
composerStrictValidation = false;
|
||||||
|
@ -59,6 +93,42 @@ php.buildComposerProject (finalAttrs: {
|
||||||
--replace-fail "Imagick::ALPHACHANNEL_ACTIVATE" "Imagick::ALPHACHANNEL_ON"
|
--replace-fail "Imagick::ALPHACHANNEL_ACTIVATE" "Imagick::ALPHACHANNEL_ON"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
preBuild = lib.optionalString minify.script.enable ''
|
||||||
|
find ./public -type f -iname "*.js" \
|
||||||
|
| parallel ${lib.escapeShellArgs [
|
||||||
|
"--will-cite"
|
||||||
|
"-j $NIX_BUILD_CORES"
|
||||||
|
''
|
||||||
|
tmp="$(mktemp)"
|
||||||
|
esbuild {} --minify --target=${lib.escapeShellArg minify.script.target} --outfile=$tmp
|
||||||
|
[[ "$(stat -c %s $tmp)" -lt "$(stat -c %s {})" ]] && mv $tmp {}
|
||||||
|
''
|
||||||
|
]}
|
||||||
|
'' + lib.optionalString minify.style.enable ''
|
||||||
|
export BROWSERLIST=${lib.escapeShellArg minify.style.browserslist}
|
||||||
|
find ./public -type f -iname "*.css" \
|
||||||
|
| parallel ${lib.escapeShellArgs [
|
||||||
|
"--will-cite"
|
||||||
|
"-j $NIX_BUILD_CORES"
|
||||||
|
''
|
||||||
|
tmp="$(mktemp)"
|
||||||
|
lightningcss {} --minify --browserslist --output-file=$tmp
|
||||||
|
[[ "$(stat -c %s $tmp)" -lt "$(stat -c %s {})" ]] && mv $tmp {}
|
||||||
|
''
|
||||||
|
]}
|
||||||
|
'' + lib.optionalString minify.svg.enable ''
|
||||||
|
find ./public -type f -iname "*.svg" -a -not -path "*/emojis/*" \
|
||||||
|
| parallel ${lib.escapeShellArgs [
|
||||||
|
"--will-cite"
|
||||||
|
"-j $NIX_BUILD_CORES"
|
||||||
|
''
|
||||||
|
tmp="$(mktemp)"
|
||||||
|
scour -i {} -o $tmp --disable-style-to-xml --enable-comment-stripping --enable-viewboxing --indent=tab
|
||||||
|
[[ "$(stat -c %s $tmp)" -lt "$(stat -c %s {})" ]] && mv $tmp {}
|
||||||
|
''
|
||||||
|
]}
|
||||||
|
'';
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
mkdir -p $out/bin
|
mkdir -p $out/bin
|
||||||
echo "#!${lib.getExe dash}" > $out/bin/movim
|
echo "#!${lib.getExe dash}" > $out/bin/movim
|
||||||
|
|
Loading…
Reference in a new issue