scrap lua manifest generation

This commit is contained in:
LordMZTE 2022-03-05 00:42:48 +01:00
parent c79d6dd8ca
commit cecf32b413
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
4 changed files with 12 additions and 100 deletions

View file

@ -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 %}
},
}

View file

@ -3,8 +3,7 @@ use addonscript::{
installer::Installer,
link::Link,
Contributor,
File,
Manifest,
File, Manifest,
ManifestType,
Meta,
Relation,
@ -24,7 +23,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 +121,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()?;

View file

@ -1,4 +1,4 @@
use crate::{config::Locations, forge, util::make_lua_manifest};
use crate::{config::Locations, forge};
use addonscript::{
manifest::{
installer::Installer,
@ -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()?;

View file

@ -11,7 +11,6 @@ use std::{
path::{Path, PathBuf},
string::FromUtf8Error,
};
use tera::{Context, Tera};
use thiserror::Error;
use url::Url;
use walkdir::WalkDir;
@ -246,18 +245,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;