createProject function

Future<void> createProject(
  1. String projectName,
  2. String host,
  3. int port,
  4. String oydaBase,
  5. String user,
  6. String password,
)

Creates a new Oyda project with the given parameters.

  • The projectName is the name of the project to be created.
  • The host is the host address of the oydabase.
  • The port is the port number of the oydabase.
  • The oydaBase is the name of the oydabase.
  • The user is the username for authentication.
  • The password is the password for authentication.

This function connects to the oydabase using the provided parameters. If the connection is successful, it creates a new directory with the projectName. Inside the project directory, it creates the necessary subdirectories and files for an Oyda project, including 'lib/main.dart', 'test/widget_test.dart', 'README.md', and '.env' files. It also sets the 'pubspec.yaml' file to read-only.

If the connection to the oydabase fails or the project directory already exists, appropriate error messages are printed and the function returns.

After successfully creating the project, a success message is printed.

Implementation

Future<void> createProject(String projectName, String host, int port,
    String oydaBase, String user, String password) async {
  print('Creating project $projectName...');
  final result = await setOydabase(host, port, oydaBase, user, password);
  final bool isConnected = result['success'];
  final int devKey = result['dev_key'];

  if (!isConnected) {
    print(
        'Failed to connect to the oydabase. Check that the oydabase with these parameters exists and is running. \n Project creation aborted.');
    return;
  }

  createDirectory(projectName);
  createMainFile(projectName);
  createIndexFile(projectName);
  createWidgetTestFile(projectName);
  createReadmeFile(projectName);
  createTestIMLFile(projectName);
  createEnvFile(projectName, host, port, oydaBase, user, password, devKey);
  createDependenciesFile(projectName);
  createPubspecFile(projectName);
  createTableConfigFile(projectName);
  createGitignoreFile(projectName);
  await addDefaultDependencies(projectName);
  await fetchDependencies(projectName);
  print('Project $projectName created successfully.');
  print(
      'To start the project, run the following command:  \noydacli run --projectName $projectName');
}