Skip to content

Commit

Permalink
Cleaner template directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
francesca64 committed Oct 27, 2020
1 parent 5719d6a commit 7da4cb5
Show file tree
Hide file tree
Showing 67 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ After some straightforward prompts, you'll be asked to select a template pack. T
| wgpu | Minimal wgpu project derived from [hello-triangle](https://github.com/gfx-rs/wgpu-rs/tree/master/examples/hello-triangle) example |
| winit | Minimal winit project derived from [window](https://github.com/rust-windowing/winit/tree/master/examples/window) exmaple |

**Template pack contribution is encouraged**; we'd love to have very nice template packs for Bevy, Amethyst, and whatever else people find helpful! We'll write up a guide for template pack creation soon, but in the mean time, the existing ones are a great reference point. Any template pack placed into `~./cargo-mobile/app-templates/` will appear as an option in `cargo mobile init`.
**Template pack contribution is encouraged**; we'd love to have very nice template packs for Bevy, Amethyst, and whatever else people find helpful! We'll write up a guide for template pack creation soon, but in the mean time, the existing ones are a great reference point. Any template pack placed into `~./cargo-mobile/templates/apps/` will appear as an option in `cargo mobile init`.

Once you've generated your project, you can run `cargo run` as usual to run your app on desktop. However, now you can also do `cargo apple run` and `cargo android run` to run on connected iOS and Android devices respectively!

Expand Down
2 changes: 0 additions & 2 deletions app-templates/bevy.toml

This file was deleted.

18 changes: 9 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};

fn main() {
let pkg_name = std::env::var("CARGO_PKG_NAME").unwrap();
let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
let home_dir = home::home_dir().expect("failed to get user's home dir");
let old = home_dir.join("templates");
if old.is_dir() {
std::fs::remove_dir_all(old).expect("failed to delete obsolete templates directory");
}
let bike = bicycle::Bicycle::default();
for prefix in &["platform", "app"] {
let dir_name = format!("{}-templates", prefix);
let src = manifest_dir.join(&dir_name);
for rel in ["platforms", "apps"]
.iter()
.map(|prefix| Path::new("templates").join(prefix))
{
let src = manifest_dir.join(&rel);
println!("cargo:rerun-if-changed={}", src.display());
let dest = home_dir.join(format!(".{}/{}", pkg_name, dir_name));
let dest = home_dir.join(format!(".{}", pkg_name)).join(rel);
let actions = bicycle::traverse(&src, &dest, bicycle::no_transform, None)
.expect("failed to traverse src templates dir");
if dest.is_dir() {
std::fs::remove_dir_all(&dest).expect("failed to delete old templates");
}
// bicycle creates directories for us, so we don't need to worry about
// using `create_dir_all` or anything.
bike.process_actions(
actions.iter().inspect(|action| match action {
bicycle::Action::CreateDirectory { dest: in_dest } => {
Expand Down
4 changes: 2 additions & 2 deletions src/templating/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use std::{
static BRAINIUM: &[&str] = &["brainstorm", "brainstorm-demo"];

fn platform_pack_dir() -> Result<PathBuf, util::NoHomeDir> {
util::install_dir().map(|dir| dir.join("platform-templates"))
util::install_dir().map(|dir| dir.join("templates/platforms"))
}

fn app_pack_dir() -> Result<PathBuf, util::NoHomeDir> {
util::install_dir().map(|dir| dir.join("app-templates"))
util::install_dir().map(|dir| dir.join("templates/apps"))
}

#[derive(Debug)]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions templates/apps/bevy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "~/.cargo-mobile/templates/apps/bevy"
base = "bevy-demo"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 7da4cb5

Please sign in to comment.