From 7d9fad904c7f29a006cfc5398cdd36113e46bec1 Mon Sep 17 00:00:00 2001 From: Cyprien Autexier Date: Fri, 7 Oct 2016 10:12:03 +0200 Subject: [PATCH 1/3] Plist task bootstrap --- Tasks/PlistPatch/package.json | 13 ++++++ Tasks/PlistPatch/plistPatch.ts | 30 +++++++++++++ Tasks/PlistPatch/task.json | 79 ++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 Tasks/PlistPatch/package.json create mode 100644 Tasks/PlistPatch/plistPatch.ts create mode 100644 Tasks/PlistPatch/task.json diff --git a/Tasks/PlistPatch/package.json b/Tasks/PlistPatch/package.json new file mode 100644 index 0000000..6b24a9b --- /dev/null +++ b/Tasks/PlistPatch/package.json @@ -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" + } +} diff --git a/Tasks/PlistPatch/plistPatch.ts b/Tasks/PlistPatch/plistPatch.ts new file mode 100644 index 0000000..0302b6f --- /dev/null +++ b/Tasks/PlistPatch/plistPatch.ts @@ -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 yamlPatcher = require('./yamlPatcher'); + +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 yamlPatcher.YamlPatcher(patches), targetPath, patterns, outputPatchedFile); + + tl.setResult(tl.TaskResult.Succeeded, "Files Patched"); + +} catch (err) { + console.error(String(err)); + tl.setResult(tl.TaskResult.Failed, String(err)); +} diff --git a/Tasks/PlistPatch/task.json b/Tasks/PlistPatch/task.json new file mode 100644 index 0000000..630eb76 --- /dev/null +++ b/Tasks/PlistPatch/task.json @@ -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": "" + } + } +} \ No newline at end of file From 00d3bca50ea6f8989bd4738dbffc6b2e0b64dde3 Mon Sep 17 00:00:00 2001 From: Cyprien Autexier Date: Fri, 7 Oct 2016 16:49:02 +0200 Subject: [PATCH 2/3] plist --- Tasks/PlistPatch/plistPatch.ts | 4 ++-- Tasks/PlistPatch/plistPatcher.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 Tasks/PlistPatch/plistPatcher.ts diff --git a/Tasks/PlistPatch/plistPatch.ts b/Tasks/PlistPatch/plistPatch.ts index 0302b6f..9763d21 100644 --- a/Tasks/PlistPatch/plistPatch.ts +++ b/Tasks/PlistPatch/plistPatch.ts @@ -6,7 +6,7 @@ import jsYaml = require('js-yaml'); import patch = require('./common/patch'); import patchProcess = require('./common/patchProcess'); -import yamlPatcher = require('./yamlPatcher'); +import plistPatcher = require('./plistPatcher'); var targetPath = tl.getPathInput("YamlWorkingDir"); var patchContent = tl.getInput("YamlPatchContent"); @@ -20,7 +20,7 @@ try { patchProcess.expandVariablesAndParseSlickPatch(patchContent) : patchProcess.expandVariablesAndParseJson(patchContent); - patchProcess.apply(new yamlPatcher.YamlPatcher(patches), targetPath, patterns, outputPatchedFile); + patchProcess.apply(new plistPatcher.PlistPatcher(patches), targetPath, patterns, outputPatchedFile); tl.setResult(tl.TaskResult.Succeeded, "Files Patched"); diff --git a/Tasks/PlistPatch/plistPatcher.ts b/Tasks/PlistPatch/plistPatcher.ts new file mode 100644 index 0000000..22e81f3 --- /dev/null +++ b/Tasks/PlistPatch/plistPatcher.ts @@ -0,0 +1,10 @@ +import jsonPatcher = require('./common/jsonPatcher'); +import patch = require('./common/patch'); +var plist = require('plist'); + +export class PlistPatcher extends jsonPatcher.JsonPatcher { + + constructor(patches: patch.IPatch[]) { + super(patches, (content) => plist.parse(content)); + } +} \ No newline at end of file From 55595021f507d3a4520f656cc7b575d0650dde6b Mon Sep 17 00:00:00 2001 From: Cyprien Autexier Date: Fri, 7 Oct 2016 17:05:07 +0200 Subject: [PATCH 3/3] plist basic support --- Tasks/PlistPatch/plistPatcher.ts | 8 ++++-- Tests/PlistPatch/plistPatcher.spec.ts | 36 +++++++++++++++++++++++++++ Tests/YamlPatch/yamlPatcher.spec.ts | 2 +- configuration.json | 1 + tsconfig.json | 1 + 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 Tests/PlistPatch/plistPatcher.spec.ts diff --git a/Tasks/PlistPatch/plistPatcher.ts b/Tasks/PlistPatch/plistPatcher.ts index 22e81f3..41665fa 100644 --- a/Tasks/PlistPatch/plistPatcher.ts +++ b/Tasks/PlistPatch/plistPatcher.ts @@ -4,7 +4,11 @@ var plist = require('plist'); export class PlistPatcher extends jsonPatcher.JsonPatcher { - constructor(patches: patch.IPatch[]) { - super(patches, (content) => plist.parse(content)); + parse(content: string): any { + return plist.parse(content); + } + + stringify(content: any): string { + return plist.build(content); } } \ No newline at end of file diff --git a/Tests/PlistPatch/plistPatcher.spec.ts b/Tests/PlistPatch/plistPatcher.spec.ts new file mode 100644 index 0000000..b1c45a7 --- /dev/null +++ b/Tests/PlistPatch/plistPatcher.spec.ts @@ -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"); + }); + }); + }); +}); \ No newline at end of file diff --git a/Tests/YamlPatch/yamlPatcher.spec.ts b/Tests/YamlPatch/yamlPatcher.spec.ts index fdc8246..42d9667 100644 --- a/Tests/YamlPatch/yamlPatcher.spec.ts +++ b/Tests/YamlPatch/yamlPatcher.spec.ts @@ -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", () => { diff --git a/configuration.json b/configuration.json index e2db3cf..629a1b4 100644 --- a/configuration.json +++ b/configuration.json @@ -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" diff --git a/tsconfig.json b/tsconfig.json index 34d07d5..8623481 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,6 +20,7 @@ "node_modules", "Tasks/JsonPatch/node_modules", "Tasks/YamlPatch/node_modules", + "Tasks/PlistPatch/node_modules", "Common", "BuildScripts/node_modules", ".BuildOutput"