bundling work in progress
This commit is contained in:
27
Cargo.lock
generated
27
Cargo.lock
generated
@@ -8,6 +8,15 @@ version = "1.0.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
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]]
|
[[package]]
|
||||||
name = "async-trait"
|
name = "async-trait"
|
||||||
version = "0.1.63"
|
version = "0.1.63"
|
||||||
@@ -118,6 +127,7 @@ name = "docki"
|
|||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
"regex",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"zip-extract",
|
"zip-extract",
|
||||||
]
|
]
|
||||||
@@ -567,6 +577,23 @@ dependencies = [
|
|||||||
"bitflags",
|
"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]]
|
[[package]]
|
||||||
name = "remove_dir_all"
|
name = "remove_dir_all"
|
||||||
version = "0.5.3"
|
version = "0.5.3"
|
||||||
|
|||||||
@@ -9,5 +9,6 @@ license-file = "LICENSE.txt"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-trait = "0.1.63"
|
async-trait = "0.1.63"
|
||||||
|
regex = "1.7.1"
|
||||||
reqwest = {version = "0.11.14", features = ["blocking"]}
|
reqwest = {version = "0.11.14", features = ["blocking"]}
|
||||||
zip-extract = "0.1.1"
|
zip-extract = "0.1.1"
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
use std::process;
|
use std::{process, fmt::format};
|
||||||
|
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
use super::Builder;
|
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 {
|
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());
|
let revealjs_path = path_between(out_path.to_string(), "./dist/slides/revealjs".to_string());
|
||||||
|
|
||||||
command
|
command
|
||||||
.arg(format!("{in_path}"))
|
.arg(format!("{in_path}"))
|
||||||
|
.arg(format!("-a revealjsdir={revealjs_path}"))
|
||||||
.arg(format!("--out-file={out_path}"));
|
.arg(format!("--out-file={out_path}"));
|
||||||
|
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path_between(from: String, to: String) -> String {
|
pub fn path_between(from: String, to: String) -> String {
|
||||||
let from_segments: Vec<&str> = from.split("/").collect();
|
let from_segments = transform_input_to_clone_split(&from);
|
||||||
let to_segments: Vec<&str> = to.split("/").collect();
|
let to_segments = transform_input_to_clone_split(&to);
|
||||||
let last_matching_index = last_matching_index(&from_segments, &to_segments);
|
let last_matching_index = matching_from_start(&from_segments, &to_segments);
|
||||||
let number_of_backs = from_segments.len() - last_matching_index;
|
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() {
|
for (index, from_segment) in from_segments.iter().enumerate() {
|
||||||
if let Some(to_segment) = to_segments.get(index){
|
if let Some(to_segment) = to_segments.get(index){
|
||||||
if from_segment != to_segment {
|
if from_segment != to_segment {
|
||||||
return index - 1;
|
return index;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return index - 1;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,18 +2,36 @@ use crate::app::builder::asciidoctor;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn last_matching_index_0() {
|
fn last_matching_index_0() {
|
||||||
let vec1 = vec!["dings", "dings", "dingens"];
|
let vec1 = vec!["dings", "dings", "dingens"].iter().map(|s| s.to_string()).collect();
|
||||||
let vec2 = vec!["dings", "dings", "dings"];
|
let vec2 = vec!["dings", "dings", "dings"].iter().map(|s| s.to_string()).collect();
|
||||||
|
|
||||||
let last_maching = asciidoctor::last_matching_index(&vec1, &vec2);
|
let last_maching = asciidoctor::matching_from_start(&vec1, &vec2);
|
||||||
assert_eq!(last_maching, 1);
|
assert_eq!(last_maching, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn last_matching_index_1() {
|
fn last_matching_index_1() {
|
||||||
let vec1 = vec!["dings", "dings", "dingens", "dings", "dingens"];
|
let vec1 = vec!["dings", "dings", "dingens", "dings", "dingens"].iter().map(|s| s.to_string()).collect();
|
||||||
let vec2 = vec!["dings", "dings", "dingens", "dings"];
|
let vec2 = vec!["dings", "dings", "dingens", "dings"].iter().map(|s| s.to_string()).collect();
|
||||||
|
|
||||||
let last_maching = asciidoctor::last_matching_index(&vec1, &vec2);
|
let last_maching = asciidoctor::matching_from_start(&vec1, &vec2);
|
||||||
assert_eq!(last_maching, 3);
|
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")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user