From 43fbf5f6f6f6567bc73a5054df1f76c8b5388cd3 Mon Sep 17 00:00:00 2001 From: maxstrb Date: Mon, 5 Jan 2026 23:40:20 +0100 Subject: [PATCH] non important commit --- create-project.nix | 12 ++++ .../modules/create-project/create-project.nix | 6 +- main.nu | 59 +++++++++++++++++++ 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 create-project.nix create mode 100644 main.nu diff --git a/create-project.nix b/create-project.nix new file mode 100644 index 0000000..ba45fac --- /dev/null +++ b/create-project.nix @@ -0,0 +1,12 @@ +{pkgs, ...}: let + blueprints = ../project-blueprints; + mainScript = builtins.readFile ./main.nu; + scriptWithSubstitutions = + builtins.replaceStrings + ["@BLUEPRINTS@"] + ["${blueprints}"] + mainScript; +in '' + #!${pkgs.nushell}/bin/nu + ${scriptWithSubstitutions} +'' diff --git a/home/modules/create-project/create-project.nix b/home/modules/create-project/create-project.nix index b2a94fe..7f11962 100644 --- a/home/modules/create-project/create-project.nix +++ b/home/modules/create-project/create-project.nix @@ -16,7 +16,7 @@ in { ] { if $name == null or $type == null { - print "Usage: create-project [Options: -l]" + print "Usage: create-project [Options: -l]" exit 1 } @@ -40,8 +40,8 @@ in { mkdir $name cd $name - if ($blueprint_dir | path expand | ls $in | length) > 0 { - glob $"($blueprint_dir)/*" | each { ||file| cp $file . } + if (ls $blueprint_dir | length) > 0 { + glob $"($blueprint_dir)/*" | each { |file| cp $file . } chmod -R u+w . } diff --git a/main.nu b/main.nu new file mode 100644 index 0000000..5ac95b5 --- /dev/null +++ b/main.nu @@ -0,0 +1,59 @@ +def main [ + name?: string + type?: string + --local (-l) +] { + if $name == null or $type == null { + print "Usage: create-project [Options: -l]" + exit 1 + } + + if ($name | str contains "/") or ($name | str contains ".") { + print "This is not a valid name for a project" + exit 1 + } + + if ($type | str contains "/") or ($type | str contains ".") { + print "This is not a valid project type" + exit 1 + } + + let blueprint_dir = $"@BLUEPRINTS@/($type)" + + if ($blueprint_dir | path type) != "dir" { + print "This project type doesn't exist" + exit 1 + } + + mkdir $name + cd $name + + if (ls $blueprint_dir | length) > 0 { + glob $"($blueprint_dir)/*" | each { |file| cp $file . } + ^chmod -R u+w . + } + + if ("./init.sh" | path type) == "file" { + bash "./init.sh" $name + rm "init.sh" + } + + echo "use flake" | save .envrc + direnv allow + + git init + git add . + git commit -m "Project setup" + + if $local { + print "You are all done" + exit 0 + } + + tea repos create --name $name + git remote add origin $"https://git.stribrny.org/max_ag/($name).git" + git push -u origin main + + print "You are all done" + exit 0 +}