mirror of
https://github.com/OBKoro1/autoCommit.git
synced 2024-12-23 09:39:19 +08:00
parent
fede0d0836
commit
b67fd727ee
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1 @@
|
|||||||
out
|
|
||||||
node_modules
|
node_modules
|
||||||
.vscode-test/
|
|
||||||
*.vsix
|
|
||||||
|
7
.vscode/extensions.json
vendored
7
.vscode/extensions.json
vendored
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
|
||||||
// for the documentation about the extensions.json format
|
|
||||||
"recommendations": [
|
|
||||||
"ms-vscode.vscode-typescript-tslint-plugin"
|
|
||||||
]
|
|
||||||
}
|
|
35
.vscode/launch.json
vendored
35
.vscode/launch.json
vendored
@ -1,36 +1,17 @@
|
|||||||
// A launch configuration that compiles the extension and then opens it inside a new window
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
{
|
{
|
||||||
|
// 使用 IntelliSense 了解相关属性。
|
||||||
|
// 悬停以查看现有属性的描述。
|
||||||
|
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Run Extension",
|
"type": "node",
|
||||||
"type": "extensionHost",
|
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"runtimeExecutable": "${execPath}",
|
"name": "启动程序",
|
||||||
"args": [
|
"skipFiles": [
|
||||||
"--extensionDevelopmentPath=${workspaceFolder}"
|
"<node_internals>/**"
|
||||||
],
|
],
|
||||||
"outFiles": [
|
"program": "${workspaceFolder}/src/index.js"
|
||||||
"${workspaceFolder}/out/**/*.js"
|
|
||||||
],
|
|
||||||
"preLaunchTask": "${defaultBuildTask}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Extension Tests",
|
|
||||||
"type": "extensionHost",
|
|
||||||
"request": "launch",
|
|
||||||
"runtimeExecutable": "${execPath}",
|
|
||||||
"args": [
|
|
||||||
"--extensionDevelopmentPath=${workspaceFolder}",
|
|
||||||
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
|
|
||||||
],
|
|
||||||
"outFiles": [
|
|
||||||
"${workspaceFolder}/out/test/**/*.js"
|
|
||||||
],
|
|
||||||
"preLaunchTask": "${defaultBuildTask}"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
11
.vscode/settings.json
vendored
11
.vscode/settings.json
vendored
@ -1,11 +0,0 @@
|
|||||||
// Place your settings in this file to overwrite default and user settings.
|
|
||||||
{
|
|
||||||
"files.exclude": {
|
|
||||||
"out": false // set this to true to hide the "out" folder with the compiled JS files
|
|
||||||
},
|
|
||||||
"search.exclude": {
|
|
||||||
"out": true // set this to false to include "out" folder in search results
|
|
||||||
},
|
|
||||||
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
|
|
||||||
"typescript.tsc.autoDetect": "off"
|
|
||||||
}
|
|
20
.vscode/tasks.json
vendored
20
.vscode/tasks.json
vendored
@ -1,20 +0,0 @@
|
|||||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
|
||||||
// for the documentation about the tasks.json format
|
|
||||||
{
|
|
||||||
"version": "2.0.0",
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"type": "npm",
|
|
||||||
"script": "watch",
|
|
||||||
"problemMatcher": "$tsc-watch",
|
|
||||||
"isBackground": true,
|
|
||||||
"presentation": {
|
|
||||||
"reveal": "never"
|
|
||||||
},
|
|
||||||
"group": {
|
|
||||||
"kind": "build",
|
|
||||||
"isDefault": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
.vscode/**
|
|
||||||
.vscode-test/**
|
|
||||||
out/test/**
|
|
||||||
src/**
|
|
||||||
.gitignore
|
|
||||||
vsc-extension-quickstart.md
|
|
||||||
**/tsconfig.json
|
|
||||||
**/tslint.json
|
|
||||||
**/*.map
|
|
||||||
**/*.ts
|
|
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,11 +0,0 @@
|
|||||||
# 更新日志
|
|
||||||
|
|
||||||
### 如果觉得本插件还不错的话,给个[Star](https://github.com/OBKoro1/autoCommit)吧~
|
|
||||||
|
|
||||||
<!-- TODO: package 关键词 -->
|
|
||||||
<!-- TODO: wiki readme -->
|
|
||||||
<!-- TODO: npm包形式 -->
|
|
||||||
|
|
||||||
### [V1.0.0]
|
|
||||||
|
|
||||||
- Initial release
|
|
65
README.md
65
README.md
@ -1,65 +0,0 @@
|
|||||||
# autoCommit README
|
|
||||||
|
|
||||||
This is the README for your extension "autoCommit". After writing up a brief description, we recommend including the following sections.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.
|
|
||||||
|
|
||||||
For example if there is an image subfolder under your extension project workspace:
|
|
||||||
|
|
||||||
\!\[feature X\]\(images/feature-x.png\)
|
|
||||||
|
|
||||||
> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
If you have any requirements or dependencies, add a section describing those and how to install and configure them.
|
|
||||||
|
|
||||||
## Extension Settings
|
|
||||||
|
|
||||||
Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
This extension contributes the following settings:
|
|
||||||
|
|
||||||
* `myExtension.enable`: enable/disable this extension
|
|
||||||
* `myExtension.thing`: set to `blah` to do something
|
|
||||||
|
|
||||||
## Known Issues
|
|
||||||
|
|
||||||
Calling out known issues can help limit users opening duplicate issues against your extension.
|
|
||||||
|
|
||||||
## Release Notes
|
|
||||||
|
|
||||||
Users appreciate release notes as you update your extension.
|
|
||||||
|
|
||||||
### 1.0.0
|
|
||||||
|
|
||||||
Initial release of ...
|
|
||||||
|
|
||||||
### 1.0.1
|
|
||||||
|
|
||||||
Fixed issue #.
|
|
||||||
|
|
||||||
### 1.1.0
|
|
||||||
|
|
||||||
Added features X, Y, and Z.
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
## Working with Markdown
|
|
||||||
|
|
||||||
**Note:** You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
|
|
||||||
|
|
||||||
* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux)
|
|
||||||
* Toggle preview (`Shift+CMD+V` on macOS or `Shift+Ctrl+V` on Windows and Linux)
|
|
||||||
* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (macOS) to see a list of Markdown snippets
|
|
||||||
|
|
||||||
### For more information
|
|
||||||
|
|
||||||
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
|
|
||||||
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
|
|
||||||
|
|
||||||
**Enjoy!**
|
|
4930
package-lock.json
generated
4930
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
68
package.json
68
package.json
@ -1,63 +1,21 @@
|
|||||||
{
|
{
|
||||||
"name": "autoCommit",
|
"name": "autocommit",
|
||||||
"displayName": "autoCommit",
|
"version": "1.0.0",
|
||||||
"description": "自动提交commit到github",
|
"description": "自动commit工具",
|
||||||
"version": "0.0.1",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"vscode:prepublish": "npm run compile",
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
"compile": "tsc -p ./",
|
|
||||||
"watch": "tsc -watch -p ./",
|
|
||||||
"pretest": "npm run compile",
|
|
||||||
"test": "node ./out/test/runTest.js"
|
|
||||||
},
|
},
|
||||||
"engines": {
|
"repository": {
|
||||||
"vscode": "^1.40.0"
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/OBKoro1/autoCommit.git"
|
||||||
},
|
},
|
||||||
"categories": [
|
"author": "",
|
||||||
"Other"
|
"license": "ISC",
|
||||||
],
|
"bugs": {
|
||||||
"activationEvents": [
|
"url": "https://github.com/OBKoro1/autoCommit/issues"
|
||||||
"onCommand:extension.autoCommit"
|
|
||||||
],
|
|
||||||
"main": "./out/extension.js",
|
|
||||||
"contributes": {
|
|
||||||
"commands": [
|
|
||||||
{
|
|
||||||
"command": "extension.autoCommit",
|
|
||||||
"title": "Github自动提交 autoCommit"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"vscode korofileheader",
|
|
||||||
"korofileheader",
|
|
||||||
"annotation",
|
|
||||||
"comment",
|
|
||||||
"vscode comment",
|
|
||||||
"vscode annotation",
|
|
||||||
"vscode 注释",
|
|
||||||
"vscode 文件头部注释",
|
|
||||||
"注释",
|
|
||||||
"文件注释",
|
|
||||||
"头部注释",
|
|
||||||
"函数注释",
|
|
||||||
"fileheader",
|
|
||||||
"vscode-fileheader",
|
|
||||||
"Document This",
|
|
||||||
"obkoro1",
|
|
||||||
"koro1"
|
|
||||||
],
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/glob": "^7.1.1",
|
|
||||||
"@types/mocha": "^5.2.7",
|
|
||||||
"@types/node": "^12.11.7",
|
|
||||||
"@types/vscode": "^1.41.0",
|
|
||||||
"glob": "^7.1.5",
|
|
||||||
"mocha": "^6.2.2",
|
|
||||||
"typescript": "^3.6.4",
|
|
||||||
"tslint": "^5.20.0",
|
|
||||||
"vscode-test": "^1.2.2"
|
|
||||||
},
|
},
|
||||||
|
"homepage": "https://github.com/OBKoro1/autoCommit#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"moment": "^2.24.0"
|
"moment": "^2.24.0"
|
||||||
}
|
}
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author : OBKoro1
|
|
||||||
* Date : 2019-12-25 15:15:42
|
|
||||||
* LastEditors : OBKoro1
|
|
||||||
* LastEditTime : 2019-12-25 17:49:37
|
|
||||||
* FilePath : /autoCommit/src/extension.ts
|
|
||||||
* Description : 自动commit插件 入口
|
|
||||||
* https://github.com/OBKoro1
|
|
||||||
*/
|
|
||||||
|
|
||||||
import * as vscode from 'vscode';
|
|
||||||
import ExtensionLogic from './models/index'
|
|
||||||
import { setExtensionContext } from './util/vscodeUtil'
|
|
||||||
|
|
||||||
|
|
||||||
// 扩展激活 默认运行
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
|
||||||
setExtensionContext(context)
|
|
||||||
|
|
||||||
const autoCommit = vscode.commands.registerCommand('extension.autoCommit', () => {
|
|
||||||
new ExtensionLogic(context)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 当插件关闭时被清理的可清理列表
|
|
||||||
context.subscriptions.push(autoCommit);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 扩展被禁用 调用
|
|
||||||
export function deactivate() {}
|
|
139
src/index.js
139
src/index.js
@ -2,96 +2,91 @@
|
|||||||
* Author : OBKoro1
|
* Author : OBKoro1
|
||||||
* Date : 2019-12-19 20:23:57
|
* Date : 2019-12-19 20:23:57
|
||||||
* LastEditors : OBKoro1
|
* LastEditors : OBKoro1
|
||||||
* LastEditTime : 2019-12-25 15:23:38
|
* LastEditTime : 2019-12-23 19:56:54
|
||||||
* FilePath : /autoCommit/src/index.js
|
* FilePath : /autoCommit/index.js
|
||||||
* Description : 自动commit
|
* Description : 自动commit
|
||||||
* https://github.com/OBKoro1
|
* https://github.com/OBKoro1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { execSync } = require('child_process')
|
const { execSync } = require('child_process');
|
||||||
const moment = require('moment')
|
const moment = require('moment');
|
||||||
const fs = require('fs')
|
const fs = require('fs');
|
||||||
|
|
||||||
class autoCommit {
|
class autoCommit {
|
||||||
constructor () {
|
constructor() {
|
||||||
this.init()
|
this.init();
|
||||||
}
|
}
|
||||||
getData () {
|
getData() {
|
||||||
this.getAllDay(this.paramsObj.beginDay, this.paramsObj.endDay)
|
this.getAllDay(this.paramsObj.beginDay, this.paramsObj.endDay);
|
||||||
this.readyCommit()
|
this.readyCommit();
|
||||||
|
console.log('timeArr', this.timeArr);
|
||||||
}
|
}
|
||||||
// 格式化日期
|
formatTime(time) {
|
||||||
formatTime (time) {
|
return `${time} 08:00`;
|
||||||
return `${time} 08:00`
|
|
||||||
}
|
}
|
||||||
// 获取两个日期之间的间隔: [ '2019-02-02', '2019-02-03' ... ]
|
getAllDay(begin, end) {
|
||||||
getAllDay (begin, end) {
|
this.timeArr = [];
|
||||||
this.timeArr = []
|
const beginSplit = begin.split('-');
|
||||||
const beginSplit = begin.split('-')
|
const endSplit = end.split('-');
|
||||||
const endSplit = end.split('-')
|
const beginDate = new Date();
|
||||||
const beginDate = new Date()
|
beginDate.setUTCFullYear(beginSplit[0], beginSplit[1] - 1, beginSplit[2]);
|
||||||
beginDate.setUTCFullYear(beginSplit[0], beginSplit[1] - 1, beginSplit[2])
|
const endDate = new Date();
|
||||||
const endDate = new Date()
|
endDate.setUTCFullYear(endSplit[0], endSplit[1] - 1, endSplit[2]);
|
||||||
endDate.setUTCFullYear(endSplit[0], endSplit[1] - 1, endSplit[2])
|
const beginNumber = beginDate.getTime();
|
||||||
const beginNumber = beginDate.getTime()
|
const endNumber = endDate.getTime();
|
||||||
const endNumber = endDate.getTime()
|
for (let k = beginNumber; k <= endNumber; ) {
|
||||||
for (let k = beginNumber; k <= endNumber;) {
|
const day = new Date(parseInt(k));
|
||||||
const day = new Date(parseInt(k))
|
const dayFormat = moment(day).format('YYYY-MM-DD');
|
||||||
const dayFormat = moment(day).format('YYYY-MM-DD')
|
this.timeArr.push(dayFormat);
|
||||||
this.timeArr.push(dayFormat)
|
k = k + 24 * 60 * 60 * 1000;
|
||||||
k = k + 24 * 60 * 60 * 1000
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
init () {
|
// 只commit今天
|
||||||
// TODO: 获取参数
|
commitToday() {
|
||||||
|
const time = moment().format('DD/MM/YYYY HH:MM:ss');
|
||||||
|
// TODO:
|
||||||
|
}
|
||||||
|
init() {
|
||||||
let paramsObj = {
|
let paramsObj = {
|
||||||
beginDay: '2019-12-20',
|
beginDay: '2019-02-02',
|
||||||
itemSrc: '/Users/koro/work/web_my/testCommit' // 要commit的项目地址
|
endDay: '2019-03-02',
|
||||||
}
|
itemSrc: '../../testCommit', // 要commit的项目地址
|
||||||
let defaultOption = {
|
|
||||||
beginDay: moment().format('YYYY-MM-DD'), // 默认为今天
|
|
||||||
endDay: moment().format('YYYY-MM-DD'), // 默认为今天
|
|
||||||
fileSrc: `commit.md`,
|
|
||||||
commitNumber: 1 // 每天commit 次数
|
commitNumber: 1 // 每天commit 次数
|
||||||
|
};
|
||||||
|
let defaultOption = {
|
||||||
|
endDay: moment().format('YYYY-MM-DD'), // 默认为今天
|
||||||
|
fileSrc: `${paramsObj.itemSrc}/commit.md`
|
||||||
|
};
|
||||||
|
this.paramsObj = paramsObj;
|
||||||
|
this.getData();
|
||||||
|
// this.commit();
|
||||||
}
|
}
|
||||||
this.paramsObj = Object.assign(defaultOption, paramsObj)
|
readyCommit() {
|
||||||
this.getData()
|
|
||||||
}
|
|
||||||
// commit
|
|
||||||
readyCommit () {
|
|
||||||
console.log('日期数组:', this.timeArr)
|
|
||||||
console.log('每个日期提交次数:', this.paramsObj.commitNumber)
|
|
||||||
let totalNum = 0 // 总commit次数
|
|
||||||
// 遍历日期
|
// 遍历日期
|
||||||
this.timeArr.forEach(item => {
|
this.timeArr.forEach(item => {
|
||||||
// 每个日期commit次数
|
// 每个日期commit次数
|
||||||
for (let i = 0; i < this.paramsObj.commitNumber; i++) {
|
for (let i = 0; i++; i < this.paramsObj.commitNumber) {
|
||||||
let time = this.formatTime(item) // 2019-01-02 08:00
|
let time = this.formatTime(item); // 2019-01-02 08:00
|
||||||
time = moment(time).format() // 2019-01-02T00:00:00+0800
|
time = moment(time).format(); // 2019-01-02T00:00:00+0800
|
||||||
const commitContent = `${time}${i}`
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
`${this.paramsObj.itemSrc}/${this.paramsObj.fileSrc}`,
|
`${this.paramsObj.itemSrc}/commit.md`,
|
||||||
commitContent,
|
`${time}${i}`,
|
||||||
'utf-8'
|
'utf-8'
|
||||||
)
|
);
|
||||||
|
console.log('each', time);
|
||||||
|
}
|
||||||
|
// this.commit()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
commit(commitTime) {
|
||||||
|
// git commit --amend --date="2019-01-02T00:00:00+0800" -am 'autoCommit'
|
||||||
|
// TODO: cd 项目 重写文件和commit
|
||||||
this.myExecSync(
|
this.myExecSync(
|
||||||
`cd ${this.paramsObj.itemSrc} && git add . && git commit -m 'autoCommit' --date='${time}' && git pull && git push origin master`
|
`cd ${this.paramsObj.itemSrc} && git add . && git commit -m 'autoCommit' --date='${commitTime}' && git pull && git push origin master`
|
||||||
)
|
);
|
||||||
let cmd = `git log -1 \
|
|
||||||
--date=iso --pretty=format:'{"commit": "%h","author": "%aN <%aE>","date": "%ad","message": "%s"},' \
|
|
||||||
$@ | \
|
|
||||||
perl -pe 'BEGIN{print "["}; END{print "]\n"}' | \
|
|
||||||
perl -pe 's/},]/}]/'`
|
|
||||||
this.myExecSync(cmd)
|
|
||||||
this.totalNum++
|
|
||||||
|
|
||||||
console.log('commit内容', commitContent)
|
|
||||||
console.log(`总commit次数${totalNum}`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
myExecSync (cmd) {
|
myExecSync(cmd) {
|
||||||
// 除了该方法直到子进程完全关闭后才返回 执行完毕 返回
|
// 除了该方法直到子进程完全关闭后才返回 执行完毕 返回
|
||||||
try {
|
try {
|
||||||
const res = execSync(cmd, {
|
const res = execSync(cmd, {
|
||||||
@ -101,12 +96,12 @@ class autoCommit {
|
|||||||
killSignal: 'SIGTERM',
|
killSignal: 'SIGTERM',
|
||||||
cwd: undefined,
|
cwd: undefined,
|
||||||
env: undefined
|
env: undefined
|
||||||
})
|
});
|
||||||
return res
|
return res;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(`执行命令出错:${cmd}`)
|
console.log(`执行命令出错:${cmd}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new autoCommit()
|
new autoCommit();
|
||||||
|
@ -1,111 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author : OBKoro1
|
|
||||||
* Date : 2019-12-26 13:49:02
|
|
||||||
* LastEditors : OBKoro1
|
|
||||||
* LastEditTime : 2019-12-26 15:24:08
|
|
||||||
* FilePath : /autoCommit/src/models/WebView.ts
|
|
||||||
* Description : 创建webview
|
|
||||||
* https://github.com/OBKoro1
|
|
||||||
*/
|
|
||||||
|
|
||||||
import * as vscode from 'vscode';
|
|
||||||
import * as path from 'path';
|
|
||||||
import * as fs from 'fs';
|
|
||||||
import { showMessage } from '../util/vscodeUtil';
|
|
||||||
import { webviewMsg } from '../util/dataStatement'
|
|
||||||
|
|
||||||
// webview 设置
|
|
||||||
interface WebviewPanelOption {
|
|
||||||
type: string; // webview type
|
|
||||||
title: string; // webview title
|
|
||||||
fileName: string; // webview 加载的资源
|
|
||||||
}
|
|
||||||
|
|
||||||
class WebView {
|
|
||||||
private currentPanel!: vscode.WebviewPanel;
|
|
||||||
public readonly context: vscode.ExtensionContext;
|
|
||||||
public MessageCallBack: Function; // webview消息回调
|
|
||||||
|
|
||||||
public constructor(context: vscode.ExtensionContext, callBack: Function) {
|
|
||||||
this.context = context;
|
|
||||||
this.MessageCallBack = callBack;
|
|
||||||
}
|
|
||||||
public create(
|
|
||||||
WebviewPanelOption: WebviewPanelOption,
|
|
||||||
column: vscode.ViewColumn = vscode.ViewColumn.One
|
|
||||||
) {
|
|
||||||
// 获取资源地址
|
|
||||||
// TODO: 打包
|
|
||||||
const srcPath = process.env.NODE_ENV !== 'production' ? 'src' : 'dist';
|
|
||||||
this.currentPanel = vscode.window.createWebviewPanel(
|
|
||||||
WebviewPanelOption.type,
|
|
||||||
WebviewPanelOption.title,
|
|
||||||
column,
|
|
||||||
{
|
|
||||||
// 只允许webview加载我们插件的`src/assets`目录下的资源
|
|
||||||
localResourceRoots: [
|
|
||||||
vscode.Uri.file(
|
|
||||||
path.join(this.context.extensionPath, `${srcPath}/assets`)
|
|
||||||
)
|
|
||||||
],
|
|
||||||
// 启用javascript
|
|
||||||
enableScripts: true,
|
|
||||||
retainContextWhenHidden: true // 隐藏保存状态
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const htmlPath = path.join(
|
|
||||||
this.context.extensionPath,
|
|
||||||
`${srcPath}/views/${WebviewPanelOption.fileName}.html`
|
|
||||||
);
|
|
||||||
this.currentPanel.webview.html = this.getWebViewContent(htmlPath);
|
|
||||||
// 接收webview的消息回调
|
|
||||||
this.currentPanel.webview.onDidReceiveMessage(
|
|
||||||
this.handleMessage.bind(this),
|
|
||||||
undefined,
|
|
||||||
this.context.subscriptions
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取html模板内容
|
|
||||||
* @param templatePath 模板文件路径
|
|
||||||
* @param content 模板内容
|
|
||||||
*/
|
|
||||||
private getWebViewContent(templatePath: string, content?: string): string {
|
|
||||||
const dirPath = path.dirname(templatePath);
|
|
||||||
|
|
||||||
content = content || fs.readFileSync(templatePath, 'utf-8');
|
|
||||||
|
|
||||||
content = content.replace(
|
|
||||||
/(<link.+?href="|<script.+?src="|<img.+?src=")(.+?)"/g,
|
|
||||||
(m, $1, $2) => {
|
|
||||||
return `${$1}${vscode.Uri.file(path.resolve(dirPath, $2))
|
|
||||||
.with({ scheme: 'vscode-resource' })
|
|
||||||
.toString()}"`;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关闭webview
|
|
||||||
*/
|
|
||||||
public close() {
|
|
||||||
const panel = this.currentPanel;
|
|
||||||
if (!panel) return;
|
|
||||||
panel.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
// webview消息回调
|
|
||||||
public handleMessage(message: webviewMsg) {
|
|
||||||
const { command, data } = message;
|
|
||||||
if (command === 'event') {
|
|
||||||
this.MessageCallBack(message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
showMessage(data, command);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default WebView;
|
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author : OBKoro1
|
|
||||||
* Date : 2019-12-25 17:08:18
|
|
||||||
* LastEditors : OBKoro1
|
|
||||||
* LastEditTime : 2019-12-26 17:41:05
|
|
||||||
* FilePath : /autoCommit/src/models/index.ts
|
|
||||||
* Description : 插件逻辑入口
|
|
||||||
* https://github.com/OBKoro1
|
|
||||||
*/
|
|
||||||
import * as vscode from 'vscode';
|
|
||||||
import WebView from './WebView';
|
|
||||||
import { webviewMsg } from '../util/dataStatement'
|
|
||||||
|
|
||||||
|
|
||||||
class ExtensionLogic {
|
|
||||||
public readonly context: vscode.ExtensionContext;
|
|
||||||
public MessageCallBack: any;
|
|
||||||
public autoCommitView: WebView;
|
|
||||||
|
|
||||||
public constructor(context: vscode.ExtensionContext) {
|
|
||||||
this.context = context;
|
|
||||||
this.autoCommitView = new WebView(this.context, this.messageCallBack);
|
|
||||||
}
|
|
||||||
createView() {
|
|
||||||
const option = {
|
|
||||||
type: 'autoCommit',
|
|
||||||
title: 'Github自动提交commit工具',
|
|
||||||
fileName: 'autoCommit'
|
|
||||||
}
|
|
||||||
this.autoCommitView.create(option)
|
|
||||||
}
|
|
||||||
// 处理webview的消息
|
|
||||||
private messageCallBack(message: webviewMsg) {
|
|
||||||
if (message.data.id === 'user-login-message') {
|
|
||||||
// this.userLogin(message.params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ExtensionLogic;
|
|
@ -1,23 +0,0 @@
|
|||||||
import * as path from 'path';
|
|
||||||
|
|
||||||
import { runTests } from 'vscode-test';
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
try {
|
|
||||||
// The folder containing the Extension Manifest package.json
|
|
||||||
// Passed to `--extensionDevelopmentPath`
|
|
||||||
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
|
|
||||||
|
|
||||||
// The path to test runner
|
|
||||||
// Passed to --extensionTestsPath
|
|
||||||
const extensionTestsPath = path.resolve(__dirname, './suite/index');
|
|
||||||
|
|
||||||
// Download VS Code, unzip it and run the integration test
|
|
||||||
await runTests({ extensionDevelopmentPath, extensionTestsPath });
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to run tests');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
main();
|
|
@ -1,15 +0,0 @@
|
|||||||
import * as assert from 'assert';
|
|
||||||
|
|
||||||
// You can import and use all API from the 'vscode' module
|
|
||||||
// as well as import your extension to test it
|
|
||||||
import * as vscode from 'vscode';
|
|
||||||
// import * as myExtension from '../extension';
|
|
||||||
|
|
||||||
suite('Extension Test Suite', () => {
|
|
||||||
vscode.window.showInformationMessage('Start all tests.');
|
|
||||||
|
|
||||||
test('Sample test', () => {
|
|
||||||
assert.equal(-1, [1, 2, 3].indexOf(5));
|
|
||||||
assert.equal(-1, [1, 2, 3].indexOf(0));
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,37 +0,0 @@
|
|||||||
import * as path from 'path';
|
|
||||||
import * as Mocha from 'mocha';
|
|
||||||
import * as glob from 'glob';
|
|
||||||
|
|
||||||
export function run(): Promise<void> {
|
|
||||||
// Create the mocha test
|
|
||||||
const mocha = new Mocha({
|
|
||||||
ui: 'tdd',
|
|
||||||
});
|
|
||||||
mocha.useColors(true);
|
|
||||||
|
|
||||||
const testsRoot = path.resolve(__dirname, '..');
|
|
||||||
|
|
||||||
return new Promise((c, e) => {
|
|
||||||
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
|
|
||||||
if (err) {
|
|
||||||
return e(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add files to the test suite
|
|
||||||
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Run the mocha test
|
|
||||||
mocha.run(failures => {
|
|
||||||
if (failures > 0) {
|
|
||||||
e(new Error(`${failures} tests failed.`));
|
|
||||||
} else {
|
|
||||||
c();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
e(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author : OBKoro1
|
|
||||||
* Date : 2019-12-26 15:01:37
|
|
||||||
* LastEditors : OBKoro1
|
|
||||||
* LastEditTime : 2019-12-26 17:24:02
|
|
||||||
* FilePath : /autoCommit/src/models/dataStatement.ts
|
|
||||||
* Description : 数据类型
|
|
||||||
* https://github.com/OBKoro1
|
|
||||||
*/
|
|
||||||
|
|
||||||
interface webviewMsg {
|
|
||||||
command: string; // 回调类型
|
|
||||||
data: any; // 回调数据
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
webviewMsg,
|
|
||||||
};
|
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author : OBKoro1
|
|
||||||
* Date : 2019-12-25 17:13:30
|
|
||||||
* LastEditors : OBKoro1
|
|
||||||
* LastEditTime : 2019-12-26 14:51:21
|
|
||||||
* FilePath : /autoCommit/src/util/vscodeUtil.ts
|
|
||||||
* Description : vscode 相关的公共方法
|
|
||||||
* https://github.com/OBKoro1
|
|
||||||
*/
|
|
||||||
import * as vscode from 'vscode'
|
|
||||||
|
|
||||||
|
|
||||||
let extensionContext = ''
|
|
||||||
|
|
||||||
// 存储插件上下午文
|
|
||||||
function setExtensionContext(context: any) {
|
|
||||||
extensionContext = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取插件上下文
|
|
||||||
function getExtensionContext() {
|
|
||||||
return extensionContext
|
|
||||||
}
|
|
||||||
|
|
||||||
// vscode 消息通知
|
|
||||||
function showMessage(message: string, type = 'error') {
|
|
||||||
const actions: any = {
|
|
||||||
info: () => {
|
|
||||||
vscode.window.showInformationMessage(message)
|
|
||||||
},
|
|
||||||
alert: () => {
|
|
||||||
vscode.window.showWarningMessage(message)
|
|
||||||
},
|
|
||||||
error: () => {
|
|
||||||
vscode.window.showErrorMessage(message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
actions[type]()
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
showMessage, // vscode 消息通知
|
|
||||||
setExtensionContext, // 存储插件上下文
|
|
||||||
getExtensionContext // 获取插件上下文
|
|
||||||
}
|
|
@ -1,101 +0,0 @@
|
|||||||
<!--
|
|
||||||
* @Github: https://github.com/OBKoro1
|
|
||||||
* @Author: OBKoro1
|
|
||||||
* @Date: 2019-06-29 13:27:49
|
|
||||||
* @LastEditors: OBKoro1
|
|
||||||
* @LastEditTime: 2019-11-27 11:32:30
|
|
||||||
* @Description: webview 登录页面
|
|
||||||
-->
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>晓黑板登录</title>
|
|
||||||
|
|
||||||
<link href="../assets/styles/base.css" rel="stylesheet" />
|
|
||||||
<link href="../assets/styles/login.css" rel="stylesheet" />
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="form-container text-center v-cloak" id="xpLogin">
|
|
||||||
<div class="form-head">
|
|
||||||
<p class="form-title">晓黑板账号密码登录</p>
|
|
||||||
</div>
|
|
||||||
<div class="form-input-group">
|
|
||||||
<input ref="elUserName" @keyup.enter="login" type="text" class="form-input" placeholder="一统账号" v-model.number="userName" />
|
|
||||||
</div>
|
|
||||||
<div class="form-input-group">
|
|
||||||
<input ref="elPassword" @keyup.enter="login" type="password" class="form-input" placeholder="一统密码" v-model="password" />
|
|
||||||
</div>
|
|
||||||
<div class="form-input-group">
|
|
||||||
<a href="javascript:;" class="btn-login" @click="login">登录</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="../assets/scripts/vue.min.js"></script>
|
|
||||||
<script>
|
|
||||||
const vscode = acquireVsCodeApi()
|
|
||||||
|
|
||||||
new Vue({
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
// userName: 18850985993,
|
|
||||||
// password: 'HgbOBKoro1'
|
|
||||||
userName: '',
|
|
||||||
password: ''
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.initListener()
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
// 登录
|
|
||||||
login() {
|
|
||||||
const { elUserName, elPassword } = this.$refs
|
|
||||||
const { userName, password } = this.$data
|
|
||||||
const formData = {
|
|
||||||
username: String(userName),
|
|
||||||
password: String(password)
|
|
||||||
}
|
|
||||||
if (!userName) {
|
|
||||||
this.postMessage('用户名不能为空')
|
|
||||||
elUserName.focus()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!password) {
|
|
||||||
this.postMessage('密码不能为空')
|
|
||||||
elPassword.focus()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.postMessage('user-login-message', 'event', formData)
|
|
||||||
},
|
|
||||||
// 发送消息到插件
|
|
||||||
postMessage(text, command = 'alert', params) {
|
|
||||||
vscode.postMessage({
|
|
||||||
command,
|
|
||||||
text,
|
|
||||||
params
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
// 注册
|
|
||||||
initListener() {
|
|
||||||
window.addEventListener('message', event => {
|
|
||||||
console.log('event', event)
|
|
||||||
const { command, data } = event.data
|
|
||||||
console.log('登录成功 addEventListener', event)
|
|
||||||
if (command === 'success') {
|
|
||||||
// 登录成功
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}).$mount('#xpLogin')
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"module": "commonjs",
|
|
||||||
"target": "es6",
|
|
||||||
"outDir": "out",
|
|
||||||
"lib": [
|
|
||||||
"es6"
|
|
||||||
],
|
|
||||||
"sourceMap": true,
|
|
||||||
"rootDir": "src",
|
|
||||||
"strict": true /* enable all strict type-checking options */
|
|
||||||
/* Additional Checks */
|
|
||||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
||||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
||||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
||||||
},
|
|
||||||
"exclude": [
|
|
||||||
"node_modules",
|
|
||||||
".vscode-test"
|
|
||||||
]
|
|
||||||
}
|
|
15
tslint.json
15
tslint.json
@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"rules": {
|
|
||||||
"no-string-throw": true,
|
|
||||||
"no-unused-expression": true,
|
|
||||||
"no-duplicate-variable": true,
|
|
||||||
"curly": true,
|
|
||||||
"class-name": true,
|
|
||||||
"semicolon": [
|
|
||||||
true,
|
|
||||||
"always"
|
|
||||||
],
|
|
||||||
"triple-equals": true
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
# Welcome to your VS Code Extension
|
|
||||||
|
|
||||||
## What's in the folder
|
|
||||||
|
|
||||||
* This folder contains all of the files necessary for your extension.
|
|
||||||
* `package.json` - this is the manifest file in which you declare your extension and command.
|
|
||||||
* The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin.
|
|
||||||
* `src/extension.ts` - this is the main file where you will provide the implementation of your command.
|
|
||||||
* The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
|
|
||||||
* We pass the function containing the implementation of the command as the second parameter to `registerCommand`.
|
|
||||||
|
|
||||||
## Get up and running straight away
|
|
||||||
|
|
||||||
* Press `F5` to open a new window with your extension loaded.
|
|
||||||
* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`.
|
|
||||||
* Set breakpoints in your code inside `src/extension.ts` to debug your extension.
|
|
||||||
* Find output from your extension in the debug console.
|
|
||||||
|
|
||||||
## Make changes
|
|
||||||
|
|
||||||
* You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`.
|
|
||||||
* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes.
|
|
||||||
|
|
||||||
|
|
||||||
## Explore the API
|
|
||||||
|
|
||||||
* You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`.
|
|
||||||
|
|
||||||
## Run tests
|
|
||||||
|
|
||||||
* Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Extension Tests`.
|
|
||||||
* Press `F5` to run the tests in a new window with your extension loaded.
|
|
||||||
* See the output of the test result in the debug console.
|
|
||||||
* Make changes to `src/test/suite/extension.test.ts` or create new test files inside the `test/suite` folder.
|
|
||||||
* The provided test runner will only consider files matching the name pattern `**.test.ts`.
|
|
||||||
* You can create folders inside the `test` folder to structure your tests any way you want.
|
|
||||||
|
|
||||||
## Go further
|
|
||||||
|
|
||||||
* Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension).
|
|
||||||
* [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VSCode extension marketplace.
|
|
||||||
* Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration).
|
|
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author : OBKoro1
|
|
||||||
* Date : 2019-12-26 17:42:32
|
|
||||||
* LastEditors : OBKoro1
|
|
||||||
* LastEditTime : 2019-12-26 17:44:26
|
|
||||||
* FilePath : /autoCommit/webpack.config.js
|
|
||||||
* Description : webpack 配置
|
|
||||||
* https://github.com/OBKoro1
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
//@ts-check
|
|
||||||
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
const path = require('path')
|
|
||||||
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
||||||
const outputPathName = 'dist'
|
|
||||||
|
|
||||||
const pathResolve = p => {
|
|
||||||
return path.resolve(__dirname, p)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**@type {import('webpack').Configuration}*/
|
|
||||||
const config = {
|
|
||||||
target: 'node', // vscode插件运行在Node.js环境中 📖 -> https://webpack.js.org/configuration/node/
|
|
||||||
|
|
||||||
entry: './src/extension.ts', // 插件的入口文件 📖 -> https://webpack.js.org/configuration/entry-context/
|
|
||||||
output: {
|
|
||||||
// 打包好的文件储存在'dist'文件夹中 (请参考package.json), 📖 -> https://webpack.js.org/configuration/output/
|
|
||||||
path: pathResolve(outputPathName),
|
|
||||||
filename: 'extension.js',
|
|
||||||
libraryTarget: 'commonjs2',
|
|
||||||
devtoolModuleFilenameTemplate: '../[resource-path]'
|
|
||||||
},
|
|
||||||
devtool: 'source-map',
|
|
||||||
externals: {
|
|
||||||
vscode: 'commonjs vscode' // vscode-module是热更新的临时目录,所以要排除掉。 在这里添加其他不应该被webpack打包的文件, 📖 -> https://webpack.js.org/configuration/externals/
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
alias: {
|
|
||||||
'~': pathResolve('src')
|
|
||||||
},
|
|
||||||
// 支持读取TypeScript和JavaScript文件, 📖 -> https://github.com/TypeStrong/ts-loader
|
|
||||||
extensions: ['.ts', '.js']
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
test: /\.ts$/,
|
|
||||||
exclude: /node_modules/,
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
loader: 'ts-loader'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
// {
|
|
||||||
// test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
|
||||||
// loader: 'url-loader',
|
|
||||||
// options: {
|
|
||||||
// limit: 10000,
|
|
||||||
// name: pathResolve(`${outputPathName}/fonts/[name].[hash:7].[ext]`)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
new CopyWebpackPlugin([
|
|
||||||
{
|
|
||||||
from: pathResolve('src/views'),
|
|
||||||
to: pathResolve(`${outputPathName}/views`),
|
|
||||||
ignore: ['.*']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
from: pathResolve('src/assets'),
|
|
||||||
to: pathResolve(`${outputPathName}/assets`),
|
|
||||||
ignore: ['.*']
|
|
||||||
}
|
|
||||||
])
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = config
|
|
Loading…
Reference in New Issue
Block a user