@appswap/cli
Version: 
A comprehensive CLI tool for CI/CD pipelines to manage versioning and publishing across multiple platforms
162 lines • 6.16 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigManager = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const yaml = __importStar(require("js-yaml"));
class ConfigManager {
    static getConfigPath(projectRoot = process.cwd()) {
        return path.join(projectRoot, this.CONFIG_DIR);
    }
    static configExists(projectRoot = process.cwd()) {
        const configPath = this.getConfigPath(projectRoot);
        return fs.existsSync(configPath) &&
            fs.existsSync(path.join(configPath, this.PUBLISH_CONFIG_FILE));
    }
    static loadConfig(projectRoot = process.cwd()) {
        const configPath = this.getConfigPath(projectRoot);
        if (!this.configExists(projectRoot)) {
            throw new Error(`AppSwap configuration not found. Run 'appswap init' to create configuration files.`);
        }
        const publishConfigPath = path.join(configPath, this.PUBLISH_CONFIG_FILE);
        const versionConfigPath = path.join(configPath, this.VERSION_CONFIG_FILE);
        let publishConfig;
        let versionConfig;
        try {
            publishConfig = yaml.load(fs.readFileSync(publishConfigPath, 'utf8'));
        }
        catch (error) {
            throw new Error(`Failed to load publish config: ${error instanceof Error ? error.message : String(error)}`);
        }
        try {
            if (fs.existsSync(versionConfigPath)) {
                versionConfig = yaml.load(fs.readFileSync(versionConfigPath, 'utf8'));
            }
            else {
                versionConfig = this.getDefaultVersionConfig();
            }
        }
        catch (error) {
            throw new Error(`Failed to load version config: ${error instanceof Error ? error.message : String(error)}`);
        }
        return {
            publish: publishConfig,
            version: versionConfig
        };
    }
    static saveConfig(config, projectRoot = process.cwd()) {
        const configPath = this.getConfigPath(projectRoot);
        if (!fs.existsSync(configPath)) {
            fs.mkdirSync(configPath, { recursive: true });
        }
        const publishConfigPath = path.join(configPath, this.PUBLISH_CONFIG_FILE);
        const versionConfigPath = path.join(configPath, this.VERSION_CONFIG_FILE);
        try {
            fs.writeFileSync(publishConfigPath, yaml.dump(config.publish, { indent: 2 }));
            fs.writeFileSync(versionConfigPath, yaml.dump(config.version, { indent: 2 }));
        }
        catch (error) {
            throw new Error(`Failed to save config: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    static getDefaultPublishConfig() {
        return {
            branches: {
                main: {
                    destinations: ['npm', 'github'],
                    versionStrategy: 'minor',
                    distTag: 'latest'
                },
                develop: {
                    destinations: ['npm'],
                    versionStrategy: 'minor',
                    distTag: 'dev'
                },
                'feature/*': {
                    destinations: ['npm'],
                    versionStrategy: 'branch',
                    distTag: 'feature'
                },
                'hotfix/*': {
                    destinations: ['npm', 'github'],
                    versionStrategy: 'patch',
                    distTag: 'hotfix'
                }
            },
            destinations: {
                npm: {
                    type: 'npm',
                    registry: 'https://registry.npmjs.org',
                    distTag: 'latest'
                },
                github: {
                    type: 'github',
                    releaseNotes: true
                },
                gitlab: {
                    type: 'gitlab',
                    releaseNotes: true
                }
            },
            hooks: {
                prepublish: ['npm run build', 'npm test'],
                postpublish: ['echo "Published successfully!"']
            }
        };
    }
    static getDefaultVersionConfig() {
        return {
            defaultStrategy: 'patch',
            tagPrefix: 'v',
            changelog: {
                enabled: true,
                format: 'conventional',
                file: 'CHANGELOG.md'
            }
        };
    }
    static getDefaultConfig() {
        return {
            publish: this.getDefaultPublishConfig(),
            version: this.getDefaultVersionConfig()
        };
    }
}
exports.ConfigManager = ConfigManager;
ConfigManager.CONFIG_DIR = '.appswap';
ConfigManager.PUBLISH_CONFIG_FILE = 'publish.yaml';
ConfigManager.VERSION_CONFIG_FILE = 'version.yaml';
//# sourceMappingURL=config-manager.js.map