bundling work in progress

This commit is contained in:
2023-01-28 18:32:13 +01:00
parent a9eb073b55
commit 06b47440dd
4 changed files with 90 additions and 18 deletions

View File

@@ -1,4 +1,6 @@
use std::process;
use std::{process, fmt::format};
use regex::Regex;
use super::Builder;
@@ -28,32 +30,56 @@ fn asciidoctor_docs(in_path: &str, out_path: &str) -> process::Command {
}
fn asciidoctor_slides(in_path: &str, out_path: &str) -> process::Command {
let mut command = process::Command::new(format!("asciidoctor-revealjs-linux"));
let mut command = process::Command::new(format!("asciidoctor-revealjs"));
let revealjs_path = path_between(out_path.to_string(), "./dist/slides/revealjs".to_string());
command
.arg(format!("{in_path}"))
.arg(format!("-a revealjsdir={revealjs_path}"))
.arg(format!("--out-file={out_path}"));
return command;
}
fn path_between(from: String, to: String) -> String {
let from_segments: Vec<&str> = from.split("/").collect();
let to_segments: Vec<&str> = to.split("/").collect();
let last_matching_index = last_matching_index(&from_segments, &to_segments);
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;
return "".to_string();
let mut path_between = path_back(number_of_backs);
dbg!(&path_between);
let path_to_to_path = &to_segments[last_matching_index..];
path_between.push_str(&path_to_to_path.join("/"));
return path_between;
}
pub fn last_matching_index(from_segments: &Vec<&str>, to_segments: &Vec<&str>) -> usize {
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 - 1;
return index;
}
} else {
return index - 1;
return index;
}
}