9 Commits

10 changed files with 118 additions and 82 deletions

View File

@@ -1,12 +1,10 @@
name: Docker name: Deploy Docker Image to Github Container Registry
on: on:
push: push:
branches: ["main"] branches: ["main"]
paths: paths:
- "Cargo.toml" - "Cargo.toml"
pull_request:
branches: ["main"]
env: env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always

View File

@@ -1,29 +0,0 @@
name: Rust
on:
push:
branches: [ "main" ]
paths:
- 'Cargo.toml'
pull_request:
branches: [ "main" ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: |
cargo publish --verbose

26
.github/workflows/rust_deploy.yml vendored Normal file
View File

@@ -0,0 +1,26 @@
name: Deploy Rust to Crates.io
on:
push:
branches: ["main"]
paths:
- "Cargo.toml"
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: |
cargo publish --verbose

24
.github/workflows/rust_test.yml vendored Normal file
View File

@@ -0,0 +1,24 @@
name: Test Rust
on:
push:
branches: ["main", "develop"]
paths:
- "./src/**"
- "./Cargo.toml"
pull_request:
branches: ["main", "develop"]
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

37
Cargo.lock generated
View File

@@ -630,17 +630,6 @@ dependencies = [
"unicode-width", "unicode-width",
] ]
[[package]]
name = "colored"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd"
dependencies = [
"atty",
"lazy_static",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "concurrent-queue" name = "concurrent-queue"
version = "2.1.0" version = "2.1.0"
@@ -864,11 +853,11 @@ dependencies = [
"bytes", "bytes",
"clap 4.1.8", "clap 4.1.8",
"clap_complete", "clap_complete",
"colored",
"futures", "futures",
"home", "home",
"live-server", "live-server",
"notify 5.1.0", "notify 5.1.0",
"nu-ansi-term",
"regex", "regex",
"reqwest", "reqwest",
"text_io", "text_io",
@@ -1872,6 +1861,15 @@ dependencies = [
"windows-sys 0.42.0", "windows-sys 0.42.0",
] ]
[[package]]
name = "nu-ansi-term"
version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [
"windows-sys 0.61.2",
]
[[package]] [[package]]
name = "num-integer" name = "num-integer"
version = "0.1.45" version = "0.1.45"
@@ -3206,6 +3204,12 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.42.0" version = "0.42.0"
@@ -3230,6 +3234,15 @@ dependencies = [
"windows-targets", "windows-targets",
] ]
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
[[package]] [[package]]
name = "windows-targets" name = "windows-targets"
version = "0.42.1" version = "0.42.1"

View File

@@ -12,7 +12,6 @@ exclude = [".gitlab", ".github"]
[dependencies] [dependencies]
bytes = "1.4.0" bytes = "1.4.0"
clap = { version = "4.1.8", features = ["derive"] } clap = { version = "4.1.8", features = ["derive"] }
colored = "2.0.0"
futures = "0.3.26" futures = "0.3.26"
home = "0.5.4" home = "0.5.4"
live-server = "0.6.0" live-server = "0.6.0"
@@ -23,3 +22,4 @@ text_io = "0.1.12"
tokio = { version = "1.26.0", features = ["full"] } tokio = { version = "1.26.0", features = ["full"] }
zip-extract = "0.1.1" zip-extract = "0.1.1"
clap_complete = "4.1.4" clap_complete = "4.1.4"
nu-ansi-term = "0.50.3"

View File

