mirror of
https://github.com/OBKoro1/autoCommit.git
synced 2024-12-22 09:09:19 +08:00
feat: init eslint
This commit is contained in:
parent
696d85e918
commit
48913a7d35
4
.eslintignore
Normal file
4
.eslintignore
Normal file
@ -0,0 +1,4 @@
|
||||
out
|
||||
node_modules
|
||||
*.vsix
|
||||
src/test
|
16
.eslintrc.js
Normal file
16
.eslintrc.js
Normal file
@ -0,0 +1,16 @@
|
||||
module.exports = {
|
||||
extends: ['airbnb-typescript/base'],
|
||||
parserOptions: {
|
||||
project: './tsconfig.json',
|
||||
},
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint'],
|
||||
rules: {
|
||||
'no-restricted-syntax': 'off',
|
||||
'no-continue': 'off',
|
||||
// 禁止使用 var
|
||||
'no-var': 'error',
|
||||
// 优先使用 interface 而不是 type
|
||||
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
|
||||
},
|
||||
}
|
1901
package-lock.json
generated
1901
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@ -11,7 +11,8 @@
|
||||
"watch": "webpack --mode none --watch",
|
||||
"pretest": "npm run compile",
|
||||
"postinstall": "node ./node_modules/vscode/bin/install",
|
||||
"test": "yarn run compile && node ./node_modules/vscode/bin/test"
|
||||
"test": "yarn run compile && node ./node_modules/vscode/bin/test",
|
||||
"lint": "eslint --ext .ts,.vue src --fix"
|
||||
},
|
||||
"homepage": "https://github.com/OBKoro1/autoCommit",
|
||||
"license": "MIT",
|
||||
@ -79,17 +80,21 @@
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "^12.11.7",
|
||||
"@types/vscode": "^1.41.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.4.1",
|
||||
"@typescript-eslint/parser": "^4.6.1",
|
||||
"copy-webpack-plugin": "^5.1.1",
|
||||
"eslint": "^7.12.1",
|
||||
"eslint-config-airbnb-typescript": "^12.0.0",
|
||||
"glob": "^7.1.5",
|
||||
"mocha": "^6.2.2",
|
||||
"typescript": "^3.9.7",
|
||||
"ts-loader": "^6.2.1",
|
||||
"tslint": "^5.20.0",
|
||||
"typescript": "^3.6.4",
|
||||
"vscode": "^1.1.36",
|
||||
"webpack": "^4.41.4",
|
||||
"webpack-cli": "^3.3.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
"moment": "^2.24.0"
|
||||
}
|
||||
}
|
||||
|
@ -2,26 +2,26 @@
|
||||
* Author : OBKoro1
|
||||
* Date : 2019-12-25 15:15:42
|
||||
* LastEditors : OBKoro1
|
||||
* LastEditTime : 2019-12-31 16:29:11
|
||||
* FilePath : /autoCommit/src/extension.ts
|
||||
* LastEditTime : 2020-12-10 16:36:03
|
||||
* 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'
|
||||
|
||||
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)
|
||||
})
|
||||
setExtensionContext(context);
|
||||
const autoCommit = vscode.commands.registerCommand('extension.autoCommit', () => {
|
||||
const extensionLogic = new ExtensionLogic(context);
|
||||
extensionLogic.init();
|
||||
});
|
||||
|
||||
// 当插件关闭时被清理的可清理列表
|
||||
context.subscriptions.push(autoCommit);
|
||||
context.subscriptions.push(autoCommit);
|
||||
}
|
||||
|
||||
// 扩展被禁用 调用
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Author : OBKoro1
|
||||
* Date : 2019-12-26 13:49:02
|
||||
* @LastEditors : OBKoro1
|
||||
* @LastEditTime : 2020-01-02 21:31:10
|
||||
* FilePath : /autoCommit/src/models/WebView.ts
|
||||
* LastEditors : OBKoro1
|
||||
* LastEditTime : 2020-12-10 17:15:43
|
||||
* FilePath : \autoCommit\src\models\WebView.ts
|
||||
* Description : 创建webview
|
||||
* https://github.com/OBKoro1
|
||||
*/
|
||||
@ -12,7 +12,7 @@ import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import { showMessage, isProduction } from '../util/vscodeUtil';
|
||||
import { webviewMsg } from '../util/dataStatement';
|
||||
import { WebviewMsg } from '../util/dataStatement';
|
||||
|
||||
// webview 设置
|
||||
interface WebviewPanelOption {
|
||||
@ -21,18 +21,41 @@ interface WebviewPanelOption {
|
||||
fileName: string; // webview 加载的资源
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取html模板内容
|
||||
* @param templatePath 模板文件路径
|
||||
* @param content 模板内容
|
||||
*/
|
||||
const getWebViewContent = (templatePath: string, content?: string): string => {
|
||||
const dirPath = path.dirname(templatePath);
|
||||
|
||||
let res:string = content || fs.readFileSync(templatePath, 'utf-8');
|
||||
|
||||
res = res.replace(
|
||||
/(<link.+?href="|<script.+?src="|<img.+?src=")(.+?)"/g,
|
||||
(m, $1, $2) => `${$1}${vscode.Uri.file(path.resolve(dirPath, $2))
|
||||
.with({ scheme: 'vscode-resource' })
|
||||
.toString()}"`,
|
||||
);
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
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
|
||||
column: vscode.ViewColumn = vscode.ViewColumn.One,
|
||||
) {
|
||||
// 获取资源地址
|
||||
const srcPath = isProduction() ? 'out' : 'src';
|
||||
@ -44,49 +67,27 @@ class WebView {
|
||||
// 只允许webview加载我们插件的`src/assets`目录下的资源
|
||||
localResourceRoots: [
|
||||
vscode.Uri.file(
|
||||
path.join(this.context.extensionPath, `${srcPath}/assets`)
|
||||
)
|
||||
path.join(this.context.extensionPath, `${srcPath}/assets`),
|
||||
),
|
||||
],
|
||||
// 启用javascript
|
||||
enableScripts: true,
|
||||
retainContextWhenHidden: true // 隐藏保存状态
|
||||
}
|
||||
retainContextWhenHidden: true, // 隐藏保存状态
|
||||
},
|
||||
);
|
||||
const htmlPath = path.join(
|
||||
this.context.extensionPath,
|
||||
`${srcPath}/views/${WebviewPanelOption.fileName}.html`
|
||||
`${srcPath}/views/${WebviewPanelOption.fileName}.html`,
|
||||
);
|
||||
this.currentPanel.webview.html = this.getWebViewContent(htmlPath);
|
||||
this.currentPanel.webview.html = getWebViewContent(htmlPath);
|
||||
// 接收webview的消息回调
|
||||
this.currentPanel.webview.onDidReceiveMessage(
|
||||
this.handleMessage.bind(this),
|
||||
undefined,
|
||||
this.context.subscriptions
|
||||
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
|
||||
*/
|
||||
@ -96,7 +97,7 @@ class WebView {
|
||||
}
|
||||
|
||||
// webview消息回调
|
||||
public handleMessage(message: webviewMsg) {
|
||||
public handleMessage(message: WebviewMsg) {
|
||||
const { command, data } = message;
|
||||
if (command !== 'msg') {
|
||||
this.MessageCallBack(message);
|
||||
|
@ -2,43 +2,90 @@
|
||||
* Author : OBKoro1
|
||||
* Date : 2019-12-30 16:59:30
|
||||
* LastEditors : OBKoro1
|
||||
* LastEditTime : 2020-08-31 11:33:00
|
||||
* LastEditTime : 2020-12-10 18:51:54
|
||||
* FilePath : \autoCommit\src\models\commitHandle.ts
|
||||
* Description : commit 具体操作
|
||||
* https://github.com/OBKoro1
|
||||
*/
|
||||
|
||||
import { webviewMsg } from '../util/dataStatement';
|
||||
import * as moment from 'moment';
|
||||
import * as fs from 'fs';
|
||||
import { execSync, exec } from 'child_process';
|
||||
import { exec } from 'child_process';
|
||||
import { sep } from 'path';
|
||||
import { WebviewMsg } from '../util/dataStatement';
|
||||
import { RandomNumber } from '../util/util';
|
||||
import {
|
||||
getPanelWebview,
|
||||
outputLog,
|
||||
isProduction,
|
||||
getExtensionContext
|
||||
getExtensionContext,
|
||||
} from '../util/vscodeUtil';
|
||||
import WebView from './WebView';
|
||||
import { sep } from 'path';
|
||||
|
||||
interface timeElement {
|
||||
interface TimeElement {
|
||||
value: Array<string>;
|
||||
commitNumber: number;
|
||||
}
|
||||
|
||||
interface dayTime {
|
||||
interface DayTime {
|
||||
value: string;
|
||||
commitNumber: number;
|
||||
}
|
||||
|
||||
// 获取两个日期之间的间隔: [ '2019-02-02', '2019-02-03' ... ]
|
||||
const getAllDay = (begin: string, end: string) => {
|
||||
const timeArr = [];
|
||||
const beginSplit: Array<string> = begin.split('-');
|
||||
const endSplit: Array<string> = end.split('-');
|
||||
const beginDate = new Date();
|
||||
beginDate.setUTCFullYear(
|
||||
Number(beginSplit[0]),
|
||||
Number(beginSplit[1]) - 1,
|
||||
Number(beginSplit[2]),
|
||||
);
|
||||
const endDate = new Date();
|
||||
endDate.setUTCFullYear(
|
||||
Number(endSplit[0]),
|
||||
Number(endSplit[1]) - 1,
|
||||
Number(endSplit[2]),
|
||||
);
|
||||
const beginNumber = beginDate.getTime();
|
||||
const endNumber = endDate.getTime();
|
||||
for (let k: any = beginNumber; k <= endNumber;) {
|
||||
// eslint-disable-next-line radix
|
||||
const day = new Date(parseInt(k));
|
||||
const dayFormat = moment(day).format('YYYY-MM-DD');
|
||||
timeArr.push(dayFormat);
|
||||
k += 24 * 60 * 60 * 1000;
|
||||
}
|
||||
return timeArr;
|
||||
};
|
||||
|
||||
// 获取当天的随机时间
|
||||
const getTodayRandomNumber = (time: string) => {
|
||||
const hour1 = RandomNumber(0, 2);
|
||||
let hour2 = RandomNumber(0, 9);
|
||||
if (hour1 === 2) {
|
||||
// 小时第一个数字为2 则小时第二个数字最多为3
|
||||
hour2 = RandomNumber(0, 3);
|
||||
}
|
||||
const minute = `${RandomNumber(0, 5)}${RandomNumber(0, 9)}`;
|
||||
const hour = `${hour1}${hour2}`;
|
||||
return `${time} ${hour}:${minute}`;
|
||||
};
|
||||
|
||||
class CommitHandle {
|
||||
public paramsObj: any;
|
||||
|
||||
public moreObj: any;
|
||||
public timeArr: Array<dayTime>;
|
||||
|
||||
public timeArr: Array<DayTime>;
|
||||
|
||||
public autoCommitView: WebView;
|
||||
|
||||
private userCancel: boolean;
|
||||
constructor(message: webviewMsg) {
|
||||
|
||||
constructor(message: WebviewMsg) {
|
||||
this.paramsObj = message.data.form;
|
||||
this.moreObj = message.data.moreObj;
|
||||
this.timeArr = [];
|
||||
@ -46,94 +93,95 @@ class CommitHandle {
|
||||
this.autoCommitView = getPanelWebview();
|
||||
this.userCancel = false;
|
||||
}
|
||||
|
||||
// 处理所有时间段
|
||||
timeHandle() {
|
||||
// 处理所有时间范围
|
||||
this.paramsObj.timeArr.forEach((item: timeElement) => {
|
||||
this.paramsObj.timeArr.forEach((item: TimeElement) => {
|
||||
// 获取每个时间范围的具体日期
|
||||
let detailTimeArr = this.getAllDay(item.value[0], item.value[1]);
|
||||
const detailTimeArr = getAllDay(item.value[0], item.value[1]);
|
||||
// 日期去重 组织数据
|
||||
detailTimeArr.forEach(ele => {
|
||||
let index = this.timeArr.findIndex(element => {
|
||||
return element.value === ele;
|
||||
});
|
||||
detailTimeArr.forEach((ele) => {
|
||||
const index = this.timeArr.findIndex((element) => element.value === ele);
|
||||
// 删除重复日期
|
||||
if (index !== -1) {
|
||||
this.timeArr.splice(index, 1);
|
||||
}
|
||||
this.timeArr.push({
|
||||
value: ele,
|
||||
commitNumber: item.commitNumber
|
||||
commitNumber: item.commitNumber,
|
||||
});
|
||||
});
|
||||
});
|
||||
this.sortTime();
|
||||
}
|
||||
|
||||
// 日期排序
|
||||
sortTime() {
|
||||
this.timeArr = this.timeArr.sort(
|
||||
(item1: dayTime, item2: dayTime): number => {
|
||||
(item1: DayTime, item2: DayTime): number => {
|
||||
const dateArr1: Array<any> = item1.value.split('-');
|
||||
const dateArr2: Array<any> = item2.value.split('-');
|
||||
if (dateArr1[0] === dateArr2[0]) {
|
||||
if (dateArr1[1] === dateArr2[1]) {
|
||||
// 日期不同就比较日期
|
||||
return dateArr1[2] - dateArr2[2];
|
||||
} else {
|
||||
// 月份不同就比较月份
|
||||
return dateArr1[1] - dateArr2[1];
|
||||
}
|
||||
} else {
|
||||
// 年份不同就比较年份
|
||||
return dateArr1[0] - dateArr2[0];
|
||||
// 月份不同就比较月份
|
||||
return dateArr1[1] - dateArr2[1];
|
||||
}
|
||||
}
|
||||
// 年份不同就比较年份
|
||||
return dateArr1[0] - dateArr2[0];
|
||||
},
|
||||
);
|
||||
this.deleteDayArrDay()
|
||||
this.commitFn()
|
||||
this.deleteDayArrDay();
|
||||
this.commitFn();
|
||||
}
|
||||
|
||||
// 随机删除日期数组中的某几天
|
||||
deleteDayArrDay() {
|
||||
const noCommitDay = this.moreObj.noCommitDay
|
||||
const scopeDay = this.moreObj.scopeDay
|
||||
if(scopeDay < 1 || noCommitDay < 1) return // 必须大于1
|
||||
if(scopeDay > this.timeArr.length) return // 日期不够
|
||||
const { noCommitDay } = this.moreObj;
|
||||
const { scopeDay } = this.moreObj;
|
||||
if (scopeDay < 1 || noCommitDay < 1) return; // 必须大于1
|
||||
if (scopeDay > this.timeArr.length) return; // 日期不够
|
||||
// 删除
|
||||
for(let i = 0; i < noCommitDay; i++){
|
||||
let ranDomNum = Math.floor(Math.random() * this.timeArr.length); // 随机数
|
||||
this.timeArr.splice(ranDomNum, 1);
|
||||
}
|
||||
for (let i = 0; i < noCommitDay; i++) {
|
||||
const ranDomNum = Math.floor(Math.random() * this.timeArr.length); // 随机数
|
||||
this.timeArr.splice(ranDomNum, 1);
|
||||
}
|
||||
}
|
||||
|
||||
async commitFn() {
|
||||
await outputLog('将要commit的日期:', JSON.stringify(this.timeArr));
|
||||
let totalNum = 0; // 总commit次数
|
||||
// 遍历日期
|
||||
for (let item of this.timeArr.values()) {
|
||||
for (const item of this.timeArr.values()) {
|
||||
if (this.cancelCommit()) break;
|
||||
// 每个日期commit次数
|
||||
let dayCommitNumber = this.getDayCommitNumber(item);
|
||||
if(sep === '\\'){
|
||||
const reg = new RegExp(/\\/g)
|
||||
const dayCommitNumber = this.getDayCommitNumber(item);
|
||||
if (sep === '\\') {
|
||||
const reg = new RegExp(/\\/g);
|
||||
this.paramsObj.itemSrc = `${this.paramsObj.itemSrc.replace(reg, '/')}`;
|
||||
}
|
||||
|
||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||
for (let i = 0; i < dayCommitNumber; i++) {
|
||||
if (this.cancelCommit()) break;
|
||||
let time = this.formatTime(item.value); // 2019-01-02 08:00
|
||||
let time = getTodayRandomNumber(item.value); // 2019-01-02 08:00
|
||||
time = moment(time).format(); // 2019-01-02T00:00:00+0800
|
||||
let commitContent = this.commitFileContent(time, totalNum);
|
||||
const commitContent = this.commitFileContent(time, totalNum);
|
||||
let commitMsg: string = '';
|
||||
const isDebug = false; // 手动更改调试模拟是否提交git
|
||||
if (!isProduction() || !isDebug) {
|
||||
try {
|
||||
// 异步执行命令 让出线程 打印日志 等
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
commitMsg = await new Promise((resolve, reject) => {
|
||||
const cmd = `git add . && git commit -m '${this.paramsObj.commitMsg}' --date='${time}'`;
|
||||
exec(cmd, {
|
||||
encoding: 'utf8',
|
||||
cwd: this.paramsObj.itemSrc,
|
||||
env: undefined
|
||||
},(error, stdout, stderr) => {
|
||||
env: undefined,
|
||||
}, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
outputLog(`执行命令出错:${cmd}`);
|
||||
outputLog(`错误信息:${error}`, stderr);
|
||||
@ -148,7 +196,8 @@ class CommitHandle {
|
||||
}
|
||||
} else {
|
||||
// 模拟git提交
|
||||
const test = await new Promise((resolve, reject) => {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
outputLog('延迟一秒');
|
||||
resolve('延迟一秒');
|
||||
@ -157,11 +206,12 @@ class CommitHandle {
|
||||
}
|
||||
outputLog(`${totalNum + 1}commit内容`, commitContent);
|
||||
outputLog(`${totalNum + 1}commit信息`, commitMsg);
|
||||
totalNum++;
|
||||
totalNum += 1;
|
||||
}
|
||||
}
|
||||
this.pushCommitFn(totalNum);
|
||||
}
|
||||
|
||||
async pushCommitFn(totalNum: number) {
|
||||
const commitNumberBig = 100; // commit数量过大
|
||||
let thinkNumber = 10000; // 考虑时间 避免运行过快导致误操作
|
||||
@ -171,7 +221,7 @@ class CommitHandle {
|
||||
} else {
|
||||
thinkNumber = 2000; // 无感 考虑两秒
|
||||
}
|
||||
await new Promise((resolve, reject) => {
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, thinkNumber);
|
||||
@ -184,17 +234,17 @@ class CommitHandle {
|
||||
outputLog('提交中...');
|
||||
this.autoCommitView.postMessage('提交中...', '提交中');
|
||||
const res = await new Promise((resolve, reject) => {
|
||||
const cmd = `git pull && git push`;
|
||||
exec(cmd,{
|
||||
const cmd = 'git pull && git push';
|
||||
exec(cmd, {
|
||||
encoding: 'utf8',
|
||||
cwd: this.paramsObj.itemSrc,
|
||||
env: undefined
|
||||
},(error, stdout, stderr) => {
|
||||
env: undefined,
|
||||
}, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
outputLog(`执行命令出错:${cmd}`);
|
||||
outputLog(`错误信息:${error}`, stderr);
|
||||
outputLog(
|
||||
`git push失败很可能是你的网络有问题,请换到一个网络状况比较良好的地方,然后再项目下执行 git push操作。`
|
||||
'git push失败很可能是你的网络有问题,请换到一个网络状况比较良好的地方,然后再项目下执行 git push操作。',
|
||||
);
|
||||
reject(error);
|
||||
return;
|
||||
@ -206,12 +256,13 @@ class CommitHandle {
|
||||
this.commitEnd(totalNum);
|
||||
}
|
||||
}
|
||||
|
||||
async resetCommit(totalNum: number) {
|
||||
this.autoCommitView.postMessage('回滚', '回滚');
|
||||
outputLog('回滚中...');
|
||||
return await new Promise((resolve, reject) => {
|
||||
const p = await new Promise((resolve, reject) => {
|
||||
const cmd = `git reset --hard HEAD~${totalNum}`;
|
||||
exec(cmd,{
|
||||
exec(cmd, {
|
||||
encoding: 'utf8',
|
||||
cwd: this.paramsObj.itemSrc,
|
||||
}, (error, stdout, stderr) => {
|
||||
@ -225,7 +276,9 @@ class CommitHandle {
|
||||
resolve(stdout);
|
||||
});
|
||||
});
|
||||
return p;
|
||||
}
|
||||
|
||||
commitEnd(totalNum: number, cancel: boolean = false) {
|
||||
this.userCancel = false; // 重新打开终止开关
|
||||
if (!cancel) {
|
||||
@ -235,30 +288,34 @@ class CommitHandle {
|
||||
}
|
||||
outputLog('保存参数信息');
|
||||
}
|
||||
|
||||
cancelCommit() {
|
||||
if (this.userCancel) {
|
||||
outputLog('终止自动commit');
|
||||
}
|
||||
return this.userCancel;
|
||||
}
|
||||
|
||||
public closeCommit() {
|
||||
this.userCancel = true;
|
||||
}
|
||||
|
||||
// 组织commit文件的内容
|
||||
commitFileContent(time: string, totalNum: number) {
|
||||
const commitContent = `${time}\n随机数:${RandomNumber(
|
||||
1,
|
||||
100000
|
||||
100000,
|
||||
)}\n提交次数:${totalNum + 1}`;
|
||||
// 写入内容
|
||||
fs.writeFileSync(
|
||||
`${this.paramsObj.itemSrc}/${this.paramsObj.fileName}`,
|
||||
commitContent,
|
||||
'utf-8'
|
||||
'utf-8',
|
||||
);
|
||||
return commitContent;
|
||||
}
|
||||
getDayCommitNumber(item: dayTime) {
|
||||
|
||||
getDayCommitNumber(item: DayTime) {
|
||||
let dayCommitNumber = this.paramsObj.commitNumber;
|
||||
if (this.paramsObj.randomCommit) {
|
||||
// 随机commit次数
|
||||
@ -270,45 +327,6 @@ class CommitHandle {
|
||||
}
|
||||
return dayCommitNumber;
|
||||
}
|
||||
// 获取当天的随机时间
|
||||
formatTime(time: string) {
|
||||
const hour1 = RandomNumber(0, 2);
|
||||
let hour2 = RandomNumber(0, 9);
|
||||
if (hour1 === 2) {
|
||||
// 小时第一个数字为2 则小时第二个数字最多为3
|
||||
hour2 = RandomNumber(0, 3);
|
||||
}
|
||||
const minute = `${RandomNumber(0, 5)}${RandomNumber(0, 9)}`;
|
||||
const hour = `${hour1}${hour2}`;
|
||||
return `${time} ${hour}:${minute}`;
|
||||
}
|
||||
// 获取两个日期之间的间隔: [ '2019-02-02', '2019-02-03' ... ]
|
||||
getAllDay(begin: string, end: string) {
|
||||
const timeArr = [];
|
||||
const beginSplit: Array<string> = begin.split('-');
|
||||
const endSplit: Array<string> = end.split('-');
|
||||
const beginDate = new Date();
|
||||
beginDate.setUTCFullYear(
|
||||
Number(beginSplit[0]),
|
||||
Number(beginSplit[1]) - 1,
|
||||
Number(beginSplit[2])
|
||||
);
|
||||
const endDate = new Date();
|
||||
endDate.setUTCFullYear(
|
||||
Number(endSplit[0]),
|
||||
Number(endSplit[1]) - 1,
|
||||
Number(endSplit[2])
|
||||
);
|
||||
const beginNumber = beginDate.getTime();
|
||||
const endNumber = endDate.getTime();
|
||||
for (let k: any = beginNumber; k <= endNumber; ) {
|
||||
const day = new Date(parseInt(k));
|
||||
const dayFormat = moment(day).format('YYYY-MM-DD');
|
||||
timeArr.push(dayFormat);
|
||||
k = k + 24 * 60 * 60 * 1000;
|
||||
}
|
||||
return timeArr;
|
||||
}
|
||||
}
|
||||
|
||||
export default CommitHandle;
|
||||
|
@ -2,49 +2,67 @@
|
||||
* Author : OBKoro1
|
||||
* Date : 2019-12-25 17:08:18
|
||||
* LastEditors : OBKoro1
|
||||
* LastEditTime : 2020-01-09 21:47:12
|
||||
* FilePath : /autoCommit/src/models/index.ts
|
||||
* LastEditTime : 2020-12-10 16:39:26
|
||||
* 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';
|
||||
import { setPanelWebview, isProduction } from '../util/vscodeUtil';
|
||||
import CommitHandle from './commitHandle';
|
||||
import { outputLog } from '../util/vscodeUtil';
|
||||
import * as fs from 'fs';
|
||||
import { sep } from 'path';
|
||||
import WebView from './WebView';
|
||||
import { WebviewMsg } from '../util/dataStatement';
|
||||
import { setPanelWebview, isProduction, outputLog } from '../util/vscodeUtil';
|
||||
import CommitHandle from './commitHandle';
|
||||
|
||||
const hasGit = (itemSrc: string) => {
|
||||
const url = `${itemSrc}${sep}.git`; // 文件路径
|
||||
try {
|
||||
const isDirectory = fs.statSync(url).isDirectory(); // 判断是否为文件夹 返回布尔值
|
||||
if (isDirectory) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class ExtensionLogic {
|
||||
public readonly context: vscode.ExtensionContext;
|
||||
public MessageCallBack: any;
|
||||
public autoCommitView: WebView;
|
||||
|
||||
public autoCommitView!: WebView ; // 告诉ts我已经对它初始化了
|
||||
|
||||
public CommitHandle: any;
|
||||
|
||||
public constructor(context: vscode.ExtensionContext) {
|
||||
// 存储参数
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public init() {
|
||||
this.autoCommitView = new WebView(
|
||||
this.context,
|
||||
this.messageCallBack.bind(this)
|
||||
);
|
||||
this.messageCallBack.bind(this),
|
||||
) as WebView;
|
||||
setPanelWebview(this.autoCommitView);
|
||||
this.createView();
|
||||
}
|
||||
|
||||
createView() {
|
||||
const option = {
|
||||
type: 'autoCommit',
|
||||
title: 'autoCommit',
|
||||
fileName: 'autoCommit'
|
||||
fileName: 'autoCommit',
|
||||
};
|
||||
this.autoCommitView.create(option);
|
||||
this.autoCommitView.postMessage('isProduction', isProduction());
|
||||
const formData = this.context.globalState.get('commit-params')
|
||||
this.autoCommitView.postMessage('init-formData', formData)
|
||||
|
||||
const formData = this.context.globalState.get('commit-params');
|
||||
this.autoCommitView.postMessage('init-formData', formData);
|
||||
}
|
||||
|
||||
// 处理webview的消息
|
||||
private messageCallBack(message: webviewMsg) {
|
||||
private messageCallBack(message: WebviewMsg) {
|
||||
if (message.command === 'commit') {
|
||||
this.CommitHandle = new CommitHandle(message);
|
||||
} else if (message.command === 'choose-item') {
|
||||
@ -53,40 +71,28 @@ class ExtensionLogic {
|
||||
this.CommitHandle.closeCommit();
|
||||
}
|
||||
}
|
||||
|
||||
// 选择项目文件夹
|
||||
async publishChooseFile() {
|
||||
const urlArr: any = await vscode.window.showOpenDialog({
|
||||
canSelectFiles: false, // 允许选择文件
|
||||
canSelectFolders: true, // 是否可以选择文件夹
|
||||
canSelectMany: false // 是否可以选择多个文件
|
||||
canSelectMany: false, // 是否可以选择多个文件
|
||||
});
|
||||
if (!urlArr) return; // 用户取消选择
|
||||
let itemSrc = urlArr[0].path;
|
||||
if(sep === `\\`){
|
||||
if (sep === '\\') {
|
||||
// window 系統用不同的路径
|
||||
itemSrc = urlArr[0].fsPath;
|
||||
itemSrc = urlArr[0].fsPath;
|
||||
}
|
||||
|
||||
if (this.hasGit(itemSrc)) {
|
||||
if (hasGit(itemSrc)) {
|
||||
this.autoCommitView.postMessage('choose item success', itemSrc);
|
||||
} else {
|
||||
this.autoCommitView.postMessage('choose item error', itemSrc);
|
||||
outputLog('项目地址错误', `${itemSrc}根目录没有.git文件夹`);
|
||||
}
|
||||
}
|
||||
public hasGit(itemSrc: string) {
|
||||
const url = `${itemSrc}${sep}.git`; // 文件路径
|
||||
try {
|
||||
let isDirectory = fs.statSync(url).isDirectory(); // 判断是否为文件夹 返回布尔值
|
||||
if (isDirectory) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default ExtensionLogic;
|
||||
|
@ -1,22 +0,0 @@
|
||||
//
|
||||
// Note: This example test is leveraging the Mocha test framework.
|
||||
// Please refer to their documentation on https://mochajs.org/ for help.
|
||||
//
|
||||
|
||||
// The module 'assert' provides assertion methods from node
|
||||
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';
|
||||
|
||||
// Defines a Mocha test suite to group tests of similar kind together
|
||||
suite("Extension Tests", function () {
|
||||
|
||||
// Defines a Mocha unit test
|
||||
test("Something 1", function() {
|
||||
assert.equal(-1, [1, 2, 3].indexOf(5));
|
||||
assert.equal(-1, [1, 2, 3].indexOf(0));
|
||||
});
|
||||
});
|
@ -16,8 +16,8 @@ import * as testRunner from 'vscode/lib/testrunner';
|
||||
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options
|
||||
// for more info
|
||||
testRunner.configure({
|
||||
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
|
||||
useColors: true // colored output from test results
|
||||
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
|
||||
useColors: true, // colored output from test results
|
||||
});
|
||||
|
||||
module.exports = testRunner;
|
||||
module.exports = testRunner;
|
||||
|
@ -2,17 +2,13 @@
|
||||
* Author : OBKoro1
|
||||
* Date : 2019-12-26 15:01:37
|
||||
* LastEditors : OBKoro1
|
||||
* LastEditTime : 2019-12-26 17:24:02
|
||||
* FilePath : /autoCommit/src/models/dataStatement.ts
|
||||
* LastEditTime : 2020-12-10 18:52:26
|
||||
* FilePath : \autoCommit\src\util\dataStatement.ts
|
||||
* Description : 数据类型
|
||||
* https://github.com/OBKoro1
|
||||
*/
|
||||
|
||||
interface webviewMsg {
|
||||
export interface WebviewMsg {
|
||||
command: string; // 回调类型
|
||||
data: any; // 回调数据
|
||||
}
|
||||
|
||||
export {
|
||||
webviewMsg,
|
||||
};
|
||||
|
@ -2,17 +2,19 @@
|
||||
* Author : OBKoro1
|
||||
* Date : 2019-12-27 15:55:42
|
||||
* LastEditors : OBKoro1
|
||||
* LastEditTime : 2019-12-27 15:57:54
|
||||
* FilePath : /autoCommit/src/util/util.ts
|
||||
* LastEditTime : 2020-12-10 18:57:11
|
||||
* FilePath : \autoCommit\src\util\util.ts
|
||||
* Description : 公共函数
|
||||
* https://github.com/OBKoro1
|
||||
*/
|
||||
|
||||
// 生成指定范围的随机数
|
||||
function RandomNumber(min: number, max: number): number {
|
||||
/**
|
||||
* @description: 生成指定范围的随机数
|
||||
* @param {number} min
|
||||
* @param {number} max
|
||||
* @return {*}
|
||||
*/
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export function RandomNumber(min: number, max: number): number {
|
||||
return Math.round(Math.random() * (max - min)) + min;
|
||||
}
|
||||
|
||||
export {
|
||||
RandomNumber // 生成指定范围的随机数
|
||||
};
|
||||
|
@ -54,7 +54,7 @@ function showMessage(message: string, type = 'error') {
|
||||
},
|
||||
error: () => {
|
||||
vscode.window.showErrorMessage(message);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
actions[type]();
|
||||
@ -67,5 +67,5 @@ export {
|
||||
setPanelWebview, // 存储webview
|
||||
showMessage, // vscode 消息通知
|
||||
setExtensionContext, // 存储插件上下文
|
||||
getExtensionContext // 获取插件上下文
|
||||
getExtensionContext, // 获取插件上下文
|
||||
};
|
||||
|
@ -14,6 +14,7 @@
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
"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"
|
||||
}
|
1856
yarn-error.log
1856
yarn-error.log
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user