Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Tasks/PlistPatch/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "plistpatch",
"private": true,
"version": "0.1.0",
"dependencies": {
"fs-extra": "0.30.0",
"micromatch": "2.3.11",
"fast-json-patch": "1.0.0",
"xregexp": "3.1.1",
"vsts-task-lib": "0.9.6",
"plist": "2.0.1"
}
}
30 changes: 30 additions & 0 deletions Tasks/PlistPatch/plistPatch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import path = require('path');
import fs = require('fs-extra');
import tl = require('vsts-task-lib/task');
import micromatch = require('micromatch');
import jsYaml = require('js-yaml');

import patch = require('./common/patch');
import patchProcess = require('./common/patchProcess');
import plistPatcher = require('./plistPatcher');

var targetPath = tl.getPathInput("YamlWorkingDir");
var patchContent = tl.getInput("YamlPatchContent");

var patterns: any = tl.getInput("YamlTargetFilters")
var outputPatchedFile = tl.getBoolInput("OutputPatchFile");
var syntax = tl.getInput("SyntaxType");

try {
var patches: patch.IPatch[] = syntax == "slick" ?
patchProcess.expandVariablesAndParseSlickPatch(patchContent) :
patchProcess.expandVariablesAndParseJson(patchContent);

patchProcess.apply(new plistPatcher.PlistPatcher(patches), targetPath, patterns, outputPatchedFile);

tl.setResult(tl.TaskResult.Succeeded, "Files Patched");

} catch (err) {
console.error(String(err));
tl.setResult(tl.TaskResult.Failed, String(err));
}
14 changes: 14 additions & 0 deletions Tasks/PlistPatch/plistPatcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import jsonPatcher = require('./common/jsonPatcher');
import patch = require('./common/patch');
var plist = require('plist');

export class PlistPatcher extends jsonPatcher.JsonPatcher {

parse(content: string): any {
return plist.parse(content);
}

stringify(content: any): string {
return plist.build(content);
}
}
79 changes: 79 additions & 0 deletions Tasks/PlistPatch/task.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"id": "599b994d-c4e1-4e74-b58e-0cd3006e5aac",
"name": "PlistPatch",
"friendlyName": "Patch Plist Files",
"description": "Patch Plist files using JSON patch syntax",
"helpMarkDown": "[More Information](https://github.com/geeklearningio/gl-vsts-tasks-file-patch/wiki/Patch-Plist-Files) (Version #{Version}#)",
"category": "Utility",
"visibility": [
"Build",
"Release"
],
"author": "Geek Learning",
"version": {
"Major": 0,
"Minor": 0,
"Patch": 0
},
"demands": [
"npm"
],
"minimumAgentVersion": "1.91.0",
"instanceNameFormat": "Patch files $(PlistTargetFilters)",
"inputs": [
{
"name": "SyntaxType",
"type": "pickList",
"label": "Syntax type",
"defaultValue": "Standard",
"required": true,
"helpMarkDown": "The syntax used for the patch content. See documentation for more information.",
"options": {
"standard": "Standard Syntax",
"slick": "Slick Syntax"
}
},
{
"name": "PlistWorkingDir",
"type": "filePath",
"label": "Patch working directory",
"defaultValue": "",
"required": true,
"helpMarkDown": "Working directory. Example: $(Build.SourcesDirectory)"
},
{
"name": "PlistTargetFilters",
"type": "multiLine",
"label": "Target files",
"defaultValue": "",
"required": true,
"helpMarkDown": "Patch target file. Example: appsettings*.plist"
},
{
"name": "PlistPatchContent",
"type": "multiLine",
"label": "Patch Content",
"defaultValue": "",
"required": true,
"helpMarkDown": "Patch content.",
"properties": {
"resizable": "true",
"rows": "10",
"maxLength": "5000"
}
},
{
"name": "OutputPatchFile",
"type": "boolean",
"label": "Output patched file in logs",
"defaultValue": "false",
"helpMarkDown": "Output patched file in logs"
}
],
"execution": {
"Node": {
"target": "plistPatch.js",
"argumentFormat": ""
}
}
}
36 changes: 36 additions & 0 deletions Tests/PlistPatch/plistPatcher.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import plistPatcher = require("../../Tasks/PlistPatch/plistPatcher");
var plist = require("../../Tasks/PlistPatch/node_modules/plist");



describe("PLIST Patcher", () => {

describe("Operations", () => {

var source: string;

beforeEach(function() {
source = plist.build({
sampleValue : "12"
});
});

describe("Add", () => {
it(": should support basic add.", () => {
var patcher = new plistPatcher.PlistPatcher([
{
op: "add", path: "/added", value: {}
},{
op: "add", path: "/added/value", value: "42"
}
]);
var result = plist.parse(patcher.apply(source));

expect(result).toBeDefined();
expect(result.sampleValue).toBeDefined();
expect(result.sampleValue).toEqual("12");
expect(result.added.value).toEqual("42");
});
});
});
});
2 changes: 1 addition & 1 deletion Tests/YamlPatch/yamlPatcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import yamlPatcher = require("../../Tasks/YamlPatch/yamlPatcher");
var jsYaml = require("../../Tasks/YamlPatch/node_modules/js-yaml");


describe("YANL Patcher", () => {
describe("YAML Patcher", () => {

describe("Operations", () => {

Expand Down
1 change: 1 addition & 0 deletions configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"VssExtensionGalleryFlags": [],
"DisplayNamesSuffix": " (Development)",
"TaskIds": {
"PlistPatch" : "36db878b-3060-4465-86d2-d6a73ddbc0ad",
"YamlPatch": "14568f85-c21b-490f-b102-568d2a0da4bf",
"JsonPatch": "578A87B3-5A3F-461B-828D-E53DA43A8F3A",
"XmlPatch": "BD8DCFA1-1592-4DA9-8437-871752577791"
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"node_modules",
"Tasks/JsonPatch/node_modules",
"Tasks/YamlPatch/node_modules",
"Tasks/PlistPatch/node_modules",
"Common",
"BuildScripts/node_modules",
".BuildOutput"
Expand Down