@@ -12,9 +12,13 @@ fn exec_command(command: &mut process::Command) -> Result<(), String> {
} }
} else { } else {
println!("{}", result.unwrap_err()); println!("{}", result.unwrap_err());
return Err(
"asciidoctor not installed. For more information run docki health!".to_string(), let binary_name = command.get_program().to_str().unwrap_or("Something is");
);
return Err(format!(
"{} not installed. For more information run docki health!",
binary_name
));
} }
} }
@@ -31,11 +35,11 @@ fn asciidoctor_docs(in_path: &str, out_path: &str) -> process::Command {
fn asciidoctor_slides(in_path: &str, out_path: &str, offline_reveal: bool) -> process::Command { fn asciidoctor_slides(in_path: &str, out_path: &str, offline_reveal: bool) -> process::Command {
let mut command = process::Command::new(format!("asciidoctor-revealjs")); let mut command = process::Command::new(format!("asciidoctor-revealjs"));
let out_dir = parent_path(out_path); let out_dir = parent_path(out_path);
let revealjs_path = if offline_reveal { let revealjs_path = if offline_reveal {
path_between(out_dir.to_string(), "./dist/slides/revealjs".to_string()) path_between(out_dir.to_string(), "./dist/slides/revealjs".to_string())
} else { } else {
"https://cdn.jsdelivr.net/npm/reveal.js@5.2.1".to_string() "https://cdn.jsdelivr.net/npm/reveal.js@5.2.1".to_string()
}; };
command command
.arg(format!("{in_path}")) .arg(format!("{in_path}"))

View File

@@ -1,5 +1,5 @@
use std::{process::Command, io::ErrorKind}; use nu_ansi_term::Color::{LightGray, LightGreen, LightRed};
use colored::Colorize; use std::{io::ErrorKind, process::Command};
const INFO_ASCIIDOC: &str = " const INFO_ASCIIDOC: &str = "
Install the binary with your package manager! Install the binary with your package manager!
@@ -37,7 +37,7 @@ fn check_reveal() -> () {
} }
fn reveal_is_installed() -> bool { fn reveal_is_installed() -> bool {
return check_command("asciidoctor-revealjs") return check_command("asciidoctor-revealjs");
} }
fn check_asciidoc() -> () { fn check_asciidoc() -> () {
@@ -49,23 +49,21 @@ fn check_asciidoc() -> () {
} }
fn asciidoc_is_installed() -> bool { fn asciidoc_is_installed() -> bool {
return check_command("asciidoctor") return check_command("asciidoctor");
} }
fn check_command(command: &str) -> bool { fn check_command(command: &str) -> bool {
return match Command::new(command) return match Command::new(command).output() {
.output() {
Ok(_) => true, Ok(_) => true,
Err(e) => ErrorKind::NotFound != e.kind() Err(e) => ErrorKind::NotFound != e.kind(),
} };
} }
fn print_health_ok(name: &str) { fn print_health_ok(name: &str) {
println!("- ✔️ {}", name.bright_green()); println!("- ✔️ {}", LightGreen.paint(name));
} }
fn print_health_not_ok(name: &str, info: &str) { fn print_health_not_ok(name: &str, info: &str) {
println!("- ❗{}", name.bright_red()); println!("- ❗{}", LightRed.paint(name));
println!("{}", info.bright_black()) println!("{}", LightGray.paint(info))
} }

View File

@@ -1,4 +1,4 @@
use colored::Colorize; use nu_ansi_term::Color::Green;
use futures::StreamExt; use futures::StreamExt;
use live_server::listen; use live_server::listen;
use notify::{ use notify::{
@@ -21,15 +21,18 @@ async fn watch_and_build() {
.expect("something went wrong") .expect("something went wrong")
} }
async fn start_server(port: Option<u16>) { async fn start_server(port: Option<u16>) {
let unwrapped_port = port.unwrap_or(8080); let port = port.unwrap_or(8080);
let link = &format!("http://localhost:{}", port);
let hyperlink = Green.paint(link).hyperlink(link);
println!( println!(
"\nServing at {}{} ", "\nServing at {}",
"http://localhost:".bold(), hyperlink
unwrapped_port.to_string().bold()
); );
let Ok(()) = listen("localhost", port.unwrap_or(8080), "./dist").await else { let Ok(()) = listen("localhost", port, "./dist").await else {
panic!("could not start server") panic!("could not start server")
}; };
} }

View File

@@ -1,20 +1,19 @@
use colored::Colorize; use nu_ansi_term::Color::LightGreen;
use nu_ansi_term::Color::LightRed;
use nu_ansi_term::Style;
pub fn display_status(context1: &str, context2: &str, in_path: &str, out_path: &str) { pub fn display_status(context1: &str, context2: &str, in_path: &str, out_path: &str) {
let colored_context = color_context(context2); let colored_context = if context2 == "Error" {
LightRed.paint(context2)
} else {
LightGreen.paint(context2)
};
println!( println!(
"({}) [{}] {} -> {}", "({}) [{}] {} -> {}",
context1.bold(), Style::new().paint(context1),
colored_context, colored_context,
in_path, in_path,
out_path out_path
); );
} }
fn color_context(context: &str) -> colored::ColoredString {
if context == "Error" {
return context.bright_red()
} else {
return context.bright_green()
}
}