createDevProject function

Future<void> createDevProject({
  1. required String projectDirPath,
  2. String? appName,
})

Creates a scaffolded ADK development project at projectDirPath.

Generates adk.json, .env, root_agent.yaml, agent.dart, and README.md.

Throws a FileSystemException when the target directory exists and is not empty.

Implementation

Future<void> createDevProject({
  required String projectDirPath,
  String? appName,
}) async {
  final Directory dir = Directory(projectDirPath);
  final String dirName = projectDirName(projectDirPath);
  final String resolvedAppName = _normalizeName(appName ?? dirName);
  final DevProjectConfig config = DevProjectConfig(
    appName: resolvedAppName,
    agentName: 'root_agent',
    description: 'Tells the current time in a specified city.',
  );

  if (await dir.exists()) {
    final bool hasEntries = !(await dir.list().isEmpty);
    if (hasEntries) {
      throw FileSystemException(
        'Project directory already exists and is not empty.',
        dir.path,
      );
    }
  } else {
    await dir.create(recursive: true);
  }

  await File(
    _joinPath(dir.path, _configFileName),
  ).writeAsString(const JsonEncoder.withIndent('  ').convert(config.toJson()));
  await File(
    _joinPath(dir.path, '.env'),
  ).writeAsString('GOOGLE_API_KEY="YOUR_API_KEY"\n');
  await File(
    _joinPath(dir.path, 'root_agent.yaml'),
  ).writeAsString(_rootAgentConfigTemplate());
  await File(_joinPath(dir.path, 'agent.dart')).writeAsString(_agentTemplate());
  await File(
    _joinPath(dir.path, 'README.md'),
  ).writeAsString(_projectReadmeTemplate(projectName: dirName));
}