template
napt.build.template
Invoke-AppDeployToolkit.ps1 template generation for NAPT.
This module handles generating the Invoke-AppDeployToolkit.ps1 script by reading PSADT's template, substituting configuration values, and inserting recipe-specific install/uninstall code.
Design Principles
- PSADT template remains pristine in cache
- Generate script by substitution, not modification
- Preserve PSADT's structure and comments
- Support dynamic values (AppScriptDate, discovered version)
- Merge org defaults with recipe overrides
Example
Basic usage:
from pathlib import Path
from napt.build.template import generate_invoke_script
script = generate_invoke_script(
template_path=Path("cache/psadt/4.1.7/Invoke-AppDeployToolkit.ps1"),
config=recipe_config,
version="141.0.7390.123",
psadt_version="4.1.7"
)
Path("builds/app/version/Invoke-AppDeployToolkit.ps1").write_text(script)
generate_invoke_script
generate_invoke_script(
template_path: Path,
config: dict[str, Any],
version: str,
psadt_version: str,
architecture: str,
) -> str
Generate Invoke-AppDeployToolkit.ps1 from PSADT template and config.
Reads the PSADT template, replaces the $adtSession hashtable with values from the configuration, and inserts recipe-specific install/ uninstall code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_path
|
Path
|
Path to PSADT's Invoke-AppDeployToolkit.ps1 template. |
required |
config
|
dict[str, Any]
|
Merged configuration (org + vendor + recipe). |
required |
version
|
str
|
Application version (from filesystem). |
required |
psadt_version
|
str
|
PSADT version being used. |
required |
architecture
|
str
|
Resolved installer architecture (e.g., "x64", "x86", "arm64", "any"). Sets AppArch in the $adtSession hashtable; "any" leaves AppArch unset. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Generated PowerShell script text. |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If template doesn't exist or template parsing fails. |
Example
Generate deployment script from template:
Source code in napt/build/template.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |