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

27
Cargo.lock generated
View File

@@ -8,6 +8,15 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
dependencies = [
"memchr",
]
[[package]]
name = "async-trait"
version = "0.1.63"
@@ -118,6 +127,7 @@ name = "docki"
version = "0.1.1"
dependencies = [
"async-trait",
"regex",
"reqwest",
"zip-extract",
]
@@ -567,6 +577,23 @@ dependencies = [
"bitflags",
]
[[package]]
name = "regex"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
[[package]]
name = "remove_dir_all"
version = "0.5.3"

View File

@@ -9,5 +9,6 @@ license-file = "LICENSE.txt"
[dependencies]
async-trait = "0.1.63"
regex = "1.7.1"
reqwest = {version = "0.11.14", features = ["blocking"]}
zip-extract = "0.1.1"

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;
}
}

View File

@@ -2,18 +2,36 @@ use crate::app::builder::asciidoctor;
#[test]
fn last_matching_index_0() {
let vec1 = vec!["dings", "dings", "dingens"];
let vec2 = vec!["dings", "dings", "dings"];
let vec1 = vec!["dings", "dings", "dingens"].iter().map(|s| s.to_string()).collect();
let vec2 = vec!["dings", "dings", "dings"].iter().map(|s| s.to_string()).collect();
let last_maching = asciidoctor::last_matching_index(&vec1, &vec2);
assert_eq!(last_maching, 1);
let last_maching = asciidoctor::matching_from_start(&vec1, &vec2);
assert_eq!(last_maching, 2);
}
#[test]
fn last_matching_index_1() {
let vec1 = vec!["dings", "dings", "dingens", "dings", "dingens"];
let vec2 = vec!["dings", "dings", "dingens", "dings"];
let vec1 = vec!["dings", "dings", "dingens", "dings", "dingens"].iter().map(|s| s.to_string()).collect();
let vec2 = vec!["dings", "dings", "dingens", "dings"].iter().map(|s| s.to_string()).collect();
let last_maching = asciidoctor::last_matching_index(&vec1, &vec2);
assert_eq!(last_maching, 3);
let last_maching = asciidoctor::matching_from_start(&vec1, &vec2);
assert_eq!(last_maching, 4);
}
#[test]
fn path_between_0() {
let path1 = "./docs/dings";
let path2 = "./dist/dings";
let path_between = asciidoctor::path_between(path1.to_string(), path2.to_string());
assert_eq!(path_between, "../../dist/dings");
}
#[test]
fn path_between_1() {
let path1 = "./dist/slides/core/";
let path2 = "./dist/slides/revealjs";
let path_between = asciidoctor::path_between(path1.to_string(), path2.to_string());
assert_eq!(path_between, "../revealjs")
}