"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const fs = require("fs");
const utils_1 = require("../utils");
class PluginDescriptorParser {
    constructor(pluginDir) {
        this.pluginDir = pluginDir;
        this.pathToDescriptor = PluginDescriptorParser.getPathToDescriptor(pluginDir);
        if (!fs.existsSync(this.pathToDescriptor)) {
            console.error(utils_1.cerr `(PluginDescriptor) Failed to find plugin descriptor for ${path.basename(pluginDir)}`);
            console.error();
            console.error(utils_1.cerr `(PluginDescriptor) Try running "gradle generatePluginDescriptor" in the containing repository`);
            console.error();
            throw Error(`PluginDescriptor ${this.pathToDescriptor} does not exist`);
        }
        this.descriptor = this.parseFile();
    }
    static getPathToDescriptor(pluginDir) {
        return path.join(pluginDir, PluginDescriptorParser.DESCRIPTOR_FILE_NAME);
    }
    static doesPluginDescriptorExist(pluginDir) {
        return fs.existsSync(this.getPathToDescriptor(pluginDir));
    }
    getPluginDescriptor() {
        return this.descriptor;
    }
    parseFile() {
        const content = fs.readFileSync(this.pathToDescriptor, { encoding: 'utf8' });
        return JSON.parse(content);
    }
}
PluginDescriptorParser.DESCRIPTOR_FILE_NAME = 'pluginDescriptor.json';
exports.PluginDescriptorParser = PluginDescriptorParser;
//# sourceMappingURL=PluginDescriptorParser.js.map