create method

FutureOr create({
  1. required String newName,
  2. required Directory directoryBase,
})

Implementation

FutureOr<dynamic> create({
  required String newName,
  required Directory directoryBase,
}) async {
  Directory directory_project = await Future(() async {
    return Directory(Directory(path.join(directoryBase.uri.toFilePath(), newName.trim())).uri.toFilePath());
  });
  String project_name = path.basename(directory_project.path);

  File file_pubspec = File(path.join(directory_project.path, "pubspec.yaml"));
  if (!file_pubspec.existsSync()) {
    Process process = await Process.start(
      "dart",
      [
        "create",
        newName,
        "--no-pub",
        "--force",
      ],
      workingDirectory: directory_project.parent.uri.toFilePath(),
    );
    process.stderr.listen((event) {
      stderr.add(event);
    });
    process.stdout.listen((event) {
      stdout.add(event);
    });
    int exit_code = await (process.exitCode);
  }
  Map yaml_code = (yaml.loadYaml(file_pubspec.readAsStringSync(), recover: true) as Map);
  PubspecNotif pubspecNotif = PubspecNotif(yaml_code.clone());

  File file_guide = File(path.join(directory_project.path, "guide-notif.md"));

  await file_guide.writeAsString(guide_notif_markdown());
  // supabase file script
  File file_script_example = File(path.join(directory_project.path, "bin", "${project_name}_example.dart"));

  if (!file_script_example.existsSync()) {
    // await file_script_example.writeAsString(script_notif_native());
  }

  // supabase directory deploy
  Directory directory_script_supabase = Directory(path.join(directory_project.path, "supabase", "functions", project_name));

  // default configuration pubspec
  PubspecNotif pubspecNotif_default = PubspecNotif.create(
    repository: "https://github.com/azkadev/notif",
    homepage: "https://github.com/azkadev/notif",
    issue_tracker: "https://github.com/azkadev/notif/issues",
    documentation: "https://github.com/azkadev/notif/tree/main/docs",
    funding: [
      "https://github.com/sponsors/azkadev",
    ],
    dependencies: PubspecNotifDependencies({
      "notif": "any",
      "notif_http_client": "any",
      "general_lib": "^0.0.34",
    }),
    notif: NotifPubspecConfig.create(),
  );

  // update pubspec default
  pubspecNotif.rawData.notif_updateMapIfNotSameOrEmptyOrNull(
    data: pubspecNotif_default.toJson(),
    ignoreKeys: [
      "@type",
    ],
  );
  String yaml_documents_new = YamlWriter().write(pubspecNotif.toJson());
  await file_pubspec.writeAsString(yaml_documents_new);
  // finished update pubspec
}