-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension.js
63 lines (49 loc) · 1.82 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
let vscode = require('vscode');
let terminalStack = [];
function generateItem(context, name, command) {
let title = name.replace("task-", "").replace("-", " ").toUpperCase()
let key = "button.task." + name;
vscode.commands.registerCommand(key, () => {
if (!terminalStack[title]) {
terminalStack[title] = vscode.window.createTerminal(title);
}
terminalStack[title].show();
terminalStack[title].sendText(command);
});
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 1);
statusBarItem.command = key;
statusBarItem.text = title;
statusBarItem.show();
context.subscriptions.push(statusBarItem);
}
function generateTask(context) {
let cwd = vscode.workspace.rootPath;
vscode.workspace.openTextDocument(cwd + '/package.json').then((document) => {
let text = document.getText();
let packageJson = JSON.parse(text);
let scripts = packageJson.scripts
if (scripts) {
for (var x in scripts) {
if (x.toString().length && x.startsWith("task-")) {
generateItem(context, x, scripts[x])
}
}
}
});
vscode.window.onDidCloseTerminal((item) => {
if (terminalStack[item._name])
delete terminalStack[item._name];
})
}
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
function activate(context) {
generateTask(context)
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() {
}
exports.deactivate = deactivate;