Compare commits
1 Commits
main
...
cbb0dee97a
| Author | SHA1 | Date | |
|---|---|---|---|
| cbb0dee97a |
BIN
.github/assets/directory_structure.png
vendored
BIN
.github/assets/directory_structure.png
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 181 KiB |
4
.github/workflows/rust_deploy.yml
vendored
4
.github/workflows/rust_deploy.yml
vendored
@@ -4,7 +4,7 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches: ["main"]
|
branches: ["main"]
|
||||||
paths:
|
paths:
|
||||||
- "./Cargo.toml"
|
- "Cargo.toml"
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
@@ -16,7 +16,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --release --bin docki
|
run: cargo build --verbose
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: cargo test --verbose
|
run: cargo test --verbose
|
||||||
- name: Publish to crates.io
|
- name: Publish to crates.io
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,6 @@
|
|||||||
/target
|
/target
|
||||||
dist
|
dist
|
||||||
|
/docs
|
||||||
res/test/docs/slides/revealjs
|
res/test/docs/slides/revealjs
|
||||||
res/test/asciidocs/slides/revealjs
|
|
||||||
res/test/result
|
res/test/result
|
||||||
result
|
result
|
||||||
|
|||||||
2614
Cargo.lock
generated
2614
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
12
Cargo.toml
12
Cargo.toml
@@ -1,20 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "docki"
|
name = "docki"
|
||||||
version = "1.3.0"
|
version = "1.2.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "cli for building and publishing documentation using asciidoctor"
|
description = "cli for building and publishing documentation using asciidoctor"
|
||||||
license-file = "LICENSE.txt"
|
license-file = "LICENSE.txt"
|
||||||
authors = ["Quirin Ecker"]
|
authors = ["Quirin Ecker"]
|
||||||
exclude = [".gitlab", ".github"]
|
exclude = [".gitlab", ".github"]
|
||||||
default-run = "docki"
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "docki"
|
|
||||||
path = "src/main.rs"
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "util"
|
|
||||||
path = "src/util.rs"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
@@ -34,4 +25,3 @@ clap_complete = "4.1.4"
|
|||||||
nu-ansi-term = "0.50.3"
|
nu-ansi-term = "0.50.3"
|
||||||
config = { version = "0.15.18", features = ["toml"] }
|
config = { version = "0.15.18", features = ["toml"] }
|
||||||
serde = "1.0.228"
|
serde = "1.0.228"
|
||||||
toml = "0.9.6"
|
|
||||||
|
|||||||
19
README.md
19
README.md
@@ -1,5 +1,9 @@
|
|||||||
# Docki
|
# Docki
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> This project is under renovations. It can be used, but it might not be completely stable yet.
|
||||||
|
|
||||||
|
|
||||||
## Preview
|
## Preview
|
||||||
|
|
||||||

|

