-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
192 lines (175 loc) · 9 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
'use strict';
var vscode = require('vscode');
var fs = require('fs');
var path = require('path');
function activate(context) {
console.log('Extension "filesync" is now active!');
var scriptTypes = {
'Business rule': 'sys_script',
'Script include': 'sys_script_include',
'UI page': 'sys_ui_page',
'UI script': 'sys_ui_script',
'UI action': 'sys_ui_action',
'UI macro': 'sys_ui_macro',
'Catalog client script': 'catalog_script_client',
'Client script': 'sys_script_client',
'Email script': 'sys_script_email',
'Inbound action': 'sysevent_in_email_action',
'Processor': 'sys_processor',
'Script action': 'sysevent_script_action',
'Stylesheet': 'content_css',
'Dynamic content block': 'content_block_programmatic',
'Email template': 'sysevent_email_template',
'Fix script': 'sys_script_fix',
'Scripted web service': 'sys_web_service',
'Scripted REST resource': 'sys_ws_operation',
'Widget': 'sp_widget',
'CSS': 'content_css'
};
var scriptTypeArray = Object.keys(scriptTypes);
var vsPath = vscode.workspace.rootPath;
var first = vscode.commands.registerCommand('extension.firstRttms', function () {
if (!(fs.existsSync(path.join(vsPath, 'src')))) {
var rootPath = path.join(vsPath, 'src');
var rttmsPath = path.join(vsPath, 'src/rttmsdev');
var riotintodevPath = path.join(vsPath, 'src/riotintodev');
fs.mkdirSync(rootPath);
fs.mkdirSync(rttmsPath);
fs.mkdirSync(riotintodevPath);
}
vscode.window.showInputBox({ prompt: 'what is your rttms username? i.e corp\\bob.smith' })
.then(function (value) {
if (value == "") {
vscode.window.showErrorMessage("No username provided");
return;
} else if (value == undefined) {
return;
}
var username = value;
vscode.window.showInputBox({ prompt: 'What is your rttms password? #sorryForPlainText' })
.then(function (value) {
if (value == "") {
vscode.window.showErrorMessage("No password provided");
return;
} else if (value == undefined) {
return;
}
var pw = value;
var devPath = path.join(vsPath, 'rttmsdev.config.json');
var patchPath = path.join(vsPath, 'riotintodev.config.json');
//
//Writing username and password to patch config json file
//
fs.readFile(devPath, function (err, contents) {
if (err) throw err;
contents = JSON.parse(contents);
contents.roots['src/rttmsdev'].user = username;
contents.roots['src/rttmsdev'].pass = pw;
fs.writeFile(devPath, JSON.stringify(contents, null, '\t'), function (err) {
if (err) throw err;
vscode.window.setStatusBarMessage("finished writing username and password to rttmsdev.config.json", 3000);
});
});
//
//Writing username and password to patch config json file
//
fs.readFile(patchPath, function (err, contents) {
if (err) throw err;
contents = JSON.parse(contents);
contents.roots['src/riotintodev'].user = username;
contents.roots['src/riotintodev'].pass = pw;
fs.writeFile(patchPath, JSON.stringify(contents, null, '\t'), function (err) {
if (err) throw err;
vscode.window.setStatusBarMessage("finished writing username and password to riotintodev.config.json", 3000);
});
});
});
});
});
var gitCommit = vscode.commands.registerCommand('extension.SendToBucket', function () {
vscode.window.showInputBox({ prompt: 'Add a commit message (Mandatory)' })
.then(function (value) {
if (value == "") {
vscode.window.showErrorMessage("No commit message added..... I told you it was mandatory!");
return;
} else if (value == undefined) {
return;
}
var terminal = vscode.window.createTerminal("commit");
terminal.show(true);
terminal.sendText('cd src', true);
terminal.sendText('git add .', true);
terminal.sendText('git commit -m "' + value + '"', true);
terminal.sendText('git push -u origin', true);
vscode.window.setStatusBarMessage("Commiting and pushing files", 4000);
});
});
var watch = vscode.commands.registerCommand('extension.watchRttms', function () {
vscode.window.showQuickPick(['rttmsdev', 'riotintodev'], { placeHolder: 'Which environment?' })
.then(function (value) {
if (value == undefined)
return;
var terminal = vscode.window.createTerminal({ name: "watcher", processId: 1 });
terminal.show(true);
terminal.sendText('node bin/app.js --config ' + value + '.config.json', true);
vscode.window.setStatusBarMessage("watching file in " + value, 4000);
});
});
var sync = vscode.commands.registerCommand('extension.syncRttms', function () {
vscode.window.showQuickPick(['rttmsdev', 'riotintodev'], { placeHolder: 'Which environment?' })
.then(function (value) {
if (value == undefined)
return;
var terminal = vscode.window.createTerminal("watcher");
terminal.show(true);
terminal.sendText('node bin/app.js --config ' + value + '.config.json --resync', true);
vscode.window.setStatusBarMessage("resyncing files in environment: " + value, 4000);
});
});
var search = vscode.commands.registerCommand('extension.searchRttms', function () {
vscode.window.showQuickPick(['rttmsdev', 'riotintodev'], { placeHolder: 'Which environment?' })
.then(function (value) {
if (value == undefined)
return;
var environ = value;
vscode.window.showQuickPick(scriptTypeArray, { placeHolder: 'What type is the script?' })
.then(function (value) {
if (value == undefined)
return;
var scriptType = scriptTypes[value];
vscode.window.showInputBox({ prompt: 'What is the script name?' })
.then(function (value) {
if (value == "") {
vscode.window.showErrorMessage("No file to search for..");
return;
} else if (value == undefined) {
return;
}
var terminal = vscode.window.createTerminal("node");
terminal.show(true);
terminal.sendText('node bin/app.js --config ' + environ + '.config.json --search --search_query "name=' + value + '" + --search_table ' + scriptType + ' --download;', true);
vscode.window.setStatusBarMessage("Searching for files now...", 4000);
vscode.window.showQuickPick(['Yes', 'No'], { placeHolder: 'Do you want to watch the files now?' })
.then(function (value) {
if (value == undefined)
return;
else if (value == 'Yes')
vscode.commands.executeCommand('extension.watchRttms');
else
return;
});
});
});
});
});
context.subscriptions.push(search);
context.subscriptions.push(watch);
context.subscriptions.push(first);
context.subscriptions.push(sync);
context.subscriptions.push(gitCommit);
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() {
}
exports.deactivate = deactivate;