feat: separate develop, release, test working directory

This commit is contained in:
appflowy 2022-02-20 08:35:52 +08:00
parent e9ba9ad149
commit cdec567cbb
8 changed files with 25 additions and 22 deletions

View File

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

View File

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

View File

@ -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));

View File

@ -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");
}
}

View File

@ -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`.

View File

@ -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);
}

View File

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

View File

@ -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"