makeConfig static method

Future<void> makeConfig(
  1. String configName,
  2. String value, {
  3. String folderPath = configFolder,
  4. bool forceCreate = false,
  5. String? creationPath,
})

Creates a new config file.

Implementation

static Future<void> makeConfig(
  String configName,
  String value, {
  String folderPath = configFolder,
  bool forceCreate = false,
  String? creationPath,
}) async {
  String name = configName.replaceAll(RegExp(r'(_?config)'), "");

  // create missing directories in the project
  await _makeDirectory(folderPath);
  await createDirectoriesFromCreationPath(creationPath, folderPath);

  // create file path
  String filePath = createPathForDartFile(
    folderPath: folderPath,
    className: name,
    creationPath: creationPath,
  );

  await _checkIfFileExists(filePath, shouldForceCreate: forceCreate);
  await _createNewFile(
    filePath,
    value,
    onSuccess: () {
      final linkText = name.snakeCase;
      final link = MetroConsole.hyperlink(linkText, filePath);
      MetroConsole.writeInGreen('[Config] $link created 🎉');
    },
  );
}