Merge pull request #260000 from lelgenio/init-blade-formatter

blade-formatter: init at 1.41.1
This commit is contained in:
Peder Bergebakken Sundt 2024-06-12 01:19:56 +02:00 committed by GitHub
commit 0f817f8862
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13326 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,67 @@
{
lib,
buildNpmPackage,
fetchFromGitHub,
testers,
writeText,
runCommand,
blade-formatter,
nodejs,
}:
buildNpmPackage rec {
pname = "blade-formatter";
version = "1.41.1";
src = fetchFromGitHub {
owner = "shufo";
repo = "blade-formatter";
rev = "v${version}";
hash = "sha256-iaWpIa+H+ocAXGc042PfmCu9UcJZeso9ripWB2/1oTs=";
};
postPatch = ''
cp ${./package-lock.json} ./package-lock.json
'';
npmDepsHash = "sha256-wEz0DTbg+Fdmsf0Qyeu9QS+I8gkPJeaJC/3HuP913og=";
passthru = {
updateScript = ./update.sh;
tests = {
version = testers.testVersion {
package = blade-formatter;
command = "blade-formatter --version";
};
simple = testers.testEqualContents {
assertion = "blade-formatter formats a basic blade file";
expected = writeText "expected" ''
@if (true)
Hello world!
@endif
'';
actual =
runCommand "actual"
{
nativeBuildInputs = [ blade-formatter ];
base = writeText "base" ''
@if( true ) Hello world! @endif
'';
}
''
blade-formatter $base > $out
'';
};
};
};
meta = {
description = "Laravel Blade template formatter";
homepage = "https://github.com/shufo/blade-formatter";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ lelgenio ];
mainProgram = "blade-formatter";
inherit (nodejs.meta) platforms;
};
}

View File

@ -0,0 +1,38 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p ripgrep common-updater-scripts prefetch-npm-deps jq sd
set -xeu -o pipefail
PACKAGE_DIR="$(realpath "$(dirname "$0")")"
cd "$PACKAGE_DIR/.."
while ! test -f default.nix; do cd .. ; done
NIXPKGS_DIR="$PWD"
new_version="$(
list-git-tags --url=https://github.com/shufo/blade-formatter \
| rg '^v([\d.]*)' -r '$1' \
| sort --version-sort \
| tail -n1
)"
cd "$NIXPKGS_DIR"
update-source-version blade-formatter "$new_version"
TMPDIR="$(mktemp -d)"
cd "$TMPDIR"
src="$(nix-build --no-link "$NIXPKGS_DIR" -A blade-formatter.src)"
cp $src/package.json .
npm update
cp ./package-lock.json "$PACKAGE_DIR"
prev_npm_hash="$(nix-instantiate "$NIXPKGS_DIR" \
--eval --json \
-A blade-formatter.npmDepsHash \
| jq -r .
)"
new_npm_hash="$(prefetch-npm-deps ./package-lock.json)"
sd --fixed-strings "$prev_npm_hash" "$new_npm_hash" "$PACKAGE_DIR/package.nix"
rm -rf "$TMPDIR"