Skip to content

Commit

Permalink
feat(docs): Add website for docs
Browse files Browse the repository at this point in the history
Signed-off-by: dark0dave <dark0dave@mykolab.com>
  • Loading branch information
dark0dave committed Jul 3, 2024
1 parent 8f127ac commit de90e5f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 23 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: docs
on:
push:
branches: ["main"]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Create docs
run: |
cargo doc
mv target/doc/mod_installer ./_site
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
26 changes: 14 additions & 12 deletions src/mod_component.rs → src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use std::{
path::PathBuf,
};

// This should mirror the weidu component
// https://github.com/WeiDUorg/weidu/blob/devel/src/tp.ml#L98
#[derive(Debug, PartialEq, PartialOrd, Clone)]
pub struct ModComponent {
pub struct Component {
pub tp_file: String,
pub name: String,
pub lang: String,
Expand All @@ -15,7 +17,7 @@ pub struct ModComponent {
pub version: String,
}

impl From<String> for ModComponent {
impl From<String> for Component {
fn from(line: String) -> Self {
let mut parts = line.split('~');

Expand Down Expand Up @@ -102,7 +104,7 @@ impl From<String> for ModComponent {
.trim()
.to_string();

ModComponent {
Component {
tp_file,
name,
lang,
Expand All @@ -114,7 +116,7 @@ impl From<String> for ModComponent {
}
}

pub fn parse_weidu_log(weidu_log_path: PathBuf) -> Vec<ModComponent> {
pub fn parse_weidu_log(weidu_log_path: PathBuf) -> Vec<Component> {
let file = File::open(weidu_log_path).expect("Could not open weidu log exiting");
let reader = BufReader::new(file);

Expand All @@ -127,7 +129,7 @@ pub fn parse_weidu_log(weidu_log_path: PathBuf) -> Vec<ModComponent> {
&& !component.starts_with('\n')
&& !component.starts_with("//") =>
{
Some(ModComponent::from(component))
Some(Component::from(component))
}
_ => None,
})
Expand All @@ -147,7 +149,7 @@ mod tests {
assert_eq!(
logs,
vec![
ModComponent {
Component {
tp_file: "TEST.TP2".to_string(),
name: "test_mod_name_1".to_string(),
lang: "0".to_string(),
Expand All @@ -156,7 +158,7 @@ mod tests {
sub_component: "".to_string(),
version: "".to_string()
},
ModComponent {
Component {
tp_file: "TEST.TP2".to_string(),
name: "test_mod_name_1".to_string(),
lang: "0".to_string(),
Expand All @@ -165,7 +167,7 @@ mod tests {
sub_component: "".to_string(),
version: "".to_string()
},
ModComponent {
Component {
tp_file: "END.TP2".to_string(),
name: "test_mod_name_2".to_string(),
lang: "0".to_string(),
Expand All @@ -174,7 +176,7 @@ mod tests {
sub_component: "Standard installation".to_string(),
version: "".to_string()
},
ModComponent {
Component {
tp_file: "END.TP2".to_string(),
name: "test_mod_name_3".to_string(),
lang: "0".to_string(),
Expand All @@ -183,7 +185,7 @@ mod tests {
sub_component: "".to_string(),
version: "1.02".to_string()
},
ModComponent {
Component {
tp_file: "TWEAKS.TP2".to_string(),
name: "test_mod_name_4".to_string(),
lang: "0".to_string(),
Expand All @@ -200,8 +202,8 @@ mod tests {
#[test]
fn test_parse_windows() {
let mod_string = r"~TOBEX\TOBEX.TP2~ #0 #100 // TobEx - Core: v28";
let mod_component = ModComponent::from(mod_string.to_string());
let expected = ModComponent {
let mod_component = Component::from(mod_string.to_string());
let expected = Component {
tp_file: "TOBEX.TP2".to_string(),
name: "tobex".to_string(),
lang: "0".to_string(),
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use clap::Parser;
use env_logger::Env;

use crate::{
mod_component::parse_weidu_log,
component::parse_weidu_log,
utils::{
copy_mod_folder, create_weidu_log_if_not_exists, mod_folder_present_in_game_directory,
search_mod_folders,
Expand All @@ -14,7 +14,7 @@ use crate::{
};

mod args;
mod mod_component;
mod component;
mod state;
mod utils;
mod weidu;
Expand Down
8 changes: 4 additions & 4 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
};
use walkdir::WalkDir;

use crate::mod_component::ModComponent;
use crate::component::Component;

pub fn create_weidu_log_if_not_exists(game_directory: &Path) -> PathBuf {
let weidu_log_file = game_directory.join("weidu").with_extension("log");
Expand All @@ -33,7 +33,7 @@ pub fn copy_mod_folder(game_directory: &Path, mod_folder: &Path) {

pub fn search_mod_folders(
folder_directories: &[PathBuf],
weidu_mod: &ModComponent,
weidu_mod: &Component,
depth: usize,
) -> PathBuf {
let mod_folder_locations = folder_directories
Expand All @@ -48,7 +48,7 @@ pub fn search_mod_folders(
}
}

fn find_mod_folder(mod_component: &ModComponent, mod_dir: &Path, depth: usize) -> Option<PathBuf> {
fn find_mod_folder(mod_component: &Component, mod_dir: &Path, depth: usize) -> Option<PathBuf> {
WalkDir::new(mod_dir)
.follow_links(true)
.max_depth(depth)
Expand Down Expand Up @@ -84,7 +84,7 @@ mod tests {

#[test]
fn finds_mod_folder() {
let mod_component = ModComponent {
let mod_component = Component {
tp_file: "TEST.TP2".to_string(),
name: "test_mod_name_1".to_string(),
lang: "0".to_string(),
Expand Down
8 changes: 3 additions & 5 deletions src/weidu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use std::{
thread,
};

use crate::{
mod_component::ModComponent, state::State, utils::sleep, weidu_parser::parse_raw_output,
};
use crate::{component::Component, state::State, utils::sleep, weidu_parser::parse_raw_output};

pub fn get_user_input() -> String {
let stdin = io::stdin();
Expand All @@ -22,7 +20,7 @@ pub fn get_user_input() -> String {
input.to_string()
}

fn generate_args(weidu_mod: &ModComponent, weidu_log_mode: &str, language: &str) -> Vec<String> {
fn generate_args(weidu_mod: &Component, weidu_log_mode: &str, language: &str) -> Vec<String> {
format!("{mod_name}/{mod_tp_file} {weidu_log_mode} --force-install {component} --use-lang {game_lang} --language {mod_lang}",
mod_name = weidu_mod.name,
mod_tp_file = weidu_mod.tp_file,
Expand All @@ -45,7 +43,7 @@ pub enum InstallationResult {
pub fn install(
weidu_binary: &PathBuf,
game_directory: &PathBuf,
weidu_mod: &ModComponent,
weidu_mod: &Component,
language: &str,
weidu_log_mode: &str,
timeout: usize,
Expand Down

0 comments on commit de90e5f

Please sign in to comment.