diff --git a/mpt/assets/modpack.lua.tera b/mpt/assets/modpack.lua.tera deleted file mode 100644 index a4ff648..0000000 --- a/mpt/assets/modpack.lua.tera +++ /dev/null @@ -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 %} - }, -} diff --git a/mpt/src/commands/import.rs b/mpt/src/commands/import.rs index 405ba48..a01e61c 100644 --- a/mpt/src/commands/import.rs +++ b/mpt/src/commands/import.rs @@ -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()?; diff --git a/mpt/src/commands/init.rs b/mpt/src/commands/init.rs index e995d14..eadd3b0 100644 --- a/mpt/src/commands/init.rs +++ b/mpt/src/commands/init.rs @@ -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()?; diff --git a/mpt/src/util.rs b/mpt/src/util.rs index bc83e1d..b9920e5 100644 --- a/mpt/src/util.rs +++ b/mpt/src/util.rs @@ -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 { - 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;