-
Notifications
You must be signed in to change notification settings - Fork 7
02 Makefile.ps1
Wojtek edited this page Apr 8, 2015
·
1 revision
The Makefile.ps1 file contains definitions of all steps that would be executed during make.
It's example content is presented below:
Define-Step -Name 'Step one' -Target 'build' -Body {
echo 'Greetings from step one'
}
Define-Step -Name 'Step two' -Target 'build,deploy' -Body {
echo 'Greetings from step two'
}
Steps are defined with Define-Step
function, where each step has own:
- name (-Name parameter), which does not need to be unique,
- target (-Target parameter), which can be one or multiple comma separated targets,
- body (-Body parameter), which is a script-block that would be executed during given step.
There are few rules regarding Makefile.ps1:
- All steps are run in isolation, which means that none of state would be shared between steps. There should be no code outside Define-Step script-blocks.
- In order to use a module functions within step body, a module has to be explicitly imported first with
. (Require-Module 'psmake.mod.[module_name]')
or. (require 'psmake.mod.[module_name]')
statements. Because steps are run in isolation, each step has to import modules separately. It looks like a more of typing, but it gives a better visibility and understanding of use functions source. - All steps can use all core PsMake functions (see details below).
- All functions and variables defined in
Environment.ps1
file are available in step body. - All parameters passed with
-AdditionalParams
parameter, as well as PsMake parameters would be accessible by steps via$Context
variable (see details below).
- Call-Program - Calls external program, and throws an exception if operation is unsuccessful.
- Write-Header - Prints header in green color.
- Write-Status - Prints status in cyan color.
- Write-ShortStatus - Prints short status in cyan color.
- Fetch-Package - Fetches NuGet package of specified name and version.
- Create-Object - Creates object with properties defined in $hash parameter.
- Require-Module - Provides path to module specified in $moduleName.
- Make-ScriptBlock - Makes a script-block for remote or local execution, that would allow to access all psmake core methods and $Context variable.
In order to get help for core functions, please follow steps defined below:
- (assuming that psmake.3.1.0.0 is installed in working directory)
- execute
PS> . .\psmake.3.1.0.0\ext\psmake.core.ps1
- execute Get-Help for any of function specified above, like
PS> Get-Help Call-Program
The $Context
variable is available within step body.
It contains properties reflecting:
- PsMake standard parameters (Target, AnsiConsole, MakeDirectory, NuGetExe, NuGetSource, NuGetConfig), like
$Context.Target
reflecting -Target parameter, -
$Context.NuGetArgs
property having a list of arguments for NuGet.exe. It could be used together with @ operator to call NuGet.exe, - all parameters passed with
-AdditionalParams
, where-AdditionalParams key1:value1,key2,key3:"abc,def"
will result in$Context.key1 = value1
,$Context.key2 = $true
,$Context.key3 = "abc,def"
.
Continue reading: 03 Modules.ps1