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

Commit ffff4c8

Browse files
committed
added support for vs-cron
1 parent 53933cf commit ffff4c8

File tree

5 files changed

+160
-46
lines changed

5 files changed

+160
-46
lines changed

CHANGELOG.md

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

3+
## 1.11.0 (April 10th, 2017; cron jobs)
4+
5+
* added `getCronJobs()`, `restartCronJobs()`, `startCronJobs()` and `stopCronJobs()` methods to [ScriptCommandExecutorArguments](https://mkloubert.github.io/vs-script-commands/interfaces/_contracts_.scriptcommandexecutorarguments.html) interface, which make use of commands provided by extensions like [vs-cron](https://github.com/mkloubert/vs-cron)
6+
* added `others` property to [ScriptCommandExecutorArguments](https://mkloubert.github.io/vs-script-commands/interfaces/_contracts_.scriptcommandexecutorarguments.html) interface
7+
38
## 1.10.0 (February 20th, 2017; deploy files)
49

510
* 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

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.10.0",
5+
"version": "1.11.0",
66
"publisher": "mkloubert",
77
"engines": {
88
"vscode": "^1.5.0"

src/content.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,49 +30,6 @@ import * as sc_helpers from './helpers';
3030
import * as vscode from 'vscode';
3131

3232

33-
/**
34-
* HTML executor.
35-
*
36-
* @param {HtmlViewerExecutorArguments} args The arguments.
37-
*
38-
* @return {HtmlViewerExecutorResult} The result.
39-
*/
40-
export type HtmlViewerExecutor = (args: HtmlViewerExecutorArguments) => HtmlViewerExecutorResult;
41-
42-
/**
43-
* Arguments for a HTML executor.
44-
*/
45-
export interface HtmlViewerExecutorArguments {
46-
/**
47-
* The cancellation token.
48-
*/
49-
readonly cancelToken: vscode.CancellationToken;
50-
/**
51-
* The URI.
52-
*/
53-
readonly uri: vscode.Uri;
54-
/**
55-
*
56-
*/
57-
readonly workspaceState: Object;
58-
}
59-
60-
/**
61-
* The result of a HTML executor.
62-
*/
63-
export type HtmlViewerExecutorResult = string | Thenable<string>;
64-
65-
/**
66-
* A module that executes logic for a HTML content provider.
67-
*/
68-
export interface HtmlViewerModule {
69-
/**
70-
* The HTML executor.
71-
*/
72-
readonly execute: HtmlViewerExecutor;
73-
}
74-
75-
7633
/**
7734
* HTML content provider.
7835
*/

src/contracts.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,37 @@ export interface Configuration {
4949
showInternalVSCommands?: boolean;
5050
}
5151

52+
/**
53+
* Information about a (cron) job.
54+
*/
55+
export interface CronJobInfo {
56+
/**
57+
* Gets the description of the underlying job.
58+
*/
59+
readonly description: string;
60+
/**
61+
* Gets the details for the underlying job.
62+
*/
63+
readonly detail: string;
64+
/**
65+
* Gets if the job is currently running or not.
66+
*/
67+
readonly isRunning: boolean;
68+
/**
69+
* Gets the timestamp of the last execution in ISO format.
70+
*/
71+
readonly lastExecution: string;
72+
/**
73+
* Gets the name of the job.
74+
*/
75+
readonly name: string;
76+
}
77+
78+
/**
79+
* (Cron) Job name(s).
80+
*/
81+
export type CronJobNames = string | string[];
82+
5283
/**
5384
* A document.
5485
*/
@@ -319,6 +350,12 @@ export interface ScriptCommandExecutorArguments {
319350
* Gets the context of that extension.
320351
*/
321352
readonly extension: vscode.ExtensionContext;
353+
/**
354+
* Returns the list of current (cron) jobs.
355+
*
356+
* @return {Promise<CronJobInfo[]>} The promise.
357+
*/
358+
readonly getCronJobs: () => Promise<CronJobInfo[]>;
322359
/**
323360
* The global variables from the settings.
324361
*/
@@ -354,6 +391,10 @@ export interface ScriptCommandExecutorArguments {
354391
* Options for the execution (@see ScriptCommand).
355392
*/
356393
options?: any;
394+
/**
395+
* Gets the list of (other) commands, defined by that extension.
396+
*/
397+
readonly others: string[];
357398
/**
358399
* Gets the output channel that can be used by the underlying script.
359400
*/
@@ -370,6 +411,39 @@ export interface ScriptCommandExecutorArguments {
370411
* @return {any} The loaded module.
371412
*/
372413
require: (id: string) => any;
414+
/**
415+
* Re-starts cron jobs.
416+
*
417+
* This requires 'extension.cronJons.restartJobsByName' command as available in extensions like 'vs-cron'
418+
* s. https://github.com/mkloubert/vs-cron
419+
*
420+
* @param {CronJobNames} jobs The jobs to re-start.
421+
*
422+
* @return {Promise<any>} The promise.
423+
*/
424+
readonly restartCronJobs: (jobs: CronJobNames) => Promise<any>;
425+
/**
426+
* Starts cron jobs.
427+
*
428+
* This requires 'extension.cronJons.startJobsByName' command as available in extensions like 'vs-cron'
429+
* s. https://github.com/mkloubert/vs-cron
430+
*
431+
* @param {CronJobNames} jobs The jobs to start.
432+
*
433+
* @return {Promise<any>} The promise.
434+
*/
435+
readonly startCronJobs: (jobs: CronJobNames) => Promise<any>;
436+
/**
437+
* Stops cron jobs.
438+
*
439+
* This requires 'extension.cronJons.stopJobsByName' command as available in extensions like 'vs-cron'
440+
* s. https://github.com/mkloubert/vs-cron
441+
*
442+
* @param {CronJobNames} jobs The jobs to stop.
443+
*
444+
* @return {Promise<any>} The promise.
445+
*/
446+
readonly stopCronJobs: (jobs: CronJobNames) => Promise<any>;
373447
}
374448

375449
/**

src/controller.ts

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export interface ScriptCommandEntry {
4343
* The command object.
4444
*/
4545
command: vscode.Disposable;
46+
/**
47+
* The ID / name of the command.
48+
*/
49+
id: string;
4650
/**
4751
* The underlying script command object.
4852
*/
@@ -713,6 +717,29 @@ export class ScriptCommandController extends Events.EventEmitter implements vsco
713717
},
714718
events: undefined,
715719
extension: undefined,
720+
getCronJobs: () => {
721+
return new Promise<sc_contracts.CronJobInfo[]>((resolve, reject) => {
722+
try {
723+
let callback = (err: any, jobs: sc_contracts.CronJobInfo[]) => {
724+
if (err) {
725+
reject(err);
726+
}
727+
else {
728+
resolve(jobs);
729+
}
730+
};
731+
732+
vscode.commands.executeCommand('extension.cronJons.getJobs', callback).then(() => {
733+
//TODO
734+
}, (err) => {
735+
reject(err);
736+
});
737+
}
738+
catch (e) {
739+
reject(e);
740+
}
741+
});
742+
},
716743
globals: me.getGlobals(),
717744
globalState: undefined,
718745
log: function(msg) {
@@ -725,11 +752,54 @@ export class ScriptCommandController extends Events.EventEmitter implements vsco
725752
html, title, docId);
726753
},
727754
options: sc_helpers.cloneObject(c.options),
755+
others: undefined,
728756
outputChannel: undefined,
729757
previousValue: undefined,
730758
require: function(id) {
731759
return require(id);
732760
},
761+
restartCronJobs: (jobs) => {
762+
return new Promise<any>((resolve, reject) => {
763+
try {
764+
vscode.commands.executeCommand('extension.cronJons.restartJobsByName', jobs).then((result) => {
765+
resolve(result);
766+
}, (err) => {
767+
reject(err);
768+
});
769+
}
770+
catch (e) {
771+
reject(e);
772+
}
773+
});
774+
},
775+
startCronJobs: (jobs) => {
776+
return new Promise<any>((resolve, reject) => {
777+
try {
778+
vscode.commands.executeCommand('extension.cronJons.startJobsByName', jobs).then((result) => {
779+
resolve(result);
780+
}, (err) => {
781+
reject(err);
782+
});
783+
}
784+
catch (e) {
785+
reject(e);
786+
}
787+
});
788+
},
789+
stopCronJobs: (jobs) => {
790+
return new Promise<any>((resolve, reject) => {
791+
try {
792+
vscode.commands.executeCommand('extension.cronJons.stopJobsByName', jobs).then((result) => {
793+
resolve(result);
794+
}, (err) => {
795+
reject(err);
796+
});
797+
}
798+
catch (e) {
799+
reject(e);
800+
}
801+
});
802+
}
733803
};
734804

735805
// args.button
@@ -757,6 +827,13 @@ export class ScriptCommandController extends Events.EventEmitter implements vsco
757827
get: () => { return globalState; },
758828
});
759829

830+
// args.others
831+
Object.defineProperty(args, 'others', {
832+
enumerable: true,
833+
get: () => { return me._COMMANDS.map(c => c.id)
834+
.filter(c => c !== cmdId); },
835+
});
836+
760837
// args.outputChannel
761838
Object.defineProperty(args, 'outputChannel', {
762839
enumerable: true,
@@ -834,8 +911,8 @@ export class ScriptCommandController extends Events.EventEmitter implements vsco
834911
}
835912

836913
// color
837-
let color = sc_helpers.toStringSafe(c.button.color).toLowerCase().trim();
838-
if (color) {
914+
let color = sc_helpers.normalizeString(c.button.color);
915+
if ('' !== color) {
839916
btn.color = color;
840917
}
841918

@@ -851,6 +928,7 @@ export class ScriptCommandController extends Events.EventEmitter implements vsco
851928
me._COMMANDS.push({
852929
button: btn,
853930
command: cmd,
931+
id: cmdId,
854932
object: c,
855933
});
856934
}

0 commit comments

Comments
 (0)