From 4b31c4513fac5aef1ccc8f641387c16e6e34fd36 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Fri, 11 Apr 2025 14:51:25 +0200 Subject: [PATCH] Replace scripts nu files by one --- backend/watch_scss.nu | 1 - check_cargo_dependencies_upgrade.nu | 2 - deploy.nu | 38 ----------- do.nu | 102 ++++++++++++++++++++++++++++ generate_doc.nu | 1 - 5 files changed, 102 insertions(+), 42 deletions(-) delete mode 100644 backend/watch_scss.nu delete mode 100644 check_cargo_dependencies_upgrade.nu delete mode 100644 deploy.nu create mode 100644 do.nu delete mode 100644 generate_doc.nu diff --git a/backend/watch_scss.nu b/backend/watch_scss.nu deleted file mode 100644 index 53d8952..0000000 --- a/backend/watch_scss.nu +++ /dev/null @@ -1 +0,0 @@ -sass --no-source-map -w scss/style_dark.scss:static/style_dark.css scss/style_light.scss:static/style_light.css diff --git a/check_cargo_dependencies_upgrade.nu b/check_cargo_dependencies_upgrade.nu deleted file mode 100644 index 7ada4aa..0000000 --- a/check_cargo_dependencies_upgrade.nu +++ /dev/null @@ -1,2 +0,0 @@ -# It needs cargo-edit: https://crates.io/crates/cargo-edit . -cargo upgrade --dry-run --verbose \ No newline at end of file diff --git a/deploy.nu b/deploy.nu deleted file mode 100644 index 01910aa..0000000 --- a/deploy.nu +++ /dev/null @@ -1,38 +0,0 @@ -def main [host: string, destination: string, ssh_key: path] { - let ssh_args = [-i $ssh_key $host] - let scp_args = [-r -i $ssh_key] - - # For raspberry pi zero 1: "arm-unknown-linux-gnueabihf" - let target = "aarch64-unknown-linux-gnu" - - def invoke_ssh [command: list] { - let args = $ssh_args ++ $command - print $"Executing: ssh ($args)" - ssh ...$args - } - - def copy_ssh [source: string, destination: string] { - let args = $scp_args ++ [$source $"($host):($destination)"] - print $"Executing: scp ($args)" - scp ...$args - } - - cd frontend - trunk build --release - cd .. - - cd backend - cargo test - cargo build --target $target --release - cd .. - - invoke_ssh [sudo systemctl stop recipes] - copy_ssh ./target/($target)/release/recipes $destination - invoke_ssh [rm -rf recipes/static] - copy_ssh ./backend/static/ $destination - copy_ssh ./backend/sql/ $destination - copy_ssh ./backend/translation.ron $destination - invoke_ssh [chmod u+x recipes/recipes] - invoke_ssh [sudo systemctl start recipes] - print "Deployment finished" -} diff --git a/do.nu b/do.nu new file mode 100644 index 0000000..2c3ee04 --- /dev/null +++ b/do.nu @@ -0,0 +1,102 @@ +# Build the frontend dans backend in parallel (debug mode). +def "main build" [] { + build +} + +# Build the frontend dans backend in parallel then run the backend (debug mode). +def "main run" [] { + run +} + +# Generate the documentation in 'target/doc'. +def "main doc" [] { + cargo doc --document-private-items --no-deps +} + +# Build in release then copy the files to a given destination using scp (ssh). +def "main deploy" [ + host: string, # The host addrese, for example: "user@host.com" + destination: string, # The local path, for example: "~/recipes" + ssh_key: path # The path to the ssh key, for example: "~/.ssh/id_rsa.pub" + target: string = "" # The target architecture, for example: "aarch64-unknown-linux-gnu" +] { + let ssh_args = [-i $ssh_key $host] + let scp_args = [-r -i $ssh_key] + + def invoke_ssh [command: list] { + let args = $ssh_args ++ $command + print $"Executing: ssh ($args)" + ssh ...$args + } + + def copy_ssh [source: string, destination: string] { + let args = $scp_args ++ [$source $"($host):($destination)"] + print $"Executing: scp ($args)" + scp ...$args + } + + cd frontend + trunk build --release + cd .. + + cd backend + cargo test + + if target != "" { + cargo build --target $target --release + } else { + cargo build --release + } + cd .. + + invoke_ssh [sudo systemctl stop recipes] + copy_ssh ./target/($target)/release/recipes $destination + invoke_ssh [rm -rf recipes/static] + copy_ssh ./backend/static/ $destination + copy_ssh ./backend/sql/ $destination + copy_ssh ./backend/translation.ron $destination + invoke_ssh [chmod u+x recipes/recipes] + invoke_ssh [sudo systemctl start recipes] + print "Deployment finished" +} + +# Watch modifications on SASS files (in backend/scss/) to generate the CSS files (in backend/static). +def "main watch-scss" [] { + sass --no-source-map -w backend/scss/style_dark.scss:backend/static/style_dark.css backend/scss/style_light.scss:backend/static/style_light.css +} + +def main [] { + nu do.nu --help +} + +def build [] { + [ + {|| build_frontend } + {|| build_backend } + ] | par-each { |c| do $c } +} + +def build_frontend [] { + cd frontend + trunk build + cd .. +} + +def build_backend [] { + cd backend + cargo build + cd .. +} + +def run [] { + [ + {|| build_frontend } + {|| run_backend } + ] | par-each { |c| do $c } +} + +def run_backend [] { + cd backend + cargo run + cd .. +} \ No newline at end of file diff --git a/generate_doc.nu b/generate_doc.nu deleted file mode 100644 index 227c593..0000000 --- a/generate_doc.nu +++ /dev/null @@ -1 +0,0 @@ -cargo doc --document-private-items --no-deps \ No newline at end of file