public async init()

in powershell/internal/project.ts [204:394]


  public async init(state?: ModelState<PwshModel>): Promise<this> {
    await super.init();

    this.state = await new State(this.service).init(this);

    if (state) {
      this.state.model = state.model;
    }

    this.schemaDefinitionResolver = new PSSchemaResolver(this.state.project.fixedArray);

    this.projectNamespace = this.state.model.language.csharp?.namespace || '';

    this.overrides = {
      'Carbon.Json.Converters': `${this.projectNamespace}.Runtime.Json`,
      'Carbon.Internal.Extensions': `${this.projectNamespace}.Runtime.Json`,
      'Carbon.Internal': `${this.projectNamespace}.Runtime.Json`,
      'Carbon.Data': `${this.projectNamespace}.Runtime.Json`,
      'using Data;': '',
      'using Parser;': '',
      'using Converters;': '',
      'using Internal.Extensions;': '',

      'Carbon.Json.Parser': `${this.projectNamespace}.Runtime.Json`,
      'Carbon.Json': `${this.projectNamespace}.Runtime.Json`,
      'Microsoft.Rest.ClientRuntime': `${this.projectNamespace}.Runtime`,
      'Microsoft.Message.ClientRuntime': `${this.projectNamespace}.Runtime`,
      'Microsoft.generated.runtime.Properties': `${this.projectNamespace}.generated.runtime.Properties`,
      'Microsoft.Rest': `${this.projectNamespace}`,
    };

    // Values
    this.moduleVersion = await this.state.getValue('module-version');
    // skip-for-time-being
    //this.profiles = this.model.info.extensions['x-ms-metadata'].profiles || [];
    this.profiles = [];
    this.accountsVersionMinimum = '2.7.5';
    this.helpLinkPrefix = await this.state.getValue('help-link-prefix');
    this.metadata = await this.state.getValue<Metadata>('metadata');
    this.preprocessMetadata();
    this.license = await this.state.getValue('header-text', '');
    const pwshLicenseHeader = await this.state.getValue(
      'pwsh-license-header',
      ''
    );
    // if pwsh license header is not set, use the license set by license-header
    this.pwshCommentHeader = comment(
      pwshLicenseHeader
        ? pwshHeaderText(
          pwshLicenseHeader,
          await this.service.getValue('header-definitions')
        )
        : this.license,
      '#'
    );
    this.pwshCommentHeaderForCsharp = this.pwshCommentHeader.replace(
      /"/g,
      '""'
    );
    this.csharpCommentHeader = comment(
      pwshLicenseHeader
        ? pwshHeaderText(
          pwshLicenseHeader,
          await this.service.getValue('header-definitions')
        )
        : this.license,
      '//'
    );
    this.csharpCommentHeaderForCsharp = this.csharpCommentHeader.replace(/"/g, '""');

    // modelcmdlets are models that we will create cmdlets for.
    this.modelCmdlets = [];
    let directives: Array<any> = [];
    const allDirectives = await this.state.service.getValue('directive');
    directives = values(<any>allDirectives).toArray();
    for (const directive of directives.filter((each) => each['model-cmdlet'])) {
      this.modelCmdlets = this.modelCmdlets.concat(
        <ConcatArray<ModelCmdletDirective>>values(directive['model-cmdlet']).toArray()
      );
    }
    this.modelCmdletsInPS = this.modelCmdlets.map(each => `@{modelName="${each['model-name']}"; cmdletName="${each['cmdlet-name'] || ''}"}`).join(', ') || '';
    // input handlers
    this.inputHandlers = await this.state.getValue('input-handlers', []);
    // Flags
    this.azure = this.model.language.default.isAzure;
    this.addToString = await this.state.getValue('nested-object-to-string', this.azure ? true : false);
    // Names
    this.prefix = this.model.language.default.prefix;
    this.serviceName = this.model.language.default.serviceName;
    this.subjectPrefix = this.model.language.default.subjectPrefix;
    this.moduleName = await this.state.getValue('module-name');
    this.title = await this.state.getValue('title');
    this.rootModuleName = await this.state.getValue('root-module-name', '');
    this.dllName = await this.state.getValue('dll-name');
    // Azure PowerShell data plane configuration
    if (this.azure) {
      this.endpointResourceIdKeyName = await this.state.getValue(
        'endpoint-resource-id-key-name',
        ''
      );
      this.endpointSuffixKeyName = await this.state.getValue(
        'endpoint-suffix-key-name',
        ''
      );
    }

    // Folders
    this.baseFolder = await this.state.getValue('current-folder');
    this.moduleFolder = await this.state.getValue('module-folder');
    this.cmdletFolder = await this.state.getValue('cmdlet-folder');
    this.modelCmdletFolder = await this.state.getValue('model-cmdlet-folder');

    this.customFolder = await this.state.getValue('custom-cmdlet-folder');
    this.utilsFolder = await this.state.getValue('utils-cmdlet-folder');
    this.internalFolder = await this.state.getValue('internal-cmdlet-folder');
    this.testFolder = await this.state.getValue('test-folder');
    this.runtimeFolder = await this.state.getValue('runtime-folder');
    this.apiFolder = await this.state.getValue('api-folder');

    this.binFolder = await this.state.getValue('bin-folder');
    this.objFolder = await this.state.getValue('obj-folder');
    this.exportsFolder = await this.state.getValue('exports-folder');
    this.docsFolder = await this.state.getValue('docs-folder');
    this.dependencyModuleFolder = await this.state.getValue(
      'dependency-module-folder'
    );
    this.examplesFolder = await this.state.getValue('examples-folder');
    this.resourcesFolder = await this.state.getValue('resources-folder');
    this.uxFolder = await this.state.getValue('ux-folder');

    // configuration for whether to use fixed array in generated code of model, default is false
    this.fixedArray = await this.state.getValue('fixed-array', false);

    // File paths
    this.csproj = await this.state.getValue('csproj');
    this.dll = await this.state.getValue('dll');
    this.psd1 = await this.state.getValue('psd1');
    this.psm1 = await this.state.getValue('psm1');
    this.psm1Custom = await this.state.getValue('psm1-custom');
    this.psm1Internal = await this.state.getValue('psm1-internal');
    this.formatPs1xml = await this.state.getValue('format-ps1xml');
    this.autoSwitchView = await this.state.getValue('auto-switch-view', true);
    this.nuspec = await this.state.getValue('nuspec');
    this.gitIgnore = `${this.baseFolder}/.gitignore`;
    this.gitAttributes = `${this.baseFolder}/.gitattributes`;
    this.readme = `${this.baseFolder}/README.md`;
    this.afterBuildTasksPath = await this.state.getValue('after-build-tasks-path', '');

    const afterBuildTasksArgsDictionary: Dictionary<string> = await this.state.getValue<Dictionary<string>>('after-build-tasks-args', {});
    this.afterBuildTasksArgs = JSON.stringify(afterBuildTasksArgsDictionary);

    this.assemblyInfoPath = await this.state.getValue('assemblyInfo-path', '');
    this.assemblyCompany = await this.state.getValue('assembly-company', '');
    this.assemblyProduct = await this.state.getValue('assembly-product', '');
    this.assemblyCopyright = await this.state.getValue('assembly-copyright', '');

    // excluded properties in table view
    const excludedList = <Array<string>>(
      values(
        <any>await this.state.getValue('exclude-tableview-properties', [])
      ).toArray()
    );
    this.propertiesExcludedForTableview = excludedList
      ? excludedList.join(',')
      : '';

    // add project namespace
    this.serviceNamespace = new ModuleNamespace(this.state);
    this.serviceNamespace.header = this.license;
    this.addNamespace(this.serviceNamespace);

    this.modelsExtensions = new ModelExtensionsNamespace(
      this.serviceNamespace,
      <any>this.state.model.schemas,
      this.state.path('components', 'schemas')
    );
    this.modelsExtensions.header = this.license;
    this.addNamespace(this.modelsExtensions);

    // add cmdlet namespace
    this.cmdlets = await new CmdletNamespace(
      this.serviceNamespace,
      this.state
    ).init();
    this.cmdlets.header = this.license;
    this.addNamespace(this.cmdlets);

    // abort now if we have any errors.
    this.state.checkpoint();
    return this;
  }