"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const metadata_1 = require("./metadata/metadata");
const profile_1 = require("./profile");
const util_1 = require("./util");
/**
 * Project represents the location of the control project and provides
 * manipulation accessors.
 */
class Project {
    constructor(profileFile, projectBaseDir) {
        this.projectBaseDir = projectBaseDir;
        this.profile = new profile_1.Profile(profileFile);
    }
    /**
     * Returns the resolved package config with metadata.
     */
    packageConfig() {
        return __awaiter(this, void 0, void 0, function* () {
            return metadata_1.createPackage(yield this.packageJson(), this.baseDir());
        });
    }
    /**
     * Loads and parses the package.json file from the project.
     */
    packageJson() {
        return __awaiter(this, void 0, void 0, function* () {
            const contents = yield util_1.readFile(this.baseDir('package.json'));
            return JSON.parse(contents);
        });
    }
    /**
     * Base project directory. Joined with the optional extra path segments.
     */
    baseDir(...segments) {
        return path.join(this.projectBaseDir, ...segments);
    }
}
exports.Project = Project;
