mirror of
https://github.com/OBKoro1/autoCommit.git
synced 2025-01-07 05:25:55 +08:00
数据格式重构以及完成测试模式
This commit is contained in:
parent
5e7b687ccf
commit
54b79a2ed3
@ -1,3 +1,6 @@
|
|||||||
# autoCommit
|
# autoCommit
|
||||||
|
|
||||||
# 用于学习交流
|
# 用于学习交流
|
||||||
|
|
||||||
|
|
||||||
|
<!-- TODO: 前面先选中的日期会覆盖后面的日期 -->
|
@ -2,7 +2,7 @@
|
|||||||
* Author : OBKoro1
|
* Author : OBKoro1
|
||||||
* Date : 2019-12-30 16:59:30
|
* Date : 2019-12-30 16:59:30
|
||||||
* LastEditors : OBKoro1
|
* LastEditors : OBKoro1
|
||||||
* LastEditTime : 2019-12-31 18:00:43
|
* LastEditTime : 2020-01-01 17:32:41
|
||||||
* FilePath : /autoCommit/src/models/commitHandle.ts
|
* FilePath : /autoCommit/src/models/commitHandle.ts
|
||||||
* Description : commit 具体操作
|
* Description : commit 具体操作
|
||||||
* https://github.com/OBKoro1
|
* https://github.com/OBKoro1
|
||||||
@ -13,99 +13,144 @@ import * as moment from 'moment';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import { RandomNumber } from '../util/util';
|
import { RandomNumber } from '../util/util';
|
||||||
import { getPanelWebview, outputLog } from '../util/vscodeUtil';
|
import { getPanelWebview, outputLog, isProduction } from '../util/vscodeUtil';
|
||||||
import WebView from './WebView';
|
import WebView from './WebView';
|
||||||
|
|
||||||
|
interface timeElement {
|
||||||
|
value: Array<string>;
|
||||||
|
commitNumber: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface dayTime {
|
||||||
|
value: string;
|
||||||
|
commitNumber: number;
|
||||||
|
}
|
||||||
|
|
||||||
class CommitHandle {
|
class CommitHandle {
|
||||||
public paramsObj: any;
|
public paramsObj: any;
|
||||||
public timeArr: Array<string>;
|
public timeArr: Array<dayTime>;
|
||||||
public autoCommitView: WebView;
|
public autoCommitView: WebView;
|
||||||
|
private userCancel: boolean;
|
||||||
constructor(message: webviewMsg) {
|
constructor(message: webviewMsg) {
|
||||||
this.paramsObj = message.data;
|
this.paramsObj = message.data;
|
||||||
this.timeArr = [];
|
this.timeArr = [];
|
||||||
this.timeHandle();
|
this.timeHandle();
|
||||||
this.autoCommitView = getPanelWebview();
|
this.autoCommitView = getPanelWebview();
|
||||||
|
this.userCancel = false;
|
||||||
}
|
}
|
||||||
// 处理所有时间段
|
// 处理所有时间段
|
||||||
timeHandle() {
|
timeHandle() {
|
||||||
// 处理所有时间范围
|
// 处理所有时间范围
|
||||||
this.paramsObj.formatTime.forEach((item: Array<string>) => {
|
this.paramsObj.timeArr.forEach((item: timeElement) => {
|
||||||
// 获取每个时间范围的具体日期
|
// 获取每个时间范围的具体日期
|
||||||
let detailTimeArr = this.getAllDay(item[0], item[1]);
|
let detailTimeArr = this.getAllDay(item.value[0], item.value[1]);
|
||||||
// 日期去重
|
// 日期去重 组织数据
|
||||||
detailTimeArr = detailTimeArr.filter(ele => {
|
detailTimeArr.forEach(ele => {
|
||||||
return !this.timeArr.includes(ele);
|
let index = this.timeArr.findIndex(element => {
|
||||||
|
return element.value === ele;
|
||||||
|
});
|
||||||
|
// 添加不存在的日期
|
||||||
|
if (index === -1) {
|
||||||
|
this.timeArr.push({
|
||||||
|
value: ele,
|
||||||
|
commitNumber: item.commitNumber
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// TODO: commit number
|
|
||||||
// if(){
|
|
||||||
|
|
||||||
// }
|
|
||||||
// detailTimeArr.map(element=>{
|
|
||||||
// return {
|
|
||||||
// time: element
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
this.timeArr.push(...detailTimeArr);
|
|
||||||
});
|
});
|
||||||
this.sortTime();
|
this.sortTime();
|
||||||
}
|
}
|
||||||
// 日期排序
|
// 日期排序
|
||||||
sortTime() {
|
sortTime() {
|
||||||
this.timeArr = this.timeArr.sort((item1: string, item2: string): number => {
|
this.timeArr = this.timeArr.sort(
|
||||||
const dateArr1: Array<any> = item1.split('-');
|
(item1: dayTime, item2: dayTime): number => {
|
||||||
const dateArr2: Array<any> = item2.split('-');
|
const dateArr1: Array<any> = item1.value.split('-');
|
||||||
if (dateArr1[0] === dateArr2[0]) {
|
const dateArr2: Array<any> = item2.value.split('-');
|
||||||
if (dateArr1[1] === dateArr2[1]) {
|
if (dateArr1[0] === dateArr2[0]) {
|
||||||
// 日期不同就比较日期
|
if (dateArr1[1] === dateArr2[1]) {
|
||||||
return dateArr1[2] - dateArr2[2];
|
// 日期不同就比较日期
|
||||||
|
return dateArr1[2] - dateArr2[2];
|
||||||
|
} else {
|
||||||
|
// 月份不同就比较月份
|
||||||
|
return dateArr1[1] - dateArr2[1];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 月份不同就比较月份
|
// 年份不同就比较年份
|
||||||
return dateArr1[1] - dateArr2[1];
|
return dateArr1[0] - dateArr2[0];
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// 年份不同就比较年份
|
|
||||||
return dateArr1[0] - dateArr2[0];
|
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
this.commitFn();
|
this.commitFn();
|
||||||
}
|
}
|
||||||
// TODO: 中断
|
async commitFn() {
|
||||||
commitFn() {
|
outputLog('将要commit的日期:', JSON.stringify(this.timeArr));
|
||||||
outputLog('将要commit的日期:', this.timeArr);
|
|
||||||
outputLog('每个日期提交次数:', this.paramsObj.commitNumber);
|
|
||||||
let totalNum = 0; // 总commit次数
|
let totalNum = 0; // 总commit次数
|
||||||
// 遍历日期
|
// 遍历日期
|
||||||
this.timeArr.forEach(item => {
|
for (let item of this.timeArr.values()) {
|
||||||
|
if (this.cancelCommit()) break;
|
||||||
// 每个日期commit次数
|
// 每个日期commit次数
|
||||||
for (let i = 0; i < this.paramsObj.commitNumber; i++) {
|
let dayCommitNumber = this.paramsObj.commitNumber;
|
||||||
let time = this.formatTime(item); // 2019-01-02 08:00
|
if (item.commitNumber !== 0) {
|
||||||
|
// 如果该范围有commit次数 则用该范围的
|
||||||
|
dayCommitNumber = item.commitNumber;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < dayCommitNumber; i++) {
|
||||||
|
if (this.cancelCommit()) break;
|
||||||
|
let time = this.formatTime(item.value); // 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} \n 随机数:${RandomNumber(1, 100000)}`;
|
const commitContent = `${time} \n随机数:${RandomNumber(
|
||||||
|
1,
|
||||||
|
100000
|
||||||
|
)}\n提交次数:${totalNum + 1}`;
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
`${this.paramsObj.itemSrc}/${this.paramsObj.fileSrc}`,
|
`${this.paramsObj.itemSrc}/${this.paramsObj.fileName}`,
|
||||||
commitContent,
|
commitContent,
|
||||||
'utf-8'
|
'utf-8'
|
||||||
);
|
);
|
||||||
const res = this.myExecSync(
|
const isDebug = true; // 手动更改调试模拟是否提交git
|
||||||
`cd ${this.paramsObj.itemSrc} && git add . && git commit -m 'autoCommit' --date='${time}' && git pull && git push origin master`
|
if (!isProduction() && !isDebug) {
|
||||||
);
|
// TODO: 测试提交 以及接受log
|
||||||
console.log('res 结束', res);
|
const res = this.myExecSync(
|
||||||
// 当前最新版本commit 信息
|
`cd ${this.paramsObj.itemSrc} && git add . && git commit -m 'autoCommit' --date='${time}' && git pull && git push origin master`
|
||||||
const cmd = `git log -1 \
|
);
|
||||||
--date=iso --pretty=format:'{"commit": "%h","author": "%aN <%aE>","date": "%ad","message": "%s"},' \
|
console.log('res 结束', res);
|
||||||
$@ | \
|
// 当前最新版本commit 信息
|
||||||
perl -pe 'BEGIN{print "["}; END{print "]\n"}' | \
|
const cmd = `git log -1 \
|
||||||
perl -pe 's/},]/}]/'`;
|
--date=iso --pretty=format:'{"commit": "%h","author": "%aN <%aE>","date": "%ad","message": "%s"},' \
|
||||||
// [{"commit": "a6b5f3d","author": "OBKoro1 <1677593011@qq.com>","date": "2019-12-26 21:05:57 +0800","message": "init"}]
|
$@ | \
|
||||||
const log = this.myExecSync(cmd);
|
perl -pe 'BEGIN{print "["}; END{print "]\n"}' | \
|
||||||
console.log('log 开始', log);
|
perl -pe 's/},]/}]/'`;
|
||||||
|
// [{"commit": "a6b5f3d","author": "OBKoro1 <1677593011@qq.com>","date": "2019-12-26 21:05:57 +0800","message": "init"}]
|
||||||
|
const log = this.myExecSync(cmd);
|
||||||
|
console.log('log 开始', log);
|
||||||
|
} else {
|
||||||
|
// 模拟git提交
|
||||||
|
const test = await new Promise((resolve, reject) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
outputLog('延迟一秒');
|
||||||
|
resolve('延迟一秒');
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
}
|
||||||
totalNum++;
|
totalNum++;
|
||||||
outputLog('commit内容', commitContent);
|
outputLog('commit内容', commitContent);
|
||||||
}
|
}
|
||||||
outputLog(`总commit次数${totalNum}`);
|
}
|
||||||
outputLog('自动commit完成');
|
this.commitEnd(totalNum);
|
||||||
});
|
}
|
||||||
|
commitEnd(totalNum: number) {
|
||||||
|
this.userCancel = false; // 重新打开终止开关
|
||||||
|
this.autoCommitView.postMessage('commit 完成', 'commit 完成')
|
||||||
|
outputLog('自动commit完成', `总commit次数${totalNum}`);
|
||||||
|
}
|
||||||
|
cancelCommit() {
|
||||||
|
if (this.userCancel) {
|
||||||
|
outputLog('终止自动commit');
|
||||||
|
}
|
||||||
|
return this.userCancel;
|
||||||
|
}
|
||||||
|
public closeCommit() {
|
||||||
|
this.userCancel = true;
|
||||||
}
|
}
|
||||||
// 格式化日期
|
// 格式化日期
|
||||||
formatTime(time: string) {
|
formatTime(time: string) {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* Author : OBKoro1
|
* Author : OBKoro1
|
||||||
* Date : 2019-12-25 17:08:18
|
* Date : 2019-12-25 17:08:18
|
||||||
* LastEditors : OBKoro1
|
* LastEditors : OBKoro1
|
||||||
* LastEditTime : 2019-12-31 16:42:46
|
* LastEditTime : 2020-01-01 17:20:11
|
||||||
* FilePath : /autoCommit/src/models/index.ts
|
* FilePath : /autoCommit/src/models/index.ts
|
||||||
* Description : 插件逻辑入口
|
* Description : 插件逻辑入口
|
||||||
* https://github.com/OBKoro1
|
* https://github.com/OBKoro1
|
||||||
@ -20,7 +20,6 @@ class ExtensionLogic {
|
|||||||
public MessageCallBack: any;
|
public MessageCallBack: any;
|
||||||
public autoCommitView: WebView;
|
public autoCommitView: WebView;
|
||||||
public CommitHandle: any;
|
public CommitHandle: any;
|
||||||
public isDebug: boolean;
|
|
||||||
|
|
||||||
public constructor(context: vscode.ExtensionContext) {
|
public constructor(context: vscode.ExtensionContext) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@ -28,7 +27,6 @@ class ExtensionLogic {
|
|||||||
this.context,
|
this.context,
|
||||||
this.messageCallBack.bind(this)
|
this.messageCallBack.bind(this)
|
||||||
);
|
);
|
||||||
this.isDebug = true;
|
|
||||||
setPanelWebview(this.autoCommitView);
|
setPanelWebview(this.autoCommitView);
|
||||||
this.createView();
|
this.createView();
|
||||||
}
|
}
|
||||||
@ -47,8 +45,11 @@ class ExtensionLogic {
|
|||||||
this.CommitHandle = new CommitHandle(message);
|
this.CommitHandle = new CommitHandle(message);
|
||||||
} else if (message.command === 'choose-item') {
|
} else if (message.command === 'choose-item') {
|
||||||
this.publishChooseFile();
|
this.publishChooseFile();
|
||||||
|
} else if(message.command === 'cancel autoCommit'){
|
||||||
|
this.CommitHandle.closeCommit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 选择项目文件夹
|
||||||
async publishChooseFile() {
|
async publishChooseFile() {
|
||||||
const urlArr: any = await vscode.window.showOpenDialog({
|
const urlArr: any = await vscode.window.showOpenDialog({
|
||||||
canSelectFiles: false, // 允许选择文件
|
canSelectFiles: false, // 允许选择文件
|
||||||
|
@ -13,10 +13,9 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<div class="form-title">Github自动提交commit工具</div>
|
<div class="form-title">Github自动提交commit工具</div>
|
||||||
<div>{{ event }}</div>
|
|
||||||
<el-container>
|
<el-container>
|
||||||
<el-main>
|
<el-main>
|
||||||
<el-form ref="form" :model="form" :rules="rules" label-width="160px">
|
<el-form ref="form" :model="form" :rules="rules" label-width="180px">
|
||||||
<el-form-item class="form_item" prop="itemSrc">
|
<el-form-item class="form_item" prop="itemSrc">
|
||||||
<label slot="label">
|
<label slot="label">
|
||||||
<el-tooltip class="item" content="要提交commit的仓库文件夹" placement="top-start">
|
<el-tooltip class="item" content="要提交commit的仓库文件夹" placement="top-start">
|
||||||
@ -46,52 +45,69 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item class="form_item" prop="commitNumber">
|
<el-form-item class="form_item" prop="commitNumber">
|
||||||
<label slot="label">
|
<label slot="label">
|
||||||
<el-tooltip class="item" content="时间范围内每个日期需要commit的次数" placement="top-start">
|
<el-tooltip class="item" content="时间范围内默认每个日期需要commit的次数" placement="top-start">
|
||||||
<span>commit次数 :</span>
|
<span>默认commit次数 :</span>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</label>
|
</label>
|
||||||
<el-input-number v-model="form.commitNumber" :min="1" :max="100" size="mini"></el-input-number>
|
<el-input-number v-model="form.commitNumber" :step="1" :min="1" :max="100" size="large"></el-input-number>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item v-for="(ele, index) in form.timeArr" :key="index" :prop="'timeArr.' + index + '.value'" :rules="{
|
<el-form-item v-for="(ele, index) in form.timeArr" :key="index" :prop="'timeArr.' + index + '.value'" :rules="{
|
||||||
required: true, message: '日期不能为空', trigger: 'blur'
|
required: true, message: '日期不能为空', trigger: 'blur'
|
||||||
}">
|
}">
|
||||||
<label slot="label">
|
<label slot="label">
|
||||||
<!-- TODO: wiki:一个日期只能选中一次 去重 sort排序 切割字符串 单独比较 -->
|
<el-tooltip class="item" content="要commit的日期范围" placement="top-start">
|
||||||
<el-tooltip class="item" content="要commit的时间范围,可多选" placement="top-start">
|
|
||||||
<span>commit日期范围{{index+1}} :</span>
|
<span>commit日期范围{{index+1}} :</span>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</label>
|
</label>
|
||||||
<el-date-picker v-model="ele.value" size="middle" type="daterange" value-format="yyyy-MM-dd"
|
<el-date-picker v-model="ele.value" type="daterange" value-format="yyyy-MM-dd"
|
||||||
range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
|
range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
|
||||||
</el-date-picker>
|
</el-date-picker>
|
||||||
<el-button @click.prevent="removeTime(index)" :disabled="index === 0">删除</el-button>
|
</el-form-item>
|
||||||
|
<el-form-item v-for="(ele, index) in form.timeArr" :key="index">
|
||||||
|
<label slot="label">
|
||||||
|
<el-tooltip class="item" content="可选(默认使用默认commit次数):对应index的日期范围每个日期的commit次数" placement="top-start">
|
||||||
|
<span>该范围每天提交次数{{index+1}} :</span>
|
||||||
|
</el-tooltip>
|
||||||
|
</label>
|
||||||
|
<el-input-number v-model="ele.commitNumber" :step="1" :min="0" :max="100" ></el-input-number>
|
||||||
|
<el-button @click.prevent="removeTime(index)" :disabled="index === 0">删除</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" @click="submitForm('form')" :disabled="runNow !== 1 && runNow!== 0">开始commit</el-button>
|
<el-button type="primary" @click="submitForm('form')" :disabled="runNow === 1 && runNow !== 0">开始commit</el-button>
|
||||||
<el-button @click="addTimeRange">新增时间范围</el-button>
|
<el-button @click="addTimeRange" :disabled="runNow === 1">新增日期范围</el-button>
|
||||||
<el-button @click="reset" :disabled="runNow === 1">取消commit</el-button>
|
<el-button @click="reset" :disabled="runNow !== 1">取消commit</el-button>
|
||||||
<el-button @click="clearLog" :disabled="showText.logStr !== ''">清空日志</el-button>
|
<el-button @click="clearLog" :disabled="showText.logStr === ''">清空日志</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<div class="form-title2">日志和文档</div>
|
<div class="form-title2">日志和文档</div>
|
||||||
<el-main>
|
<el-main>
|
||||||
<div class="log_form_father">
|
<div class="log_form_father">
|
||||||
<el-form label-width="160px">
|
<el-form label-width="160px">
|
||||||
<el-form-item label="插件运行日志 :">
|
<el-form-item>
|
||||||
|
<label slot="label">
|
||||||
|
<el-tooltip content="通过日志了解插件运行信息" placement="top-start">
|
||||||
|
<span>插件运行日志 :</span>
|
||||||
|
</el-tooltip>
|
||||||
|
</label>
|
||||||
<el-input @input="formatLog" type="textarea"
|
<el-input @input="formatLog" type="textarea"
|
||||||
:autosize="{ minRows: 1, maxRows: 8}"
|
:autosize="{ minRows: 1, maxRows: 8}"
|
||||||
placeholder="无法输入 仅用于展示" v-model="showText.logStr" :disabled="runNow === 1 || runNow === 0">
|
placeholder="无法输入 仅用于展示" v-model="showText.logStr" :disabled="runNow === 1 || runNow === 0">
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="开始commit的参数 :">
|
<el-form-item>
|
||||||
|
<label slot="label">
|
||||||
|
<el-tooltip content="点击开始commit,插件运行所需要的参数" placement="top-start">
|
||||||
|
<span>程序参数 :</span>
|
||||||
|
</el-tooltip>
|
||||||
|
</label>
|
||||||
<el-input @input="watchParamsChange" type="textarea"
|
<el-input @input="watchParamsChange" type="textarea"
|
||||||
:autosize="{ minRows: 1, maxRows: 4}"
|
:autosize="{ minRows: 1, maxRows: 4}"
|
||||||
placeholder="无法输入 仅用于展示" v-model="showText.paramsStr" :disabled="showText.paramsStr === ''">
|
placeholder="无法输入 仅用于展示" v-model="showText.paramsStr" :disabled="showText.paramsStr === ''">
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="wiki文档 :">
|
<el-form-item label="请先阅读文档 :">
|
||||||
<el-link href="https://element.eleme.io" type="primary" target="_blank">Readme</el-link>
|
<el-link href="https://element.eleme.io" type="primary" target="_blank">Readme</el-link>
|
||||||
<el-link href="https://element.eleme.io" type="primary" target="_blank">更新日志</el-link>
|
<el-link href="https://element.eleme.io" type="primary" target="_blank">更新日志</el-link>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<div class="tip">觉得这个插件还不错的话, 请给我点个<el-link href="https://element.eleme.io" type="primary" target="_blank">Star⭐️</el-link>吧~</div>
|
<div class="tip">觉得这个插件还不错的话, 请给我点个<el-link href="https://github.com/OBKoro1/autoCommit" type="primary" target="_blank">Star⭐️</el-link>吧~</div>
|
||||||
</div>
|
</div>
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-input>
|
</el-input>
|
||||||
@ -104,7 +120,13 @@
|
|||||||
<script src="../assets/scripts/vue.min.js"></script>
|
<script src="../assets/scripts/vue.min.js"></script>
|
||||||
<script src="../assets/scripts/element2.13.min.js"></script>
|
<script src="../assets/scripts/element2.13.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const vscode = acquireVsCodeApi()
|
let isWeb = false // 是否网页 不在vscode插件生态内
|
||||||
|
let vscode;
|
||||||
|
try{
|
||||||
|
vscode = acquireVsCodeApi()
|
||||||
|
}catch(err){
|
||||||
|
isWeb = true
|
||||||
|
}
|
||||||
new Vue({
|
new Vue({
|
||||||
el: '#app',
|
el: '#app',
|
||||||
data() {
|
data() {
|
||||||
@ -117,7 +139,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
isProduction: false,
|
isProduction: false, // 是否为调试模式
|
||||||
|
mockLogTime: null, // 模拟数据的定时器
|
||||||
showText:{
|
showText:{
|
||||||
oldParams: '', // 保存的参数
|
oldParams: '', // 保存的参数
|
||||||
paramsStr: '', // commit参数
|
paramsStr: '', // commit参数
|
||||||
@ -126,13 +149,15 @@
|
|||||||
},
|
},
|
||||||
runNow: 0, // 0 初始化 1运行中 2运行结束 3取消运行
|
runNow: 0, // 0 初始化 1运行中 2运行结束 3取消运行
|
||||||
form: {
|
form: {
|
||||||
|
// TODO: 保存其他几个参数
|
||||||
// itemSrc: '/Users/koro/work/web_my/testCommit',
|
// itemSrc: '/Users/koro/work/web_my/testCommit',
|
||||||
itemSrc: '点击选择要commit的项目文件夹',
|
itemSrc: '点击选择要commit的项目文件夹',
|
||||||
fileName: 'commit.md',
|
fileName: 'commit.md',
|
||||||
commitMsg: 'autoCommit',
|
commitMsg: 'autoCommit',
|
||||||
timeArr: [
|
timeArr: [
|
||||||
{
|
{
|
||||||
value: ''
|
value: '',
|
||||||
|
commitNumber: 0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
commitNumber: 1,
|
commitNumber: 1,
|
||||||
@ -167,6 +192,9 @@
|
|||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.initListener();
|
this.initListener();
|
||||||
|
if(isWeb){
|
||||||
|
this.form.itemSrc = '随便一个地址'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
submitForm(formName) {
|
submitForm(formName) {
|
||||||
@ -180,13 +208,15 @@
|
|||||||
},
|
},
|
||||||
// 开始commit
|
// 开始commit
|
||||||
runCommit() {
|
runCommit() {
|
||||||
let params = this.form
|
|
||||||
params.formatTime = this.mapTimeData()
|
|
||||||
this.runNow = 1
|
this.runNow = 1
|
||||||
this.showText.paramsStr = JSON.stringify(params)
|
this.clearLog()
|
||||||
|
this.showText.paramsStr = JSON.stringify(this.form)
|
||||||
this.showText.oldParams = this.showText.paramsStr
|
this.showText.oldParams = this.showText.paramsStr
|
||||||
// this.mockLog()
|
if(isWeb){
|
||||||
this.postMessage('commit', params);
|
this.mockLog()
|
||||||
|
}else{
|
||||||
|
this.postMessage('commit', this.form);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// 发送消息到插件
|
// 发送消息到插件
|
||||||
postMessage(command, data) {
|
postMessage(command, data) {
|
||||||
@ -200,6 +230,7 @@
|
|||||||
this.showText.logArr.unshift(`数据: ${data}`);
|
this.showText.logArr.unshift(`数据: ${data}`);
|
||||||
this.formatLog()
|
this.formatLog()
|
||||||
},
|
},
|
||||||
|
// 接收日志
|
||||||
acceptLogFn(paramArr){
|
acceptLogFn(paramArr){
|
||||||
const logStr = paramArr.join(' ')
|
const logStr = paramArr.join(' ')
|
||||||
this.showText.logArr.unshift(logStr);
|
this.showText.logArr.unshift(logStr);
|
||||||
@ -219,9 +250,13 @@
|
|||||||
message: `${data}根目录没有.git文件夹`,
|
message: `${data}根目录没有.git文件夹`,
|
||||||
duration: 0
|
duration: 0
|
||||||
});
|
});
|
||||||
|
} else if(command === 'commit 完成'){
|
||||||
|
// commit 完成
|
||||||
|
this.runNow = 2
|
||||||
} else if(command === 'console-log'){
|
} else if(command === 'console-log'){
|
||||||
this.acceptLogFn(data)
|
this.acceptLogFn(data)
|
||||||
}else if(command === 'isProduction'){
|
}else if(command === 'isProduction'){
|
||||||
|
// 调试模式 查看通信
|
||||||
this.isProduction = data
|
this.isProduction = data
|
||||||
}
|
}
|
||||||
if(!this.isProduction){
|
if(!this.isProduction){
|
||||||
@ -231,12 +266,15 @@
|
|||||||
},
|
},
|
||||||
// 重置: commit成功和中断commit
|
// 重置: commit成功和中断commit
|
||||||
reset() {
|
reset() {
|
||||||
// TODO: runNow 3 取消运行
|
this.runNow = 3;
|
||||||
this.runNow = 2;
|
if(isWeb){
|
||||||
this.showText.paramsStr = ''
|
clearInterval(this.mockLogTime)
|
||||||
this.showText.oldParams = ''
|
this.mockLogTime = null
|
||||||
|
} else{
|
||||||
|
this.postMessage('cancel autoCommit')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// 写html时用
|
// 模拟日志 写html时用
|
||||||
mockLog(){
|
mockLog(){
|
||||||
this.showText.logArr = [
|
this.showText.logArr = [
|
||||||
'res 开始 undefined',
|
'res 开始 undefined',
|
||||||
@ -247,14 +285,13 @@
|
|||||||
'总commit次数1'
|
'总commit次数1'
|
||||||
]
|
]
|
||||||
let num = 0;
|
let num = 0;
|
||||||
let timeId = setInterval(() => {
|
this.mockLogTime = setInterval(() => {
|
||||||
if(num< 100){
|
if(num< 100){
|
||||||
num++
|
num++
|
||||||
this.showText.logArr.unshift(`一些文字${num}`)
|
this.showText.logArr.unshift(`一些文字${num}`)
|
||||||
this.formatLog()
|
this.formatLog()
|
||||||
}else{
|
}else{
|
||||||
this.reset()
|
this.reset()
|
||||||
clearInterval(timeId)
|
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
},
|
},
|
||||||
@ -272,19 +309,14 @@
|
|||||||
removeTime(index) {
|
removeTime(index) {
|
||||||
this.form.timeArr.splice(index, 1)
|
this.form.timeArr.splice(index, 1)
|
||||||
},
|
},
|
||||||
// format 一下时间 少嵌套一层
|
|
||||||
mapTimeData() {
|
|
||||||
return this.form.timeArr.map(item => {
|
|
||||||
return item.value
|
|
||||||
})
|
|
||||||
},
|
|
||||||
chooseItem() {
|
chooseItem() {
|
||||||
this.postMessage('choose-item')
|
this.postMessage('choose-item')
|
||||||
},
|
},
|
||||||
// 增加时间范围选择
|
// 增加时间范围选择
|
||||||
addTimeRange() {
|
addTimeRange() {
|
||||||
this.form.timeArr.push({
|
this.form.timeArr.push({
|
||||||
value: ''
|
value: '',
|
||||||
|
commitNumber: 0
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
fileNameChange(value) {
|
fileNameChange(value) {
|
||||||
@ -298,7 +330,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}).$mount('#xpLogin');
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user