diff --git a/src/commands/init.rs b/src/commands/init.rs index b7c46a2..4434a15 100644 --- a/src/commands/init.rs +++ b/src/commands/init.rs @@ -1,7 +1,7 @@ +use askama::Template; use std::fmt::Display; use std::fs::{create_dir, write}; use std::process::Stdio; -use askama::Template; use clap::ValueEnum; use execute::{command, Execute}; @@ -55,14 +55,17 @@ fn create_project(crate_name: &str, lib_type: LibType, plain: bool) -> Result<() lib_type: lib_type.identifier(), }; let lib_rs_content = templating::LibRs { plain }; - let udl_content = templating::LibUdl { namespace: &namespace, plain }; - let build_rs_content = templating::BuildRs { plain }; + let udl_content = templating::LibUdl { + namespace: &namespace, + plain, + }; + let build_rs_content = templating::BuildRs {}; write_project_files( - &cargo_toml_content.render()?, - &build_rs_content.render()?, - &lib_rs_content.render()?, - &udl_content.render()?, + &cargo_toml_content.render().unwrap(), + &build_rs_content.render().unwrap(), + &lib_rs_content.render().unwrap(), + &udl_content.render().unwrap(), crate_name, )?; diff --git a/src/swiftpackage.rs b/src/swiftpackage.rs index bff55d2..0d1c5ad 100644 --- a/src/swiftpackage.rs +++ b/src/swiftpackage.rs @@ -1,6 +1,7 @@ +use askama::Template; use std::fs::{copy, create_dir_all, write}; -use crate::{recreate_dir, Result}; +use crate::{recreate_dir, templating, Result}; /// Create artifacts for a swift package given the package name /// @@ -8,11 +9,16 @@ use crate::{recreate_dir, Result}; pub fn create_swiftpackage(package_name: &str, namespace: &str) -> Result<()> { // TODO: Instead of assuming the directory and the xcframework, let this manage directory // recreation and let it copy the xcframework - let package_manifest = - include_str!("../template/template.Package.swift").replace("", package_name); - - write(format!("{}/Package.swift", package_name), package_manifest) - .map_err(|e| format!("Could not write Package.swift: \n {e}"))?; + let package_manifest = templating::PackageSwift { + package_name, + enable_warnings: false, + }; + + write( + format!("{}/Package.swift", package_name), + package_manifest.render().unwrap(), + ) + .map_err(|e| format!("Could not write Package.swift: \n {e}"))?; create_dir_all(format!("{}/Sources/{}", package_name, package_name)) .map_err(|e| format!("Could not create module sources directory: \n {e}"))?; diff --git a/src/templating.rs b/src/templating.rs index b29e648..8c229bc 100644 --- a/src/templating.rs +++ b/src/templating.rs @@ -1,7 +1,5 @@ use askama::Template; -use crate::LibType; - #[derive(Template)] #[template(path = "Cargo.toml", escape = "none")] pub(crate) struct CargoToml<'a> { @@ -13,9 +11,7 @@ pub(crate) struct CargoToml<'a> { #[derive(Template)] #[template(path = "build.rs", escape = "none")] -pub(crate) struct BuildRs { - pub(crate) plain: bool, -} +pub(crate) struct BuildRs {} #[derive(Template)] #[template(path = "lib.rs", escape = "none")] @@ -35,4 +31,5 @@ pub(crate) struct LibUdl<'a> { pub(crate) struct PackageSwift<'a> { pub(crate) package_name: &'a str, pub(crate) enable_warnings: bool, -} \ No newline at end of file +} + diff --git a/template/template.Package.swift b/template/template.Package.swift deleted file mode 100644 index 6befe1f..0000000 --- a/template/template.Package.swift +++ /dev/null @@ -1,29 +0,0 @@ -// swift-tools-version:5.5 -// The swift-tools-version declares the minimum version of Swift required to build this package. -// Swift Package: - -import PackageDescription; - -let package = Package( - name: "", - platforms: [ - .iOS(.v13), - .macOS(.v10_10) - ], - products: [ - .library( - name: "", - targets: [""] - ) - ], - dependencies: [ ], - targets: [ - .binaryTarget(name: "RustFramework", path: "./RustFramework.xcframework"), - .target( - name: "", - dependencies: [ - .target(name: "RustFramework") - ] - ), - ] -)