Skip to content

Commit f65d31a

Browse files
authored
Plist patch (#11)
Plist Support
1 parent fab3585 commit f65d31a

File tree

8 files changed

+175
-1
lines changed

8 files changed

+175
-1
lines changed

Tasks/PlistPatch/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "plistpatch",
3+
"private": true,
4+
"version": "0.1.0",
5+
"dependencies": {
6+
"fs-extra": "0.30.0",
7+
"micromatch": "2.3.11",
8+
"fast-json-patch": "1.0.0",
9+
"xregexp": "3.1.1",
10+
"vsts-task-lib": "0.9.6",
11+
"plist": "2.0.1"
12+
}
13+
}

Tasks/PlistPatch/plistPatch.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import path = require('path');
2+
import fs = require('fs-extra');
3+
import tl = require('vsts-task-lib/task');
4+
import micromatch = require('micromatch');
5+
import jsYaml = require('js-yaml');
6+
7+
import patch = require('./common/patch');
8+
import patchProcess = require('./common/patchProcess');
9+
import plistPatcher = require('./plistPatcher');
10+
11+
var targetPath = tl.getPathInput("YamlWorkingDir");
12+
var patchContent = tl.getInput("YamlPatchContent");
13+
14+
var patterns: any = tl.getInput("YamlTargetFilters")
15+
var outputPatchedFile = tl.getBoolInput("OutputPatchFile");
16+
var syntax = tl.getInput("SyntaxType");
17+
18+
try {
19+
var patches: patch.IPatch[] = syntax == "slick" ?
20+
patchProcess.expandVariablesAndParseSlickPatch(patchContent) :
21+
patchProcess.expandVariablesAndParseJson(patchContent);
22+
23+
patchProcess.apply(new plistPatcher.PlistPatcher(patches), targetPath, patterns, outputPatchedFile);
24+
25+
tl.setResult(tl.TaskResult.Succeeded, "Files Patched");
26+
27+
} catch (err) {
28+
console.error(String(err));
29+
tl.setResult(tl.TaskResult.Failed, String(err));
30+
}

Tasks/PlistPatch/plistPatcher.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import jsonPatcher = require('./common/jsonPatcher');
2+
import patch = require('./common/patch');
3+
var plist = require('plist');
4+
5+
export class PlistPatcher extends jsonPatcher.JsonPatcher {
6+
7+
parse(content: string): any {
8+
return plist.parse(content);
9+
}
10+
11+
stringify(content: any): string {
12+
return plist.build(content);
13+
}
14+
}

Tasks/PlistPatch/task.json

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"id": "599b994d-c4e1-4e74-b58e-0cd3006e5aac",
3+
"name": "PlistPatch",
4+
"friendlyName": "Patch Plist Files",
5+
"description": "Patch Plist files using JSON patch syntax",
6+
"helpMarkDown": "[More Information](https://github.com/geeklearningio/gl-vsts-tasks-file-patch/wiki/Patch-Plist-Files) (Version #{Version}#)",
7+
"category": "Utility",
8+
"visibility": [
9+
"Build",
10+
"Release"
11+
],
12+
"author": "Geek Learning",
13+
"version": {
14+
"Major": 0,
15+
"Minor": 0,
16+
"Patch": 0
17+
},
18+
"demands": [
19+
"npm"
20+
],
21+
"minimumAgentVersion": "1.91.0",
22+
"instanceNameFormat": "Patch files $(PlistTargetFilters)",
23+
"inputs": [
24+
{
25+
"name": "SyntaxType",
26+
"type": "pickList",
27+
"label": "Syntax type",
28+
"defaultValue": "Standard",
29+
"required": true,
30+
"helpMarkDown": "The syntax used for the patch content. See documentation for more information.",
31+
"options": {
32+
"standard": "Standard Syntax",
33+
"slick": "Slick Syntax"
34+
}
35+
},
36+
{
37+
"name": "PlistWorkingDir",
38+
"type": "filePath",
39+
"label": "Patch working directory",
40+
"defaultValue": "",
41+
"required": true,
42+
"helpMarkDown": "Working directory. Example: $(Build.SourcesDirectory)"
43+
},
44+
{
45+
"name": "PlistTargetFilters",
46+
"type": "multiLine",
47+
"label": "Target files",
48+
"defaultValue": "",
49+
"required": true,
50+
"helpMarkDown": "Patch target file. Example: appsettings*.plist"
51+
},
52+
{
53+
"name": "PlistPatchContent",
54+
"type": "multiLine",
55+
"label": "Patch Content",
56+
"defaultValue": "",
57+
"required": true,
58+
"helpMarkDown": "Patch content.",
59+
"properties": {
60+
"resizable": "true",
61+
"rows": "10",
62+
"maxLength": "5000"
63+
}
64+
},
65+
{
66+
"name": "OutputPatchFile",
67+
"type": "boolean",
68+
"label": "Output patched file in logs",
69+
"defaultValue": "false",
70+
"helpMarkDown": "Output patched file in logs"
71+
}
72+
],
73+
"execution": {
74+
"Node": {
75+
"target": "plistPatch.js",
76+
"argumentFormat": ""
77+
}
78+
}
79+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import plistPatcher = require("../../Tasks/PlistPatch/plistPatcher");
2+
var plist = require("../../Tasks/PlistPatch/node_modules/plist");
3+
4+
5+
6+
describe("PLIST Patcher", () => {
7+
8+
describe("Operations", () => {
9+
10+
var source: string;
11+
12+
beforeEach(function() {
13+
source = plist.build({
14+
sampleValue : "12"
15+
});
16+
});
17+
18+
describe("Add", () => {
19+
it(": should support basic add.", () => {
20+
var patcher = new plistPatcher.PlistPatcher([
21+
{
22+
op: "add", path: "/added", value: {}
23+
},{
24+
op: "add", path: "/added/value", value: "42"
25+
}
26+
]);
27+
var result = plist.parse(patcher.apply(source));
28+
29+
expect(result).toBeDefined();
30+
expect(result.sampleValue).toBeDefined();
31+
expect(result.sampleValue).toEqual("12");
32+
expect(result.added.value).toEqual("42");
33+
});
34+
});
35+
});
36+
});

Tests/YamlPatch/yamlPatcher.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import yamlPatcher = require("../../Tasks/YamlPatch/yamlPatcher");
22
var jsYaml = require("../../Tasks/YamlPatch/node_modules/js-yaml");
33

44

5-
describe("YANL Patcher", () => {
5+
describe("YAML Patcher", () => {
66

77
describe("Operations", () => {
88

configuration.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"VssExtensionGalleryFlags": [],
3131
"DisplayNamesSuffix": " (Development)",
3232
"TaskIds": {
33+
"PlistPatch" : "36db878b-3060-4465-86d2-d6a73ddbc0ad",
3334
"YamlPatch": "14568f85-c21b-490f-b102-568d2a0da4bf",
3435
"JsonPatch": "578A87B3-5A3F-461B-828D-E53DA43A8F3A",
3536
"XmlPatch": "BD8DCFA1-1592-4DA9-8437-871752577791"

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"node_modules",
2121
"Tasks/JsonPatch/node_modules",
2222
"Tasks/YamlPatch/node_modules",
23+
"Tasks/PlistPatch/node_modules",
2324
"Common",
2425
"BuildScripts/node_modules",
2526
".BuildOutput"

0 commit comments

Comments
 (0)