Skip to content

Commit 0642da9

Browse files
committed
Now using prettier. working on commit command, more testing needed
1 parent 0bada44 commit 0642da9

File tree

6 files changed

+230
-165
lines changed

6 files changed

+230
-165
lines changed

src/commands.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1-
const {commands} = require('vscode');
1+
const { commands, scm, window } = require("vscode");
2+
const Svn = require("./svn");
3+
const { inputCommitMessage } = require("./messages");
24

35
function SvnCommands() {
4-
//some form of loop that gets the prototypes and registers them with vscode.
6+
this.svn = new Svn();
7+
8+
commands.registerCommand("svn.fileOpen", this.fileOpen);
9+
commands.registerCommand("svn.commitAll", this.commitAll);
510
}
611

7-
SvnCommands.prototype.fileOpen = (resourceUri) {
8-
commands.executeCommand('vscode.open', resourceUri);
9-
}
12+
SvnCommands.prototype.fileOpen = resourceUri => {
13+
commands.executeCommand("vscode.open", resourceUri);
14+
};
15+
16+
SvnCommands.prototype.commitAll = () => {
17+
inputCommitMessage(scm.inputBox.value)
18+
.then(result => this.svn.commitAll(result))
19+
.then(() => {
20+
scm.inputBox.value = "";
21+
})
22+
.catch(err => console.log(err));
23+
};
24+
25+
module.exports = SvnCommands;

src/extension.js

Lines changed: 123 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,137 @@
1-
const vscode = require('vscode');
2-
const path = require('path');
3-
const Svn = require('./svn');
4-
const svnSCM = require('./svnSCM');
5-
const svnContentProvider = require('./svnContentProvider');
6-
7-
const checkAllFiles = (svn) => {
8-
return new Promise((resolve, reject) => {
9-
svn.getStatus()
10-
.then((data) => resolve(data))
11-
.catch((err) => reject(err));
12-
});
1+
const vscode = require("vscode");
2+
const path = require("path");
3+
const Svn = require("./svn");
4+
const svnSCM = require("./svnSCM");
5+
const svnContentProvider = require("./svnContentProvider");
6+
const SvnCommands = require("./commands");
7+
8+
const checkAllFiles = svn => {
9+
return new Promise((resolve, reject) => {
10+
svn
11+
.getStatus()
12+
.then(data => resolve(data))
13+
.catch(err => reject(err));
14+
});
1315
};
1416

1517
function createResourceUri(relativePath) {
16-
const absolutePath = path.join(vscode.workspace.rootPath, relativePath);
17-
return vscode.Uri.file(absolutePath);
18-
}
18+
const absolutePath = path.join(vscode.workspace.rootPath, relativePath);
19+
return vscode.Uri.file(absolutePath);
20+
}
1921

2022
const updateResourceGroup = (data, type) => {
21-
var matches = [];
22-
23-
data.forEach(item => {
24-
if (item['wc-status'].$.item == type) {
25-
matches.push({resourceUri: createResourceUri(item.$.path)});
26-
}
27-
});
28-
29-
return matches;
30-
}
23+
var matches = [];
3124

32-
const updateChangesResourceGroup = (data) => {
33-
const changes = ['added', 'modified', 'deleted', 'missing', 'conflicted', 'replaced'];
34-
let matches = [];
35-
const iconsRootPath = path.join(__dirname, 'icons');
36-
37-
data.forEach(item => {
38-
if (changes.indexOf(item['wc-status'].$.item) != -1) {
39-
matches.push({
40-
resourceUri: createResourceUri(item.$.path),
41-
decorations: {
42-
iconPath: vscode.Uri.file(path.join(iconsRootPath, `${item['wc-status'].$.item}.svg`)),
43-
tooltip: item['wc-status'].$.item,
44-
},
45-
command: {
46-
command: 'svn.fileOpen',
47-
title: 'Open',
48-
arguments: [createResourceUri(item.$.path)]
49-
}
50-
});
51-
}
52-
});
53-
54-
return matches;
55-
}
25+
data.forEach(item => {
26+
if (item["wc-status"].$.item == type) {
27+
matches.push({ resourceUri: createResourceUri(item.$.path) });
28+
}
29+
});
5630

