Compare commits
6 Commits
958856dcc0
...
6d2f76eb72
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d2f76eb72 | |||
| 451015d2f2 | |||
| 1a009bac61 | |||
| cc65ce3e7c | |||
| 926944e8dd | |||
| 78e2acb325 |
2
.github/workflows/docker.yml
vendored
2
.github/workflows/docker.yml
vendored
@@ -5,8 +5,6 @@ on:
|
||||
branches: ["main"]
|
||||
paths:
|
||||
- "Cargo.toml"
|
||||
pull_request:
|
||||
branches: ["main"]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
7
.github/workflows/rust.yml
vendored
7
.github/workflows/rust.yml
vendored
@@ -2,18 +2,15 @@ name: Rust
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
branches: ["main"]
|
||||
paths:
|
||||
- 'Cargo.toml'
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
- "Cargo.toml"
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
|
||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -859,7 +859,7 @@ checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
|
||||
|
||||
[[package]]
|
||||
name = "docki"
|
||||
version = "1.2.2"
|
||||
version = "1.2.3"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"clap 4.1.8",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "docki"
|
||||
version = "1.2.2"
|
||||
version = "1.2.3"
|
||||
edition = "2021"
|
||||
description = "cli for building and publishing documentation using asciidoctor"
|
||||
license-file = "LICENSE.txt"
|
||||
|
||||
@@ -16,10 +16,15 @@ pub enum ShellArg {
|
||||
#[derive(Subcommand)]
|
||||
pub enum CommandArg {
|
||||
/// Builds the documentation into a dist folder
|
||||
Build,
|
||||
Build {
|
||||
/// When set to true, docki will download revealjs before building the documentation.
|
||||
/// Otherwise it will use the cdn for revealjs
|
||||
#[arg(short, long)]
|
||||
offline_reveal: bool,
|
||||
},
|
||||
/// Checks if everything required for docki is installed
|
||||
Health,
|
||||
/// Helper command for installing asciidoctor-reveal-js
|
||||
/// Deprecated: Helper command for installing asciidoctor-reveal-js
|
||||
InstallReveal,
|
||||
/// Starts a Webserver with the live preview of the Documentation
|
||||
Serve {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use regex::Regex;
|
||||
use std::process;
|
||||
|
||||
fn exec_command(command: &mut process::Command) -> Result<(), String> {
|
||||
@@ -27,9 +28,14 @@ fn asciidoctor_docs(in_path: &str, out_path: &str) -> process::Command {
|
||||
return command;
|
||||
}
|
||||
|
||||
fn asciidoctor_slides(in_path: &str, out_path: &str) -> 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 revealjs_path = "/slides/revealjs";
|
||||
let out_dir = parent_path(out_path);
|
||||
let revealjs_path = if offline_reveal {
|
||||
path_between(out_dir.to_string(), "./dist/slides/revealjs".to_string())
|
||||
} else {
|
||||
"https://cdn.jsdelivr.net/npm/reveal.js@5.2.1".to_string()
|
||||
};
|
||||
|
||||
command
|
||||
.arg(format!("{in_path}"))
|
||||
@@ -40,13 +46,67 @@ fn asciidoctor_slides(in_path: &str, out_path: &str) -> process::Command {
|
||||
return command;
|
||||
}
|
||||
|
||||
fn parent_path(child_path: &str) -> String {
|
||||
let split: Vec<&str> = child_path.split("/").collect();
|
||||
let slice = &split[..split.len() - 1];
|
||||
return slice.join("/");
|
||||
}
|
||||
|
||||
pub fn path_between(from: String, to: String) -> String {
|
||||
let from_segments = transform_input_to_clone_split(&from);
|
||||
let to_segments = transform_input_to_clone_split(&to);
|
||||
let last_matching_index = matching_from_start(&from_segments, &to_segments);
|
||||
let number_of_backs = from_segments.len() - last_matching_index;
|
||||
let mut path_between = path_back(number_of_backs);
|
||||
let path_to_to_path = &to_segments[last_matching_index..];
|
||||
path_between.push_str(&path_to_to_path.join("/"));
|
||||
return path_between;
|
||||
}
|
||||
|
||||
fn transform_input_to_clone_split(input: &String) -> Vec<String> {
|
||||
let regex = Regex::new(r"/$").unwrap();
|
||||
let first_transformation = input.clone().replace("./", "");
|
||||
return regex
|
||||
.replace_all(&first_transformation, "")
|
||||
.to_string()
|
||||
.split("/")
|
||||
.collect::<Vec<&str>>()
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect();
|
||||
}
|
||||
|
||||
fn path_back(count: usize) -> String {
|
||||
let mut path = "".to_string();
|
||||
|
||||
for _ in 0..count {
|
||||
path.push_str("../");
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
pub fn matching_from_start(from_segments: &Vec<String>, to_segments: &Vec<String>) -> usize {
|
||||
for (index, from_segment) in from_segments.iter().enumerate() {
|
||||
if let Some(to_segment) = to_segments.get(index) {
|
||||
if from_segment != to_segment {
|
||||
return index;
|
||||
}
|
||||
} else {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
return from_segments.len();
|
||||
}
|
||||
|
||||
pub fn build_doc(in_path: &str, out_path: &str) -> Result<(), String> {
|
||||
let mut command = asciidoctor_docs(in_path, out_path);
|
||||
return exec_command(&mut command);
|
||||
}
|
||||
|
||||
pub fn build_slide(in_path: &str, out_path: &str) -> Result<(), String> {
|
||||
let mut command = asciidoctor_slides(in_path, out_path);
|
||||
pub fn build_slide(in_path: &str, out_path: &str, offline_reveal: bool) -> Result<(), String> {
|
||||
let mut command = asciidoctor_slides(in_path, out_path, offline_reveal);
|
||||
return exec_command(&mut command);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@ use super::fs_util;
|
||||
|
||||
pub mod asciidoctor;
|
||||
|
||||
pub fn docki_build(in_path: &str) -> DockiBuildResult {
|
||||
pub fn docki_build(in_path: &str, offline_reveal: bool) -> DockiBuildResult {
|
||||
let out_path = in_path.replace("/docs/", "/dist/");
|
||||
let convert_out_path = out_path.replace(".adoc", ".html");
|
||||
|
||||
if in_path.starts_with("./docs/slides/") && in_path.ends_with(".adoc") {
|
||||
if let Err(err) = build_slide(&in_path, &convert_out_path) {
|
||||
if let Err(err) = build_slide(&in_path, &convert_out_path, offline_reveal) {
|
||||
return DockiBuildResult::Err(err);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ pub fn docki_build(in_path: &str) -> DockiBuildResult {
|
||||
|
||||
DockiBuildResult::Doc(convert_out_path)
|
||||
} else {
|
||||
if in_path.starts_with("./docs/slides/revealjs") && !offline_reveal {
|
||||
return DockiBuildResult::Silent;
|
||||
}
|
||||
|
||||
if let Err(err) = copy(&in_path, &out_path) {
|
||||
return DockiBuildResult::Err(err);
|
||||
}
|
||||
@@ -46,4 +50,5 @@ pub enum DockiBuildResult {
|
||||
Doc(String),
|
||||
Copy(String),
|
||||
Err(String),
|
||||
Silent,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::executions::build_execution::BuildExecution;
|
||||
|
||||
pub async fn build() -> () {
|
||||
pub async fn build(offline_reveal: bool) -> () {
|
||||
let mut build_execution = BuildExecution::new();
|
||||
build_execution.execute().await.expect("build failed")
|
||||
build_execution.execute(offline_reveal).await.expect("build failed")
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ impl BuildExecution {
|
||||
};
|
||||
}
|
||||
|
||||
pub async fn execute(&mut self) -> Result<(), String> {
|
||||
pub async fn execute(&mut self, offline_reveal: bool) -> Result<(), String> {
|
||||
let path = "./docs/".to_string();
|
||||
|
||||
if !fs_util::directory_exists(&path) {
|
||||
@@ -30,21 +30,25 @@ impl BuildExecution {
|
||||
);
|
||||
}
|
||||
|
||||
if let Err(error) = Self::prepare().await {
|
||||
if let Err(error) = Self::prepare(offline_reveal).await {
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
return self.build_dir(&path);
|
||||
return self.build_dir(&path, offline_reveal);
|
||||
}
|
||||
|
||||
|
||||
async fn prepare() -> Result<(), String> {
|
||||
async fn prepare(offline_reveal: bool) -> Result<(), String> {
|
||||
if !offline_reveal {
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
let reveal_version = "5.2.1";
|
||||
let target = format!("https://github.com/hakimel/reveal.js/archive/{reveal_version}.zip");
|
||||
|
||||
create_dir_recursive("./docs/slides");
|
||||
|
||||
let response = reqwest::get(target.clone()).await.unwrap();
|
||||
reqwest::get(target.clone()).await.unwrap();
|
||||
let Ok(response) = reqwest::get(target).await else {
|
||||
return Err("could not downlaod revealjs".to_string())
|
||||
};
|
||||
@@ -62,7 +66,7 @@ impl BuildExecution {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fn build_dir(&mut self, path: &str) -> Result<(), String> {
|
||||
fn build_dir(&mut self, path: &str, offline_reveal: bool) -> Result<(), String> {
|
||||
let result = fs_util::fetch_paths_recursive(&path);
|
||||
|
||||
let Ok(paths) = result else {
|
||||
@@ -72,7 +76,7 @@ impl BuildExecution {
|
||||
for (index, in_path) in paths.iter().enumerate() {
|
||||
self.progress = index + 1;
|
||||
self.goal = paths.len();
|
||||
let result = docki_build(&in_path);
|
||||
let result = docki_build(&in_path, offline_reveal);
|
||||
|
||||
match result {
|
||||
DockiBuildResult::Err(err) => {
|
||||
@@ -81,7 +85,8 @@ impl BuildExecution {
|
||||
},
|
||||
DockiBuildResult::Copy(out_path) => self.display_building_status("Copy", &in_path, &out_path),
|
||||
DockiBuildResult::Slide(out_path) => self.display_building_status("Slide", &in_path, &out_path),
|
||||
DockiBuildResult::Doc(out_path) => self.display_building_status("Doc", &in_path, &out_path)
|
||||
DockiBuildResult::Doc(out_path) => self.display_building_status("Doc", &in_path, &out_path),
|
||||
DockiBuildResult::Silent => ()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::app::{ watcher::watcher, build::{docki_build, DockiBuildResult}, comm
|
||||
|
||||
|
||||
pub async fn serve(port: Option<u16>) {
|
||||
build().await;
|
||||
build(false).await;
|
||||
tokio::join!(watch_and_build(), start_server(port));
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ fn build_file(paths: Vec<std::path::PathBuf>) {
|
||||
.expect(invalid_path_message);
|
||||
|
||||
let in_path = format!("./{}", in_path);
|
||||
let result = docki_build(&in_path);
|
||||
let result = docki_build(&in_path, false);
|
||||
|
||||
match result {
|
||||
DockiBuildResult::Slide(out_path) => display_rebuilding_status("Slide", &in_path, &out_path),
|
||||
@@ -75,6 +75,7 @@ fn build_file(paths: Vec<std::path::PathBuf>) {
|
||||
display_rebuilding_status("Error", &in_path, "");
|
||||
println!("{}", err);
|
||||
},
|
||||
DockiBuildResult::Silent => ()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ impl App {
|
||||
Self::setup_environment_variables();
|
||||
|
||||
match args.command {
|
||||
CommandArg::Build => build().await,
|
||||
CommandArg::Build { offline_reveal } => build(offline_reveal).await,
|
||||
CommandArg::Health => health(),
|
||||
CommandArg::InstallReveal => install_reveal().await,
|
||||
CommandArg::Serve { port } => serve(port).await,
|
||||
|
||||
Reference in New Issue
Block a user