Compare commits
78 Commits
242d5b7582
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1bb50c09bf | |||
| 1995e5310d | |||
| 379a337611 | |||
| bc3283eb29 | |||
| 89c4d48c1c | |||
| bf5782fc5e | |||
| b0617efe93 | |||
| f4d91aabe6 | |||
| 904d9ccb28 | |||
| 1f2d9e4363 | |||
| 3ae1b2cc6e | |||
| f6940f1db8 | |||
| c33428f3e1 | |||
| fc98b48601 | |||
| bf30e8eeb6 | |||
| fa9f282194 | |||
| 64400c07c7 | |||
| b3d6d21ea5 | |||
| a0bdc34792 | |||
| 659bb5da63 | |||
| 24e1ade129 | |||
| 88dc0e47b1 | |||
| 0ae02c8950 | |||
| e053f51bf3 | |||
| f3bfd8c114 | |||
| 2ed789aa46 | |||
| 131bf15240 | |||
| fd1fe0d896 | |||
| 5996db8d80 | |||
| 2df54930bb | |||
| f7a1f84730 | |||
| bb82dad4cf | |||
| 303309fff9 | |||
| 6d2f76eb72 | |||
| 451015d2f2 | |||
| 1a009bac61 | |||
| cc65ce3e7c | |||
| 926944e8dd | |||
| 78e2acb325 | |||
| 958856dcc0 | |||
| deb30aacea | |||
| 9075b34ca3 | |||
| 7325e3a0c9 | |||
| 34e8ad4eb4 | |||
| 8a6dacf1c8 | |||
|
|
8a65a5e596 | ||
| 47996b81bc | |||
| a2f9622aaa | |||
| 5b3ef929c4 | |||
| d706ba9f56 | |||
| bb4b2ad3f5 | |||
| bd77f0daff | |||
| cd439006bb | |||
| 77eda0841b | |||
| 21b6434145 | |||
| ff4b237651 | |||
| 4b11b0ada2 | |||
| 7e40620df6 | |||
| 4025bf9c7f | |||
| d7a387cf45 | |||
| e56a9fc1b5 | |||
| 948df90006 | |||
| 161ce02042 | |||
| 97ab59a424 | |||
| c3761464ee | |||
| fb32fcfdb1 | |||
| 89d921299e | |||
| 9591ead7ea | |||
| 7a47b73d08 | |||
| a5005d777f | |||
| 961fe4ce56 | |||
| fe8e3e3e63 | |||
| 9945b45aa9 | |||
| 0713ec0c80 | |||
| 96d200888a | |||
| 13e56f057b | |||
| bb098ce77e | |||
| 4a2f852f30 |
@@ -1 +0,0 @@
|
||||
**
|
||||
BIN
.github/assets/directory_structure.png
vendored
Normal file
BIN
.github/assets/directory_structure.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 181 KiB |
|
Before Width: | Height: | Size: 18 MiB After Width: | Height: | Size: 18 MiB |
40
.github/workflows/docker_deploy.yml
vendored
Normal file
40
.github/workflows/docker_deploy.yml
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
name: Deploy Docker Image to Github Container Registry
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
paths:
|
||||
- "Cargo.toml"
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
packages: write
|
||||
contents: read
|
||||
attestations: write
|
||||
id-token: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: hustcer/setup-nu@v3
|
||||
- uses: cachix/install-nix-action@v31
|
||||
with:
|
||||
nix_path: nixpkgs=channel:nixos-unstable
|
||||
|
||||
- run: nix build .#docker
|
||||
|
||||
- run: |
|
||||
export CARGO_VERSION=$(nu -c "cargo metadata --format-version=1 --no-deps | from json | get packages | first | get version")
|
||||
echo "CARGO_VERSION=$CARGO_VERSION" >> $GITHUB_ENV
|
||||
|
||||
- run: docker load -i result
|
||||
- name: Log in to registry
|
||||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
|
||||
- run: docker tag docki:latest "ghcr.io/quirinecker/docki:$CARGO_VERSION"
|
||||
- run: docker tag docki:latest "ghcr.io/quirinecker/docki:latest"
|
||||
- run: docker push ghcr.io/quirinecker/docki:$CARGO_VERSION
|
||||
- run: docker push ghcr.io/quirinecker/docki:latest
|
||||
26
.github/workflows/rust_deploy.yml
vendored
Normal file
26
.github/workflows/rust_deploy.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
name: Deploy Rust to Crates.io
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
paths:
|
||||
- "./Cargo.toml"
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build
|
||||
run: cargo build --release --bin docki
|
||||
- name: Run tests
|
||||
run: cargo test --verbose
|
||||
- name: Publish to crates.io
|
||||
env:
|
||||
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
|
||||
run: |
|
||||
cargo publish --verbose
|
||||
24
.github/workflows/rust_test.yml
vendored
Normal file
24
.github/workflows/rust_test.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
name: Test Rust
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main", "develop"]
|
||||
paths:
|
||||
- "./src/**"
|
||||
- "./Cargo.toml"
|
||||
pull_request:
|
||||
branches: ["main", "develop"]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build
|
||||
run: cargo build --verbose
|
||||
- name: Run tests
|
||||
run: cargo test --verbose
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
/target
|
||||
dist
|
||||
/docs
|
||||
res/test/docs/slides/revealjs
|
||||
res/test/asciidocs/slides/revealjs
|
||||
res/test/result
|
||||
result
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
workflow:
|
||||
rules:
|
||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"'
|
||||
|
||||
default:
|
||||
image: 'quirinecker/rust-openssl'
|
||||
|
||||
build:
|
||||
script:
|
||||
- cargo build
|
||||
|
||||
test:
|
||||
script:
|
||||
- cargo test
|
||||
|
||||
# publish:
|
||||
# script:
|
||||
# - export CARGO_REGISTRY_TOKEN=$CARGO_TOKEN
|
||||
# - cargo publish
|
||||
|
||||
2979
Cargo.lock
generated
2979
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
24
Cargo.toml
24
Cargo.toml
@@ -1,20 +1,26 @@
|
||||
# Cargo.toml
|
||||
build = "build.rs"
|
||||
|
||||
[package]
|
||||
name = "docki"
|
||||
version = "1.1.0"
|
||||
version = "1.3.0"
|
||||
edition = "2021"
|
||||
description = "cli for building and publishing documentation using asciidoctor"
|
||||
license-file = "LICENSE.txt"
|
||||
authors = ["Quirin Ecker"]
|
||||
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
|
||||
|
||||
[dependencies]
|
||||
bytes = "1.4.0"
|
||||
clap = { version = "4.1.8", features = ["derive"] }
|
||||
colored = "2.0.0"
|
||||
futures = "0.3.26"
|
||||
home = "0.5.4"
|
||||
live-server = "0.6.0"
|
||||
@@ -24,8 +30,8 @@ reqwest = { version = "0.11.14", features = ["blocking"] }
|
||||
text_io = "0.1.12"
|
||||
tokio = { version = "1.26.0", features = ["full"] }
|
||||
zip-extract = "0.1.1"
|
||||
|
||||
[build-dependencies]
|
||||
clap = { version = "4.1.8", features = ["derive"] }
|
||||
clap_complete = "4.1.4"
|
||||
|
||||
nu-ansi-term = "0.50.3"
|
||||
config = { version = "0.15.18", features = ["toml"] }
|
||||
serde = "1.0.228"
|
||||
toml = "0.9.6"
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
FROM rust:slim
|
||||
|
||||
WORKDIR /opt/rust
|
||||
|
||||
RUN apt update \
|
||||
&& apt-get -y upgrade \
|
||||
&& apt-get -y install libssl-dev pkg-config
|
||||
139
README.md
139
README.md
@@ -1,42 +1,145 @@
|
||||
# Docki
|
||||
|
||||
> [!NOTE]
|
||||
> This project is under renovations. While installing it right now might work, it is not guaranteed
|
||||
|
||||
|
||||
## Preview
|
||||
|
||||

