"use strict";

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

/**
 * Adds empty objects for all dependency groups if necessary
 *
 * @param dependencies Dependencies from the coat manifest or template
 */
function getStrictDependencies(dependencies) {
  var _dependencies$depende, _dependencies$devDepe, _dependencies$optiona, _dependencies$peerDep;

  return {
    dependencies: (_dependencies$depende = dependencies === null || dependencies === void 0 ? void 0 : dependencies.dependencies) !== null && _dependencies$depende !== void 0 ? _dependencies$depende : {},
    devDependencies: (_dependencies$devDepe = dependencies === null || dependencies === void 0 ? void 0 : dependencies.devDependencies) !== null && _dependencies$devDepe !== void 0 ? _dependencies$devDepe : {},
    optionalDependencies: (_dependencies$optiona = dependencies === null || dependencies === void 0 ? void 0 : dependencies.optionalDependencies) !== null && _dependencies$optiona !== void 0 ? _dependencies$optiona : {},
    peerDependencies: (_dependencies$peerDep = dependencies === null || dependencies === void 0 ? void 0 : dependencies.peerDependencies) !== null && _dependencies$peerDep !== void 0 ? _dependencies$peerDep : {}
  };
}
/**
 * Adds all missing properties to a coat manifest or template file
 * to access these properties safely in following code.
 *
 * @param coatManifest The manifest file that has been read from the disk
 */


function getStrictCoatManifest(coatManifest) {
  var _coatManifest$files, _coatManifest$scripts, _coatManifest$setup;

  let extendsEntries = [];

  if (coatManifest.extends) {
    if (typeof coatManifest.extends === "string") {
      extendsEntries.push(coatManifest.extends);
    } else {
      extendsEntries = coatManifest.extends;
    }
  } // TODO: See #18
  // Validate all properties
  // e.g. file type
  // also check that it is not a promise
  // (e.g. from importing and calling an async function)


  const strictManifest = { ...coatManifest,
    extends: extendsEntries,
    files: (_coatManifest$files = coatManifest.files) !== null && _coatManifest$files !== void 0 ? _coatManifest$files : [],
    dependencies: getStrictDependencies(coatManifest.dependencies),
    scripts: (_coatManifest$scripts = coatManifest.scripts) !== null && _coatManifest$scripts !== void 0 ? _coatManifest$scripts : [],
    setup: (_coatManifest$setup = coatManifest.setup) !== null && _coatManifest$setup !== void 0 ? _coatManifest$setup : []
  };
  return strictManifest;
}