createServerApp method

Future<bool> createServerApp()

Create a server app

Implementation

Future<bool> createServerApp() async {
  if (!config.createServer) {
    return false;
  }

  final projectPath = p.join(config.outputDir, config.serverPackageName);

  info('Creating server app: ${config.serverPackageName}');

  // Use flutter create with linux only for server
  final args = [
    'create',
    '--org',
    config.orgDomain,
    '--project-name',
    config.serverPackageName,
    '--platforms',
    'linux',
    projectPath,
  ];

  final result = await _runner.runWithRetry(
    'flutter',
    args,
    operationName: 'Create server app',
  );

  if (result == null || !result.success) {
    error('Failed to create server app');
    return false;
  }

  // Delete the generated lib folder to replace with template
  final libDir = Directory(p.join(projectPath, 'lib'));
  if (libDir.existsSync()) {
    await libDir.delete(recursive: true);
  }

  success('Server app created at: $projectPath');
  return true;
}