Skip to content

Storage

Persistent key-value storage for your plugin.

Data is stored in ~/.gemshell/plugins/your-plugin/storage.json.

Methods

get(key, defaultValue?)

Get a value:

javascript
const count = gemshell.storage.get('buildCount', 0);
const config = gemshell.storage.get('config', { enabled: true });

set(key, value)

Set a value:

javascript
gemshell.storage.set('buildCount', 42);
gemshell.storage.set('lastBuild', new Date().toISOString());
gemshell.storage.set('config', { enabled: true, threshold: 100 });

delete(key)

Delete a value:

javascript
gemshell.storage.delete('tempData');

clear()

Clear all storage:

javascript
gemshell.storage.clear();

has(key)

Check if key exists:

javascript
if (gemshell.storage.has('config')) {
  // ...
}

keys()

Get all keys:

javascript
const allKeys = gemshell.storage.keys();
// ['buildCount', 'lastBuild', 'config']

Supported Types

Storage supports:

  • Strings
  • Numbers
  • Booleans
  • Arrays
  • Objects
  • null

Example: Build Counter

javascript
module.exports = {
  name: 'Build Counter',
  version: '1.0.0',
  
  async onPreBuild(context, settings) {
    const count = gemshell.storage.get('buildCount', 0);
    gemshell.storage.set('buildCount', count + 1);
    gemshell.log(`Build #${count + 1}`);
  },
  
  async onPostBuild(context, settings) {
    gemshell.storage.set('lastBuild', {
      time: new Date().toISOString(),
      game: context.config.title,
      platform: context.platform
    });
  }
};

Example: Caching

javascript
module.exports = {
  name: 'Asset Optimizer',
  version: '1.0.0',
  
  async onModifyAssets(context, settings) {
    const cache = gemshell.storage.get('processedFiles', {});
    const files = gemshell.glob('**/*.png');
    
    for (const file of files) {
      const stat = gemshell.fs.stat(file);
      const cacheKey = `${file}:${stat.mtime}`;
      
      if (cache[file] === cacheKey) {
        gemshell.log(`Skipping ${file} (cached)`);
        continue;
      }
      
      // Process file...
      cache[file] = cacheKey;
    }
    
    gemshell.storage.set('processedFiles', cache);
  }
};