|
||||

|
||||
|
||||
Docki is cli for converting asciidoctor files into html files. You can build your documentation with `docki build` and write documenation using the live server with `docki serve`.
|
||||
Docki is cli for converting asciidoctor files into html files.
|
||||
|
||||
## 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]
|
||||
> The input directory can be defined either with a cli argument or the config file. Default is `./docs`
|
||||
|
||||
### Building the documentation
|
||||
|
||||
```shell
|
||||
docki build
|
||||
```
|
||||
|
||||
### Serving the documentation with a live server
|
||||
|
||||
```shell
|
||||
docki serve
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
### Nix
|
||||
|
||||
This installation method is recommended, becuase it is the most maintained due to me using nix in development.
|
||||
|
||||
Note: This is the most basic installation. If you are already more experienced, you might want to add it to your shell or home manager configuration.
|
||||
|
||||
```nix
|
||||
nix profile install github:quirinecker/docki
|
||||
```
|
||||
|
||||
### Homebrew
|
||||
|
||||
```
|
||||
brew tap quirinecker/docki-homebrew https://gitlab.com/quirinecker/docki-homebrew
|
||||
```shell
|
||||
brew tap quirinecker/homebrew-docki https://github.com/quirinecker/homebrew-docki
|
||||
```
|
||||
|
||||
```
|
||||
brew install docki
|
||||
```
|
||||
|
||||
### Nix
|
||||
|
||||
If you just want to try it out real quick and the nix package manager is available on your system you can use the following command.
|
||||
|
||||
```shell
|
||||
nix develop github:quirinecker/docki#preview
|
||||
```
|
||||
|
||||
This will open a shell evnironment with docki installed. If you want to install it permanently with nix, i would recommend following the instructions in the [Nix (Advanced, Flake)](#nix-advanced-flake) section.
|
||||
|
||||
### Cargo
|
||||
|
||||
> [!NOTE]
|
||||
> This is the most basic installation. It will not include asciidoctor_revealjs and asciidoctor itself. Installing asciidoctor has to be done manually, while installing asciidoctor_revealjs can be done with `docki install-reveal`
|
||||
|
||||
```shell
|
||||
cargo install docki
|
||||
```
|
||||
|
||||
### Docker
|
||||
|
||||
There is also a docker image available to use. It is primarily used for the gh actions.
|
||||
|
||||
```shell
|
||||
docker pull ghcr.io/quirinecker/docki:latest
|
||||
```
|
||||
|
||||
You can also build it yourself with nix.
|
||||
|
||||
```
|
||||
nix build .#docker && docker load -i result
|
||||
```
|
||||
|
||||
### Nix (Advanced, Flake)
|
||||
|
||||
> [!NOTE]
|
||||
> There are multiple ways to install docki with nix. This is the way I installed it on my machine.
|
||||
|
||||
1. Add it to the flake inputs
|
||||
|
||||
```nix
|
||||
docki = {
|
||||
url = "github:quirinecker/docki";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
```
|
||||
|
||||
2. Add `@inputs` at the end of the outputs (if you haven't already)
|
||||
|
||||
```nix
|
||||
outputs = {
|
||||
nixpkgs
|
||||
...
|
||||
}@inputs:
|
||||
...Rest of your flake...
|
||||
```
|
||||
|
||||
3. Add the input to your system packages (system configuration) or home packages (home manager configuration)
|
||||
|
||||
```nix
|
||||
environment.systemPackages = with pkgs; [
|
||||
inputs.docki.packages.${system}.default
|
||||
]
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```nix
|
||||
home.packages = with pkgs; [
|
||||
inputs.docki.packages.${system}.default
|
||||
]
|
||||
```
|
||||
|
||||
## 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
|
||||
|
||||
### Running it
|
||||
|
||||
If you just want to run it, you can use the `nix run` command. This will install all the build dependencies, build the binary and run it.
|
||||
|
||||
```shell
|
||||
nix run
|
||||
```
|
||||
|
||||
### Development Shell
|
||||
|
||||
You can also use the development shell with the command below. In this shell all dependencies for building and running the project are installed.
|
||||
|
||||
```shell
|
||||
nix develop
|
||||
```
|
||||
|
||||
Afterwards it can be built and run with cargo
|
||||
|
||||
```shell
|
||||
cargo run -- <args>
|
||||
```
|
||||
|
||||
|
||||
23
build.rs
23
build.rs
@@ -1,23 +0,0 @@
|
||||
use std::io::Error;
|
||||
|
||||
use clap::CommandFactory;
|
||||
use clap_complete::{generate_to, shells::{Bash, Zsh, Fish}};
|
||||
|
||||
include!("src/app/args/structure.rs");
|
||||
include!("src/app/fs_util/mod.rs");
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
generate_completions()
|
||||
}
|
||||
|
||||
fn generate_completions() -> Result<(), Error> {
|
||||
let mut command = Args::command();
|
||||
let home_path = env::var("HOME").expect("could not get home path");
|
||||
let out_dir = format!("{}/.docki/completions/", home_path);
|
||||
create_dir_recursive(&out_dir);
|
||||
generate_to(Bash, &mut command, "docki", &out_dir)?;
|
||||
generate_to(Zsh, &mut command, "docki", &out_dir)?;
|
||||
generate_to(Fish, &mut command, "docki", &out_dir)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
4
config/docki.config.toml
Normal file
4
config/docki.config.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
port = 8080
|
||||
input_dir = "./docs"
|
||||
offline_reveal = false
|
||||
output_dir = "./dist"
|
||||
77
flake.lock
generated
77
flake.lock
generated
@@ -1,6 +1,63 @@
|
||||
{
|
||||
"nodes": {
|
||||
"fenix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"naersk",
|
||||
"nixpkgs"
|
||||
],
|
||||
"rust-analyzer-src": "rust-analyzer-src"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1752475459,
|
||||
"narHash": "sha256-z6QEu4ZFuHiqdOPbYss4/Q8B0BFhacR8ts6jO/F/aOU=",
|
||||
"owner": "nix-community",
|
||||
"repo": "fenix",
|
||||
"rev": "bf0d6f70f4c9a9cf8845f992105652173f4b617f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "fenix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"naersk": {
|
||||
"inputs": {
|
||||
"fenix": "fenix",
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1752689277,
|
||||
"narHash": "sha256-uldUBFkZe/E7qbvxa3mH1ItrWZyT6w1dBKJQF/3ZSsc=",
|
||||
"owner": "nix-community",
|
||||
"repo": "naersk",
|
||||
"rev": "0e72363d0938b0208d6c646d10649164c43f4d64",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "naersk",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1752077645,
|
||||
"narHash": "sha256-HM791ZQtXV93xtCY+ZxG1REzhQenSQO020cu6rHtAPk=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "be9e214982e20b8310878ac2baa063a961c1bdf6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1760934318,
|
||||
"narHash": "sha256-/oUYsC0lUCBory65VK+UHqCCsCspbL1Vgfcf1KUYqVw=",
|
||||
@@ -18,10 +75,28 @@
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs",
|
||||
"naersk": "naersk",
|
||||
"nixpkgs": "nixpkgs_2",
|
||||
"systems": "systems"
|
||||
}
|
||||
},
|
||||
"rust-analyzer-src": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1752428706,
|
||||
"narHash": "sha256-EJcdxw3aXfP8Ex1Nm3s0awyH9egQvB2Gu+QEnJn2Sfg=",
|
||||
"owner": "rust-lang",
|
||||
"repo": "rust-analyzer",
|
||||
"rev": "591e3b7624be97e4443ea7b5542c191311aa141d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "rust-lang",
|
||||
"ref": "nightly",
|
||||
"repo": "rust-analyzer",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
|
||||
104
flake.nix
104
flake.nix
@@ -12,11 +12,14 @@
|
||||
nixpkgs,
|
||||
systems,
|
||||
naersk,
|
||||
self,
|
||||
...
|
||||
}:
|
||||
let
|
||||
eachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system});
|
||||
build_asciidoctor_revealjs = pkgs: pkgs.buildRubyGem {
|
||||
build_asciidoctor_revealjs =
|
||||
pkgs:
|
||||
pkgs.buildRubyGem {
|
||||
gemName = "asciidoctor-revealjs";
|
||||
version = "5.2.0";
|
||||
source = {
|
||||
@@ -26,7 +29,9 @@
|
||||
};
|
||||
};
|
||||
|
||||
build_asciidoctor = pkgs: pkgs.buildRubyGem {
|
||||
build_asciidoctor =
|
||||
pkgs:
|
||||
pkgs.buildRubyGem {
|
||||
gemName = "asciidoctor";
|
||||
version = "2.0.25";
|
||||
source = {
|
||||
@@ -35,6 +40,48 @@
|
||||
sha256 = "sha256-sG/oIrCRDU4l6g9WL+z8eUjpRuIi79lJSEnSfaQmfRk=";
|
||||
};
|
||||
};
|
||||
|
||||
build_docki =
|
||||
{ naerskLib, pkgs }:
|
||||
let
|
||||
runtimeDeps = with pkgs; [
|
||||
(ruby.withPackages (
|
||||
p: with p; [
|
||||
(build_asciidoctor_revealjs pkgs)
|
||||
(build_asciidoctor pkgs)
|
||||
bundler
|
||||
]
|
||||
))
|
||||
];
|
||||
in
|
||||
naerskLib.buildPackage {
|
||||
src = ./.;
|
||||
buildInputs = [
|
||||
];
|
||||
nativeBuildInputs = with pkgs; [
|
||||
pkg-config
|
||||
openssl.dev
|
||||
libiconv
|
||||
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 = ''
|
||||
mkdir -p $out/share/bash-completion/completions
|
||||
mkdir -p $out/share/zsh/site-functions
|
||||
mkdir -p $out/share/fish/vendor_completions.d
|
||||
|
||||
$out/bin/docki completions bash > $out/share/bash-completion/completions/docki
|
||||
$out/bin/docki completions zsh > $out/share/zsh/site-functions/_docki
|
||||
$out/bin/docki completions fish > $out/share/fish/vendor_completions.d/docki.fish
|
||||
|
||||
wrapProgram $out/bin/docki --prefix PATH : ${pkgs.lib.makeBinPath runtimeDeps}
|
||||
'';
|
||||
};
|
||||
|
||||
in
|
||||
{
|
||||
devShells = eachSystem (pkgs: {
|
||||
@@ -56,36 +103,47 @@
|
||||
))
|
||||
];
|
||||
};
|
||||
|
||||
preview = pkgs.mkShell {
|
||||
name = "docki-preview";
|
||||
buildInputs = [
|
||||
pkgs.zsh
|
||||
pkgs.fish
|
||||
pkgs.bash
|
||||
self.packages.${pkgs.system}.default
|
||||
];
|
||||
};
|
||||
});
|
||||
|
||||
packages = eachSystem (
|
||||
pkgs:
|
||||
let
|
||||
naerskLib = pkgs.callPackage naersk { };
|
||||
runtimeDeps = with pkgs; [
|
||||
(ruby.withPackages (
|
||||
p: with p; [
|
||||
(build_asciidoctor_revealjs pkgs)
|
||||
(build_asciidoctor pkgs)
|
||||
bundler
|
||||
]
|
||||
))
|
||||
];
|
||||
in
|
||||
{
|
||||
default = naerskLib.buildPackage {
|
||||
src = ./.;
|
||||
buildInputs =[
|
||||
default = build_docki {
|
||||
naerskLib = naerskLib;
|
||||
pkgs = pkgs;
|
||||
};
|
||||
|
||||
docker = pkgs.dockerTools.buildImage {
|
||||
name = "docki";
|
||||
tag = "latest";
|
||||
config = {
|
||||
WorkingDir = "/app";
|
||||
};
|
||||
copyToRoot = pkgs.buildEnv {
|
||||
name = "docki-docker";
|
||||
paths = [
|
||||
pkgs.coreutils
|
||||
pkgs.bash
|
||||
pkgs.cacert
|
||||
(build_docki {
|
||||
naerskLib = naerskLib;
|
||||
pkgs = pkgs;
|
||||
})
|
||||
];
|
||||
nativeBuildInputs = with pkgs; [
|
||||
pkg-config
|
||||
openssl.dev
|
||||
libiconv
|
||||
makeWrapper
|
||||
];
|
||||
postInstall = ''
|
||||
wrapProgram $out/bin/docki --prefix PATH : ${pkgs.lib.makeBinPath runtimeDeps}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
16
res/test/asciidocs/index.adoc
Normal file
16
res/test/asciidocs/index.adoc
Normal file
@@ -0,0 +1,16 @@
|
||||
= 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.
|
||||
19
res/test/asciidocs/slides/index.adoc
Normal file
19
res/test/asciidocs/slides/index.adoc
Normal file
@@ -0,0 +1,19 @@
|
||||
# Slides
|
||||
|
||||
## Slide 1
|
||||
|
||||
* First
|
||||
* Second
|
||||
* Third
|
||||
|
||||
## Slide 2
|
||||
|
||||
* First
|
||||
* Second
|
||||
* Third
|
||||
|
||||
### Slide 3
|
||||
|
||||
* First
|
||||
* Second
|
||||
* Third
|
||||
3
res/test/docki.config.toml
Normal file
3
res/test/docki.config.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
docs_dir = "./asciidocs"
|
||||
port = 6969
|
||||
offline_reveal = false
|
||||
@@ -0,0 +1,16 @@
|
||||
= 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.
|
||||
|
||||
19
res/test/docs/slides/index.adoc
Normal file
19
res/test/docs/slides/index.adoc
Normal file
@@ -0,0 +1,19 @@
|
||||
# Slides
|
||||
|
||||
## Slide 1
|
||||
|
||||
* First
|
||||
* Second
|
||||
* Third
|
||||
|
||||
## Slide 2
|
||||
|
||||
* First
|
||||
* Second
|
||||
* Third
|
||||
|
||||
### Slide 3
|
||||
|
||||
* First
|
||||
* Second
|
||||
* Third
|
||||
@@ -1,25 +0,0 @@
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
#[derive(Parser)]
|
||||
pub struct Args {
|
||||
#[command(subcommand)]
|
||||
pub command: CommandArg
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub enum CommandArg {
|
||||
/// Builds the documentation into a dist folder
|
||||
Build,
|
||||
/// Checks if everything required for docki is installed
|
||||
Health,
|
||||
/// Helper command for installing asciidoctor-reveal-js
|
||||
InstallReveal,
|
||||
/// Starts a Webserver with the live preview of the Documentation
|
||||
Serve {
|
||||
/// Port for the Live Server
|
||||
#[arg(short, long)]
|
||||
port: Option<u16>
|
||||
},
|
||||
/// Information about the completions
|
||||
Completions
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
use regex::Regex;
|
||||
use std::process;
|
||||
|
||||
use regex::Regex;
|
||||
use crate::app::config::config::Config;
|
||||
|
||||
fn exec_command(command: &mut process::Command) -> Result<(), String> {
|
||||
let result = command.output();
|
||||
@@ -13,9 +14,13 @@ fn exec_command(command: &mut process::Command) -> Result<(), String> {
|
||||
}
|
||||
} else {
|
||||
println!("{}", result.unwrap_err());
|
||||
return Err(
|
||||
"asciidoctor not installed. For more information run docki health!".to_string(),
|
||||
);
|
||||
|
||||
let binary_name = command.get_program().to_str().unwrap_or("Something is");
|
||||
|
||||
return Err(format!(
|
||||
"{} not installed. For more information run docki health!",
|
||||
binary_name
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +34,17 @@ fn asciidoctor_docs(in_path: &str, out_path: &str) -> process::Command {
|
||||
return command;
|
||||
}
|
||||
|
||||
fn asciidoctor_slides(in_path: &str, out_path: &str) -> process::Command {
|
||||
fn asciidoctor_slides(in_path: &str, out_path: &str, config: &Config) -> process::Command {
|
||||
let mut command = process::Command::new(format!("asciidoctor-revealjs"));
|
||||
let out_dir = parent_path(out_path);
|
||||
let revealjs_path = "/slides/revealjs";
|
||||
let revealjs_path = if config.offline_reveal {
|
||||
path_between(
|
||||
out_dir.to_string(),
|
||||
format!("{}/slides/revealjs", config.output_dir),
|
||||
)
|
||||
} else {
|
||||
"https://cdn.jsdelivr.net/npm/reveal.js@5.2.1".to_string()
|
||||
};
|
||||
|
||||
command
|
||||
.arg(format!("{in_path}"))
|
||||
@@ -97,13 +109,13 @@ pub fn matching_from_start(from_segments: &Vec<String>, to_segments: &Vec<String
|
||||
return from_segments.len();
|
||||
}
|
||||
|
||||
pub fn build_doc(in_path: &str, out_path: &str) -> Result<(), String> {
|
||||
pub fn build_doc(in_path: &str, out_path: &str, _: &Config) -> Result<(), String> {
|
||||
let mut command = asciidoctor_docs(in_path, out_path);
|
||||
return exec_command(&mut command);
|
||||
}
|
||||
|
||||
pub fn build_slide(in_path: &str, out_path: &str) -> Result<(), String> {
|
||||
let mut command = asciidoctor_slides(in_path, out_path);
|
||||
pub fn build_slide(in_path: &str, out_path: &str, config: &Config) -> Result<(), String> {
|
||||
let mut command = asciidoctor_slides(in_path, out_path, config);
|
||||
return exec_command(&mut command);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,33 +1,121 @@
|
||||
use std::fs;
|
||||
|
||||
use self::asciidoctor::{build_doc, build_slide};
|
||||
|
||||
use super::fs_util;
|
||||
|
||||
pub mod asciidoctor;
|
||||
|
||||
pub trait Builder {
|
||||
fn build(&self, in_path: &str, out_path: &str) -> Result<(), String>;
|
||||
use std::{
|
||||
fs, io::Cursor, path::PathBuf
|
||||
};
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
pub fn docki_build(in_path: &str) -> DockiBuildResult {
|
||||
let out_path = in_path.replace("/docs/", "/dist/");
|
||||
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");
|
||||
|
||||
if in_path.starts_with("./docs/slides/") && in_path.ends_with(".adoc") {
|
||||
if let Err(err) = build_slide(&in_path, &convert_out_path) {
|
||||
if path.starts_with(format!("{}/slides/", &self.config.input_dir).as_str()) && path.ends_with(".adoc") {
|
||||
if let Err(err) = build_slide(&path, &convert_out_path, self.config) {
|
||||
return DockiBuildResult::Err(err);
|
||||
}
|
||||
|
||||
DockiBuildResult::Slide(convert_out_path)
|
||||
} else if in_path.ends_with(".adoc") {
|
||||
if let Err(err) = build_doc(&in_path, &convert_out_path) {
|
||||
} else if path.ends_with(".adoc") {
|
||||
if let Err(err) = build_doc(&path, &convert_out_path, self.config) {
|
||||
return DockiBuildResult::Err(err);
|
||||
}
|
||||
|
||||
DockiBuildResult::Doc(convert_out_path)
|
||||
} else {
|
||||
if let Err(err) = copy(&in_path, &out_path) {
|
||||
if let Err(err) = Self::copy(&path, &out_path) {
|
||||
return DockiBuildResult::Err(err);
|
||||
}
|
||||
|
||||
@@ -39,12 +127,21 @@ fn copy(in_path: &str, out_path: &str) -> Result<(), String> {
|
||||
fs_util::create_parent_dir_recursive(out_path);
|
||||
|
||||
if let Err(err) = fs::copy(in_path, out_path) {
|
||||
return Err(err.to_string())
|
||||
return Err(err.to_string());
|
||||
}
|
||||
|
||||
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 {
|
||||
Slide(String),
|
||||
Doc(String),
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
use super::executions::build_execution::BuildExecution;
|
||||
use crate::app::config::config::Config;
|
||||
|
||||
pub async fn build() -> () {
|
||||
let mut build_execution = BuildExecution::new();
|
||||
build_execution.execute().await.expect("build failed")
|
||||
use crate::app::build::DockiBuilder;
|
||||
|
||||
pub async fn build(config: &Config) -> () {
|
||||
let mut builder = DockiBuilder::new(config);
|
||||
|
||||
builder.prepare().await.expect("could not prepare for build");
|
||||
builder.build_docs().expect("build failed")
|
||||
}
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
use colored::Colorize;
|
||||
use std::io;
|
||||
|
||||
const INFO: &str = "
|
||||
You can add completions for docki with the following methods. If you want the completions to be persistent add
|
||||
them to a init file e.g. ~/.zshrc, ~/.bashrc, ~/.config/fish/config.fish.
|
||||
use clap::CommandFactory;
|
||||
use clap_complete::{generate, shells::{Bash, Fish, Zsh}};
|
||||
|
||||
Get Fish Completions
|
||||
source ~/.docki/completions/docki.fish
|
||||
use crate::app::config::arguments::{Args, ShellArg};
|
||||
|
||||
Get Zsh Completions
|
||||
source ~/.docki/completions/_docki
|
||||
pub fn completions(shell: ShellArg) {
|
||||
let mut command = Args::command();
|
||||
|
||||
Get Bash Completions
|
||||
source ~/.docki/completions/docki.bash
|
||||
";
|
||||
|
||||
pub fn completions() {
|
||||
println!();
|
||||
println!("{}", "Completions".blue().bold());
|
||||
println!("{}", INFO.bright_black());
|
||||
match shell {
|
||||
ShellArg::Bash => generate(Bash, &mut command, "docki", &mut io::stdout()),
|
||||
ShellArg::Fish => generate(Fish, &mut command, "docki", &mut io::stdout()),
|
||||
ShellArg::Zsh => generate(Zsh, &mut command, "docki", &mut io::stdout()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
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) -> 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().await {
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
return self.build_dir(&path);
|
||||
}
|
||||
|
||||
|
||||
async fn prepare() -> Result<(), String> {
|
||||
let reveal_version = "3.9.2";
|
||||
let target = format!("https://github.com/hakimel/reveal.js/archive/{reveal_version}.zip");
|
||||
|
||||
create_dir_recursive("./docs/slides");
|
||||
|
||||
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) -> 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);
|
||||
|
||||
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(());
|
||||
}
|
||||
|
||||
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 +0,0 @@
|
||||
pub mod build_execution;
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{process::Command, io::ErrorKind};
|
||||
use colored::Colorize;
|
||||
use nu_ansi_term::Color::{LightGray, LightGreen, LightRed};
|
||||
use std::{io::ErrorKind, process::Command};
|
||||
|
||||
const INFO_ASCIIDOC: &str = "
|
||||
Install the binary with your package manager!
|
||||
@@ -37,7 +37,7 @@ fn check_reveal() -> () {
|
||||
}
|
||||
|
||||
fn reveal_is_installed() -> bool {
|
||||
return check_command("asciidoctor-revealjs")
|
||||
return check_command("asciidoctor-revealjs");
|
||||
}
|
||||
|
||||
fn check_asciidoc() -> () {
|
||||
@@ -49,23 +49,21 @@ fn check_asciidoc() -> () {
|
||||
}
|
||||
|
||||
fn asciidoc_is_installed() -> bool {
|
||||
return check_command("asciidoctor")
|
||||
return check_command("asciidoctor");
|
||||
}
|
||||
|
||||
fn check_command(command: &str) -> bool {
|
||||
return match Command::new(command)
|
||||
.output() {
|
||||
return match Command::new(command).output() {
|
||||
Ok(_) => true,
|
||||
Err(e) => ErrorKind::NotFound != e.kind()
|
||||
}
|
||||
Err(e) => ErrorKind::NotFound != e.kind(),
|
||||
};
|
||||
}
|
||||
|
||||
fn print_health_ok(name: &str) {
|
||||
println!("- ✔️ {}", name.bright_green());
|
||||
println!("- ✔️ {}", LightGreen.paint(name));
|
||||
}
|
||||
|
||||
fn print_health_not_ok(name: &str, info: &str) {
|
||||
println!("- ❗{}", name.bright_red());
|
||||
println!("{}", info.bright_black())
|
||||
println!("- ❗{}", LightRed.paint(name));
|
||||
println!("{}", LightGray.paint(info))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
pub mod build;
|
||||
pub mod completions;
|
||||
pub mod executions;
|
||||
pub mod health;
|
||||
pub mod install_reveal;
|
||||
pub mod serve;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use colored::Colorize;
|
||||
use nu_ansi_term::Color::Green;
|
||||
use futures::StreamExt;
|
||||
use live_server::listen;
|
||||
use notify::{
|
||||
@@ -7,72 +7,97 @@ use notify::{
|
||||
};
|
||||
use std::{env, path::Path};
|
||||
|
||||
use crate::app::{ watcher::watcher, build::{docki_build, DockiBuildResult}, commands::build::build, log::display_status};
|
||||
use crate::app::watcher::watcher;
|
||||
use crate::app::log::display_status;
|
||||
use crate::app::config::config::Config;
|
||||
use crate::app::build::{DockiBuildResult, DockiBuilder};
|
||||
|
||||
|
||||
pub async fn serve(port: Option<u16>) {
|
||||
build().await;
|
||||
tokio::join!(watch_and_build(), start_server(port));
|
||||
pub async fn serve(config: &Config) {
|
||||
let builder = DockiBuilder::new(config);
|
||||
let mut server = Server::new(builder, config);
|
||||
server.serve().await;
|
||||
}
|
||||
|
||||
async fn watch_and_build() {
|
||||
watch(Path::new("./docs"))
|
||||
.await
|
||||
.expect("something went wrong")
|
||||
struct Server<'a> {
|
||||
builder: DockiBuilder<'a>,
|
||||
config: &'a Config,
|
||||
}
|
||||
|
||||
async fn start_server(port: Option<u16>) {
|
||||
let unwrapped_port = port.unwrap_or(8080);
|
||||
impl <'a> Server <'a> {
|
||||
fn new(builder: DockiBuilder<'a>, config: &'a Config) -> Self {
|
||||
return Self {
|
||||
builder,
|
||||
config: config
|
||||
}
|
||||
}
|
||||
|
||||
async fn serve(&mut self) {
|
||||
self.builder.prepare().await.expect("could not prepare for build");
|
||||
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);
|
||||
|
||||
println!(
|
||||
"\nServing at {}{} ",
|
||||
"http://localhost:".bold(),
|
||||
unwrapped_port.to_string().bold()
|
||||
"\nServing at {}",
|
||||
hyperlink
|
||||
);
|
||||
|
||||
let Ok(()) = listen("localhost", port.unwrap_or(8080), "./dist").await else {
|
||||
let Ok(()) = listen("localhost", self.config.port, self.config.output_dir.clone()).await else {
|
||||
panic!("could not start server")
|
||||
};
|
||||
}
|
||||
|
||||
async fn watch(path: &Path) -> notify::Result<()> {
|
||||
async fn watch_and_build(&self) {
|
||||
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()?;
|
||||
|
||||
watcher.watch(path.as_ref(), RecursiveMode::Recursive)?;
|
||||
|
||||
while let Some(res) = rx.next().await {
|
||||
let event = res.expect("watching failed");
|
||||
file_change(event)
|
||||
self.file_change(event)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
}
|
||||
|
||||
fn file_change(event: Event) {
|
||||
fn file_change(&self, event: Event) {
|
||||
match event.kind {
|
||||
EventKind::Modify(ModifyKind::Data(_)) => build_file(event.paths),
|
||||
EventKind::Modify(ModifyKind::Data(_)) => self.build_valid_files(event.paths),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn build_file(paths: Vec<std::path::PathBuf>) {
|
||||
fn build_valid_files(&self, paths: Vec<std::path::PathBuf>) {
|
||||
let invalid_path_message = "changed path is invalid";
|
||||
let in_path = paths
|
||||
.first()
|
||||
.expect(invalid_path_message)
|
||||
.to_str()
|
||||
.strip_prefix(&Self::current_dir())
|
||||
.expect(invalid_path_message)
|
||||
.replace(¤t_dir(), "")
|
||||
.replace("/./", "./");
|
||||
.to_str()
|
||||
.expect(invalid_path_message);
|
||||
|
||||
|
||||
let result = docki_build(&in_path);
|
||||
let in_path = format!("./{}", in_path);
|
||||
let result = self.builder.build_file(&in_path);
|
||||
|
||||
match result {
|
||||
DockiBuildResult::Slide(out_path) => display_rebuilding_status("Slide", &in_path, &out_path),
|
||||
DockiBuildResult::Doc(out_path) => display_rebuilding_status("Doc", &in_path, &out_path),
|
||||
DockiBuildResult::Copy(out_path) => display_rebuilding_status("Copy", &in_path, &out_path),
|
||||
DockiBuildResult::Slide(out_path) => Self::display_rebuilding_status("Slide", &in_path, &out_path),
|
||||
DockiBuildResult::Doc(out_path) => Self::display_rebuilding_status("Doc", &in_path, &out_path),
|
||||
DockiBuildResult::Copy(out_path) => Self::display_rebuilding_status("Copy", &in_path, &out_path),
|
||||
DockiBuildResult::Err(err) => {
|
||||
display_rebuilding_status("Error", &in_path, "");
|
||||
Self::display_rebuilding_status("Error", &in_path, "");
|
||||
println!("{}", err);
|
||||
},
|
||||
}
|
||||
@@ -91,4 +116,6 @@ fn current_dir() -> String {
|
||||
.expect(err_message),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
60
src/app/config/arguments.rs
Normal file
60
src/app/config/arguments.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
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)]
|
||||
#[command(after_help = format!("More information like defaults can be found at {}", github_hyperlink()))]
|
||||
pub struct Args {
|
||||
#[command(subcommand)]
|
||||
pub command: CommandArg,
|
||||
|
||||
/// The directory where the documentation is located
|
||||
#[arg(short, long, global = true)]
|
||||
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)]
|
||||
pub enum ShellArg {
|
||||
Bash,
|
||||
Fish,
|
||||
Zsh,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub enum CommandArg {
|
||||
/// Builds the documentation into the specified output_dir
|
||||
Build,
|
||||
/// Checks if everything required for docki is installed
|
||||
Health,
|
||||
/// Deprecated: Helper command for installing asciidoctor-reveal-js
|
||||
InstallReveal,
|
||||
/// Starts a Webserver with the live preview of the Documentation
|
||||
Serve {
|
||||
/// Port for the Live Server
|
||||
#[arg(short, long)]
|
||||
port: Option<u16>,
|
||||
},
|
||||
/// Generates completions for the desired shell
|
||||
Completions {
|
||||
#[command(subcommand)]
|
||||
shell: ShellArg,
|
||||
},
|
||||
}
|
||||
|
||||
impl Args {}
|
||||
44
src/app/config/config.rs
Normal file
44
src/app/config/config.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::app::config::arguments::CommandArg;
|
||||
|
||||
#[derive(Deserialize, Debug, Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct Config {
|
||||
pub port: u16,
|
||||
pub input_dir: String,
|
||||
pub offline_reveal: bool,
|
||||
pub output_dir: String,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load() -> Result<Self, config::ConfigError> {
|
||||
let s = config::Config::builder()
|
||||
.add_source(config::File::with_name("./docki.config.toml"))
|
||||
.build()?;
|
||||
s.try_deserialize()
|
||||
}
|
||||
|
||||
pub fn merge_with_args(self, args: &super::arguments::Args) -> Self {
|
||||
Self {
|
||||
port: match args.command {
|
||||
CommandArg::Serve { port } => port.unwrap_or(self.port),
|
||||
_ => self.port,
|
||||
},
|
||||
input_dir: args.input_dir.clone().unwrap_or(self.input_dir),
|
||||
output_dir: args.output_dir.clone().unwrap_or(self.output_dir),
|
||||
offline_reveal: args.offline_reveal || self.offline_reveal,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
port: 8080,
|
||||
input_dir: "./docs".to_string(),
|
||||
output_dir: "./dist".to_string(),
|
||||
offline_reveal: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
use clap::Parser;
|
||||
|
||||
use self::structure::Args;
|
||||
use self::arguments::Args;
|
||||
|
||||
pub mod structure;
|
||||
pub mod arguments;
|
||||
pub mod config;
|
||||
|
||||
pub fn args() -> Args {
|
||||
return Args::parse();
|
||||
|
||||
}
|
||||
@@ -1,20 +1,19 @@
|
||||
use colored::Colorize;
|
||||
use nu_ansi_term::Color::LightGreen;
|
||||
use nu_ansi_term::Color::LightRed;
|
||||
use nu_ansi_term::Style;
|
||||
|
||||
pub fn display_status(context1: &str, context2: &str, in_path: &str, out_path: &str) {
|
||||
let colored_context = color_context(context2);
|
||||
let colored_context = if context2 == "Error" {
|
||||
LightRed.paint(context2)
|
||||
} else {
|
||||
LightGreen.paint(context2)
|
||||
};
|
||||
|
||||
println!(
|
||||
"({}) [{}] {} -> {}",
|
||||
context1.bold(),
|
||||
Style::new().paint(context1),
|
||||
colored_context,
|
||||
in_path,
|
||||
out_path
|
||||
);
|
||||
}
|
||||
|
||||
fn color_context(context: &str) -> colored::ColoredString {
|
||||
if context == "Error" {
|
||||
return context.bright_red()
|
||||
} else {
|
||||
return context.bright_green()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ pub mod build;
|
||||
pub mod fs_util;
|
||||
pub mod watcher;
|
||||
pub mod log;
|
||||
mod args;
|
||||
pub mod config;
|
||||
|
||||
use std::env;
|
||||
|
||||
use self::args::{args, structure::CommandArg};
|
||||
use crate::app::config::config::Config;
|
||||
|
||||
use self::config::{args, arguments::CommandArg};
|
||||
use self::commands::build::build;
|
||||
use self::commands::completions::completions;
|
||||
use self::commands::health::health;
|
||||
@@ -20,14 +22,15 @@ impl App {
|
||||
|
||||
pub async fn start(&self) {
|
||||
let args = args();
|
||||
let config = Config::load().unwrap_or(Config::default()).merge_with_args(&args);
|
||||
Self::setup_environment_variables();
|
||||
|
||||
match args.command {
|
||||
CommandArg::Build => build().await,
|
||||
CommandArg::Build { .. } => build(&config).await,
|
||||
CommandArg::Health => health(),
|
||||
CommandArg::InstallReveal => install_reveal().await,
|
||||
CommandArg::Serve { port } => serve(port).await,
|
||||
CommandArg::Completions => completions()
|
||||
CommandArg::Serve { .. } => serve(&config).await,
|
||||
CommandArg::Completions { shell } => completions(shell)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
use crate::app::build::asciidoctor;
|
||||
|
||||
#[test]
|
||||
fn last_matching_index_0() {
|
||||
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::matching_from_start(&vec1, &vec2);
|
||||
assert_eq!(last_maching, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn last_matching_index_1() {
|
||||
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::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")
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ fn test_fetch_asciidoctor_paths_recursive() {
|
||||
let paths = fs_util::fetch_paths_recursive("res/test/docs").unwrap();
|
||||
let len = paths.len();
|
||||
dbg!(paths);
|
||||
assert_eq!(len, 5);
|
||||
assert_eq!(len, 2);
|
||||
}
|
||||
|
||||
34
src/util.rs
Normal file
34
src/util.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
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