mirror of
https://github.com/pomber/git-history.git
synced 2024-10-26 15:09:56 +03:00
Add vscode provider
This commit is contained in:
parent
8fe1e9cd08
commit
e803429650
@ -1,12 +1,13 @@
|
||||
import cliProvider from "./cli-provider";
|
||||
import githubProvider from "./github-provider";
|
||||
import vscodeProvider from "./vscode-provider";
|
||||
|
||||
export default function getGitProvider() {
|
||||
switch (process.env.REACT_APP_GIT_PROVIDER) {
|
||||
case "cli":
|
||||
return cliProvider;
|
||||
case "vscode":
|
||||
return null;
|
||||
return vscodeProvider;
|
||||
default:
|
||||
return githubProvider;
|
||||
}
|
||||
|
38
src/git-providers/vscode-provider.js
Normal file
38
src/git-providers/vscode-provider.js
Normal file
@ -0,0 +1,38 @@
|
||||
const vscode = window.vscode;
|
||||
|
||||
function getPath() {
|
||||
return window._PATH;
|
||||
}
|
||||
|
||||
function showLanding() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function getCommits() {
|
||||
const path = getPath();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
window.addEventListener(
|
||||
"message",
|
||||
event => {
|
||||
const commits = event.data;
|
||||
commits.forEach(c => (c.date = new Date(c.date)));
|
||||
resolve(commits);
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
|
||||
vscode.postMessage({
|
||||
command: "commits",
|
||||
params: {
|
||||
path
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
showLanding,
|
||||
getPath,
|
||||
getCommits
|
||||
};
|
@ -43,28 +43,38 @@ function activate(context) {
|
||||
);
|
||||
|
||||
const index = fs.readFileSync(indexPath, "utf-8");
|
||||
const newIndex = index
|
||||
.replace(
|
||||
"<body>",
|
||||
`<body><script>/*<!--*/window.vscode=acquireVsCodeApi();window._PATH='${currentPath}'/*-->*/</script>`
|
||||
)
|
||||
.replace(
|
||||
"<head>",
|
||||
`<head><base href="${vscode.Uri.file(
|
||||
path.join(context.extensionPath, "site")
|
||||
).with({
|
||||
scheme: "vscode-resource"
|
||||
})}/"/>`
|
||||
);
|
||||
|
||||
getCommits(currentPath)
|
||||
.then(commits => {
|
||||
const newIndex = index
|
||||
.replace(
|
||||
"<script>window._CLI=null</script>",
|
||||
`<script>/*<!--*/window._CLI={commits:${JSON.stringify(
|
||||
commits
|
||||
)},path:'${currentPath}'}/*-->*/</script>`
|
||||
)
|
||||
.replace(
|
||||
"<head>",
|
||||
`<head><base href="${vscode.Uri.file(
|
||||
path.join(context.extensionPath, "site")
|
||||
).with({
|
||||
scheme: "vscode-resource"
|
||||
})}/"/>`
|
||||
);
|
||||
panel.webview.html = newIndex;
|
||||
|
||||
panel.webview.html = newIndex;
|
||||
})
|
||||
.catch(console.error);
|
||||
panel.webview.onDidReceiveMessage(
|
||||
message => {
|
||||
switch (message.command) {
|
||||
case "commits":
|
||||
const path = message.params.path;
|
||||
getCommits(path)
|
||||
.then(commits => {
|
||||
console.log(path, commits);
|
||||
panel.webview.postMessage(commits);
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
},
|
||||
undefined,
|
||||
context.subscriptions
|
||||
);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
throw e;
|
||||
|
Loading…
Reference in New Issue
Block a user