refactor(cli): move generated Kotlin files to the generated folder

This commit is contained in:
Lucas Nogueira 2022-09-04 22:06:56 -03:00
parent f333656876
commit e1b8ee2b7a
No known key found for this signature in database
GPG Key ID: FFEA6C72E73482F1
4 changed files with 32 additions and 13 deletions

View File

@ -110,11 +110,15 @@ pub fn get_config(
set_var("WRY_ANDROID_APP_NAME_SNAKE_CASE", app.name());
set_var(
"WRY_ANDROID_KOTLIN_FILES_OUT_DIR",
config.project_dir().join("app/src/main").join(format!(
"java/{}/{}",
app.reverse_domain().replace('.', "/"),
app.name()
)),
config
.project_dir()
.join("app/src/main")
.join(format!(
"java/{}/{}",
app.reverse_domain().replace('.', "/"),
app.name()
))
.join("generated"),
);
(app, config, metadata)

View File

@ -85,6 +85,8 @@ pub fn gen(
let domain = config.app().reverse_domain().replace('.', "/");
let package_path = format!("java/{}/{}", domain, config.app().name());
map.insert("package-path", &package_path);
let mut created_dirs = Vec::new();
template::render_with_generator(
&handlebars,
@ -92,13 +94,25 @@ pub fn gen(
&TEMPLATE_DIR,
&dest,
&mut |path| {
let path = if path.extension() == Some(OsStr::new("kt")) {
let parent = path.parent().unwrap();
let file_name = path.file_name().unwrap();
let out_dir = dest.join(parent).join(&package_path);
out_dir.join(file_name)
} else {
dest.join(path)
let mut iter = path.iter();
let root = iter.next().unwrap().to_str().unwrap();
let path_without_root: std::path::PathBuf = iter.collect();
let path = match (
root,
path.extension().and_then(|o| o.to_str()),
path_without_root.strip_prefix("src/main"),
) {
("app" | "buildSrc", Some("kt"), Ok(path)) => {
let parent = path.parent().unwrap();
let file_name = path.file_name().unwrap();
let out_dir = dest
.join(root)
.join("src/main")
.join(&package_path)
.join(parent);
out_dir.join(file_name)
}
_ => dest.join(path),
};
let parent = path.parent().unwrap().to_path_buf();

View File

@ -1 +1,2 @@
/build
/src/main/{{package-path}}/generated