From f69405deb88a0da75390273af1b9627f4fe1fe1f Mon Sep 17 00:00:00 2001 From: Marcel Kloubert Date: Sat, 29 Apr 2017 02:05:14 +0200 Subject: [PATCH] added 'applyValuesTo' for packages and targets --- CHANGELOG.md | 4 + package.json | 202 ++++++++++++++++++++++++++++++++++++++++++++++- src/contracts.ts | 16 +++- src/deploy.ts | 18 ++--- src/helpers.ts | 37 +++++++++ 5 files changed, 264 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61eb457..84cac56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log (vs-deploy) +## 8.16.0 (April 29th, 2017; apply values to packages and targets) + +* added `applyValuesTo` settings for [packages](https://github.com/mkloubert/vs-deploy/wiki#packages-) and [targets](https://github.com/mkloubert/vs-deploy/wiki#targets-), that define objects with lists of property names and their values that should be applied to the underlying setting object + ## 8.15.0 (April 29th, 2017; execute commands on FTP server) * added `beforeUpload`, `closing`, `connected` and `uploaded` for [ftp](https://github.com/mkloubert/vs-deploy/wiki/target_ftp) targets, which can execute commands on a server (s. [Execute commands on server](https://github.com/mkloubert/vs-deploy/wiki/target_ftp#execute-commands-on-server)) diff --git a/package.json b/package.json index 0c3f2b5..1446571 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vs-deploy", "displayName": "Deploy", "description": "Commands for deploying files of your workspace to a destination.", - "version": "8.15.1", + "version": "8.16.0", "publisher": "mkloubert", "engines": { "vscode": "^1.6.0" @@ -941,6 +941,16 @@ "type": "boolean", "description": "Indicates if a 'fast' file check should be used for 'deploy on save' for this package or not.", "default": false + }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that package.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } } } } @@ -1195,6 +1205,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -2248,6 +2268,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -3314,6 +3344,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -4347,6 +4387,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -5393,6 +5443,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -6461,6 +6521,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -7624,6 +7694,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -8692,6 +8772,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -9733,6 +9823,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -10807,6 +10907,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -11850,6 +11960,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -12885,6 +13005,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -13949,6 +14079,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -15088,6 +15228,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -16298,6 +16448,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -17330,6 +17490,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -18391,6 +18561,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -19422,6 +19602,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { @@ -20467,6 +20657,16 @@ ], "default": 0 }, + "applyValuesTo": { + "description": "A list of property names and their values that should be applied to that target.", + "type": "object", + "patternProperties": { + ".*": { + "description": "The value (with optional placeholders) that should be applied to the property.", + "type": "string" + } + } + }, "deployed": { "type": "array", "items": { diff --git a/src/contracts.ts b/src/contracts.ts index 2d72298..c274ce4 100644 --- a/src/contracts.ts +++ b/src/contracts.ts @@ -173,6 +173,18 @@ export interface AfterDeployedWaitOperation extends AfterDeployedOperation, Depl export interface AfterDeployedWebDeployOperation extends AfterDeployedOperation, DeployWebDeployOperation { } +/** + * An object that can apply to (its) properties by using + * generated values by placeholders. + */ +export interface Applyable { + /** + * A list of property names and their values + * that should be applied to that object. + */ + applyValuesTo?: { [prop: string]: any }; +} + /** * Describes an event handler that is raised BEFORE a file starts to be deployed. * @@ -974,7 +986,7 @@ export enum DeployOperationKind { /** * A package. */ -export interface DeployPackage extends ConditionalItem, Hideable, MachineItem, PlatformItem, Sortable { +export interface DeployPackage extends Applyable, ConditionalItem, Hideable, MachineItem, PlatformItem, Sortable { /** * Settings for a "package button". */ @@ -1335,7 +1347,7 @@ export interface DeploySqlOperation extends DeployOperation { /** * A target. */ -export interface DeployTarget extends ConditionalItem, Hideable, MachineItem, PlatformItem, Sortable { +export interface DeployTarget extends Applyable, ConditionalItem, Hideable, MachineItem, PlatformItem, Sortable { /** * List of operations that should be invoked BEFORE * target is being deployed. diff --git a/src/deploy.ts b/src/deploy.ts index 6bfe4ea..cfe5650 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -1817,10 +1817,7 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable { public getPackages(): deploy_contracts.DeployPackage[] { let me = this; - let packages = this.config.packages; - if (!packages) { - packages = []; - } + let packages = this.config.packages || []; let myName = this.name; packages = deploy_helpers.sortPackages(packages, () => myName); @@ -1844,7 +1841,9 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable { // if packages = me.filterConditionalItems(packages); - return packages; + return packages.map(p => { + return deploy_helpers.applyValues(p, me.getValues()); + }); } /** @@ -1855,10 +1854,7 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable { public getTargets(): deploy_contracts.DeployTarget[] { let me = this; - let targets = this.config.targets; - if (!targets) { - targets = []; - } + let targets = this.config.targets || []; let myName = this.name; targets = deploy_helpers.sortTargets(targets, () => myName); @@ -1882,7 +1878,9 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable { // if targets = me.filterConditionalItems(targets); - return targets; + return targets.map(t => { + return deploy_helpers.applyValues(t, me.getValues()); + }); } /** diff --git a/src/helpers.ts b/src/helpers.ts index 618590c..ac079df 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -95,6 +95,43 @@ export type SimpleCompletedAction = (err?: any, result?: TResult) => vo let nextHtmlDocId = -1; + +/** + * Applies values to an object. + * + * @param {T} obj The object to apply the values to. + * @param {deploy_values.ValueBase|deploy_values.ValueBase[]} values The values to apply. + * @param {boolean} [cloneObj] Clone object or not. + * + * @return {T} The object with the applied values. + */ +export function applyValues(obj: T, + values: deploy_values.ValueBase | deploy_values.ValueBase[], + cloneObj = true): T { + values = asArray(values).filter(v => v); + + if (toBooleanSafe(cloneObj)) { + obj = cloneObject(obj); + } + + if (obj) { + let applyTo = cloneObject(obj.applyValuesTo); + + if (applyTo) { + for (let p in applyTo) { + let valueToSet = applyTo[p]; + if (values.length > 0) { + valueToSet = deploy_values.replaceWithValues(values, valueToSet); + } + + obj[p] = valueToSet; + } + } + } + + return obj; +} + /** * Returns a value as array. *