Compare commits
2 commits
c79d6dd8ca
...
5ead609763
Author | SHA1 | Date | |
---|---|---|---|
LordMZTE | 5ead609763 | ||
LordMZTE | cecf32b413 |
|
@ -1,4 +1,11 @@
|
|||
# 0.1.3
|
||||
|
||||
- add support for defines
|
||||
- update dependencies
|
||||
- switch from structopt to clap with macro
|
||||
|
||||
# 0.1.2
|
||||
|
||||
- optimize curseforge relation meta querying
|
||||
- add debug logging
|
||||
- import and init now set the modpack's ID to a kebab-case version of the name
|
||||
|
|
|
@ -6,6 +6,6 @@ edition = "2018"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.129", features = ["derive"] }
|
||||
thiserror = "1.0.26"
|
||||
serde = { version = "1.0.136", features = ["derive"] }
|
||||
thiserror = "1.0.30"
|
||||
url = { version = "2.2.2", features = ["serde"] }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "mpt"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
edition = "2018"
|
||||
|
||||
[[bin]]
|
||||
|
@ -11,24 +11,24 @@ path = "src/main.rs"
|
|||
|
||||
[dependencies]
|
||||
addonscript = { path = "../addonscript" }
|
||||
async-trait = "0.1.51"
|
||||
crossterm = "0.21.0"
|
||||
async-trait = "0.1.52"
|
||||
clap = { version = "3.1.5", features = ["derive"] }
|
||||
crossterm = "0.23.0"
|
||||
futures = "0.3.16"
|
||||
heck = "0.3.3"
|
||||
heck = "0.4.0"
|
||||
indicatif = "0.16.2"
|
||||
json5 = "0.3.0"
|
||||
json5 = "0.4.1"
|
||||
log = "0.4.14"
|
||||
miette = { version = "3.1.0", features = ["fancy"] }
|
||||
mlua = { version = "0.6.6", features = ["luajit", "serialize"] }
|
||||
miette = { version = "4.2.1", features = ["fancy"] }
|
||||
mlua = { version = "0.7.4", features = ["luajit", "serialize"] }
|
||||
percent-encoding = "2.1.0"
|
||||
reqwest = { version = "0.11.4", features = ["stream"] }
|
||||
serde = { version = "1.0.129", features = ["derive"] }
|
||||
serde_json = "1.0.67"
|
||||
simplelog = "0.10.0"
|
||||
structopt = "0.3.22"
|
||||
tera = "1.12.1"
|
||||
thiserror = "1.0.28"
|
||||
tokio = { version = "1.10.1", features = ["rt-multi-thread", "macros", "fs"] }
|
||||
reqwest = { version = "0.11.9", features = ["stream"] }
|
||||
serde = { version = "1.0.136", features = ["derive"] }
|
||||
serde_json = "1.0.79"
|
||||
simplelog = "0.11.2"
|
||||
tera = "1.15.0"
|
||||
thiserror = "1.0.30"
|
||||
tokio = { version = "1.17.0", features = ["rt-multi-thread", "macros", "fs"] }
|
||||
toml = "0.5.8"
|
||||
twitch = { path = "../twitch" }
|
||||
url = "2.2.2"
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
manifest = {
|
||||
id = "{{ id }}",
|
||||
type = "{{ type }}",
|
||||
meta = {
|
||||
name = "{{ meta.name }}",
|
||||
contributors = {
|
||||
{% for cont in meta.contributors %} {
|
||||
name = "{{ cont.name }}",
|
||||
roles = {% for role in cont.roles %}{
|
||||
"{{ role }}",
|
||||
{% endfor %}},
|
||||
{% endfor %}},
|
||||
{% if meta.description %}description = "{{ meta.description }}",
|
||||
{% endif %}{% if meta.icon_url %}icon_url = "{{ meta.icon_url }}",
|
||||
{% endif %}{% if meta.website_url %}website_url = "{{ meta.website_url }}",
|
||||
{% endif %}},
|
||||
},
|
||||
versions = {
|
||||
{% for ver in versions %}{
|
||||
version = "{{ ver.version }}",
|
||||
mcversion = {
|
||||
{% for mcver in ver.mcversion %} "{{ mcver }}",
|
||||
{% endfor %}},
|
||||
files = {
|
||||
{% for file in ver.files %} {
|
||||
{% if file.artifact %}installer = "{{ file.installer }}",
|
||||
artifact = "{{ file.artifact }}",
|
||||
repository = "{{ file.repository }}",{% else %}{% if file.id %}id = "{{ file.id }}",{% endif %}
|
||||
installer = "{{ file.installer }}",
|
||||
link = "{{ file.link }}",{% if file.options %}
|
||||
options = {
|
||||
{% for opt in file.options %} "{{ opt }}",
|
||||
{% endfor %}},{% endif %}{% endif %}
|
||||
},{% endfor %}
|
||||
},
|
||||
},
|
||||
relations = {
|
||||
{% for rel in ver.relations %} {
|
||||
id = "{{ rel.id }}",
|
||||
{% if rel.file %}file = {
|
||||
{% if file.artifact %}installer = "{{ file.installer }}",
|
||||
artifact = "{{ file.artifact }}",
|
||||
repository = "{{ file.repository }}",{% else %}{% if file.id %}id = "{{ file.id }}",{% endif %}
|
||||
installer = "{{ file.installer }}",
|
||||
link = "{{ file.link }}",{% if file.options %}
|
||||
options = {
|
||||
{% for opt in file.options %} "{{ opt }}",
|
||||
{% endfor %}},{% endif %}{% endif %}
|
||||
},
|
||||
{% endif %}{% if rel.versions %}versions = "{{ rel.versions }}",
|
||||
{% endif %}{% if rel.meta %}meta = {
|
||||
name = "{{ rel.meta.name }}",
|
||||
contributors = {
|
||||
{% for cont in rel.meta.contributors %} {
|
||||
name = "{{ cont.name }}",
|
||||
roles = {% for role in cont.roles %}{
|
||||
"{{ role }}",
|
||||
{% endfor %}},
|
||||
{% endfor %}},
|
||||
{% if rel.meta.description %}description = "{{ rel.meta.description }}",
|
||||
{% endif %}{% if rel.meta.icon_url %}icon_url = "{{ rel.meta.icon_url }}",
|
||||
{% endif %}{% if rel.meta.website_url %}website_url = "{{ rel.meta.website_url }}",
|
||||
{% endif %}},
|
||||
{% endif %}type = "{{ rel.type }}",
|
||||
options = {
|
||||
{% for opt in rel.options %} "{{ opt }}",
|
||||
{% endfor %}},
|
||||
},{% endfor %}
|
||||
},
|
||||
},{% endfor %}
|
||||
repositories = {
|
||||
{% for repo in repositories %} {
|
||||
id = "{{ repo.id }}",
|
||||
type = "{{ repo.type }}",
|
||||
url = "{{ repo.url }}",
|
||||
},{% endfor %}
|
||||
},
|
||||
}
|
|
@ -16,7 +16,7 @@ use addonscript::{
|
|||
util::default_file_opts,
|
||||
};
|
||||
use crossterm::style::Stylize;
|
||||
use heck::KebabCase;
|
||||
use heck::ToKebabCase;
|
||||
use log::info;
|
||||
use miette::{bail, IntoDiagnostic, WrapErr};
|
||||
use twitch::manifest::Manifest as TwManifest;
|
||||
|
@ -24,7 +24,7 @@ use url::Url;
|
|||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::{config::Config, util::make_lua_manifest};
|
||||
use crate::config::Config;
|
||||
|
||||
pub async fn run(config: Config, infile: PathBuf) -> miette::Result<()> {
|
||||
if config.locations.src.join("modpack.json").exists() ||
|
||||
|
@ -122,8 +122,10 @@ pub async fn run(config: Config, infile: PathBuf) -> miette::Result<()> {
|
|||
.await
|
||||
.into_diagnostic()?;
|
||||
tokio::fs::write(
|
||||
config.locations.src.join("modpack.lua"),
|
||||
make_lua_manifest(&manif)?,
|
||||
config.locations.src.join("modpack.json5"),
|
||||
serde_json::to_vec_pretty(&manif)
|
||||
.into_diagnostic()
|
||||
.wrap_err("Failed to generate json data")?,
|
||||
)
|
||||
.await
|
||||
.into_diagnostic()?;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{config::Locations, forge, util::make_lua_manifest};
|
||||
use crate::{config::Locations, forge};
|
||||
use addonscript::{
|
||||
manifest::{
|
||||
installer::Installer,
|
||||
|
@ -30,7 +30,7 @@ use crossterm::{
|
|||
},
|
||||
ExecutableCommand,
|
||||
};
|
||||
use heck::KebabCase;
|
||||
use heck::ToKebabCase;
|
||||
use miette::{IntoDiagnostic, WrapErr};
|
||||
use reqwest::Client;
|
||||
use std::path::Path;
|
||||
|
@ -164,7 +164,7 @@ pub async fn run(
|
|||
.await
|
||||
.into_diagnostic()?;
|
||||
|
||||
let data = make_lua_manifest(&Manifest {
|
||||
let data = serde_json::to_vec_pretty(&Manifest {
|
||||
id: modpack_name.to_kebab_case(),
|
||||
manifest_type: ManifestType::Modpack,
|
||||
versions: vec![Version {
|
||||
|
@ -193,9 +193,11 @@ pub async fn run(
|
|||
icon_url: None,
|
||||
website_url: None,
|
||||
},
|
||||
})?;
|
||||
})
|
||||
.into_diagnostic()
|
||||
.wrap_err("Failed to generate json data")?;
|
||||
|
||||
tokio::fs::write(path.join("modpack.lua"), data)
|
||||
tokio::fs::write(path.join("modpack.json5"), data)
|
||||
.await
|
||||
.into_diagnostic()?;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use clap::{Parser, Subcommand};
|
||||
use log::{info, LevelFilter};
|
||||
use miette::{IntoDiagnostic, WrapErr};
|
||||
use simplelog::{ColorChoice, TermLogger, TerminalMode};
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
|
||||
mod commands;
|
||||
mod config;
|
||||
|
@ -10,72 +10,79 @@ mod downloader;
|
|||
mod forge;
|
||||
mod util;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
#[derive(Parser)]
|
||||
struct Opt {
|
||||
#[structopt(short, long, parse(from_occurrences), help = "enable verbose logging")]
|
||||
/// enable verbose logging
|
||||
#[clap(short, long, parse(from_occurrences))]
|
||||
verbose: u8,
|
||||
|
||||
#[structopt(subcommand)]
|
||||
/// add a parameter to be used by the build script
|
||||
/// (only useful with lua manifests)
|
||||
#[clap(short = 'D')]
|
||||
defines: Vec<String>,
|
||||
|
||||
#[clap(subcommand)]
|
||||
cmd: Command,
|
||||
}
|
||||
|
||||
#[derive(StructOpt)]
|
||||
#[derive(Subcommand)]
|
||||
enum Command {
|
||||
#[structopt(about = "Initializes a new modpack")]
|
||||
/// Initializes a new modpack
|
||||
Init {
|
||||
#[structopt(help = "The name of the modpack")]
|
||||
/// The name of the modpack
|
||||
modpack_name: String,
|
||||
#[structopt(help = "Name of the modpack author")]
|
||||
/// Name of the modpack author
|
||||
name: String,
|
||||
#[structopt(help = "The minecraft version of the modpack")]
|
||||
|
||||
/// The minecraft version of the modpack
|
||||
mcversion: String,
|
||||
},
|
||||
|
||||
#[structopt(name = "downloadmods", about = "Downloads mods of the pack")]
|
||||
/// Downloads mods of the pack
|
||||
#[clap(name = "downloadmods")]
|
||||
DownloadMods {
|
||||
#[structopt(help = "Directory to download mods to")]
|
||||
/// Directory to download mods to
|
||||
dir: PathBuf,
|
||||
#[structopt(short, long, help = "Download all relations and not just mods")]
|
||||
|
||||
/// Download all relations and not just mods
|
||||
#[clap(short, long)]
|
||||
all: bool,
|
||||
},
|
||||
|
||||
#[structopt(name = "buildtwitch", about = "Builds a twitch export of the pack")]
|
||||
/// Builds a twitch export of the pack
|
||||
#[clap(name = "buildtwitch")]
|
||||
BuildTwitch {
|
||||
#[structopt(
|
||||
short,
|
||||
long,
|
||||
help = "Downloads all relations instead of just required ones"
|
||||
)]
|
||||
/// Downloads all relations instead of just required ones
|
||||
#[clap(short, long)]
|
||||
all: bool,
|
||||
},
|
||||
|
||||
#[structopt(about = "Deletes artifacts and temporary files")]
|
||||
/// Deletes artifacts and temporary files
|
||||
Clean,
|
||||
|
||||
#[structopt(
|
||||
name = "createmodlist",
|
||||
about = "Creates a HTML list of the pack's mods."
|
||||
)]
|
||||
/// Creates a HTML list of the pack's mods
|
||||
#[clap(name = "createmodlist")]
|
||||
CreateModList {
|
||||
#[structopt(
|
||||
default_value = "build/modlist.html",
|
||||
help = "File to write the mod list to"
|
||||
)]
|
||||
/// File to write the mod list to
|
||||
#[clap(default_value = "build/modlist.html")]
|
||||
outfile: PathBuf,
|
||||
},
|
||||
|
||||
#[structopt(
|
||||
about = "Imports a twitch manifest file and converts it to an addonscript modpack.json"
|
||||
)]
|
||||
/// Imports a twitch manifest file and converts it to an addonscript
|
||||
/// modpack.json
|
||||
Import {
|
||||
#[structopt(help = "Twitch manifest to convert")]
|
||||
/// Twitch manifest to convert
|
||||
infile: PathBuf,
|
||||
},
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> miette::Result<()> {
|
||||
let Opt { cmd, verbose } = Opt::from_args();
|
||||
let Opt {
|
||||
cmd,
|
||||
defines,
|
||||
verbose,
|
||||
} = Opt::parse();
|
||||
|
||||
let log_level = match verbose {
|
||||
0 => LevelFilter::Off,
|
||||
|
@ -104,7 +111,7 @@ async fn main() -> miette::Result<()> {
|
|||
};
|
||||
|
||||
(manifest: $cmd:ident $($args:expr),* $(,)?) => {
|
||||
run_cmd!($cmd util::parse_config_and_manifest().await?, $($args),*)
|
||||
run_cmd!($cmd util::parse_config_and_manifest(defines, stringify!($cmd)).await?, $($args),*)
|
||||
};
|
||||
|
||||
($cmd:ident $($args:expr),* $(,)?) => {{
|
||||
|
|
|
@ -11,7 +11,6 @@ use std::{
|
|||
path::{Path, PathBuf},
|
||||
string::FromUtf8Error,
|
||||
};
|
||||
use tera::{Context, Tera};
|
||||
use thiserror::Error;
|
||||
use url::Url;
|
||||
use walkdir::WalkDir;
|
||||
|
@ -25,15 +24,19 @@ pub async fn parse_config() -> miette::Result<Config> {
|
|||
.await
|
||||
.into_diagnostic()
|
||||
.wrap_err("Failed to read config")?;
|
||||
Ok(toml::from_slice(&conf)
|
||||
|
||||
toml::from_slice(&conf)
|
||||
.into_diagnostic()
|
||||
.wrap_err("Failed to parse config")?)
|
||||
.wrap_err("Failed to parse config")
|
||||
}
|
||||
|
||||
/// parses the config from the current working directory, reads the location of
|
||||
/// the manifest file from it, parses the manifest and returns both the conig
|
||||
/// and the manifest.
|
||||
pub async fn parse_config_and_manifest() -> miette::Result<(Config, Manifest)> {
|
||||
pub async fn parse_config_and_manifest(
|
||||
defines: Vec<String>,
|
||||
command: &str,
|
||||
) -> miette::Result<(Config, Manifest)> {
|
||||
let config = parse_config().await?;
|
||||
let src = Path::new(&config.locations.src);
|
||||
|
||||
|
@ -56,6 +59,13 @@ pub async fn parse_config_and_manifest() -> miette::Result<(Config, Manifest)> {
|
|||
|
||||
let manifest = if is_lua {
|
||||
let lua = Lua::new();
|
||||
|
||||
let mpt = lua.create_table().into_diagnostic()?;
|
||||
mpt.set("defines", defines).into_diagnostic()?;
|
||||
mpt.set("command", command).into_diagnostic()?;
|
||||
|
||||
lua.globals().set("mpt", mpt).into_diagnostic()?;
|
||||
|
||||
lua.load(&data)
|
||||
.exec()
|
||||
.into_diagnostic()
|
||||
|
@ -186,8 +196,7 @@ pub enum UrlFileNameError {
|
|||
pub fn url_file_name(url: &Url) -> Result<String, UrlFileNameError> {
|
||||
let file_name = url
|
||||
.path_segments()
|
||||
.map(Iterator::last)
|
||||
.flatten()
|
||||
.and_then(Iterator::last)
|
||||
.ok_or(UrlFileNameError::BaseUrl)?;
|
||||
|
||||
if file_name.is_empty() {
|
||||
|
@ -246,18 +255,6 @@ pub async fn copy_dir(from: PathBuf, to: PathBuf) -> io::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn make_lua_manifest(manif: &Manifest) -> miette::Result<String> {
|
||||
Tera::one_off(
|
||||
include_str!("../assets/modpack.lua.tera"),
|
||||
&Context::from_serialize(manif)
|
||||
.into_diagnostic()
|
||||
.wrap_err("Failed to create context for tera")?,
|
||||
false,
|
||||
)
|
||||
.into_diagnostic()
|
||||
.wrap_err("Failed to create lua manifest.")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use addonscript::manifest::RepositoryType;
|
||||
|
|
|
@ -7,6 +7,6 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
addonscript = { path = "../addonscript" }
|
||||
serde = { version = "1.0.130", features = ["derive"] }
|
||||
thiserror = "1.0.28"
|
||||
serde = { version = "1.0.136", features = ["derive"] }
|
||||
thiserror = "1.0.30"
|
||||
url = { version = "2.2.2", features = ["serde"] }
|
||||
|
|
Loading…
Reference in a new issue