diff --git a/src/actions/downloadCodeSite.ts b/src/actions/downloadCodeSite.ts new file mode 100644 index 0000000..7f2d737 --- /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 66a5cd6..cdf882c 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 0000000..b0c3b18 --- /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); + } +}