Skip to content

[Feature Request]: Code optimization - retrieve module relative path through dedicated function #3187

Open

Description

@eriqua

Description

Implement helper function to retrieve the module relative path given the full path, e.g., Get-FormattedModuleRelativePath

Replace lines like

$moduleRelative = $moduleRoot.Replace('\', '/').split('modules/')[1]

used e.g., by Pester test, with a call to that function

Activity

  1. AlexanderSehr commented on May 9, 2023

    @AlexanderSehr
    Contributor

    Should link to

    $moduleRelative = $moduleRoot.Replace('\', '/').split('modules/')[1]
    $splitHyphens = $moduleRelative.split('-')
    $splitHyphens = $splitHyphens | ForEach-Object { $_.substring(0, 1).toupper() + $_.substring(1) }
    $splitHyphens = $splitHyphens -join ''
    $fullModuleIdentifier = 'Microsoft.{0}' -f $splitHyphens.Replace('-', '')
  2. moved this from Needs triage to To do in Backlogon May 9, 2023
  3. eriqua commented on May 9, 2023

    @eriqua
    ContributorAuthor

    Alexander Sehr (@AlexanderSehr) so I get the function should return the module full resourceType and not only the relative path, correct? If so I guess we should go with something like Get-ModuleResourceType?

  4. eriqua commented on May 11, 2023

    @eriqua
    ContributorAuthor

    Should also include an update to custom modules to include their suffix in the readme title

    Example
    modules\Web\sites\config--authsettingsv2\README.md

    Site AuthSettingsV2 Config [Microsoft.Web/sites/config]

  5. AlexanderSehr commented on May 13, 2023

    @AlexanderSehr
    Contributor

    Alexander Sehr (@AlexanderSehr) so I get the function should return the module full resourceType and not only the relative path, correct? If so I guess we should go with something like Get-ModuleResourceType?

    Correct. So network/virtual-networks should return Microsoft.Network/virtualNetworks.

  6. eriqua commented on May 20, 2023

    @eriqua
    ContributorAuthor

    Ref updated Set-DeploymentExamplesSection in Set-ModuleReadme for cleaner code to convert from kebab-case to camelCase or PascalCase:

        # Convert moduleName from kebab-case to camelCase
        $First, $Rest = $moduleName -Split '-',2
        $moduleNameCamelCase = $First.Tolower() + (Get-Culture).TextInfo.ToTitleCase($Rest) -Replace '-'
        # Convert moduleName from kebab-case to PascalCase
        $moduleNamePascalCase = (Get-Culture).TextInfo.ToTitleCase($moduleName) -Replace '-'
  7. added this to the milestone on May 19, 2024
  8. removed this from the milestone on Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [cat] testingenhancement

    Type

    No type

    Projects

    • Status
      To do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions