-
Notifications
You must be signed in to change notification settings - Fork 83
/
extension.js
112 lines (101 loc) · 3.53 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
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
var vscode = require("vscode");
global.STATUS_TIMEOUT = 3000;
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
function activate(context) {
var syncHelper, currentConfig;
var ftpConfig = require("./modules/ftp-config");
var getSyncHelper = function() {
var oldConfig = currentConfig;
currentConfig = ftpConfig.getSyncConfig();
if (!syncHelper) syncHelper = require("./modules/sync-helper")();
else if (ftpConfig.connectionChanged(oldConfig)) syncHelper.disconnect();
syncHelper.useConfig(currentConfig);
return syncHelper;
};
var initCommand = vscode.commands.registerCommand(
"extension.ftpsyncinit",
require("./modules/init-command")
);
var syncCommand = vscode.commands.registerCommand(
"extension.ftpsyncupload",
function() {
require("./modules/sync-command")(true, getSyncHelper);
}
);
var downloadCommand = vscode.commands.registerCommand(
"extension.ftpsyncdownload",
function() {
require("./modules/sync-command")(false, getSyncHelper);
}
);
var commitCommand = vscode.commands.registerCommand(
"extension.ftpsynccommit",
function() {
require("./modules/commit-command")(getSyncHelper);
}
);
var singleCommand = vscode.commands.registerTextEditorCommand(
"extension.ftpsyncsingle",
function(editor) {
require("./modules/sync-single-command")(editor, getSyncHelper);
}
);
var uploadcurrentCommand = vscode.commands.registerCommand(
"extension.ftpsyncuploadselected",
function(fileUrl) {
require("./modules/uploadcurrent-command")(fileUrl, getSyncHelper);
}
);
var downloadcurrentCommand = vscode.commands.registerCommand(
"extension.ftpsyncdownloadselected",
function(fileUrl) {
require("./modules/downloadcurrent-command")(fileUrl, getSyncHelper);
}
);
var listcurrentCommand = vscode.commands.registerCommand(
"extension.ftpsynclistselected",
function(fileUrl) {
require("./modules/list-command")(fileUrl, getSyncHelper);
}
);
var onSave = require("./modules/on-save");
var onGenerate = require("./modules/on-generate");
var currentConfig = getSyncHelper().getConfig();
if (currentConfig.generatedFiles.extensionsToInclude.length > 0) {
fsw = vscode.workspace.createFileSystemWatcher(
currentConfig.getGeneratedDir() + "/**"
);
fsw.onDidChange(function(ev) {
//an attempt to normalize onDidChange with onDidSaveTextDocument.
ev["uri"] = { fsPath: ev.fsPath };
onGenerate(ev, getSyncHelper);
});
fsw.onDidCreate(function(ev) {
ev["uri"] = { fsPath: ev.fsPath };
onGenerate(ev, getSyncHelper);
});
fsw.onDidDelete(function(ev) {
ev["uri"] = { fsPath: ev.fsPath };
onGenerate(ev, getSyncHelper);
});
}
vscode.workspace.onDidSaveTextDocument(function(file) {
onSave(file, getSyncHelper);
});
context.subscriptions.push(initCommand);
context.subscriptions.push(syncCommand);
context.subscriptions.push(downloadCommand);
context.subscriptions.push(commitCommand);
context.subscriptions.push(singleCommand);
context.subscriptions.push(uploadcurrentCommand);
context.subscriptions.push(downloadcurrentCommand);
context.subscriptions.push(listcurrentCommand);
}
exports.activate = activate;
function deactivate() {
fsw.dispose();
}
exports.deactivate = deactivate;