xrelease
Version:
xrelease (pronounced cross-release) helps you setup automated releases for your project for any language
43 lines • 1.37 kB
JavaScript
import fs from 'fs/promises';
import yaml from 'yaml';
import path from 'path';
const DEFAULT_CONFIG = {
version: 1,
release: {
branch: 'main',
defaultBump: 'patch',
changelog: {
enabled: true,
template: 'conventional',
},
},
};
const DEFAULT_CONFIG_PATH = '.xrelease.yml';
export async function readConfig(configPath) {
try {
// Resolve config path
const resolvedPath = configPath ? path.resolve(configPath) : path.resolve(DEFAULT_CONFIG_PATH);
const configFile = await fs.readFile(resolvedPath, 'utf-8');
const config = yaml.parse(configFile);
// Validate and merge with defaults
return {
version: config.version || DEFAULT_CONFIG.version,
release: {
...DEFAULT_CONFIG.release,
...config.release,
},
};
}
catch (error) {
if (error instanceof Error && error.message.includes('ENOENT')) {
if (configPath) {
// If a specific path was provided but not found, that's an error
throw new Error(`Config file not found at: ${configPath}`);
}
// No config file at default path, use defaults
return DEFAULT_CONFIG;
}
throw error;
}
}
//# sourceMappingURL=config.js.map