Read and write Godot export_presets.cfg files.
This library provides a simple way to programmatically manage Godot export presets. It handles parsing the config file format, merging presets, and includes base presets for common platforms.
The parsing and serialization logic is based on Godot's source code, specifically the ConfigFile, VariantParser, and VariantWriter implementations from the Godot engine repository. This attempts to ensure compatibility with Godot's native export preset format.
npm install godot-export-presetsRequires Node.js 18 or higher.
import { loadExportPresets, findPreset, saveExportPresets } from 'godot-export-presets';
// Load existing presets
const presets = await loadExportPresets('./export_presets.cfg');
// Find preset by platform name
const androidPreset = findPreset(presets, { platform: 'Android' });
if (androidPreset) {
androidPreset.export_path = 'game.apk';
}
// Save
await saveExportPresets('./export_presets.cfg', presets);Load a file, find a preset by name, make changes, and save:
import { loadExportPresets, findPreset, saveExportPresets } from 'godot-export-presets';
const presets = await loadExportPresets('./export_presets.cfg');
console.log(`Found ${presets.presets.length} presets`);
// Find preset by platform (case-insensitive)
const androidPreset = findPreset(presets, { platform: 'android' });
if (androidPreset) {
androidPreset.export_path = 'game.apk';
}
// Or find by preset name
const iosPreset = findPreset(presets, { name: 'iOS' });
if (iosPreset) {
iosPreset.export_path = 'game.ipa';
}
await saveExportPresets('./export_presets.cfg', presets);The library includes base presets for Android and iOS on Godot 3.x and 4.x:
import { getBasePreset, getMajorVersion } from 'godot-export-presets';
// Get base preset for Android (Godot 4.x)
const baseAndroid = getBasePreset('Android', 4);
// Extract version from string
const version = getMajorVersion('4.3.2'); // returns 4
const baseForVersion = getBasePreset('iOS', version);Main functions:
loadExportPresets(filePath)- Load presets from filesaveExportPresets(filePath, presets)- Save presets to fileparseExportPresets(content)- Parse from stringserializeExportPresets(presets)- Serialize to stringfindPreset(presets, criteria)- Find preset by platform/name/indexgetPreset(presets, index)- Get preset by indexsetPreset(presets, preset, index?)- Add or update presetremovePreset(presets, index)- Remove presetmergePresets(...presets)- Merge multiple presetsgetBasePreset(platform, version)- Get base presetgetMajorVersion(version)- Extract major version from string
For full TypeScript types and API details, see the type definitions in dist/index.d.ts.
This library is based on Godot's source code. The parsing logic follows Godot's VariantParser implementation, and the serialization follows VariantWriter and String::property_name_encode. The base presets are extracted from real Godot export configurations.
This implementation was created with tool assistance using Cursor and Claude, porting Godot's C++ logic to TypeScript while maintaining compatibility with the original format.
Key Godot source files referenced:
core/io/config_file.cpp- ConfigFile parsing and writingcore/variant/variant_parser.cpp- Variant parsing logiccore/string/ustring.cpp- String encoding for keyseditor/export/editor_export.cpp- Export preset structure
MIT