updated some things like help text, fixing custom docs dir
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
docs_dir = "./asciidocs"
|
docs_dir = "./docs"
|
||||||
port = 6969
|
port = 6969
|
||||||
|
offline_reveal = false
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ use super::fs_util;
|
|||||||
|
|
||||||
pub mod asciidoctor;
|
pub mod asciidoctor;
|
||||||
|
|
||||||
pub fn docki_build(in_path: &str, offline_reveal: bool) -> DockiBuildResult {
|
pub fn docki_build(in_path: &str, offline_reveal: bool, docs_dir: &str) -> DockiBuildResult {
|
||||||
let out_path = in_path.replace("/docs/", "/dist/");
|
let out_path = in_path.replace(docs_dir, "./dist");
|
||||||
let convert_out_path = out_path.replace(".adoc", ".html");
|
let convert_out_path = out_path.replace(".adoc", ".html");
|
||||||
|
|
||||||
if in_path.starts_with("./docs/slides/") && in_path.ends_with(".adoc") {
|
if in_path.starts_with(format!("{}/slides/", docs_dir).as_str()) && in_path.ends_with(".adoc") {
|
||||||
if let Err(err) = build_slide(&in_path, &convert_out_path, offline_reveal) {
|
if let Err(err) = build_slide(&in_path, &convert_out_path, offline_reveal) {
|
||||||
return DockiBuildResult::Err(err);
|
return DockiBuildResult::Err(err);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,6 @@ use crate::app::config::config::Config;
|
|||||||
use super::executions::build_execution::BuildExecution;
|
use super::executions::build_execution::BuildExecution;
|
||||||
|
|
||||||
pub async fn build(config: &Config) -> () {
|
pub async fn build(config: &Config) -> () {
|
||||||
let mut build_execution = BuildExecution::new(&config.docs_dir);
|
let mut build_execution = BuildExecution::new(&config.input_dir);
|
||||||
build_execution.execute(&config).await.expect("build failed")
|
build_execution.execute(&config).await.expect("build failed")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fmt::format, io::Cursor, path::PathBuf
|
io::Cursor, path::PathBuf
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::app::{
|
use crate::app::{
|
||||||
@@ -73,15 +73,16 @@ impl BuildExecution {
|
|||||||
return Err(result.unwrap_err())
|
return Err(result.unwrap_err())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let reveal_dir = format!("{}/slides/revealjs", path);
|
||||||
let paths = paths.into_iter()
|
let paths = paths.into_iter()
|
||||||
.filter(|path| offline_reveal || !path.starts_with("./docs/slides/revealjs"))
|
.filter(|path| offline_reveal || !path.starts_with(reveal_dir.as_str()))
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
self.goal = paths.len();
|
self.goal = paths.len();
|
||||||
|
|
||||||
for (index, in_path) in paths.iter().enumerate() {
|
for (index, in_path) in paths.iter().enumerate() {
|
||||||
self.progress = index + 1;
|
self.progress = index + 1;
|
||||||
let result = docki_build(&in_path, offline_reveal);
|
let result = docki_build(&in_path, offline_reveal, &self.docs_dir);
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
DockiBuildResult::Err(err) => {
|
DockiBuildResult::Err(err) => {
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ use crate::app::{ build::{DockiBuildResult, docki_build}, commands::build::build
|
|||||||
|
|
||||||
pub async fn serve(config: &Config) {
|
pub async fn serve(config: &Config) {
|
||||||
build(config).await;
|
build(config).await;
|
||||||
tokio::join!(watch_and_build(&config.docs_dir), start_server(config.port));
|
tokio::join!(watch_and_build(&config.input_dir), start_server(config.port));
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn watch_and_build(docs_dir: &str) {
|
async fn watch_and_build(docs_dir: &str) {
|
||||||
watch(Path::new(docs_dir))
|
watch(Path::new(docs_dir), docs_dir)
|
||||||
.await
|
.await
|
||||||
.expect("something went wrong")
|
.expect("something went wrong")
|
||||||
}
|
}
|
||||||
@@ -36,27 +36,27 @@ async fn start_server(port: u16) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn watch(path: &Path) -> notify::Result<()> {
|
async fn watch(path: &Path, docs_dir: &str) -> notify::Result<()> {
|
||||||
let (mut watcher, mut rx) = watcher()?;
|
let (mut watcher, mut rx) = watcher()?;
|
||||||
|
|
||||||
watcher.watch(path.as_ref(), RecursiveMode::Recursive)?;
|
watcher.watch(path.as_ref(), RecursiveMode::Recursive)?;
|
||||||
|
|
||||||
while let Some(res) = rx.next().await {
|
while let Some(res) = rx.next().await {
|
||||||
let event = res.expect("watching failed");
|
let event = res.expect("watching failed");
|
||||||
file_change(event)
|
file_change(event, docs_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn file_change(event: Event) {
|
fn file_change(event: Event, docs_dir: &str) {
|
||||||
match event.kind {
|
match event.kind {
|
||||||
EventKind::Modify(ModifyKind::Data(_)) => build_file(event.paths),
|
EventKind::Modify(ModifyKind::Data(_)) => build_file(event.paths, docs_dir),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_file(paths: Vec<std::path::PathBuf>) {
|
fn build_file(paths: Vec<std::path::PathBuf>, docs_dir: &str) {
|
||||||
let invalid_path_message = "changed path is invalid";
|
let invalid_path_message = "changed path is invalid";
|
||||||
let in_path = paths
|
let in_path = paths
|
||||||
.first()
|
.first()
|
||||||
@@ -67,7 +67,7 @@ fn build_file(paths: Vec<std::path::PathBuf>) {
|
|||||||
.expect(invalid_path_message);
|
.expect(invalid_path_message);
|
||||||
|
|
||||||
let in_path = format!("./{}", in_path);
|
let in_path = format!("./{}", in_path);
|
||||||
let result = docki_build(&in_path, false);
|
let result = docki_build(&in_path, false, docs_dir);
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
DockiBuildResult::Slide(out_path) => display_rebuilding_status("Slide", &in_path, &out_path),
|
DockiBuildResult::Slide(out_path) => display_rebuilding_status("Slide", &in_path, &out_path),
|
||||||
|
|||||||
@@ -1,13 +1,27 @@
|
|||||||
use super::config::Config;
|
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
use nu_ansi_term::{AnsiGenericString, Style};
|
||||||
|
|
||||||
|
fn github_hyperlink() -> AnsiGenericString<'static, str> {
|
||||||
|
return Style::new()
|
||||||
|
.bold()
|
||||||
|
.underline()
|
||||||
|
.paint("https://github.com/quirinecker/docki")
|
||||||
|
.hyperlink("https://github.com/quirinecker/docki")
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
#[command(after_help = format!("More information like defaults can be found at {}", github_hyperlink()))]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
pub command: CommandArg,
|
pub command: CommandArg,
|
||||||
|
|
||||||
|
/// The directory where the documentation is located
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
pub docs_dir: Option<String>,
|
pub input_dir: Option<String>,
|
||||||
|
|
||||||
|
/// The directory where the documentation will be built
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub output_dir: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ use crate::app::config::arguments::CommandArg;
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
pub docs_dir: String,
|
pub input_dir: String,
|
||||||
pub offline_reveal: bool,
|
pub offline_reveal: bool,
|
||||||
|
pub output_dir: String
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn load() -> Result<Self, config::ConfigError> {
|
pub fn load() -> Result<Self, config::ConfigError> {
|
||||||
|
|
||||||
let s = config::Config::builder()
|
let s = config::Config::builder()
|
||||||
.add_source(config::File::with_name("./docki.config.toml"))
|
.add_source(config::File::with_name("./docki.config.toml"))
|
||||||
.build()?;
|
.build()?;
|
||||||
@@ -25,14 +25,15 @@ impl Config {
|
|||||||
CommandArg::Serve { port } => port.unwrap_or(self.port),
|
CommandArg::Serve { port } => port.unwrap_or(self.port),
|
||||||
_ => self.port,
|
_ => self.port,
|
||||||
},
|
},
|
||||||
docs_dir: args.docs_dir.clone().unwrap_or(self.docs_dir),
|
input_dir: args.input_dir.clone().unwrap_or(self.input_dir),
|
||||||
|
output_dir: args.output_dir.clone().unwrap_or(self.output_dir),
|
||||||
offline_reveal: {
|
offline_reveal: {
|
||||||
if let CommandArg::Build { offline_reveal } = args.command {
|
if let CommandArg::Build { offline_reveal } = args.command {
|
||||||
offline_reveal
|
offline_reveal
|
||||||
} else {
|
} else {
|
||||||
self.offline_reveal
|
self.offline_reveal
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,7 +42,8 @@ impl Default for Config {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
port: 8080,
|
port: 8080,
|
||||||
docs_dir: "./docs".to_string(),
|
input_dir: "./docs".to_string(),
|
||||||
|
output_dir: "./dist".to_string(),
|
||||||
offline_reveal: false,
|
offline_reveal: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user