Browse Source

feat: separate develop, release, test working directory

appflowy 3 years ago
parent
commit
cdec567cbb

+ 1 - 1
frontend/app_flowy/.gitignore

@@ -60,4 +60,4 @@ windows/flutter/dart_ffi/
 **/**/*.dll
 **/**/*.so
 **/**/Brewfile.lock.json
-**/.appflowy_dev
+**/.sandbox

+ 1 - 1
frontend/app_flowy/lib/main.dart

@@ -14,5 +14,5 @@ void main() async {
   WidgetsFlutterBinding.ensureInitialized();
   await EasyLocalization.ensureInitialized();
 
-  await System.run(FlowyApp());
+  await FlowySystem.run(FlowyApp());
 }

+ 4 - 8
frontend/app_flowy/lib/startup/startup.dart

@@ -30,15 +30,11 @@ abstract class EntryPoint {
   Widget create();
 }
 
-class System {
+class FlowySystem {
   static Future<void> run(EntryPoint f) async {
     // Specify the env
     final env = integrationEnv();
-
-    // Config the deps graph
-    getIt.registerFactory<EntryPoint>(() => f);
-
-    resolveDependencies(env);
+    initGetIt(getIt, env, f);
 
     // add task
     getIt<AppLauncher>().addTask(InitRustSDKTask());
@@ -53,12 +49,12 @@ class System {
   }
 }
 
-void resolveDependencies(IntegrationEnv env) => initGetIt(getIt, env);
-
 Future<void> initGetIt(
   GetIt getIt,
   IntegrationEnv env,
+  EntryPoint f,
 ) async {
+  getIt.registerFactory<EntryPoint>(() => f);
   getIt.registerLazySingleton<FlowySDK>(() => const FlowySDK());
   getIt.registerLazySingleton<AppLauncher>(() => AppLauncher(env, getIt));
 

+ 9 - 3
frontend/app_flowy/lib/startup/tasks/init_sdk.dart

@@ -11,6 +11,12 @@ class InitRustSDKTask extends LaunchTask {
   Future<void> initialize(LaunchContext context) async {
     switch (context.env) {
       case IntegrationEnv.develop:
+        Directory directory = await getApplicationDocumentsDirectory();
+        return Directory('${directory.path}/flowy_dev').create().then(
+          (Directory directory) async {
+            await context.getIt<FlowySDK>().init(directory);
+          },
+        );
       case IntegrationEnv.release:
         Directory directory = await getApplicationDocumentsDirectory();
         return Directory('${directory.path}/flowy').create().then(
@@ -19,14 +25,14 @@ class InitRustSDKTask extends LaunchTask {
           },
         );
       case IntegrationEnv.test:
-        await context.getIt<FlowySDK>().init(testDir());
+        await context.getIt<FlowySDK>().init(testWorkingDirectory());
         break;
       default:
         assert(false, 'Unsupported env');
     }
   }
 
-  Directory testDir() {
-    return Directory("${Directory.current.path}/.appflowy_dev");
+  Directory testWorkingDirectory() {
+    return Directory("${Directory.current.path}/.sandbox");
   }
 }

+ 3 - 3
frontend/app_flowy/packages/flowy_sdk/lib/ffi.dart

@@ -13,21 +13,21 @@ final DynamicLibrary _dl = _open();
 final DynamicLibrary dl = _dl;
 DynamicLibrary _open() {
   if (Platform.environment.containsKey('FLUTTER_TEST')) {
-    final prefix = "${Directory.current.path}/.appflowy_dev";
+    final prefix = "${Directory.current.path}/.sandbox";
     if (Platform.isLinux) return DynamicLibrary.open('${prefix}/libdart_ffi.so');
     if (Platform.isAndroid) return DynamicLibrary.open('${prefix}/libdart_ffi.so');
     if (Platform.isMacOS) return DynamicLibrary.open('${prefix}/libdart_ffi.dylib');
     if (Platform.isIOS) return DynamicLibrary.open('${prefix}/libdart_ffi.dylib');
     if (Platform.isWindows) return DynamicLibrary.open('${prefix}/dart_ffi.dll');
-    throw UnsupportedError('This platform is not supported.');
   } else {
     if (Platform.isLinux) return DynamicLibrary.open('libdart_ffi.so');
     if (Platform.isAndroid) return DynamicLibrary.open('libdart_ffi.so');
     if (Platform.isMacOS) return DynamicLibrary.executable();
     if (Platform.isIOS) return DynamicLibrary.executable();
     if (Platform.isWindows) return DynamicLibrary.open('dart_ffi.dll');
-    throw UnsupportedError('This platform is not supported.');
   }
+
+  throw UnsupportedError('This platform is not supported.');
 }
 
 /// C function `async_event`.

+ 5 - 2
frontend/app_flowy/packages/flowy_sdk/lib/log.dart

@@ -9,8 +9,7 @@ class Log {
     _logger = Logger(
       printer: PrettyPrinter(
           methodCount: 2, // number of method calls to be displayed
-          errorMethodCount:
-              8, // number of method calls if stacktrace is provided
+          errorMethodCount: 8, // number of method calls if stacktrace is provided
           lineLength: 120, // width of the output
           colors: true, // Colorful log messages
           printEmojis: true, // Print an emoji for each log message
@@ -27,6 +26,10 @@ class Log {
     Log.shared._logger.d(msg);
   }
 
+  static void warn(dynamic msg) {
+    Log.shared._logger.w(msg);
+  }
+
   static void trace(dynamic msg) {
     Log.shared._logger.d(msg);
   }

+ 1 - 1
frontend/app_flowy/test/util/test_env.dart

@@ -10,7 +10,7 @@ class FlowyTest {
     TestWidgetsFlutterBinding.ensureInitialized();
     // await EasyLocalization.ensureInitialized();
 
-    await System.run(FlowyTestApp());
+    await FlowySystem.run(FlowyTestApp());
     return FlowyTest();
   }
 

+ 1 - 3
frontend/scripts/makefile/desktop.toml

@@ -138,12 +138,10 @@ script = [
   """
     # Copy the flowy_sdk lib to system temp directory for flutter unit test.
     lib = set lib${LIB_NAME}.${SDK_EXT}
-    dest = set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/.appflowy_dev/${lib}
+    dest = set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/.sandbox/${lib}
     rm ${dest}
     cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/${lib} \
     ${dest}
-
-    echo copy ${lib} to ${dest}
   """,
 ]
 script_runner = "@duckscript"