Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
executeOnStartup and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Dec 30, 2017
1 parent 67bcb60 commit 6eabc27
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 106 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log (vscode-deploy-reloaded)

## 0.10.0 (December 30th, 2017; shell commands)

* added `executeOnStartup` [setting](https://github.com/mkloubert/vscode-deploy-reloaded/wiki#settings--), which runs [shell commands on startup](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/execute_on_startup)
* fixed use of [if](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/if) property in setting objects

## 0.9.0 (December 30th, 2017; [Composer](https://getcomposer.org/))

* added tools for handling [Composer](https://getcomposer.org/) packages:
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 46 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-deploy-reloaded",
"displayName": "Deploy (Reloaded)",
"description": "Deploys files of a workspace to a destination.",
"version": "0.9.0",
"version": "0.10.0",
"publisher": "mkloubert",
"engines": {
"vscode": "^1.19.0"
Expand Down Expand Up @@ -238,6 +238,51 @@
}
}
},
"executeOnStartup": {
"description": "One or more shell commands to execute.",
"type": "array",
"items": {
"oneOf": [
{
"description": "The shell command to execute.",
"type": "string",
"pattern": "\\S+"
},
{
"description": "Settings for a shell command to execute.",
"type": "object",
"properties": {
"command": {
"description": "The shell command to execute.",
"type": "string",
"pattern": "\\S+"
},
"cwd": {
"description": "The custom working directory.",
"type": "string"
},
"ignoreIfFail": {
"description": "Ignore if command fails or not.",
"type": "boolean",
"default": false
},
"name": {
"description": "The custom name to display.",
"type": "string"
},
"noPlaceHolders": {
"description": "Do not use placeholders in 'command' property.",
"type": "boolean",
"default": false
}
},
"required": [
"command"
]
}
]
}
},
"globals": {
"description": "Global data to define, which can be access by scripts, e.g."
},
Expand Down
10 changes: 8 additions & 2 deletions src/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ export function exec<TResult = any, TContext = any>(context: CodeExecutionContex
};
const $v = deploy_values.toValueStorage(context.values);

return eval(
$h.toStringSafe(context.code)
const $e = (code: any) => {
return eval(
$h.toStringSafe(code)
);
};

return $e(
context.code
);
}
31 changes: 31 additions & 0 deletions src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ export interface Configuration extends deploy_values.WithValueItems {
*/
readonly vars?: KeyValuePairs;
};
/**
* One or more shell commands that should be run on startup.
*/
readonly executeOnStartup?: ShellCommand | ShellCommand[];
/**
* Global data to define.
*/
Expand Down Expand Up @@ -429,6 +433,33 @@ export interface ScriptArguments {
state: any;
}

/**
* A shell command value.
*/
export type ShellCommand = string | ShellCommandSettings;

/**
* Settings of a shell command.
*/
export interface ShellCommandSettings extends ConditionalItem, WithOptionalName {
/**
* The command to execute.
*/
readonly command: string;
/**
* The custom working directory to use.
*/
readonly cwd?: string;
/**
* Ignore if execution fails or not.
*/
readonly ignoreIfFail?: boolean;
/**
* Do not use placeholders in 'command' property.
*/
readonly noPlaceHolders?: boolean;
}

/**
* A startup command.
*/
Expand Down
50 changes: 0 additions & 50 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,56 +767,6 @@ export function exists(path: string | Buffer) {
});
}

/**
* Filters items with 'if' code.
*
* @param {TItem | TItem[]} items The items to filter.
* @param {boolean} [throwOnError] Throw on error or not.
* @param {any} [errorResult] The custom result when an error occurred.
*
* @return {TItem[]} The filtered items.
*/
export function filterConditionalItems<TItem extends deploy_contracts.ConditionalItem = deploy_contracts.ConditionalItem>(
items: TItem | TItem[],
throwOnError = false,
errorResult: any = false,
): TItem[] {
if (isNullOrUndefined(items)) {
return <any>items;
}

items = asArray(items, false);
throwOnError = toBooleanSafe(throwOnError);

return items.filter(i => {
try {
if (!isNullOrUndefined(i)) {
const CONDITION = toStringSafe(i.if);
if ('' !== CONDITION.trim()) {
const CTX: deploy_code.CodeExecutionContext = {
code: CONDITION,
values: [],
};

return deploy_code.exec( CTX );
}
}

return true;
}
catch (e) {
deploy_log.CONSOLE
.trace(e, 'helpers.filterConditionalItems()');

if (throwOnError) {
throw e;
}

return errorResult;
}
});
}

/**
* Filters platform specific objects.
*
Expand Down
3 changes: 3 additions & 0 deletions src/i18.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ export interface Translation {
sftp?: {
privateKeyNotFound?: string;
};
shell?: {
executing?: string;
};
sql?: {
notSupported?: string;
};
Expand Down
3 changes: 3 additions & 0 deletions src/lang/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ export const translation: Translation = {
sftp: {
privateKeyNotFound: "Der private Schlüssel{0:trim,surround,leading_space} wurde nicht gefunden!",
},
shell: {
executing: "Führe{0:trim,surround,leading_space} aus ...",
},
sql: {
notSupported: "Der SQL-Typ{0:trim,surround,leading_space} wird nicht unterstützt!",
},
Expand Down
3 changes: 3 additions & 0 deletions src/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ export const translation: Translation = {
sftp: {
privateKeyNotFound: "Private key file{0:trim,surround,leading_space} not found!",
},
shell: {
executing: "Executing{0:trim,surround,leading_space} ...",
},
sql: {
notSupported: "SQL type{0:trim,surround,leading_space} is not supported!",
},
Expand Down
31 changes: 19 additions & 12 deletions src/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as deploy_code from './code';
import * as deploy_contracts from './contracts';
import * as deploy_helpers from './helpers';
import * as deploy_log from './log';
import * as Enumerable from 'node-enumerable';
import * as OS from 'os';


Expand Down Expand Up @@ -375,18 +376,24 @@ export function loadFromItems(items: WithValueItems,
let doesMatch: any;

try {
const IF_CODE = deploy_helpers.toStringSafe(i.if);
if (!deploy_helpers.isEmptyString(IF_CODE)) {
doesMatch = deploy_code.exec({
code: IF_CODE,
context: {
i: i,
},
values: [].concat( getPredefinedValues() )
.concat( getEnvVars() )
.concat( o ),
});
}
doesMatch = Enumerable.from( deploy_helpers.asArray(i.if) ).all((c) => {
let res: any;

const IF_CODE = deploy_helpers.toStringSafe(c);
if (!deploy_helpers.isEmptyString(IF_CODE)) {
res = deploy_code.exec({
code: IF_CODE,
context: {
i: i,
},
values: [].concat( getPredefinedValues() )
.concat( getEnvVars() )
.concat( o ),
});
}

return deploy_helpers.toBooleanSafe(res, true);
});
}
catch (e) {
deploy_log.CONSOLE
Expand Down
Loading

0 comments on commit 6eabc27

Please sign in to comment.