From 822274351954c6fb193a6ccaaed0bf2a3c7bd6de Mon Sep 17 00:00:00 2001 From: EatThePooh Date: Thu, 18 Dec 2025 11:40:05 +0700 Subject: [PATCH] initial commit --- .gitignore | 4 +++ AGENTS.md | 19 +++++++++++ flake.lock | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 36 ++++++++++++++++++++ package.nix | 18 ++++++++++ src/deno.json | 10 ++++++ src/deno.lock | 63 ++++++++++++++++++++++++++++++++++ src/impl.ts | 44 ++++++++++++++++++++++++ src/main.ts | 27 +++++++++++++++ 9 files changed, 314 insertions(+) create mode 100644 .gitignore create mode 100644 AGENTS.md create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 package.nix create mode 100644 src/deno.json create mode 100644 src/deno.lock create mode 100644 src/impl.ts create mode 100644 src/main.ts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3af79fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.deno_cache +.emacs* +.oc_local +result \ No newline at end of file diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..019f8e1 --- /dev/null +++ b/AGENTS.md @@ -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 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..bfacb4e --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..00c9d8a --- /dev/null +++ b/flake.nix @@ -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; + }; + }; +} diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..967228e --- /dev/null +++ b/package.nix @@ -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} < { + loggingSetup(flags.verbose); + log.info("about to say hello"); + await $`echo hello`; + }, + parameters: { flags: { ...commonFlags } }, + docs: { + brief: "Prints 'hello'" + } +}); diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..c4d62e4 --- /dev/null +++ b/src/main.ts @@ -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 +});