|
||||||
@@ -8,15 +12,8 @@ Docki is cli for converting asciidoctor files into html files.
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Docki must be run in a directory with the following structure
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
1. Will be converted into asciidoc format
|
|
||||||
2. Will be converted into asciidocs slides
|
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> The input directory can be defined either with a cli argument or the config file. Default is `./docs`
|
> This works in a directory with a directory called `docs`, which contains the asciidoctor documentation.
|
||||||
|
|
||||||
### Building the documentation
|
### Building the documentation
|
||||||
|
|
||||||
@@ -24,7 +21,7 @@ Docki must be run in a directory with the following structure
|
|||||||
docki build
|
docki build
|
||||||
```
|
```
|
||||||
|
|
||||||
### Serving the documentation with a live server
|
### Serving the documentation on a live server
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docki serve
|
docki serve
|
||||||
@@ -115,10 +112,6 @@ home.packages = with pkgs; [
|
|||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
You can configure some of the cli arguments with a config file. It is always located relatively to the current directory under `./docki.config.toml`. Available options and their defaults can be found in the [docki.config.toml](config/docki.config.toml) file. CLI arguments with the same names as in the config usually have also the same default values. As a fallback you can also use the [config.rs](src/app/config/config.rs) file for reference.
|
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
### Running it
|
### Running it
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
port = 8080
|
|
||||||
input_dir = "./docs"
|
|
||||||
offline_reveal = false
|
|
||||||
output_dir = "./dist"
|
|
||||||
@@ -64,11 +64,6 @@
|
|||||||
libiconv
|
libiconv
|
||||||
makeWrapper
|
makeWrapper
|
||||||
];
|
];
|
||||||
binaries = [ "docki" ];
|
|
||||||
# only including the main binary in build
|
|
||||||
# There is no better option at the time of writing this
|
|
||||||
# https://github.com/nix-community/naersk/issues/127
|
|
||||||
copyBinsFilter = ''select(.reason == "compiler-artifact" and .executable != null and .profile.test == false and .target.name == "docki")'';
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
mkdir -p $out/share/bash-completion/completions
|
mkdir -p $out/share/bash-completion/completions
|
||||||
mkdir -p $out/share/zsh/site-functions
|
mkdir -p $out/share/zsh/site-functions
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
= My Project
|
|
||||||
:toc:
|
|
||||||
:toc-title:
|
|
||||||
:toclevels: 2
|
|
||||||
|
|
||||||
== Introduction
|
|
||||||
|
|
||||||
This is my project.
|
|
||||||
|
|
||||||
== Slides
|
|
||||||
|
|
||||||
* link:slides/index.html[Presentation]
|
|
||||||
|
|
||||||
== License
|
|
||||||
|
|
||||||
This project is licensed under the MIT License - see the link:LICENSE[LICENSE] file for details.
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
# Slides
|
|
||||||
|
|
||||||
## Slide 1
|
|
||||||
|
|
||||||
* First
|
|
||||||
* Second
|
|
||||||
* Third
|
|
||||||
|
|
||||||
## Slide 2
|
|
||||||
|
|
||||||
* First
|
|
||||||
* Second
|
|
||||||
* Third
|
|
||||||
|
|
||||||
### Slide 3
|
|
||||||
|
|
||||||
* First
|
|
||||||
* Second
|
|
||||||
* Third
|
|
||||||
@@ -1,3 +1 @@
|
|||||||
docs_dir = "./asciidocs"
|
|
||||||
port = 6969
|
port = 6969
|
||||||
offline_reveal = false
|
|
||||||
|
|||||||
0
res/test/docs/core/functions.adoc
Normal file
0
res/test/docs/core/functions.adoc
Normal file
0
res/test/docs/core/index.adoc
Normal file
0
res/test/docs/core/index.adoc
Normal file
0
res/test/docs/fail.txt
Normal file
0
res/test/docs/fail.txt
Normal file
0
res/test/docs/functions.adoc
Normal file
0
res/test/docs/functions.adoc
Normal file
@@ -1,16 +0,0 @@
|
|||||||
= My Project
|
|
||||||
:toc:
|
|
||||||
:toc-title:
|
|
||||||
:toclevels: 2
|
|
||||||
|
|
||||||
== Introduction
|
|
||||||
|
|
||||||
This is my project.
|
|
||||||
|
|
||||||
== Slides
|
|
||||||
|
|
||||||
* link:slides/index.html[Presentation]
|
|
||||||
|
|
||||||
== License
|
|
||||||
|
|
||||||
This project is licensed under the MIT License - see the link:LICENSE[LICENSE] file for details.
|
|
||||||
|
|||||||
@@ -1,19 +1,11 @@
|
|||||||
# Slides
|
= My cool presentation
|
||||||
|
:author: John Doe
|
||||||
|
:email: john@doe.com
|
||||||
|
|
||||||
## Slide 1
|
== First slide
|
||||||
|
|
||||||
* First
|
Content
|
||||||
* Second
|
|
||||||
* Third
|
|
||||||
|
|
||||||
## Slide 2
|
== Second slide
|
||||||
|
|
||||||
* First
|
Content
|
||||||
* Second
|
|
||||||
* Third
|
|
||||||
|
|
||||||
### Slide 3
|
|
||||||
|
|
||||||
* First
|
|
||||||
* Second
|
|
||||||
* Third
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
use crate::app::config::config::Config;
|
|
||||||
|
|
||||||
fn exec_command(command: &mut process::Command) -> Result<(), String> {
|
fn exec_command(command: &mut process::Command) -> Result<(), String> {
|
||||||
let result = command.output();
|
let result = command.output();
|
||||||
|
|
||||||
@@ -14,13 +12,9 @@ fn exec_command(command: &mut process::Command) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("{}", result.unwrap_err());
|
println!("{}", result.unwrap_err());
|
||||||
|
return Err(
|
||||||
let binary_name = command.get_program().to_str().unwrap_or("Something is");
|
"asciidoctor not installed. For more information run docki health!".to_string(),
|
||||||
|
);
|
||||||
return Err(format!(
|
|
||||||
"{} not installed. For more information run docki health!",
|
|
||||||
binary_name
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,14 +28,11 @@ fn asciidoctor_docs(in_path: &str, out_path: &str) -> process::Command {
|
|||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn asciidoctor_slides(in_path: &str, out_path: &str, config: &Config) -> 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 mut command = process::Command::new(format!("asciidoctor-revealjs"));
|
||||||
let out_dir = parent_path(out_path);
|
let out_dir = parent_path(out_path);
|
||||||
let revealjs_path = if config.offline_reveal {
|
let revealjs_path = if offline_reveal {
|
||||||
path_between(
|
path_between(out_dir.to_string(), "./dist/slides/revealjs".to_string())
|
||||||
out_dir.to_string(),
|
|
||||||
format!("{}/slides/revealjs", config.output_dir),
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
"https://cdn.jsdelivr.net/npm/reveal.js@5.2.1".to_string()
|
"https://cdn.jsdelivr.net/npm/reveal.js@5.2.1".to_string()
|
||||||
};
|
};
|
||||||
@@ -109,13 +100,13 @@ pub fn matching_from_start(from_segments: &Vec<String>, to_segments: &Vec<String
|
|||||||
return from_segments.len();
|
return from_segments.len();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_doc(in_path: &str, out_path: &str, _: &Config) -> Result<(), String> {
|
pub fn build_doc(in_path: &str, out_path: &str) -> Result<(), String> {
|
||||||
let mut command = asciidoctor_docs(in_path, out_path);
|
let mut command = asciidoctor_docs(in_path, out_path);
|
||||||
return exec_command(&mut command);
|
return exec_command(&mut command);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_slide(in_path: &str, out_path: &str, config: &Config) -> Result<(), String> {
|
pub fn build_slide(in_path: &str, out_path: &str, offline_reveal: bool) -> Result<(), String> {
|
||||||
let mut command = asciidoctor_slides(in_path, out_path, config);
|
let mut command = asciidoctor_slides(in_path, out_path, offline_reveal);
|
||||||
return exec_command(&mut command);
|
return exec_command(&mut command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,121 +1,33 @@
|
|||||||
|
use std::fs;
|
||||||
|
|
||||||
|
use self::asciidoctor::{build_doc, build_slide};
|
||||||
|
|
||||||
|
use super::fs_util;
|
||||||
|
|
||||||
pub mod asciidoctor;
|
pub mod asciidoctor;
|
||||||
|
|
||||||
use std::{
|
pub fn docki_build(in_path: &str, offline_reveal: bool) -> DockiBuildResult {
|
||||||
fs, io::Cursor, path::PathBuf
|
let out_path = in_path.replace("/docs/", "/dist/");
|
||||||
};
|
|
||||||
|
|
||||||
use crate::app::{
|
|
||||||
build::{asciidoctor::build_slide, asciidoctor::build_doc}, config::config::Config, fs_util::{self, create_dir_recursive}, log::display_status
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct DockiBuilder<'a> {
|
|
||||||
progress: usize,
|
|
||||||
goal: usize,
|
|
||||||
config: &'a Config
|
|
||||||
}
|
|
||||||
|
|
||||||
impl <'a> DockiBuilder <'a> {
|
|
||||||
pub fn new(config: &'a Config) -> Self {
|
|
||||||
return Self {
|
|
||||||
progress: 0,
|
|
||||||
goal: 0,
|
|
||||||
config: config
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Prepares everything for building the documentation
|
|
||||||
///
|
|
||||||
/// 1. Checks if the input directory exists and if not, returns an error
|
|
||||||
/// 2. When offline_reveal is set to true, it downloads revealjs. When it fails, it returns an error
|
|
||||||
pub async fn prepare(&self) -> Result<(), String> {
|
|
||||||
if !fs_util::directory_exists(&self.config.input_dir) {
|
|
||||||
return Err(
|
|
||||||
"docs directory does not exist it. Create it or use the template".to_string(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if !self.config.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(format!("{}/slides", self.config.input_dir).as_str());
|
|
||||||
|
|
||||||
reqwest::get(target.clone()).await.unwrap();
|
|
||||||
let Ok(response) = reqwest::get(target).await else {
|
|
||||||
return Err("could not downlaod revealjs".to_string())
|
|
||||||
};
|
|
||||||
|
|
||||||
let Ok(bytes) = response.bytes().await else {
|
|
||||||
return Err("could not extract bytes".to_string())
|
|
||||||
};
|
|
||||||
|
|
||||||
let out = PathBuf::from(format!("{}/slides/revealjs", self.config.input_dir));
|
|
||||||
|
|
||||||
if zip_extract::extract(Cursor::new(bytes), &out, true).is_err() {
|
|
||||||
return Err("could not write extracted archive to disk".to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Builds all files in the input directory with a pretty output
|
|
||||||
pub fn build_docs(&mut self) -> Result<(), String> {
|
|
||||||
let result = fs_util::fetch_paths_recursive(&self.config.input_dir);
|
|
||||||
let Ok(paths) = result else {
|
|
||||||
return Err(result.unwrap_err())
|
|
||||||
};
|
|
||||||
|
|
||||||
let reveal_dir = format!("{}/slides/revealjs", self.config.input_dir);
|
|
||||||
let paths = paths.into_iter()
|
|
||||||
.filter(|path| self.config.offline_reveal || !path.starts_with(reveal_dir.as_str()))
|
|
||||||
.collect::<Vec<String>>();
|
|
||||||
|
|
||||||
self.goal = paths.len();
|
|
||||||
|
|
||||||
for (index, in_path) in paths.iter().enumerate() {
|
|
||||||
self.progress = index + 1;
|
|
||||||
let result = self.build_file(&in_path);
|
|
||||||
|
|
||||||
match result {
|
|
||||||
DockiBuildResult::Err(err) => {
|
|
||||||
self.display_building_status("Error", &in_path, "");
|
|
||||||
println!("{}", err)
|
|
||||||
},
|
|
||||||
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),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Builds a single file without a pretty output
|
|
||||||
pub fn build_file(&self, path: &str) -> DockiBuildResult {
|
|
||||||
let out_path = path.replace(&self.config.input_dir, &self.config.output_dir);
|
|
||||||
let convert_out_path = out_path.replace(".adoc", ".html");
|
let convert_out_path = out_path.replace(".adoc", ".html");
|
||||||
|
|
||||||
if path.starts_with(format!("{}/slides/", &self.config.input_dir).as_str()) && path.ends_with(".adoc") {
|
if in_path.starts_with("./docs/slides/") && in_path.ends_with(".adoc") {
|
||||||
if let Err(err) = build_slide(&path, &convert_out_path, self.config) {
|
if let Err(err) = build_slide(&in_path, &convert_out_path, offline_reveal) {
|
||||||
return DockiBuildResult::Err(err);
|
return DockiBuildResult::Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
DockiBuildResult::Slide(convert_out_path)
|
DockiBuildResult::Slide(convert_out_path)
|
||||||
} else if path.ends_with(".adoc") {
|
} else if in_path.ends_with(".adoc") {
|
||||||
if let Err(err) = build_doc(&path, &convert_out_path, self.config) {
|
if let Err(err) = build_doc(&in_path, &convert_out_path) {
|
||||||
return DockiBuildResult::Err(err);
|
return DockiBuildResult::Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
DockiBuildResult::Doc(convert_out_path)
|
DockiBuildResult::Doc(convert_out_path)
|
||||||
} else {
|
} else {
|
||||||
if let Err(err) = Self::copy(&path, &out_path) {
|
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);
|
return DockiBuildResult::Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,18 +45,10 @@ impl <'a> DockiBuilder <'a> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_building_status(&self, status_type: &str, in_path: &str, out_path: &str) -> () {
|
|
||||||
let progress_str = format!("{} / {}", self.progress, self.goal);
|
|
||||||
display_status(&progress_str, status_type, in_path, out_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Used for the Result of build_file. This way it is known what the builder did
|
|
||||||
pub enum DockiBuildResult {
|
pub enum DockiBuildResult {
|
||||||
Slide(String),
|
Slide(String),
|
||||||
Doc(String),
|
Doc(String),
|
||||||
Copy(String),
|
Copy(String),
|
||||||
Err(String),
|
Err(String),
|
||||||
|
Silent,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
use crate::app::config::config::Config;
|
use super::executions::build_execution::BuildExecution;
|
||||||
|
|
||||||
use crate::app::build::DockiBuilder;
|
pub async fn build(offline_reveal: bool) -> () {
|
||||||
|
let mut build_execution = BuildExecution::new();
|
||||||
pub async fn build(config: &Config) -> () {
|
build_execution.execute(offline_reveal).await.expect("build failed")
|
||||||
let mut builder = DockiBuilder::new(config);
|
|
||||||
|
|
||||||
builder.prepare().await.expect("could not prepare for build");
|
|
||||||
builder.build_docs().expect("build failed")
|
|
||||||
}
|
}
|
||||||
|
|||||||
101
src/app/commands/executions/build_execution.rs
Normal file
101
src/app/commands/executions/build_execution.rs
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
use std::{
|
||||||
|
io::Cursor,
|
||||||
|
path::PathBuf
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::app::{
|
||||||
|
build::{docki_build, DockiBuildResult},
|
||||||
|
fs_util::{self, create_dir_recursive}, log::display_status,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct BuildExecution {
|
||||||
|
progress: usize,
|
||||||
|
goal: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BuildExecution {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
return BuildExecution {
|
||||||
|
progress: 0,
|
||||||
|
goal: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn execute(&mut self, offline_reveal: bool) -> Result<(), String> {
|
||||||
|
let path = "./docs/".to_string();
|
||||||
|
|
||||||
|
if !fs_util::directory_exists(&path) {
|
||||||
|
return Err(
|
||||||
|
"docs directory does not exist it. Create it or use the template".to_string(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(error) = Self::prepare(offline_reveal).await {
|
||||||
|
return Err(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.build_dir(&path, offline_reveal);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
reqwest::get(target.clone()).await.unwrap();
|
||||||
|
let Ok(response) = reqwest::get(target).await else {
|
||||||
|
return Err("could not downlaod revealjs".to_string())
|
||||||
|
};
|
||||||
|
|
||||||
|
let Ok(bytes) = response.bytes().await else {
|
||||||
|
return Err("could not extract bytes".to_string())
|
||||||
|
};
|
||||||
|
|
||||||
|
let out = PathBuf::from("./docs/slides/revealjs");
|
||||||
|
|
||||||
|
if zip_extract::extract(Cursor::new(bytes), &out, true).is_err() {
|
||||||
|
return Err("could not write extracted archive to disk".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
return Err(result.unwrap_err())
|
||||||
|
};
|
||||||
|
|
||||||
|
for (index, in_path) in paths.iter().enumerate() {
|
||||||
|
self.progress = index + 1;
|
||||||
|
self.goal = paths.len();
|
||||||
|
let result = docki_build(&in_path, offline_reveal);
|
||||||
|
|
||||||
|
match result {
|
||||||
|
DockiBuildResult::Err(err) => {
|
||||||
|
self.display_building_status("Error", in_path, "");
|
||||||
|
println!("{}", err)
|
||||||
|
},
|
||||||
|
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::Silent => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn display_building_status(&self, status_type: &str, in_path: &str, out_path: &str) -> () {
|
||||||
|
let progress_str = format!("{} / {}", self.progress, self.goal);
|
||||||
|
display_status(&progress_str, status_type, in_path, out_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
1
src/app/commands/executions/mod.rs
Normal file
1
src/app/commands/executions/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod build_execution;
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
pub mod build;
|
pub mod build;
|
||||||
pub mod completions;
|
pub mod completions;
|
||||||
|
pub mod executions;
|
||||||
pub mod health;
|
pub mod health;
|
||||||
pub mod install_reveal;
|
pub mod install_reveal;
|
||||||
pub mod serve;
|
pub mod serve;
|
||||||
|
|||||||
@@ -7,38 +7,23 @@ use notify::{
|
|||||||
};
|
};
|
||||||
use std::{env, path::Path};
|
use std::{env, path::Path};
|
||||||
|
|
||||||
use crate::app::watcher::watcher;
|
use crate::app::{ watcher::watcher, build::{docki_build, DockiBuildResult}, commands::build::build, log::display_status};
|
||||||
use crate::app::log::display_status;
|
|
||||||
use crate::app::config::config::Config;
|
|
||||||
use crate::app::build::{DockiBuildResult, DockiBuilder};
|
|
||||||
|
|
||||||
pub async fn serve(config: &Config) {
|
|
||||||
let builder = DockiBuilder::new(config);
|
pub async fn serve(port: u16) {
|
||||||
let mut server = Server::new(builder, config);
|
build(false).await;
|
||||||
server.serve().await;
|
tokio::join!(watch_and_build(), start_server(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Server<'a> {
|
async fn watch_and_build() {
|
||||||
builder: DockiBuilder<'a>,
|
watch(Path::new("./docs"))
|
||||||
config: &'a Config,
|
.await
|
||||||
|
.expect("something went wrong")
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a> Server <'a> {
|
|
||||||
fn new(builder: DockiBuilder<'a>, config: &'a Config) -> Self {
|
|
||||||
return Self {
|
|
||||||
builder,
|
|
||||||
config: config
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn serve(&mut self) {
|
async fn start_server(port: u16) {
|
||||||
self.builder.prepare().await.expect("could not prepare for build");
|
let link = &format!("http://localhost:{}", port);
|
||||||
self.builder.build_docs().expect("build failed");
|
|
||||||
tokio::join!(self.start_server(), self.watch_and_build());
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn start_server(&self) {
|
|
||||||
let link = &format!("http://localhost:{}", self.config.port);
|
|
||||||
let hyperlink = Green.paint(link).hyperlink(link);
|
let hyperlink = Green.paint(link).hyperlink(link);
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
@@ -46,60 +31,53 @@ impl <'a> Server <'a> {
|
|||||||
hyperlink
|
hyperlink
|
||||||
);
|
);
|
||||||
|
|
||||||
let Ok(()) = listen("localhost", self.config.port, self.config.output_dir.clone()).await else {
|
let Ok(()) = listen("localhost", port, "./dist").await else {
|
||||||
panic!("could not start server")
|
panic!("could not start server")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn watch_and_build(&self) {
|
async fn watch(path: &Path) -> notify::Result<()> {
|
||||||
self.watch()
|
|
||||||
.await
|
|
||||||
.expect("something went wrong")
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn watch(&self) -> notify::Result<()> {
|
|
||||||
let path = Path::new(&self.config.input_dir);
|
|
||||||
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");
|
||||||
self.file_change(event)
|
file_change(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn file_change(&self, event: Event) {
|
fn file_change(event: Event) {
|
||||||
match event.kind {
|
match event.kind {
|
||||||
EventKind::Modify(ModifyKind::Data(_)) => self.build_valid_files(event.paths),
|
EventKind::Modify(ModifyKind::Data(_)) => build_file(event.paths),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_valid_files(&self, paths: Vec<std::path::PathBuf>) {
|
fn build_file(paths: Vec<std::path::PathBuf>) {
|
||||||
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()
|
||||||
.expect(invalid_path_message)
|
.expect(invalid_path_message)
|
||||||
.strip_prefix(&Self::current_dir())
|
.strip_prefix(¤t_dir())
|
||||||
.expect(invalid_path_message)
|
.expect(invalid_path_message)
|
||||||
.to_str()
|
.to_str()
|
||||||
.expect(invalid_path_message);
|
.expect(invalid_path_message);
|
||||||
|
|
||||||
let in_path = format!("./{}", in_path);
|
let in_path = format!("./{}", in_path);
|
||||||
let result = self.builder.build_file(&in_path);
|
let result = docki_build(&in_path, false);
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
DockiBuildResult::Slide(out_path) => Self::display_rebuilding_status("Slide", &in_path, &out_path),
|
DockiBuildResult::Slide(out_path) => display_rebuilding_status("Slide", &in_path, &out_path),
|
||||||
DockiBuildResult::Doc(out_path) => Self::display_rebuilding_status("Doc", &in_path, &out_path),
|
DockiBuildResult::Doc(out_path) => display_rebuilding_status("Doc", &in_path, &out_path),
|
||||||
DockiBuildResult::Copy(out_path) => Self::display_rebuilding_status("Copy", &in_path, &out_path),
|
DockiBuildResult::Copy(out_path) => display_rebuilding_status("Copy", &in_path, &out_path),
|
||||||
DockiBuildResult::Err(err) => {
|
DockiBuildResult::Err(err) => {
|
||||||
Self::display_rebuilding_status("Error", &in_path, "");
|
display_rebuilding_status("Error", &in_path, "");
|
||||||
println!("{}", err);
|
println!("{}", err);
|
||||||
},
|
},
|
||||||
|
DockiBuildResult::Silent => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,6 +94,4 @@ impl <'a> Server <'a> {
|
|||||||
.expect(err_message),
|
.expect(err_message),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +1,13 @@
|
|||||||
|
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, global = true)]
|
pub docs_dir: Option<String>,
|
||||||
pub input_dir: Option<String>,
|
|
||||||
|
|
||||||
/// The directory where the documentation will be built
|
|
||||||
#[arg(short, long, global = true)]
|
|
||||||
pub output_dir: Option<String>,
|
|
||||||
|
|
||||||
/// When set to true, docki will download revealjs before building the documentation.
|
|
||||||
/// Otherwise it will use the cdn for revealjs
|
|
||||||
#[arg(long, global = true)]
|
|
||||||
pub offline_reveal: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
@@ -38,8 +19,13 @@ pub enum ShellArg {
|
|||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub enum CommandArg {
|
pub enum CommandArg {
|
||||||
/// Builds the documentation into the specified output_dir
|
/// 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
|
/// Checks if everything required for docki is installed
|
||||||
Health,
|
Health,
|
||||||
/// Deprecated: Helper command for installing asciidoctor-reveal-js
|
/// Deprecated: Helper command for installing asciidoctor-reveal-js
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::app::config::arguments::CommandArg;
|
use crate::app::config::arguments::CommandArg;
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Serialize)]
|
#[derive(Deserialize, Debug)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
pub input_dir: String,
|
pub docs_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,9 +25,14 @@ impl Config {
|
|||||||
CommandArg::Serve { port } => port.unwrap_or(self.port),
|
CommandArg::Serve { port } => port.unwrap_or(self.port),
|
||||||
_ => self.port,
|
_ => self.port,
|
||||||
},
|
},
|
||||||
input_dir: args.input_dir.clone().unwrap_or(self.input_dir),
|
docs_dir: args.docs_dir.clone().unwrap_or(self.docs_dir),
|
||||||
output_dir: args.output_dir.clone().unwrap_or(self.output_dir),
|
offline_reveal: {
|
||||||
offline_reveal: args.offline_reveal || self.offline_reveal,
|
if let CommandArg::Build { offline_reveal } = args.command {
|
||||||
|
offline_reveal
|
||||||
|
} else {
|
||||||
|
self.offline_reveal
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,8 +41,7 @@ impl Default for Config {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
port: 8080,
|
port: 8080,
|
||||||
input_dir: "./docs".to_string(),
|
docs_dir: "./docs".to_string(),
|
||||||
output_dir: "./dist".to_string(),
|
|
||||||
offline_reveal: false,
|
offline_reveal: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ pub mod build;
|
|||||||
pub mod fs_util;
|
pub mod fs_util;
|
||||||
pub mod watcher;
|
pub mod watcher;
|
||||||
pub mod log;
|
pub mod log;
|
||||||
pub mod config;
|
mod config;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
@@ -26,10 +26,10 @@ impl App {
|
|||||||
Self::setup_environment_variables();
|
Self::setup_environment_variables();
|
||||||
|
|
||||||
match args.command {
|
match args.command {
|
||||||
CommandArg::Build { .. } => build(&config).await,
|
CommandArg::Build { .. } => build(config.offline_reveal).await,
|
||||||
CommandArg::Health => health(),
|
CommandArg::Health => health(),
|
||||||
CommandArg::InstallReveal => install_reveal().await,
|
CommandArg::InstallReveal => install_reveal().await,
|
||||||
CommandArg::Serve { .. } => serve(&config).await,
|
CommandArg::Serve { .. } => serve(config.port).await,
|
||||||
CommandArg::Completions { shell } => completions(shell)
|
CommandArg::Completions { shell } => completions(shell)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ fn test_fetch_asciidoctor_paths_recursive() {
|
|||||||
let paths = fs_util::fetch_paths_recursive("res/test/docs").unwrap();
|
let paths = fs_util::fetch_paths_recursive("res/test/docs").unwrap();
|
||||||
let len = paths.len();
|
let len = paths.len();
|
||||||
dbg!(paths);
|
dbg!(paths);
|
||||||
assert_eq!(len, 2);
|
assert_eq!(len, 6);
|
||||||
}
|
}
|
||||||
|
|||||||
34
src/util.rs
34
src/util.rs
@@ -1,34 +0,0 @@
|
|||||||
mod app;
|
|
||||||
|
|
||||||
use std::{fs::File, io::Write};
|
|
||||||
|
|
||||||
use app::config::config::Config;
|
|
||||||
use clap::{Parser, Subcommand};
|
|
||||||
|
|
||||||
#[derive(Parser)]
|
|
||||||
pub struct Args {
|
|
||||||
#[command(subcommand)]
|
|
||||||
pub command: CommandArg,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
|
||||||
pub enum CommandArg {
|
|
||||||
/// Generates a default docki.config.toml
|
|
||||||
GenerateDefaultConfig,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let args = Args::parse();
|
|
||||||
match args.command {
|
|
||||||
CommandArg::GenerateDefaultConfig => generate_default_config(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn generate_default_config() {
|
|
||||||
let default_config = Config::default();
|
|
||||||
let target_file = "config/docki.config.toml";
|
|
||||||
let mut file = File::create(target_file).unwrap();
|
|
||||||
let output = toml::to_string_pretty(&default_config).unwrap();
|
|
||||||
|
|
||||||
file.write_all(output.as_bytes()).unwrap();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user