This package provides a comprehensive set of tools for managing discloud.config files. It allows you to read, write, and validate your Discloud configurations with ease. The package is designed to be used in Dart applications that interact with the Discloud hosting service.
Add it to your pubspec.yaml as a dependencies by running the following command.
dart pub add discloud_configimport 'package:discloud_config/discloud_config.dart';You can create a DiscloudConfig instance in several ways:
// From a File
final configFile = File('path/to/your/project/discloud.config');
final config = DiscloudConfig(configFile);
// From a directory path (asynchronously)
final configFromPath = await DiscloudConfig.fromPath('path/to/your/project');
// From a FileSystemEntity (asynchronously)
final directory = Directory('path/to/your/project');
final configFromEntity = await DiscloudConfig.fromFileSystemEntity(directory);
// From a Uri (asynchronously)
final uri = Uri.file('path/to/your/project');
final configFromUri = await DiscloudConfig.fromUri(uri);All constructors accept an optional autoSave parameter. See the "Auto-saving" section for more details.
DiscloudConfigDatais read-only, seeUpdating DiscloudConfigData
// Stream<DiscloudConfigData?>
await for (final DiscloudConfigData? data in config.watch()) {
// ...
}The autoSave parameter in the constructors (DiscloudConfig.fromPath, DiscloudConfig.fromFileSystemEntity, etc.) controls whether changes are automatically written to the file.
-
If
autoSaveistrue(the default), any call tosetorsetDatawill immediately save the changes to thediscloud.configfile. -
If
autoSaveisfalse, you must manually call thesavemethod to persist any changes you've made. This can be useful for batching multiple changes together.
Example:
// With autoSave enabled (default)
final config = await DiscloudConfig.fromPath('path/to/your/project'); // autoSave is true
await config.set(DiscloudScope.RAM, 1024); // Changes are saved automatically
// With autoSave disabled
final config2 = await DiscloudConfig.fromPath('path/to/your/project', autoSave: false);
await config2.set(DiscloudScope.RAM, 2048); // Changes are not saved yet
await config2.save(); // Manually save the changesDiscloudConfigData.fromJson(Map<String, dynamic>);// Use copyWith
final DiscloudConfigData newData = oldData.copyWith(TYPE: DiscloudAppType.bot.name/*"bot"*/);// Stream<File>
await for (final File file in listDiscloudConfigFiles(Directory)) {
// ...
}// Stream<DiscloudConfig>
await for (final DiscloudConfig config in listDiscloudConfigByAppId(Directory, String)) {
// ...
}We welcome a diverse set of contributions, including, but not limited to:
- Filing bugs and feature requests
- Send a pull request
- Or, create something awesome using this API and share with us and others!
For the stability of the API and existing users, consider opening an issue first before implementing a large new feature or breaking an API. For smaller changes (like documentation, minor bug fixes), just send a pull request.
All pull requests are validated against CI, and must pass.
Ensure build runs
dart run build_runner buildEnsure code passes all our analyzer checks:
dart analyzeEnsure all code is formatted with the latest dev-channel SDK.
dart format .
dart fix --applyRun all of our unit tests:
dart testThis project is licensed under the Apache 2.0 License - see the LICENSE file for details.
