forked from netsuite-upload-org/netsuite-upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
148 lines (123 loc) · 5.38 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
let vscode = require('vscode');
let netSuiteBl = require('./bl/netSuiteBl');
function activate(context) {
console.log('Extension "netsuite-upload" is now active!');
let noProjectOpenedErrorMessage = 'No project is opened. Please open root folder. (SuiteScripts)';
let noFileSelectedErrorMessage = 'No file selected. Please right-click the file and select action from context menu.';
let downloadFileDisposable = vscode.commands.registerCommand('netsuite-upload.downloadFile', (file) => {
if (!file) {
vscode.window.showErrorMessage(noFileSelectedErrorMessage);
return;
}
// Root SuiteScript folder has to be opened
if (!vscode.workspace.rootPath) {
vscode.window.showErrorMessage(noProjectOpenedErrorMessage);
return;
}
netSuiteBl.downloadFileFromNetSuite(file);
});
context.subscriptions.push(downloadFileDisposable);
let previewFileDisposable = vscode.commands.registerCommand('netsuite-upload.previewFile', (file) => {
if (!file) {
vscode.window.showErrorMessage(noFileSelectedErrorMessage);
return;
}
// Root SuiteScript folder has to be opened
if (!vscode.workspace.rootPath) {
vscode.window.showErrorMessage(noProjectOpenedErrorMessage);
return;
}
netSuiteBl.previewFileFromNetSuite(file);
});
context.subscriptions.push(previewFileDisposable);
let uploadFileDisposable = vscode.commands.registerCommand('netsuite-upload.uploadFile', (file) => {
// Root SuiteScript folder has to be opened
if (!vscode.workspace.rootPath) {
vscode.window.showErrorMessage(noProjectOpenedErrorMessage);
return;
}
if (!file || !Object.keys(file).length) {
if (!vscode.window.activeTextEditor && !vscode.window.activeTextEditor.document.uri) {
vscode.window.showErrorMessage(noFileSelectedErrorMessage);
return;
}
else {
file = vscode.window.activeTextEditor.document.uri;
}
}
netSuiteBl.uploadFileToNetSuite(file);
});
context.subscriptions.push(uploadFileDisposable);
let deleteFileDisposable = vscode.commands.registerCommand('netsuite-upload.deleteFile', (file) => {
if (!file) {
vscode.window.showErrorMessage(noFileSelectedErrorMessage);
return;
}
// Root SuiteScript folder has to be opened
if (!vscode.workspace.rootPath) {
vscode.window.showErrorMessage(noProjectOpenedErrorMessage);
return;
}
netSuiteBl.deleteFileInNetSuite(file);
});
context.subscriptions.push(deleteFileDisposable);
let uploadFolderDisposable = vscode.commands.registerCommand('netsuite-upload.uploadFolder', (directory) => {
// Root SuiteScript folder has to be opened
if (!vscode.workspace.workspaceFolders.length) {
vscode.window.showErrorMessage(noProjectOpenedErrorMessage);
return;
}
if (!directory || !Object.keys(directory).length) {
if (!vscode.window.activeTextEditor && !vscode.window.activeTextEditor.document.uri) {
vscode.window.showErrorMessage(noFileSelectedErrorMessage);
return;
}
else {
let path = vscode.window.activeTextEditor.document.uri.path;
directory = vscode.Uri.file(path.substring(0, path.lastIndexOf("/")));
}
}
netSuiteBl.uploadDirectoryToNetSuite(directory);
});
context.subscriptions.push(uploadFolderDisposable);
let downloadFolderDisposable = vscode.commands.registerCommand('netsuite-upload.downloadFolder', (directory) => {
if (!directory) {
vscode.window.showErrorMessage('No directory selected.');
return;
}
// Root SuiteScript folder has to be opened
if (!vscode.workspace.rootPath) {
vscode.window.showErrorMessage(noProjectOpenedErrorMessage);
return;
}
netSuiteBl.downloadDirectoryFromNetSuite(directory);
});
context.subscriptions.push(downloadFolderDisposable);
let addCustomDependencyDisposable = vscode.commands.registerCommand('netsuite-upload.addCustomDependency', () => {
let editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showErrorMessage('No file is opened.');
return;
}
netSuiteBl.addCustomDependencyToActiveFile(editor);
});
context.subscriptions.push(addCustomDependencyDisposable);
let addNSDependencyDisposable = vscode.commands.registerCommand('netsuite-upload.addNSDependency', () => {
let editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showErrorMessage('No file is opened.');
return;
}
netSuiteBl.addNetSuiteDependencyToActiveFile(editor);
});
context.subscriptions.push(addNSDependencyDisposable);
let getRestletVersion = vscode.commands.registerCommand('netsuite-upload.getRestletVersion', () => {
netSuiteBl.getRestletVersion();
});
context.subscriptions.push(getRestletVersion);
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() {
}
exports.deactivate = deactivate;