-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathfiletransform.ts
37 lines (34 loc) · 2.17 KB
/
filetransform.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import tl = require('azure-pipelines-task-lib/task');
import path = require('path');
import { Package } from 'azure-pipelines-tasks-webdeployment-common/packageUtility';
var deployUtility = require('azure-pipelines-tasks-webdeployment-common/utility.js');
var zipUtility = require('azure-pipelines-tasks-webdeployment-common/ziputility.js');
var fileTransformationsUtility = require('azure-pipelines-tasks-webdeployment-common/fileTransformationsUtility.js');
async function main() {
tl.setResourcePath(path.join( __dirname, 'task.json'));
tl.setResourcePath(path.join( __dirname, 'node_modules/azure-pipelines-tasks-webdeployment-common/module.json'));
let webPackage = new Package(tl.getPathInput('folderPath', true));
let packagePath = webPackage.getPath();
const osType = tl.getPlatform();
let xmlTransformation = osType === tl.Platform.Windows ? tl.getBoolInput('enableXmlTransform', false) : false;
let xmlTransformationRules = tl.getDelimitedInput('xmlTransformationRules', '\n', false);
let xmlTargetFiles = tl.getDelimitedInput('xmlTargetFiles', '\n', false);
let jsonTargetFiles = tl.getDelimitedInput('jsonTargetFiles', '\n', false);
if ( xmlTransformation || xmlTargetFiles.length != 0 || jsonTargetFiles.length != 0) {
let isFolderBasedDeployment: boolean = tl.stats(packagePath).isDirectory();
if(!isFolderBasedDeployment) {
var folderPath = await deployUtility.generateTemporaryFolderForDeployment(isFolderBasedDeployment, packagePath, webPackage.getPackageType());
fileTransformationsUtility.enhancedFileTransformations(isFolderBasedDeployment, xmlTransformation, folderPath, xmlTransformationRules, xmlTargetFiles, jsonTargetFiles);
await zipUtility.archiveFolder(folderPath, path.dirname(packagePath), path.basename(packagePath));
}
else {
fileTransformationsUtility.enhancedFileTransformations(isFolderBasedDeployment, xmlTransformation, packagePath, xmlTransformationRules, xmlTargetFiles, jsonTargetFiles);
}
}
else {
throw Error(tl.loc('FileTranformationNotEnabled'));
}
}
main().catch((error) => {
tl.setResult(tl.TaskResult.Failed, error);
});