add hjq scroll
This commit is contained in:
parent
701e5d138a
commit
d92bc3b437
4 changed files with 54 additions and 20 deletions
20
flake.nix
20
flake.nix
|
|
@ -19,11 +19,16 @@
|
|||
in "${arch}-${vendor}-${sys}";
|
||||
|
||||
target = toDenoTarget system;
|
||||
hjq = import ./shelf/hjq/package.nix {
|
||||
inherit pkgs;
|
||||
inherit target;
|
||||
};
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
deno
|
||||
hjq
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
|
|
@ -37,20 +42,7 @@
|
|||
# unfortunately this derivation is impure because
|
||||
# managing deno's deps is HARD, so
|
||||
# nix build --option sanbox relaxed
|
||||
packages.default = import ./package.nix {
|
||||
inherit pkgs;
|
||||
inherit target;
|
||||
|
||||
name = "test-grimu-r-deno-app";
|
||||
};
|
||||
|
||||
apps.default = {
|
||||
type = "app";
|
||||
program = toString (pkgs.writeShellScript "run-deno-app" ''
|
||||
export DENO_DIR="./.deno_cache"
|
||||
exec ${pkgs.deno}/bin/deno run main.ts "$@"
|
||||
'');
|
||||
};
|
||||
packages.default = hjq;
|
||||
|
||||
});
|
||||
}
|
||||
|
|
|
|||
2
main.ts
2
main.ts
|
|
@ -1,2 +0,0 @@
|
|||
import jqModule from "npm:jq-web";
|
||||
console.log("I'M ALIVE");
|
||||
44
shelf/hjq/main.ts
Normal file
44
shelf/hjq/main.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// a basic drop-in replacement for jq to handle HJSON
|
||||
// tries to preserve comments but doesn't do a very good job :(
|
||||
|
||||
import Hjson from "npm:hjson";
|
||||
import jqModule from "npm:jq-web";
|
||||
import fs from "node:fs";
|
||||
|
||||
const jq = await jqModule;
|
||||
|
||||
var filter = process.argv[2];
|
||||
if (!filter) {
|
||||
filter = '.';
|
||||
}
|
||||
|
||||
const input = fs.readFileSync(0, 'utf8');
|
||||
|
||||
try {
|
||||
const data = Hjson.parse(input, { keepWsc: true });
|
||||
|
||||
const result = jq.json(data, filter);
|
||||
|
||||
// Only try to preserve comments if the result is an object or array
|
||||
if (result !== null && typeof result === 'object') {
|
||||
// Extract comments before transformation
|
||||
const comments = Hjson.comments.extract(data);
|
||||
|
||||
// Merge comments back into the transformed result
|
||||
if (comments) {
|
||||
Hjson.comments.merge(comments, result);
|
||||
}
|
||||
|
||||
const output = Hjson.stringify(result, {
|
||||
keepWsc: true,
|
||||
bracesSameLine: true
|
||||
});
|
||||
|
||||
console.log(output);
|
||||
} else {
|
||||
console.log(JSON.stringify(result));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{ pkgs, target, name }:
|
||||
{ pkgs, target }:
|
||||
pkgs.stdenv.mkDerivation rec {
|
||||
pname = name;
|
||||
pname = "hjq";
|
||||
version = "0.1.0";
|
||||
src = ./.;
|
||||
|
||||
|
|
@ -29,12 +29,12 @@ pkgs.stdenv.mkDerivation rec {
|
|||
|
||||
export DENORT_BIN="$TMPDIR/denort/denort"
|
||||
|
||||
deno compile --output app main.ts --target=${target}
|
||||
deno compile --target=${target} --output app main.ts
|
||||
runHook postBuild
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp app $out/bin/${name}
|
||||
cp app $out/bin/${pname}
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue