Skip to content
This repository was archived by the owner on Jan 10, 2019. It is now read-only.

Commit 53933cf

Browse files
committed
added deploy() method to ScriptCommandExecutorArguments
1 parent ee00ff1 commit 53933cf

File tree

6 files changed

+71
-1
lines changed

6 files changed

+71
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log (vs-script-commands)
22

3+
## 1.10.0 (February 20th, 2017; deploy files)
4+
5+
* added [deploy](https://mkloubert.github.io/vs-script-commands/interfaces/_contracts_.scriptcommandexecutorarguments.html#deploy) method to [ScriptCommandExecutorArguments](https://mkloubert.github.io/vs-script-commands/interfaces/_contracts_.scriptcommandexecutorarguments.html) which make use of `extension.deploy.filesTo` command, provided by [vs-deploy](https://github.com/mkloubert/vs-deploy) extension
6+
37
## 1.9.0 (February 20th, 2017; output channel)
48

59
* added [outputChannel](https://mkloubert.github.io/vs-script-commands/interfaces/_contracts_.scriptcommandexecutorarguments.html#outputChannel) property to [ScriptCommandExecutorArguments](https://mkloubert.github.io/vs-script-commands/interfaces/_contracts_.scriptcommandexecutorarguments.html) that gets the [OutputChannel](https://code.visualstudio.com/Docs/extensionAPI/vscode-api#OutputChannel) instance of that extension

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ exports.execute = function (args) {
139139
// opening HTML document failed
140140
});
141141

142+
// deploys 'index.html' to 'My SFTP server'
143+
// s. https://github.com/mkloubert/vs-deploy
144+
args.deploy(['./index.html'], ['My SFTP server']).then(function() {
145+
// file deployed
146+
}, function(err) {
147+
// deployment failed
148+
});
149+
142150
vscode.window.showInformationMessage('Hello from my extension: ' + scriptFile);
143151
}
144152
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vs-script-commands",
33
"displayName": "Script Commands",
44
"description": "Adds additional commands to Visual Studio Code that uses scripts (JavaScript) for execution.",
5-
"version": "1.9.0",
5+
"version": "1.10.0",
66
"publisher": "mkloubert",
77
"engines": {
88
"vscode": "^1.5.0"

src/contracts.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,19 @@ export interface ScriptCommandExecutorArguments {
298298
* and is available for ONLY for current command.
299299
*/
300300
commandState: any;
301+
/**
302+
* Deploys one or more file to a list of targets.
303+
*
304+
* This requires 'extension.deploy.filesTo' command as available in extensions like 'vs-deploy'
305+
* s. https://github.com/mkloubert/vs-deploy
306+
*
307+
* @param {string|string[]} files One or more file to deploy.
308+
* @param {string|string[]} targets One or more target (name) to deploy to.
309+
*
310+
* @returns {Promise<any>} The promise.
311+
*/
312+
readonly deploy: (files: string | string[],
313+
targets: string | string[]) => Promise<any>;
301314
/**
302315
* Gets the event emitter that can be used by ALL commands.
303316
*/

src/controller.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,34 @@ export class ScriptCommandController extends Events.EventEmitter implements vsco
683683
button: undefined,
684684
command: cmdId,
685685
commandState: commandState,
686+
deploy: (files, targets) => {
687+
// files
688+
files = sc_helpers.asArray(files)
689+
.map(x => sc_helpers.toStringSafe(x))
690+
.filter(x => !sc_helpers.isEmptyString(x));
691+
files = sc_helpers.distinctArray(files);
692+
693+
// targets
694+
targets = sc_helpers.asArray(targets)
695+
.map(x => sc_helpers.normalizeString(x))
696+
.filter(x => x);
697+
targets = sc_helpers.distinctArray(targets);
698+
699+
return new Promise<any>((resolve, reject) => {
700+
let completed = sc_helpers.createSimplePromiseCompletedAction(resolve, reject);
701+
702+
try {
703+
vscode.commands.executeCommand('extension.deploy.filesTo', files, targets).then((result) => {
704+
completed(null, result);
705+
}, (err) => {
706+
completed(err);
707+
});
708+
}
709+
catch (e) {
710+
completed(e);
711+
}
712+
});
713+
},
686714
events: undefined,
687715
extension: undefined,
688716
globals: me.getGlobals(),

src/helpers.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,23 @@ export function createSimplePromiseCompletedAction<TResult>(resolve: (value?: TR
118118
};
119119
}
120120

121+
/**
122+
* Removes duplicate entries from an array.
123+
*
124+
* @param {T[]} arr The input array.
125+
*
126+
* @return {T[]} The filtered array.
127+
*/
128+
export function distinctArray<T>(arr: T[]): T[] {
129+
if (!arr) {
130+
return arr;
131+
}
132+
133+
return arr.filter((x, i) => {
134+
return arr.indexOf(x) === i;
135+
});
136+
}
137+
121138
/**
122139
* Returns the value from a "parameter" object.
123140
*

0 commit comments

Comments
 (0)