Refactor project to two crates for easier publishing.

This commit is contained in:
Joel Wachsler 2022-07-10 16:32:55 +00:00
parent a56c99a45a
commit d68a1249c5
36 changed files with 19544 additions and 3432 deletions

52
Cargo.lock generated
View File

@ -17,25 +17,6 @@ version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704"
[[package]]
name = "api-gen"
version = "0.1.0"
dependencies = [
"anyhow",
"case",
"parser",
"proc-macro2",
"quote",
"regex",
"reqwest",
"serde",
"serde_json",
"syn",
"thiserror",
"tokio",
"trybuild",
]
[[package]]
name = "autocfg"
version = "1.1.0"
@ -393,10 +374,6 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]]
name = "md-parser"
version = "0.1.0"
[[package]]
name = "memchr"
version = "2.5.0"
@ -533,15 +510,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "parser"
version = "0.1.0"
dependencies = [
"case",
"md-parser",
"regex",
]
[[package]]
name = "percent-encoding"
version = "2.1.0"
@ -579,7 +547,7 @@ dependencies = [
name = "qbittorrent-web-api"
version = "0.1.0"
dependencies = [
"api-gen",
"qbittorrent-web-api-gen",
"reqwest",
"serde",
"serde_json",
@ -587,6 +555,24 @@ dependencies = [
"tokio",
]
[[package]]
name = "qbittorrent-web-api-gen"
version = "0.1.0"
dependencies = [
"anyhow",
"case",
"proc-macro2",
"quote",
"regex",
"reqwest",
"serde",
"serde_json",
"syn",
"thiserror",
"tokio",
"trybuild",
]
[[package]]
name = "quote"
version = "1.0.20"

View File

@ -10,14 +10,12 @@ path = "src/lib.rs"
[dependencies]
reqwest = { version = "0.11.11", features = ["json", "multipart"] }
tokio = { version = "1.19.2", features = ["full"] }
api-gen = { path = "./api-gen", version = "*" }
qbittorrent-web-api-gen = { path = "./qbittorrent-web-api-gen", version = "0.1.0" }
serde = { version = "1.0.138", features = ["derive"] }
serde_json = "1.0.82"
thiserror = "1.0.31"
[workspace]
members = [
"api-gen",
"parser",
"md-parser",
"qbittorrent-web-api-gen",
]

View File

@ -1,6 +0,0 @@
[package]
name = "md-parser"
version = "0.1.0"
edition = "2021"
[dependencies]

View File

@ -1,9 +0,0 @@
[package]
name = "parser"
version = "0.1.0"
edition = "2021"
[dependencies]
md-parser = { path = "../md-parser" }
case = "1.0.0"
regex = "1.6.0"

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
[package]
name = "api-gen"
name = "qbittorrent-web-api-gen"
version = "0.1.0"
edition = "2021"
@ -7,7 +7,6 @@ edition = "2021"
proc-macro = true
[dependencies]
parser = { path = "../parser" }
syn = { version = "1.0.98", features = ["extra-traits"]}
quote = "1.0.20"
proc-macro2 = "1.0.40"

View File

@ -1,11 +1,10 @@
use std::{collections::HashMap, vec::Vec};
use case::CaseExt;
use parser::types::TypeInfo;
use quote::{format_ident, quote};
use regex::Regex;
use crate::{skeleton::auth_ident, util};
use crate::{parser::{self, types::TypeInfo}, skeleton::auth_ident, util};
pub fn generate_groups(groups: Vec<parser::ApiGroup>) -> proc_macro2::TokenStream {
let gr = groups

View File

@ -1,6 +1,8 @@
mod group;
mod skeleton;
mod util;
mod parser;
mod md_parser;
use case::CaseExt;
use proc_macro::TokenStream;
@ -10,7 +12,7 @@ use syn::parse_macro_input;
use crate::group::generate_groups;
const API_CONTENT: &str = include_str!("api-4_1.md");
const API_CONTENT: &str = include_str!("../api-4_1.md");
#[proc_macro_derive(QBittorrentApiGen, attributes(api_gen))]
pub fn derive(input: TokenStream) -> TokenStream {

View File

@ -1,4 +1,4 @@
use md_parser::MdContent;
use crate::md_parser::MdContent;
pub fn get_group_description(content: &[MdContent]) -> Option<String> {
let return_desc = content

View File

@ -1,14 +1,14 @@
use crate::md_parser::TokenTree;
use self::{return_type::get_return_type, parameters::get_parameters};
use super::{ApiGroup, ApiMethod, util};
mod description;
mod parameters;
mod return_type;
mod url_parser;
use md_parser::TokenTree;
use crate::{util, ApiGroup, ApiMethod};
use self::{parameters::get_parameters, return_type::get_return_type};
pub fn parse_groups(trees: Vec<TokenTree>) -> Vec<ApiGroup> {
trees.into_iter().map(parse_api_group).collect()
}

View File

@ -1,8 +1,9 @@
use std::collections::HashMap;
use md_parser::MdContent;
use crate::types::{Type, OPTIONAL};
use crate::{
md_parser::MdContent,
parser::types::{Type, OPTIONAL},
};
pub fn get_parameters(content: &[MdContent]) -> Option<Vec<Type>> {
let mut it = content

View File

@ -1,6 +1,4 @@
use md_parser::MdContent;
use crate::{object_types::get_object_types, types::Type, ReturnType, ReturnTypeParameter};
use crate::{md_parser::MdContent, parser::{ReturnType, object_types::get_object_types, ReturnTypeParameter, types::Type}};
pub fn get_return_type(content: &[MdContent]) -> Option<ReturnType> {
let table = content

View File

@ -1,7 +1,6 @@
use md_parser::MdContent;
use regex::Regex;
use crate::util;
use crate::{md_parser::MdContent, parser::util};
pub fn get_group_url(content: &[MdContent]) -> String {
let row = util::find_content_contains(content, "API methods are under")

File diff suppressed because one or more lines are too long

View File

@ -4,9 +4,10 @@ pub mod types;
mod util;
use group_parser::parse_groups;
use md_parser::{self, TokenTree};
use types::Type;
use crate::md_parser::{self, TokenTree};
#[derive(Debug)]
pub struct ApiGroup {
pub name: String,
@ -66,7 +67,7 @@ mod tests {
use std::fs;
fn parse() -> TokenTree {
let content = include_str!("api-4_1.md");
let content = include_str!("../../api-4_1.md");
let md_tree = md_parser::TokenTreeFactory::create(content);
let output = format!("{:#?}", md_tree);

View File

@ -1,8 +1,8 @@
use std::collections::HashMap;
use md_parser::MdContent;
use crate::{md_parser::MdContent, parser::types::TypeDescriptions};
use crate::types::{TypeDescription, TypeDescriptions};
use super::types::TypeDescription;
pub fn get_object_types(content: &[MdContent]) -> HashMap<String, TypeDescription> {
let mut output = HashMap::new();

View File

@ -1,4 +1,4 @@
use md_parser::MdContent;
use crate::md_parser::MdContent;
pub fn find_content_starts_with(content: &[MdContent], starts_with: &str) -> Option<String> {
content.iter().find_map(|row| match row {

View File

@ -1,5 +1,5 @@
use anyhow::Result;
use api_gen::QBittorrentApiGen;
use qbittorrent_web_api_gen::QBittorrentApiGen;
const USERNAME: &str = "admin";
const PASSWORD: &str = "adminadmin";

View File

@ -1,5 +1,5 @@
use anyhow::Result;
use api_gen::QBittorrentApiGen;
use qbittorrent_web_api_gen::QBittorrentApiGen;
const USERNAME: &str = "admin";
const PASSWORD: &str = "adminadmin";

View File

@ -1,5 +1,5 @@
use anyhow::Result;
use api_gen::QBittorrentApiGen;
use qbittorrent_web_api_gen::QBittorrentApiGen;
const USERNAME: &str = "admin";
const PASSWORD: &str = "adminadmin";

View File

@ -1,5 +1,5 @@
use anyhow::Result;
use api_gen::QBittorrentApiGen;
use qbittorrent_web_api_gen::QBittorrentApiGen;
const USERNAME: &str = "admin";
const PASSWORD: &str = "adminadmin";

View File

@ -1,5 +1,5 @@
use anyhow::Result;
use api_gen::QBittorrentApiGen;
use qbittorrent_web_api_gen::QBittorrentApiGen;
const USERNAME: &str = "admin";
const PASSWORD: &str = "adminadmin";

View File

@ -1,5 +1,5 @@
use anyhow::Result;
use api_gen::QBittorrentApiGen;
use qbittorrent_web_api_gen::QBittorrentApiGen;
const USERNAME: &str = "admin";
const PASSWORD: &str = "adminadmin";

View File

@ -1,5 +1,5 @@
use anyhow::Result;
use api_gen::QBittorrentApiGen;
use qbittorrent_web_api_gen::QBittorrentApiGen;
use tokio::time::{sleep, Duration};
const USERNAME: &str = "admin";

View File

@ -1,5 +1,5 @@
use anyhow::Result;
use api_gen::QBittorrentApiGen;
use qbittorrent_web_api_gen::QBittorrentApiGen;
use tokio::time::{sleep, Duration};
const USERNAME: &str = "admin";

View File

@ -1,5 +1,5 @@
use anyhow::Result;
use api_gen::QBittorrentApiGen;
use qbittorrent_web_api_gen::QBittorrentApiGen;
const USERNAME: &str = "admin";
const PASSWORD: &str = "adminadmin";

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
use api_gen::QBittorrentApiGen;
use qbittorrent_web_api_gen::QBittorrentApiGen;
#[derive(QBittorrentApiGen)]
pub struct Api;