create method

Stream<GeneralLibraryApiStatus> create({
  1. required String newName,
  2. required Directory directoryBase,
})

Server Universe

Implementation

Stream<GeneralLibraryApiStatus> 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());
  });
  // ignore: unused_local_variable
  String project_name = path.basename(directory_project.path);

  File file_pubspec = File(path.join(directory_project.path, "pubspec.yaml"));
  if (!file_pubspec.existsSync()) {
    yield GeneralLibraryApiStatus(serverUniverseApiStatusType: GeneralLibraryApiStatusType.info, value: "Start Create Project: ${newName}");

    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);
    if (exit_code != 0) {
      yield GeneralLibraryApiStatus(serverUniverseApiStatusType: GeneralLibraryApiStatusType.failed, value: "Failed Create Project: ${newName}");
      return;
    } else {
      yield GeneralLibraryApiStatus(serverUniverseApiStatusType: GeneralLibraryApiStatusType.succes, value: "Succes Create Project: ${newName}");
    }
  }

  File file_guide = File(path.join(directory_project.path, "guide-dart-general-library.md"));
  if (file_guide.existsSync()) {
    yield GeneralLibraryApiStatus(serverUniverseApiStatusType: GeneralLibraryApiStatusType.info, value: "Rewrite: ${path.basename(file_guide.path)}");
  } else {
    yield GeneralLibraryApiStatus(serverUniverseApiStatusType: GeneralLibraryApiStatusType.info, value: "Create: ${path.basename(file_guide.path)}");
  }

  await file_guide.writeAsString(general_library_docs.readme());

  // supabase directory deploy

  // update pubspec default
  yield GeneralLibraryApiStatus(serverUniverseApiStatusType: GeneralLibraryApiStatusType.info, value: "Start Update Pubspec: ${path.basename(file_pubspec.path)}");

  yield GeneralLibraryApiStatus(serverUniverseApiStatusType: GeneralLibraryApiStatusType.succes, value: "Succes Update Pubspec: ${path.basename(file_pubspec.path)}");
  yield GeneralLibraryApiStatus(serverUniverseApiStatusType: GeneralLibraryApiStatusType.info, value: "Start Save Pubspec: ${path.basename(file_pubspec.path)}");

  yield GeneralLibraryApiStatus(serverUniverseApiStatusType: GeneralLibraryApiStatusType.succes, value: "Succes Save Pubspec: ${path.basename(file_pubspec.path)}");
  yield GeneralLibraryApiStatus(serverUniverseApiStatusType: GeneralLibraryApiStatusType.succes, value: "Finished Create Project: ${newName}");

  // finished update pubspec
}