57-
const updateNotTrackedResourceGroup = (data) => {
58-
let matches = [];
59-
const iconsRootPath = path.join(__dirname, 'icons');
60-
61-
data.forEach(item => {
62-
if (item['wc-status'].$.item == 'unversioned') {
63-
matches.push({
64-
resourceUri: createResourceUri(item.$.path),
65-
decorations: {
66-
iconPath: vscode.Uri.file(path.join(iconsRootPath, `unversioned.svg`)),
67-
tooltip: item['wc-status'].$.item,
68-
},
69-
command: {
70-
command: 'svn.fileOpen',
71-
title: 'Open',
72-
arguments: [createResourceUri(item.$.path)]
73-
}
74-
});
75-
}
76-
});
77-
78-
return matches;
79-
}
31+
return matches;
32+
};
8033

81-
const registerFileOpenCommand = () => {
82-
vscode.commands.registerCommand('svn.fileOpen', (resourceUri) => {
83-
vscode.commands.executeCommand('vscode.open', resourceUri);
84-
});
85-
}
34+
const updateChangesResourceGroup = data => {
35+
const changes = [
36+
"added",
37+
"modified",
38+
"deleted",
39+
"missing",
40+
"conflicted",
41+
"replaced"
42+
];
43+
let matches = [];
44+
const iconsRootPath = path.join(__dirname, "icons");
45+
46+
data.forEach(item => {
47+
if (changes.indexOf(item["wc-status"].$.item) != -1) {
48+
matches.push({
49+
resourceUri: createResourceUri(item.$.path),
50+
decorations: {
51+
iconPath: vscode.Uri.file(
52+
path.join(iconsRootPath, `${item["wc-status"].$.item}.svg`)
53+
),
54+
tooltip: item["wc-status"].$.item
55+
},
56+
command: {
57+
command: "svn.fileOpen",
58+
title: "Open",
59+
arguments: [createResourceUri(item.$.path)]
60+
}
61+
});
62+
}
63+
});
64+
65+
return matches;
66+
};
67+
68+
const updateNotTrackedResourceGroup = data => {
69+
let matches = [];
70+
const iconsRootPath = path.join(__dirname, "icons");
71+
72+
data.forEach(item => {
73+
if (item["wc-status"].$.item == "unversioned") {
74+
matches.push({
75+
resourceUri: createResourceUri(item.$.path),
76+
decorations: {
77+
iconPath: vscode.Uri.file(
78+
path.join(iconsRootPath, `unversioned.svg`)
79+
),
80+
tooltip: item["wc-status"].$.item
81+
},
82+
command: {
83+
command: "svn.fileOpen",
84+
title: "Open",
85+
arguments: [createResourceUri(item.$.path)]
86+
}
87+
});
88+
}
89+
});
90+
91+
return matches;
92+
};
8693

