createRootPubspecSync static method

void createRootPubspecSync({
  1. required String dartVersion,
  2. required String projectName,
})

Writes the workspace root pubspec.yaml with basic configuration.

Parameters:

  • sdkVersion: Dart SDK version constraint (e.g. 3.10.8).
  • name: the main application folder name included in the workspace.

Implementation

static void createRootPubspecSync({
  required String dartVersion,
  required String projectName,
}) {
  print('📝 Creating root pubspec.yaml...');
  final content =
      '''
name: _
version: 0.1.0
description: A Dart workspace example
publish_to: none

environment:
sdk: ^$dartVersion

workspace:
- $projectName
- packages/core
# If using dart 3.11+ with the new workspace syntax, uncomment the line below and remove the `workspace` section above. # - packages/*
# - packages/*

dependencies:
flutter:
  sdk: flutter

dev_dependencies:
flutter_test:
  sdk: flutter
''';

  final file = File('pubspec.yaml');
  file.writeAsStringSync(content);
  print('✅ Root pubspec.yaml created');
}