Skip to content

Add the delayed variable substitution #82

Closed

Description

@LaurentDardenne

My goal is to create a plaster manifest template.
I try to prevent the substitution of a pattern variable in a template file :

$VcsPathRepository="<!%=${PLASTER_DestinationPath}%>"
[Environment]::SetEnvironmentVariable("<%=${PLASTER_PARAM_ProjectName}%>Profile",$VcsPathRepository, "User") }

the result :

$VcsPathRepository="<%=${PLASTER_DestinationPath}%>"
[Environment]::SetEnvironmentVariable("PlasterTestProfile",$VcsPathRepository, "User") }

I combine a templatefile element and a modify element :

        <templateFile source='Templates\Project_Clone.T.Ps1'
            destination='Project_Clone.ps1'
            encoding='UTF8'/> 

        <modify path='Project_Clone.ps1'>
            <replace >
                <original><![CDATA[(?s)(<!%=)(.*?)(%>)]]></original>
                <substitute><![CDATA[<%=$2$3]]></substitute>
            </replace>
        </modify> 

This works.
But, if I want to edit multiple files I must duplicate the element Modify
Is it possible to add multiple processing for the Modify element and/or add the delayed variable substitution ?

Activity

  1. rkeithhill commented on Aug 5, 2016

    @rkeithhill
    Collaborator

    Well, the SetEnvironmentVariable call shouldn't be able to execute during template variable processing but I haven't implemented the code yet that prevents that. The way we could address this is with a new directive <setEnvironmentVariable>. One of the premises with Plaster is to have a simple set of directives of what it can do to a user's system. This should help the user feel confident in the template (it can only write to and modify the contents of the dest dir). It also helps ensure idempotency i.e. the template can be applied multiple times safely.

    Before we add such a directive can you tell me about the use case? I've used a number of scaffolders (yeoman & Visual Studio new project wizards) and I can't remember any of them creating environment variables.

  2. LaurentDardenne commented on Aug 5, 2016

    @LaurentDardenne
    Author

    The way we could address this is with a new directive .
    Why not, but i can do without this directive today.
    I use this code inside a post installation script.

    Before we add such a directive can you tell me about the use case?
    Maybe it was a bad example for my question.

    In a work team, each team member can install one identical project into a different directory.
    I use a environment variable to know where is the project profile :

       Powershell -NOPROFILE -Command {."$env:MyProjetProfile\MyProject_Profile.Ps1";IPMO Psake; Set-Location $MyProjetTools; Invoke-Psake .\Common.ps1} }

    In my case, the scaffolding is different for the first person who create a Vcs repository and the others who clone/checkout the Vcs repository.
    The main Plaster manifest create the project AND a second Plaster manifest to clone the repository and configure a workstation.

    Both Plaster manifests have common data (ex: projectName, ModuleName ...)

  3. locked and limited conversation to collaborators on Feb 26, 2021
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions