initial commit
This commit is contained in:
commit
8222743519
9 changed files with 314 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
.deno_cache
|
||||
.emacs*
|
||||
.oc_local
|
||||
result
|
||||
19
AGENTS.md
Normal file
19
AGENTS.md
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# AGENTS.md
|
||||
|
||||
## Nix
|
||||
- Enter a dev shell with `nix develop`
|
||||
- Assume nothing will work outside of the shell
|
||||
- See/edit `flake.nix` for relevant concerns
|
||||
|
||||
## Deno
|
||||
- Manage dependencies with `deno add` and `deno remove` in `./src` directory
|
||||
- Deno maintains its own `deno.lock` which Nix picks up
|
||||
- IMPORTANT: never use JSR dependencies, only NPM
|
||||
- Example: `deno add npm:chalk` then `import chalk from "chalk";` in `.ts` files
|
||||
|
||||
## Project conventions
|
||||
- Entry points are CLI subcommands (`./src/main.ts`)
|
||||
- Use `@stricli/core` for CLI
|
||||
- Prefer to do things by running shell commands via `dax-sh`
|
||||
- Verbosity implies `$.setPrintCommand(true)` for `dax-sh` to output what it runs
|
||||
- Logs always go to `stderr` so that `stdout` can be redirected to a file safely
|
||||
93
flake.lock
generated
Normal file
93
flake.lock
generated
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
{
|
||||
"nodes": {
|
||||
"deno-with-packages": {
|
||||
"locked": {
|
||||
"lastModified": 1765960297,
|
||||
"narHash": "sha256-JLb0HH1GdqqFJg82ZQ3vzS7dVVKC3kwZVjg44WGN5mQ=",
|
||||
"owner": "voleum-org",
|
||||
"repo": "deno-with-packages",
|
||||
"rev": "4cef3f1fd0eabe8d0589c61952b965cfd369bffa",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "voleum-org",
|
||||
"repo": "deno-with-packages",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": "nixpkgs-lib"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1765835352,
|
||||
"narHash": "sha256-XswHlK/Qtjasvhd1nOa1e8MgZ8GS//jBoTqWtrS1Giw=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "a34fae9c08a15ad73f295041fec82323541400a9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-root": {
|
||||
"locked": {
|
||||
"lastModified": 1723604017,
|
||||
"narHash": "sha256-rBtQ8gg+Dn4Sx/s+pvjdq3CB2wQNzx9XGFq/JVGCB6k=",
|
||||
"owner": "srid",
|
||||
"repo": "flake-root",
|
||||
"rev": "b759a56851e10cb13f6b8e5698af7b59c44be26e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "srid",
|
||||
"repo": "flake-root",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1765934234,
|
||||
"narHash": "sha256-pJjWUzNnjbIAMIc5gRFUuKCDQ9S1cuh3b2hKgA7Mc4A=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "af84f9d270d404c17699522fab95bbf928a2d92f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-lib": {
|
||||
"locked": {
|
||||
"lastModified": 1765674936,
|
||||
"narHash": "sha256-k00uTP4JNfmejrCLJOwdObYC9jHRrr/5M/a/8L2EIdo=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"rev": "2075416fcb47225d9b68ac469a5c4801a9c4dd85",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"deno-with-packages": "deno-with-packages",
|
||||
"flake-parts": "flake-parts",
|
||||
"flake-root": "flake-root",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
36
flake.nix
Normal file
36
flake.nix
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
deno-with-packages.url = "github:voleum-org/deno-with-packages";
|
||||
flake-root.url = "github:srid/flake-root";
|
||||
};
|
||||
|
||||
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
imports = [
|
||||
inputs.flake-root.flakeModule
|
||||
inputs.deno-with-packages.flakeModule
|
||||
];
|
||||
|
||||
systems = [ "x86_64-linux" ];
|
||||
|
||||
perSystem = { pkgs, config, ... }:
|
||||
let
|
||||
# rename me
|
||||
name = "deno-cli-package";
|
||||
package = import ./package.nix { inherit pkgs config name; };
|
||||
in {
|
||||
deno-with-packages = {
|
||||
lockfiles = [ ./src/deno.lock ];
|
||||
dir = "$FLAKE_ROOT/.deno_cache";
|
||||
};
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
inputsFrom = [ config.flake-root.devShell ];
|
||||
packages = [ package config.deno-with-packages.package ];
|
||||
};
|
||||
|
||||
packages.default = package;
|
||||
};
|
||||
};
|
||||
}
|
||||
18
package.nix
Normal file
18
package.nix
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{ pkgs, config, name }:
|
||||
pkgs.stdenv.mkDerivation {
|
||||
inherit name;
|
||||
src = ./src;
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
|
||||
cp -r * $out
|
||||
# This is meant to be executed from inside a devShell with Deno set up
|
||||
cat > $out/bin/${name} <<EOF
|
||||
#!/bin/sh
|
||||
cd ${builtins.placeholder "out"}
|
||||
exec ${config.deno-with-packages.package}/bin/deno task --quiet run "\$@"
|
||||
EOF
|
||||
chmod +x $out/bin/${name}
|
||||
'';
|
||||
}
|
||||
10
src/deno.json
Normal file
10
src/deno.json
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"tasks": {
|
||||
"run": "deno run -A main.ts"
|
||||
},
|
||||
"imports": {
|
||||
"@stricli/core": "npm:@stricli/core@1.2.4",
|
||||
"chalk": "npm:chalk@^5.6.2",
|
||||
"dax-sh": "npm:dax-sh@0.44.1",
|
||||
}
|
||||
}
|
||||
63
src/deno.lock
generated
Normal file
63
src/deno.lock
generated
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
{
|
||||
"version": "5",
|
||||
"specifiers": {
|
||||
"npm:@stricli/core@1.2.4": "1.2.4",
|
||||
"npm:@types/node@*": "22.15.15",
|
||||
"npm:chalk@^5.6.2": "5.6.2",
|
||||
"npm:dax-sh@0.44.1": "0.44.1"
|
||||
},
|
||||
"npm": {
|
||||
"@deno/shim-deno-test@0.5.0": {
|
||||
"integrity": "sha512-4nMhecpGlPi0cSzT67L+Tm+GOJqvuk8gqHBziqcUQOarnuIax1z96/gJHCSIz2Z0zhxE6Rzwb3IZXPtFh51j+w=="
|
||||
},
|
||||
"@deno/shim-deno@0.19.2": {
|
||||
"integrity": "sha512-q3VTHl44ad8T2Tw2SpeAvghdGOjlnLPDNO2cpOxwMrBE/PVas6geWpbpIgrM+czOCH0yejp0yi8OaTuB+NU40Q==",
|
||||
"dependencies": [
|
||||
"@deno/shim-deno-test",
|
||||
"which"
|
||||
]
|
||||
},
|
||||
"@stricli/core@1.2.4": {
|
||||
"integrity": "sha512-ujvJDQpC2FINWvlTjkFz+Qzw/vsB8p/LyZEW18idisqIyjXR6yb+sF3WTUPksl+5ZON5r4fHQnCqQWnJxeqSzg=="
|
||||
},
|
||||
"@types/node@22.15.15": {
|
||||
"integrity": "sha512-R5muMcZob3/Jjchn5LcO8jdKwSCbzqmPB6ruBxMcf9kbxtniZHP327s6C37iOfuw8mbKK3cAQa7sEl7afLrQ8A==",
|
||||
"dependencies": [
|
||||
"undici-types@6.21.0"
|
||||
]
|
||||
},
|
||||
"chalk@5.6.2": {
|
||||
"integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA=="
|
||||
},
|
||||
"dax-sh@0.44.1": {
|
||||
"integrity": "sha512-lUj0mA0LTO6CXUZmbUgFUhtlyowa+9hmg/Z4xeU8/FIdkM1oj541iZR5MELYZdX1IOFD51RLch8uiOTOHzbfSA==",
|
||||
"dependencies": [
|
||||
"@deno/shim-deno",
|
||||
"undici-types@5.28.4"
|
||||
]
|
||||
},
|
||||
"isexe@3.1.1": {
|
||||
"integrity": "sha512-LpB/54B+/2J5hqQ7imZHfdU31OlgQqx7ZicVlkm9kzg9/w8GKLEcFfJl/t7DCEDueOyBAD6zCCwTO6Fzs0NoEQ=="
|
||||
},
|
||||
"undici-types@5.28.4": {
|
||||
"integrity": "sha512-3OeMF5Lyowe8VW0skf5qaIE7Or3yS9LS7fvMUI0gg4YxpIBVg0L8BxCmROw2CcYhSkpR68Epz7CGc8MPj94Uww=="
|
||||
},
|
||||
"undici-types@6.21.0": {
|
||||
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="
|
||||
},
|
||||
"which@4.0.0": {
|
||||
"integrity": "sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg==",
|
||||
"dependencies": [
|
||||
"isexe"
|
||||
],
|
||||
"bin": true
|
||||
}
|
||||
},
|
||||
"workspace": {
|
||||
"dependencies": [
|
||||
"npm:@stricli/core@1.2.4",
|
||||
"npm:chalk@^5.6.2",
|
||||
"npm:dax-sh@0.44.1"
|
||||
]
|
||||
}
|
||||
}
|
||||
44
src/impl.ts
Normal file
44
src/impl.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import $ from 'dax-sh';
|
||||
import chalk from "chalk";
|
||||
import { buildCommand } from "@stricli/core";
|
||||
|
||||
const log = {
|
||||
verbose: false,
|
||||
setup(verbose: boolean) {
|
||||
this.verbose = verbose;
|
||||
},
|
||||
info(msg: string, ...rest: any[]) {
|
||||
if (this.verbose) {
|
||||
console.error(chalk.blue(msg), ...rest);
|
||||
}
|
||||
},
|
||||
error(msg: string, ...rest: any[]) {
|
||||
console.error(chalk.blue(msg), ...rest);
|
||||
}
|
||||
};
|
||||
|
||||
function loggingSetup(verbose: boolean) {
|
||||
log.setup(verbose);
|
||||
|
||||
$.setPrintCommand(verbose);
|
||||
}
|
||||
|
||||
const commonFlags = {
|
||||
verbose: {
|
||||
brief: "Verbose output toggle",
|
||||
kind: "boolean" as const,
|
||||
default: false
|
||||
}
|
||||
};
|
||||
|
||||
export const hello = buildCommand({
|
||||
func: async (flags: { readonly verbose: boolean }) => {
|
||||
loggingSetup(flags.verbose);
|
||||
log.info("about to say hello");
|
||||
await $`echo hello`;
|
||||
},
|
||||
parameters: { flags: { ...commonFlags } },
|
||||
docs: {
|
||||
brief: "Prints 'hello'"
|
||||
}
|
||||
});
|
||||
27
src/main.ts
Normal file
27
src/main.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import {
|
||||
buildApplication,
|
||||
buildRouteMap,
|
||||
buildCommand,
|
||||
run
|
||||
} from '@stricli/core';
|
||||
import process from 'node:process';
|
||||
import $ from 'dax-sh';
|
||||
|
||||
import {
|
||||
hello
|
||||
} from './impl.ts';
|
||||
|
||||
const root = buildRouteMap({
|
||||
routes: { hello },
|
||||
docs: {
|
||||
brief: "Deno CLI program from template"
|
||||
}
|
||||
});
|
||||
|
||||
const app = buildApplication(root, {
|
||||
name: "deno-cli-package",
|
||||
});
|
||||
|
||||
await run(app, process.argv.slice(2), {
|
||||
process
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue