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

Commit b93f607

Browse files
committed
added support for vs-cron and vs-rest-api
1 parent 23737ae commit b93f607

File tree

4 files changed

+261
-132
lines changed

4 files changed

+261
-132
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+
## 4.12.0 (May 2nd, 2017; REST API and cron jobs)
4+
5+
* added `startApi()` and `stopApi()` functions for [quick executions](https://github.com/mkloubert/vs-script-commands#quick-execution-), that can interact with extensions like [vs-rest-api](https://github.com/mkloubert/vs-rest-api)
6+
* added `getCronJobs()`, `restartCronJobs()`, `startCronJobs()` and `stopCronJobs()` functions for [quick executions](https://github.com/mkloubert/vs-script-commands#quick-execution-), that can interact with extensions like [vs-cron](https://github.com/mkloubert/vs-cron)
7+
38
## 4.11.0 (May 2nd, 2017; quick execution)
49

510
* added `$clearHistory`, `$history`, `$removeFromHistory` and `$saveToHistory` functions

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": "4.11.0",
5+
"version": "4.12.0",
66
"publisher": "mkloubert",
77
"engines": {
88
"vscode": "^1.6.0"

src/quick.ts

Lines changed: 105 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const RandomInt = require('random-int');
3636
import * as sc_contracts from './contracts';
3737
import * as sc_controller from './controller';
3838
import * as sc_helpers from './helpers';
39+
import * as sc_resources from './resources';
3940
import * as UUID from 'uuid';
4041
import * as vscode from 'vscode';
4142
import * as Workflows from 'node-workflows';
@@ -86,131 +87,6 @@ let _permanentNoResultInfo: boolean;
8687
let _permanentShowResultInTab: boolean;
8788
let _state: any;
8889

89-
const HTML_FOOTER = `
90-
91-
<div id="vsscriptcommands-footer">
92-
<p class="vsscriptcommands-generated-by">Generated by <a href="https://github.com/mkloubert/vs-script-commands" target="_blank">vs-script-commands</a></p>
93-
94-
<p class="vsscriptcommands-donate-btns">
95-
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UHVN4LRJTEXQS" title="Donate via PayPal" target="_blank">
96-
<img src="https://img.shields.io/badge/Donate-PayPal-green.svg">
97-
</a>
98-
99-
<a href="https://flattr.com/submit/auto?fid=o62pkd&url=https%3A%2F%2Fgithub.com%2Fmkloubert%2Fvs-script-commands" title="Donate via Flattr" target="_blank">
100-
<img src="https://api.flattr.com/button/flattr-badge-large.png">
101-
</a>
102-
</p>
103-
</div>
104-
</body>
105-
</html>`;
106-
107-
const HTML_HEADER = `<!DOCTYPE html>
108-
<html lang="en">
109-
<head>
110-
<meta charset="utf-8">
111-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
112-
<meta name="viewport" content="width=device-width, initial-scale=1">
113-
114-
<title>[vs-script-commands] Quick execution help</title>
115-
116-
<style type="text/css">
117-
118-
body {
119-
width: 100%;
120-
}
121-
122-
a {
123-
color: inherit;
124-
font-weight: bold;
125-
text-decoration: none;
126-
}
127-
128-
a:hover {
129-
color: white;
130-
text-decoration: underline;
131-
}
132-
133-
h1, h2 {
134-
padding-bottom: 0.3em;
135-
border-bottom: 1px solid #333;
136-
}
137-
138-
h1, h2, h3, h4, h5, h6 {
139-
margin-top: 24px;
140-
margin-bottom: 16px;
141-
}
142-
143-
table {
144-
border-spacing: 0;
145-
border-collapse: collapse;
146-
margin-top: 0;
147-
margin-bottom: 16px;
148-
margin-right: 8px;
149-
}
150-
151-
table td, table th {
152-
padding: 6px 13px;
153-
border: 1px solid #666;
154-
}
155-
156-
table th {
157-
background-color: white;
158-
color: black;
159-
font-weight: bold;
160-
}
161-
162-
table tr:nth-child(2n) {
163-
background-color: #333;
164-
}
165-
166-
pre, p {
167-
margin: 8px 8px 8px 0px;
168-
}
169-
170-
ul {
171-
display: block;
172-
list-style-type: disc;
173-
-webkit-margin-before: 1em;
174-
-webkit-margin-after: 1em;
175-
-webkit-margin-start: 0px;
176-
-webkit-margin-end: 0px;
177-
-webkit-padding-start: 40px;
178-
}
179-
180-
li {
181-
display: list-item;
182-
text-align: -webkit-match-parent;
183-
}
184-
185-
#vsscriptcommands-footer {
186-
margin-top: 32px;
187-
}
188-
189-
#vsscriptcommands-footer p {
190-
clear: both !important;
191-
display: block !important;
192-
float: right;
193-
margin-bottom: 8px;
194-
}
195-
196-
#vsscriptcommands-footer .vsscriptcommands-donate-btns img {
197-
border: 0px none transparent;
198-
height: 20px;
199-
margin-left: 8px;
200-
text-decoration: none;
201-
}
202-
203-
#vsscriptcommands-footer .vsscriptcommands-donate-btns a {
204-
text-decoration: none;
205-
}
206-
207-
</style>
208-
</head>
209-
210-
<body>
211-
212-
`;
213-
21490
const KEY_HISTORY = 'vsscQuickCommandHistory';
21591
const KEY_LAST_QUICK_COMMAND = 'vsscLastQuickCommand';
21692

@@ -529,6 +405,29 @@ function _executeExpression(_expr: string) {
529405
const $fromMarkdown = function(markdown: string): string {
530406
return _fromMarkdown(markdown);
531407
};
408+
const $getCronJobs = function(jobs: sc_contracts.CronJobNames): Promise<sc_contracts.CronJobInfo[]> {
409+
return new Promise<sc_contracts.CronJobInfo[]>((resolve, reject) => {
410+
try {
411+
let callback = (err: any, jobs: sc_contracts.CronJobInfo[]) => {
412+
if (err) {
413+
reject(err);
414+
}
415+
else {
416+
resolve(jobs);
417+
}
418+
};
419+
420+
vscode.commands.executeCommand('extension.cronJons.getJobs', callback).then(() => {
421+
//TODO
422+
}, (err) => {
423+
reject(err);
424+
});
425+
}
426+
catch (e) {
427+
reject(e);
428+
}
429+
});
430+
};
532431
const $globals = $me.getGlobals();
533432
const $guid = function(v4 = true) {
534433
return sc_helpers.toBooleanSafe(v4) ? UUID.v4() : UUID.v1();
@@ -560,7 +459,6 @@ function _executeExpression(_expr: string) {
560459

561460
return comp1;
562461
}).map((h: HistoryEntryEx) => {
563-
564462
let qp: sc_contracts.ActionQuickPickItem = {
565463
action: function() {
566464
_executeExpression.apply($me,
@@ -760,6 +658,20 @@ function _executeExpression(_expr: string) {
760658
const $require = function(id: string): any {
761659
return require(sc_helpers.toStringSafe(id));
762660
};
661+
const $restartCronJobs = function(jobs: sc_contracts.CronJobNames): Promise<any> {
662+
return new Promise<any>((resolve, reject) => {
663+
try {
664+
vscode.commands.executeCommand('extension.cronJons.restartJobsByName', jobs).then((result) => {
665+
resolve(result);
666+
}, (err) => {
667+
reject(err);
668+
});
669+
}
670+
catch (e) {
671+
reject(e);
672+
}
673+
});
674+
};
763675
const $saveToHistory = function(saveGlobal = false, desc?: string): void {
764676
_saveLastExpression = false;
765677
_saveToHistory = false;
@@ -796,6 +708,62 @@ function _executeExpression(_expr: string) {
796708

797709
return _showResultInTab;
798710
};
711+
const $startApi = function(): Promise<any> {
712+
return new Promise<any>((resolve, reject) => {
713+
try {
714+
vscode.commands.executeCommand('extension.restApi.startHost').then((result) => {
715+
resolve(result);
716+
}, (err) => {
717+
reject(err);
718+
});
719+
}
720+
catch (e) {
721+
reject(e);
722+
}
723+
});
724+
};
725+
const $startCronJobs = function(jobs: sc_contracts.CronJobNames): Promise<any> {
726+
return new Promise<any>((resolve, reject) => {
727+
try {
728+
vscode.commands.executeCommand('extension.cronJons.startJobsByName', jobs).then((result) => {
729+
resolve(result);
730+
}, (err) => {
731+
reject(err);
732+
});
733+
}
734+
catch (e) {
735+
reject(e);
736+
}
737+
});
738+
};
739+
const $stopCronJobs = function(jobs: sc_contracts.CronJobNames): Promise<any> {
740+
return new Promise<any>((resolve, reject) => {
741+
try {
742+
vscode.commands.executeCommand('extension.cronJons.stopJobsByName', jobs).then((result) => {
743+
resolve(result);
744+
}, (err) => {
745+
reject(err);
746+
});
747+
}
748+
catch (e) {
749+
reject(e);
750+
}
751+
});
752+
};
753+
const $stopApi = function(): Promise<any> {
754+
return new Promise<any>((resolve, reject) => {
755+
try {
756+
vscode.commands.executeCommand('extension.restApi.stopHost').then((result) => {
757+
resolve(result);
758+
}, (err) => {
759+
reject(err);
760+
});
761+
}
762+
catch (e) {
763+
reject(e);
764+
}
765+
});
766+
};
799767
let $thisArgs: any;
800768
const $toHexView = function(val: any): string {
801769
return Hexy.hexy(val);
@@ -919,6 +887,7 @@ function _generateHelpHTML(): string {
919887
markdown += "| `$exists(path: string): boolean` | Checks if a path exists. |\n";
920888
markdown += "| `$findFiles(globPattern: string, ignore?: string[]): string[]` | Finds files using [glob patterns](https://github.com/isaacs/node-glob). |\n";
921889
markdown += "| `$fromMarkdown(markdown: string): string` | Converts [Markdown](https://guides.github.com/features/mastering-markdown/) to HTML. |\n";
890+
markdown += "| `$getCronJobs(): Promise<CronJobInfo[]>` | Returns a list of available [cron jobs](https://github.com/mkloubert/vs-cron). |\n";
922891
markdown += "| `$guid(v4: boolean = true): string` | Alias for `$uuid`. |\n";
923892
markdown += "| `$hash(algorithm: string, data: any, asBuffer: boolean = false): string` | Hashes data. |\n";
924893
markdown += "| `$help(): vscode.Thenable<any>` | Shows this help document. |\n";
@@ -940,11 +909,16 @@ function _generateHelpHTML(): string {
940909
markdown += "| `$readString(file: string, encoding?: string = 'utf8'): string` | Reads a file as string. |\n";
941910
markdown += "| `$removeFromHistory(index?: number, fromGlobal = false): void` | Removes an expression from history. |\n";
942911
markdown += "| `$require(id: string): any` | Loads a module from execution / extension context. |\n";
912+
markdown += "| `$restartCronJobs(jobNames: string[]): Promise<any>` | (Re-)Starts a list of [cron jobs](https://github.com/mkloubert/vs-cron). |\n";
943913
markdown += "| `$saveToHistory(saveGlobal: boolean = false, description?: string): void` | Saves the current expression to history. |\n";
944914
markdown += "| `$setState(newValue: any): any` | Sets the value of `$state` variable and returns the new value. |\n";
945915
markdown += "| `$sha1(data: any, asBuffer: boolean = false): string` | Hashes data by SHA-1. |\n";
946916
markdown += "| `$sha256(data: any, asBuffer: boolean = false): string` | Hashes data by SHA-256. |\n";
947917
markdown += "| `$showResultInTab(flag?: boolean, permanent?: boolean = false): boolean` | Gets or sets if result should be shown in a tab window or a popup. |\n";
918+
markdown += "| `$startApi(): Promise<any>` | Starts an [API host](https://github.com/mkloubert/vs-rest-api). |\n";
919+
markdown += "| `$startCronJobs(jobNames: string[]): Promise<any>` | Starts a list of [cron jobs](https://github.com/mkloubert/vs-cron). |\n";
920+
markdown += "| `$stopApi(): Promise<any>` | Stops an [API host](https://github.com/mkloubert/vs-rest-api). |\n";
921+
markdown += "| `$stopCronJobs(jobNames: string[]): Promise<any>` | Stops a list of [cron jobs](https://github.com/mkloubert/vs-cron). |\n";
948922
markdown += "| `$toHexView(val: any): string` | Converts a value, like a buffer or string, to 'hex view'. |\n";
949923
markdown += "| `$unlink(path: string): boolean` | Removes a file or folder. |\n";
950924
markdown += "| `$uuid(v4: boolean = true): string` | Generates a new unique ID. |\n";
@@ -960,7 +934,7 @@ function _generateHelpHTML(): string {
960934
markdown += "| `$config: Configuration` | The current [settings](https://mkloubert.github.io/vs-script-commands/interfaces/_contracts_.configuration.html) of that extension. |\n";
961935
markdown += "| `$doNotShowResult: Symbol` | A unique symbol that can be used as result and indicates NOT to show a result tab or popup. |\n";
962936
markdown += "| `$extension: vscode.ExtensionContext` | Stores the [context](https://code.visualstudio.com/docs/extensionAPI/vscode-api#_a-nameextensioncontextaspan-classcodeitem-id1016extensioncontextspan) of that extension. |\n";
963-
markdown += "| `$globals: any` | Stores the global data from the settings. |\n";
937+
markdown += "| `$globals: any` | Stores the global data from the [settings](https://github.com/mkloubert/vs-script-commands#settings-). |\n";
964938
markdown += "| `$me: ScriptCommandController` | The [controller](https://mkloubert.github.io/vs-script-commands/classes/_controller_.scriptcommandcontroller.html) of that extension. |\n";
965939
markdown += "| `$output: vscode.OutputChannel` | Stores the [output channel](https://code.visualstudio.com/docs/extensionAPI/vscode-api#OutputChannel) of that extension. |\n";
966940
markdown += "| `$state: any` | Stores a value that should be available for next executions. |\n";
@@ -969,11 +943,11 @@ function _generateHelpHTML(): string {
969943

970944
let html = '';
971945

972-
html += HTML_HEADER;
946+
html += sc_resources.HTML_HEADER;
973947

974948
html += _fromMarkdown(markdown);
975949

976-
html += HTML_FOOTER;
950+
html += sc_resources.HTML_FOOTER;
977951

978952
return html;
979953
}
@@ -985,7 +959,7 @@ function _generateHTMLForResult(expr: string, result: any, disableHexView: boole
985959

986960
let html = '';
987961

988-
html += HTML_HEADER;
962+
html += sc_resources.HTML_HEADER;
989963

990964
let codeBlockLang = 'json';
991965

@@ -1040,7 +1014,7 @@ function _generateHTMLForResult(expr: string, result: any, disableHexView: boole
10401014

10411015
html += _fromMarkdown(markdown);
10421016

1043-
html += HTML_FOOTER;
1017+
html += sc_resources.HTML_FOOTER;
10441018

10451019
return html;
10461020
}

0 commit comments

Comments
 (0)