export async function exportEnvironmentTemplate()

in tasks/Node/src/modules/task-utils/envutil.ts [10:33]


export async function exportEnvironmentTemplate(exportEnvTemplateLocation: string, envTemplateLocation: string, envTemplateSasToken: string): Promise<void> {
    if (!envTemplateLocation || !envTemplateSasToken) {
        throw 'Missing Environment Location or Environment SAS Token as outputs variables.';
    }

    console.log('Exporting environment template.');

    const templateFileName = 'azuredeploy.json';
    const credential = new storage.AnonymousCredential();
    const pipeline = storage.newPipeline(credential);

    const blobUrl = new storage.BlobClient(`${envTemplateLocation}/${templateFileName}${envTemplateSasToken}`, pipeline);
    const response: storage.BlobDownloadResponseParsed = await blobUrl.download();

    if (response && response.readableStreamBody) {
        tl.mkdirP(exportEnvTemplateLocation);
        const templateFileLocation = `${exportEnvTemplateLocation}/${templateFileName}`;
        const data = response.readableStreamBody.read().toString();
        fs.writeFileSync(templateFileLocation, data, 'utf8');
        console.log(`Environment template has been exported to file: ${templateFileLocation}`);
    }

    console.log('Environment template has been exported successfully.');
}