From ff00a051545bf14ec911791f193abbe347266138 Mon Sep 17 00:00:00 2001 From: Rishabh Jain Date: Thu, 26 Feb 2026 08:15:41 +0000 Subject: [PATCH] Add downloadCodeSite and uploadCodeSite action wrappers Add wrapper functions for the new `pac pages download-code-site` and `pac pages upload-code-site` CLI commands, following the existing downloadPaportal/uploadPaportal pattern. Export both from the actions barrel file. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/actions/downloadCodeSite.ts | 41 +++++++++++++++++++++++++++++++++ src/actions/index.ts | 2 ++ src/actions/uploadCodeSite.ts | 41 +++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 src/actions/downloadCodeSite.ts create mode 100644 src/actions/uploadCodeSite.ts diff --git a/src/actions/downloadCodeSite.ts b/src/actions/downloadCodeSite.ts new file mode 100644 index 00000000..7f2d737d --- /dev/null +++ b/src/actions/downloadCodeSite.ts @@ -0,0 +1,41 @@ +import { HostParameterEntry, IHostAbstractions } from "../host/IHostAbstractions"; +import { InputValidator } from "../host/InputValidator"; +import { authenticateEnvironment, clearAuthentication } from "../pac/auth/authenticate"; +import createPacRunner from "../pac/createPacRunner"; +import { RunnerParameters } from "../Parameters"; +import { AuthCredentials } from "../pac/auth/authParameters"; + +export interface DownloadCodeSiteParameters { + credentials: AuthCredentials; + environmentUrl: string; + path: HostParameterEntry; + websiteId: HostParameterEntry; + overwrite: HostParameterEntry; +} + +export async function downloadCodeSite(parameters: DownloadCodeSiteParameters, runnerParameters: RunnerParameters, host: IHostAbstractions): Promise { + const logger = runnerParameters.logger; + const pac = createPacRunner(runnerParameters); + + try { + const authenticateResult = await authenticateEnvironment(pac, parameters.credentials, parameters.environmentUrl, logger); + logger.log("The Authentication Result: " + authenticateResult); + + const pacArgs = ["pages", "download-code-site"] + const validator = new InputValidator(host); + + validator.pushInput(pacArgs, "--path", parameters.path); + validator.pushInput(pacArgs, "--webSiteId", parameters.websiteId); + validator.pushInput(pacArgs, "--overwrite", parameters.overwrite); + + logger.log("Calling pac cli inputs: " + pacArgs.join(" ")); + const pacResult = await pac(...pacArgs); + logger.log("DownloadCodeSite Action Result: " + pacResult); + } catch (error) { + logger.error(`failed: ${error instanceof Error ? error.message : error}`); + throw error; + } finally { + const clearAuthResult = await clearAuthentication(pac); + logger.log("The Clear Authentication Result: " + clearAuthResult); + } +} diff --git a/src/actions/index.ts b/src/actions/index.ts index 66a5cd69..cdf882c9 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -6,6 +6,7 @@ export * from "./whoAmI"; export * from "./importSolution"; export * from "./upgradeSolution"; export * from "./deleteEnvironment"; +export * from "./downloadCodeSite"; export * from "./backupEnvironment"; export * from "./checkSolution"; export * from "./publishSolution"; @@ -17,6 +18,7 @@ export * from "./packSolution"; export * from "./unpackSolution"; export * from "./resetEnvironment"; export * from "./copyEnvironment"; +export * from "./uploadCodeSite"; export * from "./uploadPaportal"; export * from "./downloadPaportal"; export * from "./cloneSolution"; diff --git a/src/actions/uploadCodeSite.ts b/src/actions/uploadCodeSite.ts new file mode 100644 index 00000000..b0c3b186 --- /dev/null +++ b/src/actions/uploadCodeSite.ts @@ -0,0 +1,41 @@ +import { HostParameterEntry, IHostAbstractions } from "../host/IHostAbstractions"; +import { InputValidator } from "../host/InputValidator"; +import { authenticateEnvironment, clearAuthentication } from "../pac/auth/authenticate"; +import createPacRunner from "../pac/createPacRunner"; +import { RunnerParameters } from "../Parameters"; +import { AuthCredentials } from "../pac/auth/authParameters"; + +export interface UploadCodeSiteParameters { + credentials: AuthCredentials; + environmentUrl: string; + rootPath: HostParameterEntry; + compiledPath: HostParameterEntry; + siteName: HostParameterEntry; +} + +export async function uploadCodeSite(parameters: UploadCodeSiteParameters, runnerParameters: RunnerParameters, host: IHostAbstractions): Promise { + const logger = runnerParameters.logger; + const pac = createPacRunner(runnerParameters); + + try { + const authenticateResult = await authenticateEnvironment(pac, parameters.credentials, parameters.environmentUrl, logger); + logger.log("The Authentication Result: " + authenticateResult); + + const pacArgs = ["pages", "upload-code-site"] + const validator = new InputValidator(host); + + validator.pushInput(pacArgs, "--rootPath", parameters.rootPath); + validator.pushInput(pacArgs, "--compiledPath", parameters.compiledPath); + validator.pushInput(pacArgs, "--siteName", parameters.siteName); + + logger.log("Calling pac cli inputs: " + pacArgs.join(" ")); + const pacResult = await pac(...pacArgs); + logger.log("UploadCodeSite Action Result: " + pacResult); + } catch (error) { + logger.error(`failed: ${error instanceof Error ? error.message : error}`); + throw error; + } finally { + const clearAuthResult = await clearAuthentication(pac); + logger.log("The Clear Authentication Result: " + clearAuthResult); + } +}