createJasprApp method

Future<bool> createJasprApp()

Create a Jaspr web app project

Implementation

Future<bool> createJasprApp() async {
  if (!config.template.isJasprApp) {
    return false;
  }

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

  info('Creating Jaspr web app: ${config.webPackageName}');

  // Use dart create -t package as base structure for Jaspr
  final List<String> args = <String>[
    'create',
    '-t',
    'package',
    projectPath,
  ];

  final ProcessResult? result = await _runner.runWithRetry(
    'dart',
    args,
    operationName: 'Dart create (Jaspr)',
  );

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

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

  final Directory exampleDir = Directory(p.join(projectPath, 'example'));
  if (exampleDir.existsSync()) {
    await exampleDir.delete(recursive: true);
  }

  success('Jaspr app created at: $projectPath');

  // arcane_jaspr_flutter_embed ships a companion Flutter web app as the
  // embed payload. Scaffold it now so the template copier has a place to
  // drop the Flutter sources.
  if (config.template == TemplateType.arcaneJasprFlutterEmbed) {
    if (!await _createEmbeddedFlutterApp()) {
      return false;
    }
  }

  return true;
}