Skip to content

Commit 716b135

Browse files
committed
feat: 0.1.2 release
1 parent b1a1981 commit 716b135

5 files changed

Lines changed: 44 additions & 35 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# git-auto-commit
1+
# git-auto-commit
22

33
这是一个可以自动帮你保存代码的插件。在某一次不小心把咖啡洒在了电脑上而诞生。
44

@@ -10,10 +10,7 @@
1010

1111
![feature](image/img1.png)
1212

13-
> Tip: 由于vscode中的限制,只能获取到工作区的地址。所以在使用本插件之前你需要点击菜单中的 ```文件->将工作区另存为``` 然后选择你的项目根目录保存工作区文件。git 提交会在工作区文件的同级目录中运行。所以请保证工作区文件和 .git文件为同一个路径。
14-
15-
## 插件设置
16-
13+
## 插件设置
1714

1815
* `git-auto-commit.commitTimeInterval`: 自动commit间隔 默认为最后一次写代码后的 一小时。
1916
* `git-auto-commit.autoPush`: 是否自动推送到当前分支的远程。
@@ -28,13 +25,16 @@ Users appreciate release notes as you update your extension.
2825

2926
### 0.1.0
3027

31-
Initial release
28+
Initial release
3229

3330
### 0.1.1
3431

3532
修复了一些bug。
3633
新增 git commit的时候会跳过检查。
3734
修改 由代码编辑触发更改为保存触发。
3835

36+
### 0.1.2
37+
38+
修复了window 平台的 路径问题。优化运行逻辑。
3939

4040
**Enjoy!**

src/Scheduler.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@ export default class Scheduler {
1212
changeOptions(option: Option) {
1313
this.$option = option
1414
}
15-
changeListener(e?: any) {
16-
// if (e.contentChanges.length > 0) {
15+
changeListener(e:vscode.TextDocument) {
1716
if (timer) {
1817
clearTimeout(timer)
1918
}
20-
2119
timer = setTimeout(() => {
22-
23-
this.run()
24-
clearTimeout(timer)
20+
this.run()
21+
clearTimeout(timer)
2522
}, this.$option.commitTimeInterval)
26-
// }
2723
}
2824
private _getUnCommitChange(path: string) {
2925
let cmd = `cd ${path}`;
@@ -46,24 +42,18 @@ export default class Scheduler {
4642
}
4743
run() {
4844
if (this.$option.path) {
49-
const reg = /\/.*\//
50-
const res = reg.exec(this.$option.path)
51-
if (res !== null) {
52-
const cmd = `cd ${res[0]} && git add . && git commit -n -m "自动提交" `;
45+
const cmd = `cd ${this.$option.path} && git add . && git commit -n -m "自动提交" `;
5346
exec(cmd, (err, stdout) => {
5447
if (err) {
5548
ReminderView.show(this.$option.context,err.message)
5649
} else {
57-
this._getUnCommitChange(res[0]).then(res => {
50+
this._getUnCommitChange(this.$option.path as string).then(res => {
5851
ReminderView.show(this.$option.context,`${getNow()} 自动提交成功 ${stdout} ${res}`,)
5952
})
6053
}
6154
})
6255
}
63-
}else{
64-
6556
}
66-
}
6757
destroy() {
6858
clearTimeout(timer)
6959
}

src/TextView.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export class ReminderView {
44
private static panel: vscode.WebviewPanel | undefined;
55

66
public static show(context: vscode.ExtensionContext, content:string) {
7-
const title="自动提交完成"
7+
const title="自动提交完成"
88
if (this.panel) {
99
this.panel.webview.html = this.generateHtml(title,content);
1010
this.panel.reveal();
@@ -21,17 +21,36 @@ export class ReminderView {
2121
}
2222

2323
protected static generateHtml(title: string,content: string): string {
24-
let contentLine = content.split('\n').map(line => `<div><h3>${line}</h3></div>`)
24+
let contentLine = content.split('\n').map(line => `<h3 class="line">${line}</h3>`).join('')
2525
let html = `<!DOCTYPE html>
2626
<html lang="en">
2727
<head>
2828
<meta charset="UTF-8">
2929
<meta name="viewport" content="width=device-width, initial-scale=1.0">
30+
<style>
31+
.code{
32+
margin: 0;
33+
padding: 0;
34+
overflow: auto;
35+
color: #000000d9;
36+
font-size: 13px;
37+
direction: ltr;
38+
text-align: left;
39+
background: #f5f5f5;
40+
border: none;
41+
}
42+
.code h3{
43+
color: #999;
44+
}
45+
</style>
3046
<title>杨超越</title>
3147
</head>
3248
<body>
3349
<div><h1>${title}</h1></div>
50+
<div class="code">
3451
${contentLine}
52+
</div>
53+
3554
</body>
3655
</html>`;
3756

src/extension.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@ let instance:Scheduler
88

99
export function activate(context: vscode.ExtensionContext) {
1010
let config:Option = {
11-
path:vscode.workspace.workspaceFile?.path,
12-
commitTimeInterval:getConfig('commitTimeInterval') as number,
13-
autoPush:getConfig('autoPush') as boolean,
11+
commitTimeInterval:getConfig<number>('commitTimeInterval')|| 0,
12+
autoPush:getConfig<boolean>('autoPush') || false,
1413
context
1514
}
16-
vscode.window.showInformationMessage('git-auto-commit成功启用');
17-
if(!vscode.workspace.workspaceFile){
18-
vscode.window.showErrorMessage('当前目录下不存在工作区,无法获取执行目录。请先将本项目保存为工作区');
15+
if(!vscode.workspace.workspaceFolders){
16+
vscode.window.showErrorMessage('当前目录不合法');
17+
return
1918
}else{
20-
instance = new Scheduler({...config,context});
19+
config.path = vscode.workspace.workspaceFolders[0].uri.fsPath
20+
instance = new Scheduler({...config,context})
21+
vscode.window.showInformationMessage('git-auto-commit成功启用');
2122
vscode.workspace.onDidSaveTextDocument((e)=>{instance.changeListener(e)})
22-
2323
}
2424
let disposable = vscode.commands.registerCommand('code-auto-commit.runCommit', () => {
2525

2626
});
2727

2828
context.subscriptions.push(disposable);
2929
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(() => {
30-
config.commitTimeInterval = getConfig('commitTimeInterval') as number;
31-
config.autoPush = getConfig('autoPush') as boolean;
30+
config.commitTimeInterval = getConfig<number>('commitTimeInterval') ||0;
31+
config.autoPush = getConfig<boolean>('autoPush') || false;
3232
instance.changeOptions(config)
3333
}));
3434
}

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export function getNow() {
1515
dateTime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
1616
return dateTime
1717
}
18-
export function getConfig(key: string) {
19-
return vscode.workspace.getConfiguration().get(`code-auto-commit.${key}`);
18+
export function getConfig<T = any>(key: string) {
19+
return vscode.workspace.getConfiguration().get<T>(`code-auto-commit.${key}`);
2020
}

0 commit comments

Comments
 (0)