detect static method
Detect the ServerPod project root
Implementation
static String detect([String? currentPath]) {
currentPath ??= p.normalize(Directory.current.path);
// 1. Environment variable
final envRoot = Platform.environment['SERVERPOD_BOOST_PROJECT_ROOT'];
if (envRoot != null && Directory(envRoot).existsSync()) {
return envRoot;
}
// 2. If in .ai/boost/, navigate up
if (currentPath.contains('.ai${p.separator}boost')) {
final root = currentPath.split('.ai${p.separator}boost')[0];
if (root.isNotEmpty && Directory(root).existsSync()) {
return p.normalize(root);
}
}
// 3. Detect *_server package
final serverMatch = RegExp(r'(.+[/\\])\w+_server').firstMatch(currentPath);
if (serverMatch != null) {
final root = serverMatch.group(1)!;
if (Directory(root).existsSync()) {
return p.normalize(root);
}
}
// 4. Fallback
return currentPath;
}