Skip to content

Ideas for simplifying accelerators.yaml #4

@ericbottard

Description

@ericbottard

After looking at the machine generated accelerator.yaml file in a bit more detail, I think the following recipes could be used to make it more "natural" (and concise):

  1. All of the preprocessor #if x #endif directives could be replaced by a ReplaceText with regex, e.g. like so:
  - include:
    - src/MyProjectGroup.Common/MyProjectGroup.Common.csproj
    chain:
    - type: ReplaceText
      substitutions:
      - text: |2-
                  <!--#if configserver -->
                  <PackageReference Include="Steeltoe.Extensions.Configuration.ConfigServerCore" Version="3.1.3" />
                  <!--#endif -->
        with: "''"
      condition: '!(#configserver)'
    - type: ReplaceText
      substitutions:
      - text: |2-
                  <!--#if configserver -->
                  <PackageReference Include="Steeltoe.Extensions.Configuration.ConfigServerCore" Version="3.1.3" />
                  <!--#endif -->
        with: "'        <PackageReference Include=\"Steeltoe.Extensions.Configuration.ConfigServerCore\" Version=\"3.1.3\" />'"
      condition: '#configserver'

becomes

  - include:
    - src/MyProjectGroup.Common/MyProjectGroup.Common.csproj
    chain:
    - type: ReplaceText
      regex:
        pattern: '(?s)<!--#if configserver -->(.*?)<!--#endif -->'
        with: "#configserver ? '$1' : ''"

but then of course, there is no need to have this snippet per file, so the include can become

- include: ['**/*.csproj', '**/*.xml']

and handle all files in one swoop.

You're then left with one snippet per option + comment format (xml-like, C-like, etc.)
I believe this can apply to lines 70 to 800 and scale with the number of options instead of the number of files to touch.
If you're adventurous, this could be reduced to one snippet per option if you make the regex cope with all comment styles.

  1. Then, all the RewritePath of the form
  - type: RewritePath
    regex: config/DotnetAccelerator-Development.yaml
    rewriteTo: "'config/' + #artifactId + '-Development.yaml'"
  - type: RewritePath
    regex: config/DotnetAccelerator-LocalMySQL.yaml
    rewriteTo: "'config/' + #artifactId + '-LocalMySQL.yaml'"
etc...

can be rewritten to a couple of RewritePath using capturing groups:

  - type: RewritePath
    regex: (config/)DotnetAccelerator(-Development\\.yaml)
    rewriteTo: "#g1 + #artifactId + #g2"
etc...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions