serenity-config
v0.1.3
Published
A powerful API for plugin config and file management.
Maintainers
Readme
SConfig
A powerful API for plugin config and file management, created for SerenityJS.
Features
- Create and read YAML configuration files for your plugin.
- Config files automatically update missing keys in existing configs.
- Read and write plugin data to world, player, or server storage.
How do I use this?
Install the Plugin: Install the latest version to your SerenityJS server's
pluginsdirectory.Install the Typings: Install the NPM package into your plugin project's folder.
#npm npm install serenity-config #yarn yarn add serenity-config #bun bun add serenity-config
[!NOTE] If you are having trouble with this step, try adding
--prefix <path/to/your/plugin/project>at the end of the command. 3. Import into your Plugin: In your plugin's main file, import theSConfigPluginclass.
```ts
import type { SConfigPlugin } from "serenity-config";
```- Resolve the Plugin Instance: Once your plugin is initialized, resolve the
SConfigPlugininstance that you have installed so you can use its features.import { Plugin } from "@serenityjs/plugins"; import type { SConfigPlugin } from "serenity-config"; class ExamplePlugin extends Plugin { n public onInitialize(): void { // The resolve method fetches the SConfigPlugin instance from the plugin you installed. const { Properties, Storage, StorageType } = this.resolve<SConfigPlugin>("serenity-config")!; // Notice the use of `!` can be unsafe if the plugin is not loaded correctly. } }
Usage
For full examples, check out the source. SConfig has examples for both types in its SConfigPlugin class.
Example Usage
const properties = new Properties<ExampleProperties>(
this,
"properties.yaml",
EXAMPLE_PROPERTIES_TEMPLATE
);
properties.getValue("debug");
const storage = new Storage<ExampleStorage>(
StorageType.Player,
"players.sqlite",
EXAMPLE_STORAGE_TEMPLATE
);
storage.setValue("example", true)