8794
function activate(context) {
88-
console.log('svn-scm is now active!');
89-
90-
const disposable = [];
91-
const rootPath = vscode.workspace.rootPath;
92-
93-
const watcher = vscode.workspace.createFileSystemWatcher(`${rootPath}/**/*`);
94-
95-
registerFileOpenCommand();
96-
97-
const sourceControl = new svnSCM();
98-
const contentProvider = new svnContentProvider();
99-
const svn = new Svn();
100-
101-
const changes = sourceControl.createResourceGroup('changes', 'Changes');
102-
const notTracked = sourceControl.createResourceGroup('unversioned', 'Not Tracked');
103-
104-
changes.hideWhenEmpty = true;
105-
notTracked.hideWhenEmpty = true;
106-
107-
const main = () => {
108-
return checkAllFiles(svn)
109-
.then((data) => {
110-
changes.resourceStates = updateChangesResourceGroup(data);
111-
notTracked.resourceStates = updateNotTrackedResourceGroup(data);
112-
})
113-
.catch((err) => vscode.window.showErrorMessage(err));
114-
};
115-
116-
watcher.onDidChange(main);
117-
watcher.onDidCreate(main);
118-
watcher.onDidDelete(main);
119-
120-
main();
121-
122-
context.subscriptions.push(disposable);
95+
console.log("svn-scm is now active!");
96+
97+
const disposable = [];
98+
const rootPath = vscode.workspace.rootPath;
99+
100+
const watcher = vscode.workspace.createFileSystemWatcher(`${rootPath}/**/*`);
101+
102+
const commands = new SvnCommands();
103+
const sourceControl = new svnSCM();
104+
const contentProvider = new svnContentProvider();
105+
const svn = new Svn();
106+
107+
const changes = sourceControl.createResourceGroup("changes", "Changes");
108+
const notTracked = sourceControl.createResourceGroup(
109+
"unversioned",
110+
"Not Tracked"
111+
);
112+
113+
changes.hideWhenEmpty = true;
114+
notTracked.hideWhenEmpty = true;
115+
116+
const main = () => {
117+
return checkAllFiles(svn)
118+
.then(data => {
119+
changes.resourceStates = updateChangesResourceGroup(data);
120+
notTracked.resourceStates = updateNotTrackedResourceGroup(data);
121+
})
122+
.catch(err => vscode.window.showErrorMessage(err));
123+
};
124+
125+
watcher.onDidChange(main);
126+
watcher.onDidCreate(main);
127+
watcher.onDidDelete(main);
128+
129+
main();
130+
131+
context.subscriptions.push(disposable);
123132
}
124133
exports.activate = activate;
125134

126135
// this method is called when your extension is deactivated
127-
function deactivate() {
128-
}
129-
exports.deactivate = deactivate;
136+
function deactivate() {}
137+
exports.deactivate = deactivate;

src/messages.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const { window } = require("vscode");
2+
3+
function noChangesToCommit() {
4+
return window.showInformationMessage("There are no changes to commit.");
5+
}
6+
7+
function inputCommitMessage(message) {
8+
return new Promise((resolve, reject) => {
9+
if (message) {
10+
resolve(message);
11+
return;
12+
}
13+
14+
window
15+
.showInputBox({
16+
value: "",
17+
placeHolder: "Commit message",
18+
prompt: "Please enter a commit message",
19+
ignoreFocusOut: true
20+
})
21+
.then(string => resolve(string));
22+
});
23+
}
24+
25+
exports.noChangesToCommit = noChangesToCommit;
26+
exports.inputCommitMessage = inputCommitMessage;

src/svn.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
const SvnSpawn = require('svn-spawn');
2-
const vscode = require('vscode');
1+
const SvnSpawn = require("svn-spawn");
2+
const vscode = require("vscode");
33

44
function svn() {
5-
const rootPath = vscode.workspace.rootPath;
5+
const rootPath = vscode.workspace.rootPath;
66

7-
this.client = new SvnSpawn({
8-
cwd: rootPath,
9-
noAuthCache: true,
10-
});
7+
this.client = new SvnSpawn({
8+
cwd: rootPath,
9+
noAuthCache: true
10+
});
1111
}
1212

1313
svn.prototype.cmd = function(args) {
14-
return new Promise((resolve, reject) => {
15-
this.client.cmd(args, (err, data) => err ? reject(err) : resolve(data));
16-
});
17-
}
14+
return new Promise((resolve, reject) => {
15+
this.client.cmd(args, (err, data) => (err ? reject(err) : resolve(data)));
16+
});
17+
};
1818

1919
svn.prototype.getStatus = function() {
20-
return new Promise((resolve, reject) => {
21-
this.client.getStatus((err, data) => err ? reject(err) : resolve(data));
22-
});
23-
}
20+
return new Promise((resolve, reject) => {
21+
this.client.getStatus((err, data) => (err ? reject(err) : resolve(data)));
22+
});
23+
};
2424

25+
svn.prototype.commitAll = function(message) {
26+
return new Promise((resolve, reject) => {
27+
this.client.commit(
28+
message,
29+
(err, data) => (err ? reject(err) : resolve(data))
30+
);
31+
});
32+
};
2533

26-
module.exports = svn;
34+
module.exports = svn;

0 commit comments

Comments
 (0)