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",
architecture="x64",
installer_filename="installer.msi",
)
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,
installer_filename: 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. NAPT variables ({{discovered_version}}, {{installer_filename}}) are substituted in app_vars values and in the install/uninstall code blocks.
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 |
installer_filename
|
str
|
Exact filename of the installer copied into the package's Files directory. |
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
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |