From 1834be5c188bcff65072706969b3d34ea25b4f63 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 31 Dec 2023 21:55:39 +0800 Subject: [PATCH 01/10] feat: reverse order --- frb_codegen/src/library/integration/integrator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/integration/integrator.rs b/frb_codegen/src/library/integration/integrator.rs index fc432583bd..8c455a72c8 100644 --- a/frb_codegen/src/library/integration/integrator.rs +++ b/frb_codegen/src/library/integration/integrator.rs @@ -96,7 +96,7 @@ fn modify_file( ) }) .unwrap_or_default(); - return Some((path, [&src, commented_existing_content.as_bytes()].concat())); + return Some((path, [commented_existing_content.as_bytes(), &src].concat())); // We do not care about this warning // frb-coverage:ignore-start } From 63735625cef74afe6d9bdc86c757cc110e2111bb Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 31 Dec 2023 21:57:03 +0800 Subject: [PATCH 02/10] fix: newline --- frb_codegen/src/library/integration/integrator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/integration/integrator.rs b/frb_codegen/src/library/integration/integrator.rs index 8c455a72c8..bd3253365f 100644 --- a/frb_codegen/src/library/integration/integrator.rs +++ b/frb_codegen/src/library/integration/integrator.rs @@ -91,7 +91,7 @@ fn modify_file( let commented_existing_content = existing_content .map(|x| { format!( - "\n\n{}", + "{}\n\n", x.split('\n').map(|line| format!("// {line}")).join("\n") ) }) From 3b0be90292dcf26cd62bdba54d5ae23fe208befa Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 31 Dec 2023 21:58:46 +0800 Subject: [PATCH 03/10] feat: when already exists, bail --- frb_codegen/src/library/integration/creator.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frb_codegen/src/library/integration/creator.rs b/frb_codegen/src/library/integration/creator.rs index bc40261a49..9b796718d5 100644 --- a/frb_codegen/src/library/integration/creator.rs +++ b/frb_codegen/src/library/integration/creator.rs @@ -1,5 +1,6 @@ use crate::integration::integrator; use crate::library::commands::flutter::flutter_create; +use anyhow::ensure; use log::{debug, info}; use std::path::Path; use std::{env, fs}; @@ -8,9 +9,15 @@ use std::{env, fs}; pub fn create(name: &str, enable_local_dependency: bool) -> anyhow::Result<()> { debug!("create name={name}"); + let dart_root = env::current_dir()?.join(name); + ensure!( + dart_root.exists(), + "The target folder {:?} already exists. Please use the `integrate` command in this case", + dart_root, + ); + flutter_create(name)?; - let dart_root = env::current_dir()?.join(name); env::set_current_dir(&dart_root)?; remove_unnecessary_files(&dart_root)?; From e1af604b4edb79b8aa1c765050de9812f9b82781 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 31 Dec 2023 22:00:40 +0800 Subject: [PATCH 04/10] chore: log --- frb_codegen/src/library/integration/creator.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/integration/creator.rs b/frb_codegen/src/library/integration/creator.rs index 9b796718d5..373bc14696 100644 --- a/frb_codegen/src/library/integration/creator.rs +++ b/frb_codegen/src/library/integration/creator.rs @@ -7,9 +7,9 @@ use std::{env, fs}; /// Create a new Flutter + Rust project. pub fn create(name: &str, enable_local_dependency: bool) -> anyhow::Result<()> { - debug!("create name={name}"); - let dart_root = env::current_dir()?.join(name); + debug!("create name={name} dart_root={dart_root:?}"); + ensure!( dart_root.exists(), "The target folder {:?} already exists. Please use the `integrate` command in this case", From 6a70c4945208f6c6faa9260ea4294a8fdf92aeb7 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 31 Dec 2023 22:01:08 +0800 Subject: [PATCH 05/10] fix: reverse --- frb_codegen/src/library/integration/creator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/integration/creator.rs b/frb_codegen/src/library/integration/creator.rs index 373bc14696..4d918a20e2 100644 --- a/frb_codegen/src/library/integration/creator.rs +++ b/frb_codegen/src/library/integration/creator.rs @@ -11,7 +11,7 @@ pub fn create(name: &str, enable_local_dependency: bool) -> anyhow::Result<()> { debug!("create name={name} dart_root={dart_root:?}"); ensure!( - dart_root.exists(), + !dart_root.exists(), "The target folder {:?} already exists. Please use the `integrate` command in this case", dart_root, ); From 6dff1ed7c2c4ccc37f6ef97959200a3680d21f2e Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 31 Dec 2023 22:03:25 +0800 Subject: [PATCH 06/10] chore: codegen --- .../flutter_via_integrate/lib/main.dart | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/frb_example/flutter_via_integrate/lib/main.dart b/frb_example/flutter_via_integrate/lib/main.dart index e759cff938..e3cc5bc98a 100644 --- a/frb_example/flutter_via_integrate/lib/main.dart +++ b/frb_example/flutter_via_integrate/lib/main.dart @@ -1,29 +1,3 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_via_integrate/src/rust/api/simple.dart'; -import 'package:flutter_via_integrate/src/rust/frb_generated.dart'; - -Future main() async { - await RustLib.init(); - runApp(const MyApp()); -} - -class MyApp extends StatelessWidget { - const MyApp({super.key}); - - @override - Widget build(BuildContext context) { - return MaterialApp( - home: Scaffold( - appBar: AppBar(title: const Text('flutter_rust_bridge quickstart')), - body: Center( - child: Text( - 'Action: Call Rust `greet("Tom")`\nResult: `${greet(name: "Tom")}`'), - ), - ), - ); - } -} - // import 'package:flutter/material.dart'; // // void main() { @@ -150,3 +124,29 @@ class MyApp extends StatelessWidget { // } // } // + +import 'package:flutter/material.dart'; +import 'package:flutter_via_integrate/src/rust/api/simple.dart'; +import 'package:flutter_via_integrate/src/rust/frb_generated.dart'; + +Future main() async { + await RustLib.init(); + runApp(const MyApp()); +} + +class MyApp extends StatelessWidget { + const MyApp({super.key}); + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar(title: const Text('flutter_rust_bridge quickstart')), + body: Center( + child: Text( + 'Action: Call Rust `greet("Tom")`\nResult: `${greet(name: "Tom")}`'), + ), + ), + ); + } +} From ef951101ec2ea0bc2225c5be03c13509bb4ae1a2 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Sun, 31 Dec 2023 22:08:09 +0800 Subject: [PATCH 07/10] chore: text --- frb_codegen/src/library/integration/integrator.rs | 2 +- frb_example/flutter_via_integrate/lib/main.dart | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/frb_codegen/src/library/integration/integrator.rs b/frb_codegen/src/library/integration/integrator.rs index bd3253365f..845e62cc8d 100644 --- a/frb_codegen/src/library/integration/integrator.rs +++ b/frb_codegen/src/library/integration/integrator.rs @@ -91,7 +91,7 @@ fn modify_file( let commented_existing_content = existing_content .map(|x| { format!( - "{}\n\n", + "// The original content is temporarily commented out to allow generating a self-contained demo - feel free to uncomment later.\n\n{}\n\n", x.split('\n').map(|line| format!("// {line}")).join("\n") ) }) diff --git a/frb_example/flutter_via_integrate/lib/main.dart b/frb_example/flutter_via_integrate/lib/main.dart index e3cc5bc98a..08e7f20107 100644 --- a/frb_example/flutter_via_integrate/lib/main.dart +++ b/frb_example/flutter_via_integrate/lib/main.dart @@ -1,3 +1,5 @@ +// The original content is temporarily commented out to allow generating a self-contained demo - feel free to uncomment later. + // import 'package:flutter/material.dart'; // // void main() { From 9295071ff2662c6e23d94d0374a450c5b0f8ddd1 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Mon, 1 Jan 2024 08:07:48 +0800 Subject: [PATCH 08/10] chore: cov --- frb_codegen/src/library/integration/creator.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frb_codegen/src/library/integration/creator.rs b/frb_codegen/src/library/integration/creator.rs index 4d918a20e2..6c7f54a97a 100644 --- a/frb_codegen/src/library/integration/creator.rs +++ b/frb_codegen/src/library/integration/creator.rs @@ -10,11 +10,14 @@ pub fn create(name: &str, enable_local_dependency: bool) -> anyhow::Result<()> { let dart_root = env::current_dir()?.join(name); debug!("create name={name} dart_root={dart_root:?}"); + // This will stop the whole generator and tell the users, so we do not care about testing it + // frb-coverage:ignore-start ensure!( !dart_root.exists(), "The target folder {:?} already exists. Please use the `integrate` command in this case", dart_root, ); + // frb-coverage:ignore-end flutter_create(name)?; From 8cae00dc06bedde37699c024324052cf327fc700 Mon Sep 17 00:00:00 2001 From: fzyzcjy <5236035+fzyzcjy@users.noreply.github.com> Date: Mon, 1 Jan 2024 09:21:33 +0800 Subject: [PATCH 09/10] Update creator.rs --- frb_codegen/src/library/integration/creator.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frb_codegen/src/library/integration/creator.rs b/frb_codegen/src/library/integration/creator.rs index 39af06b579..74b349c1ce 100644 --- a/frb_codegen/src/library/integration/creator.rs +++ b/frb_codegen/src/library/integration/creator.rs @@ -15,8 +15,8 @@ pub struct CreateConfig { /// Create a new Flutter + Rust project. pub fn create(config: CreateConfig) -> anyhow::Result<()> { - let dart_root = env::current_dir()?.join(name); - debug!("create name={name} dart_root={dart_root:?}"); + let dart_root = env::current_dir()?.join(config.name); + debug!("create name={} dart_root={dart_root:?}", config.name); // This will stop the whole generator and tell the users, so we do not care about testing it // frb-coverage:ignore-start @@ -27,7 +27,7 @@ pub fn create(config: CreateConfig) -> anyhow::Result<()> { ); // frb-coverage:ignore-end - flutter_create(name)?; + flutter_create(config.name)?; env::set_current_dir(&dart_root)?; From b9363b6f02f9af7d015aefcd6a47bdc8fe91bc7c Mon Sep 17 00:00:00 2001 From: fzyzcjy <5236035+fzyzcjy@users.noreply.github.com> Date: Mon, 1 Jan 2024 10:32:12 +0800 Subject: [PATCH 10/10] Update creator.rs --- frb_codegen/src/library/integration/creator.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/integration/creator.rs b/frb_codegen/src/library/integration/creator.rs index 74b349c1ce..5e70b16255 100644 --- a/frb_codegen/src/library/integration/creator.rs +++ b/frb_codegen/src/library/integration/creator.rs @@ -15,7 +15,7 @@ pub struct CreateConfig { /// Create a new Flutter + Rust project. pub fn create(config: CreateConfig) -> anyhow::Result<()> { - let dart_root = env::current_dir()?.join(config.name); + let dart_root = env::current_dir()?.join(&config.name); debug!("create name={} dart_root={dart_root:?}", config.name); // This will stop the whole generator and tell the users, so we do not care about testing it @@ -27,7 +27,7 @@ pub fn create(config: CreateConfig) -> anyhow::Result<()> { ); // frb-coverage:ignore-end - flutter_create(config.name)?; + flutter_create(&config.name)?; env::set_current_dir(&dart_root)?;