azure-pipelines-tasks-webdeployment-common 4.230.1 → 4.230.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,38 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runL1XmlVarSubTests = void 0;
4
+ const path = require("path");
5
+ const assert = require("assert");
6
+ const ltx = require("ltx");
7
+ const fs = require("fs");
8
+ const tl = require("azure-pipelines-task-lib");
9
+ const xmlvariablesubstitutionutility_1 = require("../xmlvariablesubstitutionutility");
10
+ const fileencoding_1 = require("../fileencoding");
11
+ function runL1XmlVarSubTests() {
12
+ this.timeout(60000);
13
+ beforeEach(function (done) {
14
+ tl.cp(getAbsolutePath('Web.config'), getAbsolutePath('Web_test.config'), '-f', false);
15
+ tl.cp(getAbsolutePath('Web.Debug.config'), getAbsolutePath('Web_test.Debug.config'), '-f', false);
16
+ tl.cp(getAbsolutePath('parameters.xml'), getAbsolutePath('parameters_test.xml'), '-f', false);
17
+ done();
8
18
  });
9
- };
10
- var xmlSubstitutionUtility = require('azure-pipelines-tasks-webdeployment-common/xmlvariablesubstitutionutility.js');
11
- var path = require('path');
12
- function xmlVarSub() {
13
- return __awaiter(this, void 0, void 0, function* () {
14
- var tags = ["applicationSettings", "appSettings", "connectionStrings", "configSections"];
15
- var configFiles = [path.join(__dirname, 'L1XmlVarSub/Web_test.config'), path.join(__dirname, 'L1XmlVarSub/Web_test.Debug.config')];
16
- var variableMap = {
19
+ afterEach(done => {
20
+ try {
21
+ tl.rmRF(getAbsolutePath('parameters_test.xml'));
22
+ tl.rmRF(getAbsolutePath('Web_test.Debug.config'));
23
+ tl.rmRF(getAbsolutePath('Web_test.config'));
24
+ }
25
+ catch (error) {
26
+ tl.debug(error);
27
+ }
28
+ finally {
29
+ done();
30
+ }
31
+ });
32
+ it("Runs successfully with XML variable substitution", done => {
33
+ const parameterFilePath = getAbsolutePath('parameters_test.xml');
34
+ const tags = ["applicationSettings", "appSettings", "connectionStrings", "configSections"];
35
+ const variableMap = {
17
36
  'conntype': 'new_connType',
18
37
  "MyDB": "TestDB",
19
38
  'webpages:Version': '1.1.7.3',
@@ -28,10 +47,27 @@ function xmlVarSub() {
28
47
  'log_level': 'error,warning',
29
48
  'Email:ToOverride': ''
30
49
  };
31
- var parameterFilePath = path.join(__dirname, 'L1XmlVarSub/parameters_test.xml');
32
- for (var configFile of configFiles) {
33
- yield xmlSubstitutionUtility.substituteXmlVariables(configFile, tags, variableMap, parameterFilePath);
34
- }
50
+ xmlvariablesubstitutionutility_1.substituteXmlVariables(getAbsolutePath('Web_test.config'), tags, variableMap, parameterFilePath);
51
+ xmlvariablesubstitutionutility_1.substituteXmlVariables(getAbsolutePath('Web_test.Debug.config'), tags, variableMap, parameterFilePath);
52
+ assert(compareXmlFiles('Web_test.config', 'Web_Expected.config'), 'Should have substituted variables in Web.config file');
53
+ assert(compareXmlFiles('Web_test.Debug.config', 'Web_Expected.Debug.config'), 'Should have substituted variables in Web.Debug.config file');
54
+ assert(compareXmlFiles('parameters_test.xml', 'parameters_Expected.xml'), 'Should have substituted variables in parameters.xml file');
55
+ done();
35
56
  });
57
+ function getAbsolutePath(file) {
58
+ return path.join(__dirname, 'L1XmlVarSub', file);
59
+ }
60
+ function compareXmlFiles(actualFile, expectedFile) {
61
+ const actualFilePath = getAbsolutePath(actualFile);
62
+ const expectedFilePath = getAbsolutePath(expectedFile);
63
+ var actualXml = ltx.parse(readFile(actualFilePath));
64
+ var expectedXml = ltx.parse(readFile(expectedFilePath));
65
+ return ltx.equal(actualXml, expectedXml);
66
+ }
67
+ function readFile(path) {
68
+ const buffer = fs.readFileSync(path);
69
+ const encoding = fileencoding_1.detectFileEncoding(path, buffer)[0].toString();
70
+ return buffer.toString(encoding).replace(/(?<!\r)[\n]+/gm, "\r\n");
71
+ }
36
72
  }
37
- xmlVarSub();
73
+ exports.runL1XmlVarSubTests = runL1XmlVarSubTests;
@@ -1,29 +1,86 @@
1
- var xmlSubstitutionUtility = require('azure-pipelines-tasks-webdeployment-common/xmlvariablesubstitutionutility.js');
2
- var path = require('path');
3
-
4
- async function xmlVarSub() {
5
- var tags = ["applicationSettings", "appSettings", "connectionStrings", "configSections"];
6
- var configFiles = [path.join(__dirname, 'L1XmlVarSub/Web_test.config'), path.join(__dirname, 'L1XmlVarSub/Web_test.Debug.config')];
7
- var variableMap = {
8
- 'conntype' : 'new_connType',
9
- "MyDB": "TestDB",
10
- 'webpages:Version' : '1.1.7.3',
11
- 'xdt:Transform' : 'DelAttributes',
12
- 'xdt:Locator' : 'Match(tag)',
13
- 'DefaultConnection': "Url=https://primary;Database=db1;ApiKey=11111111-1111-1111-1111-111111111111;Failover = {Url:'https://secondary', ApiKey:'11111111-1111-1111-1111-111111111111'}",
14
- 'OtherDefaultConnection': 'connectionStringValue2',
15
- 'ParameterConnection': 'New_Connection_String From xml var subs',
16
- 'connectionString': 'replaced_value',
17
- 'invariantName': 'System.Data.SqlServer',
18
- 'blatvar': 'ApplicationSettingReplacedValue',
19
- 'log_level': 'error,warning',
20
- 'Email:ToOverride': ''
1
+ import * as path from 'path';
2
+ import * as assert from 'assert';
3
+ import * as ltx from 'ltx';
4
+ import * as fs from 'fs';
5
+
6
+ import * as tl from 'azure-pipelines-task-lib';
7
+
8
+ import { substituteXmlVariables } from '../xmlvariablesubstitutionutility';
9
+ import { detectFileEncoding } from "../fileencoding";
10
+
11
+ export function runL1XmlVarSubTests(this: Mocha.Suite): void {
12
+
13
+ this.timeout(60000);
14
+
15
+ beforeEach(function (done: Mocha.Done) {
16
+ tl.cp(getAbsolutePath('Web.config'), getAbsolutePath('Web_test.config'), '-f', false);
17
+ tl.cp(getAbsolutePath('Web.Debug.config'), getAbsolutePath('Web_test.Debug.config'), '-f', false);
18
+ tl.cp(getAbsolutePath('parameters.xml'), getAbsolutePath('parameters_test.xml'), '-f', false);
19
+
20
+ done();
21
+ });
22
+
23
+ afterEach(done => {
24
+ try {
25
+ tl.rmRF(getAbsolutePath('parameters_test.xml'));
26
+ tl.rmRF(getAbsolutePath('Web_test.Debug.config'));
27
+ tl.rmRF(getAbsolutePath('Web_test.config'));
28
+ }
29
+ catch (error) {
30
+ tl.debug(error);
31
+ }
32
+ finally {
33
+ done();
34
+ }
35
+ });
36
+
37
+ it("Runs successfully with XML variable substitution", done => {
38
+ const parameterFilePath = getAbsolutePath('parameters_test.xml');
39
+ const tags = ["applicationSettings", "appSettings", "connectionStrings", "configSections"];
40
+ const variableMap = {
41
+ 'conntype': 'new_connType',
42
+ "MyDB": "TestDB",
43
+ 'webpages:Version': '1.1.7.3',
44
+ 'xdt:Transform': 'DelAttributes',
45
+ 'xdt:Locator': 'Match(tag)',
46
+ 'DefaultConnection': "Url=https://primary;Database=db1;ApiKey=11111111-1111-1111-1111-111111111111;Failover = {Url:'https://secondary', ApiKey:'11111111-1111-1111-1111-111111111111'}",
47
+ 'OtherDefaultConnection': 'connectionStringValue2',
48
+ 'ParameterConnection': 'New_Connection_String From xml var subs',
49
+ 'connectionString': 'replaced_value',
50
+ 'invariantName': 'System.Data.SqlServer',
51
+ 'blatvar': 'ApplicationSettingReplacedValue',
52
+ 'log_level': 'error,warning',
53
+ 'Email:ToOverride': ''
54
+ };
55
+
56
+ substituteXmlVariables(getAbsolutePath('Web_test.config'), tags, variableMap, parameterFilePath);
57
+ substituteXmlVariables(getAbsolutePath('Web_test.Debug.config'), tags, variableMap, parameterFilePath);
58
+
59
+ assert(compareXmlFiles('Web_test.config', 'Web_Expected.config'), 'Should have substituted variables in Web.config file');
60
+ assert(compareXmlFiles('Web_test.Debug.config', 'Web_Expected.Debug.config'), 'Should have substituted variables in Web.Debug.config file');
61
+ assert(compareXmlFiles('parameters_test.xml', 'parameters_Expected.xml'), 'Should have substituted variables in parameters.xml file');
62
+
63
+ done();
64
+ });
65
+
66
+ function getAbsolutePath(file: string): string {
67
+ return path.join(__dirname, 'L1XmlVarSub', file);
68
+ }
69
+
70
+ function compareXmlFiles(actualFile: string, expectedFile: string): boolean {
71
+ const actualFilePath = getAbsolutePath(actualFile);
72
+ const expectedFilePath = getAbsolutePath(expectedFile);
73
+
74
+ var actualXml = ltx.parse(readFile(actualFilePath));
75
+ var expectedXml = ltx.parse(readFile(expectedFilePath));
76
+
77
+ return ltx.equal(actualXml, expectedXml);
21
78
  }
22
79
 
23
- var parameterFilePath = path.join(__dirname, 'L1XmlVarSub/parameters_test.xml');
24
- for(var configFile of configFiles) {
25
- await xmlSubstitutionUtility.substituteXmlVariables(configFile, tags, variableMap, parameterFilePath);
80
+ function readFile(path: string): string {
81
+ const buffer = fs.readFileSync(path);
82
+ const encoding = detectFileEncoding(path, buffer)[0].toString();
83
+ return buffer.toString(encoding).replace(/(?<!\r)[\n]+/gm, "\r\n");
26
84
  }
27
85
  }
28
86
 
29
- xmlVarSub();
Binary file
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "azure-pipelines-tasks-webdeployment-common",
3
- "version": "4.230.1",
3
+ "version": "4.230.2",
4
4
  "description": "Common Lib for MSDeploy Utility",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+ssh://git@github.com/Microsoft/azure-pipelines-tasks.git"
8
8
  },
9
9
  "scripts": {
10
- "build": "pwsh build.ps1"
10
+ "build": "pwsh build.ps1",
11
+ "test": "nyc --all --src ./_build mocha ./_build/Tests/L0.js"
11
12
  },
12
13
  "author": "Microsoft Corporation",
13
14
  "license": "MIT",
@@ -19,6 +20,7 @@
19
20
  "@types/mocha": "^5.2.7",
20
21
  "@types/node": "^10.17.0",
21
22
  "@xmldom/xmldom": "git+https://github.com/xmldom/xmldom.git#0.8.6",
23
+ "@types/ltx": "3.0.6",
22
24
  "archiver": "1.2.0",
23
25
  "azure-pipelines-task-lib": "^4.2.0",
24
26
  "decompress-zip": "^0.3.3",
@@ -29,6 +31,8 @@
29
31
  "xml2js": "0.6.2"
30
32
  },
31
33
  "devDependencies": {
32
- "typescript": "4.0.2"
34
+ "typescript": "4.0.2",
35
+ "mocha": "^6.2.3",
36
+ "nyc": "^15.1.0"
33
37
  }
34
38
  }
package/packageUtility.js CHANGED
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Package = exports.PackageUtility = exports.PackageType = void 0;
13
13
  const tl = require("azure-pipelines-task-lib/task");
14
14
  const utility = require("./utility");
15
- var zipUtility = require('azure-pipelines-tasks-webdeployment-common/ziputility.js');
15
+ const ziputility_1 = require("./ziputility");
16
16
  const path = require("path");
17
17
  var PackageType;
18
18
  (function (PackageType) {
@@ -73,10 +73,11 @@ class Package {
73
73
  }
74
74
  isMSBuildPackage() {
75
75
  return __awaiter(this, void 0, void 0, function* () {
76
- if (this._isMSBuildPackage == undefined) {
77
- this._isMSBuildPackage = this.getPackageType() != PackageType.folder && (yield zipUtility.checkIfFilesExistsInZip(this._path, ["parameters.xml", "systeminfo.xml"]));
78
- tl.debug("Is the package an msdeploy package : " + this._isMSBuildPackage);
79
- }
76
+ if (this._isMSBuildPackage !== undefined)
77
+ return this._isMSBuildPackage;
78
+ const shouldCheckFiles = this.getPackageType() !== PackageType.folder;
79
+ this._isMSBuildPackage = shouldCheckFiles && (yield ziputility_1.checkIfFilesExistsInZip(this._path, ["parameters.xml", "systeminfo.xml"]));
80
+ tl.debug(`Is the package an msdeploy package : ${this._isMSBuildPackage}`);
80
81
  return this._isMSBuildPackage;
81
82
  });
82
83
  }
package/utility.js CHANGED
@@ -14,7 +14,7 @@ const path = require("path");
14
14
  const os = require("os");
15
15
  const tl = require("azure-pipelines-task-lib/task");
16
16
  const packageUtility_1 = require("./packageUtility");
17
- var zipUtility = require('azure-pipelines-tasks-webdeployment-common/ziputility.js');
17
+ const zipUtility = require("./ziputility");
18
18
  /**
19
19
  * Validates the input package and finds out input type
20
20
  *
@@ -1,2 +1,4 @@
1
- export declare function generateWebConfigFile(webConfigTargetPath: string, appType: string, substitutionParameters: any): void;
1
+ export declare function generateWebConfigFile(webConfigTargetPath: string, appType: string, substitutionParameters: {
2
+ [key: string]: string;
3
+ }): void;
2
4
  export declare function addWebConfigFile(folderPath: any, webConfigParameters: any, rootDirectoryPath: string): void;
@@ -21,7 +21,7 @@ exports.expandWildcardPattern = expandWildcardPattern;
21
21
  *
22
22
  */
23
23
  function applyXdtTransformation(sourceFile, transformFile, destinationFile) {
24
- var cttPath = path.join(__dirname, "..", "..", "ctt", "ctt.exe");
24
+ var cttPath = path.join(__dirname, "ctt", "ctt", "ctt.exe");
25
25
  var cttArgsArray = [
26
26
  "s:" + sourceFile,
27
27
  "t:" + transformFile,