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 **/**/*.dll
**/**/*.so **/**/*.so
**/**/Brewfile.lock.json **/**/Brewfile.lock.json
**/.appflowy_dev **/.sandbox

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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