"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getContext = getContext;

var _fs = require("fs");

var _path = _interopRequireDefault(require("path"));

var _constants = require("../constants");

var _getStrictCoatManifest = require("./get-strict-coat-manifest");

var _getCoatLockfiles = require("../lockfiles/get-coat-lockfiles");

var _getPackageJson = require("./get-package-json");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * Retrieves and parses files that are relevant
 * for a coat project
 *
 * @param cwd The directory of a coat project
 */
async function getContext(cwd) {
  // Read package.json & coat.json files
  // TODO: See #15
  // More friendly error messages if files are missing
  const [coatManifestRaw, coatGlobalLockfile, coatLocalLockfile, packageJson] = await Promise.all([_fs.promises.readFile(_path.default.join(cwd, _constants.COAT_MANIFEST_FILENAME), "utf8"), (0, _getCoatLockfiles.getCoatGlobalLockfile)(cwd), (0, _getCoatLockfiles.getCoatLocalLockfile)(cwd), (0, _getPackageJson.getPackageJson)(cwd)]);
  const coatManifest = JSON.parse(coatManifestRaw);
  const coatManifestStrict = (0, _getStrictCoatManifest.getStrictCoatManifest)(coatManifest);
  return {
    cwd,
    coatManifest: coatManifestStrict,
    coatGlobalLockfile,
    coatLocalLockfile,
    packageJson
  };
}