text: "use strict";
  /**
   * @file createComponentXml.ts
   * @Copyright (c) Microsoft Corporation.  All rights reserved.
   *
   * Creates an package's Element.Xml for a WebPart or ClientSideSolution
   */
  /// <reference path='./xml.d.ts' />
  Object.defineProperty(exports, "__esModule", { value: true });
  const path = require("path");
  const XmlGenerator = require("xml");
  const serializationOptions_1 = require("./serializationOptions");
  function createComponentXml(options, featureId) {
      const contents = {
          Elements: [
              Object.assign({}, createClientSideComponentElement(options))
          ]
      };
      switch (options.manifest.componentType) {
          case 'WebPart':
              contents.Elements.push({
                  Module: createModule(featureId, options)
              });
              break;
          case 'Application':
          case 'Extension':
          case 'Library':
              break;
          default:
              throw new Error(`Invalid Component Type: ${options.manifest.componentType}`);
      }
      contents.Elements.push({
          _attr: {
              xmlns: 'http://schemas.microsoft.com/sharepoint/'
          }
      });
      // @todo Note that the options.id is NOT necessarily the feature ID
      return {
          filename: path.posix.join(featureId, `${options.manifest.componentType}_${options.id}.xml`),
          contents: Buffer.from(XmlGenerator(contents, serializationOptions_1.default))
      };
  }
  exports.default = createComponentXml;
  /**
   * Creates a ClientSideComponent element.
   */
  function createClientSideComponentElement(options) {
      const attributes = {
          Name: options.name,
          Id: options.id,
          ComponentManifest: JSON.stringify(options.manifest),
          Type: options.manifest.componentType
      };
      if (options.requiresCustomScript) {
          // tslint:disable-next-line:no-string-literal
          attributes['ReturnIfCustomScriptDisabled'] = !options.requiresCustomScript;
      }
      return {
          ClientSideComponent: [
              {
                  _attr: attributes
              }
          ]
      };
  }
  /**
   * Creates a Module xml element with all the files.
   */
  function createModule(featureId, component) {
      const result = [{
              _attr: {
                  Name: component.name,
                  Url: '_catalogs/wp',
                  List: '113'
              }
          }];
      return result;
  }
  //# sourceMappingURL=createComponentXml.js.map