autoCommit

This commit is contained in:
OBKoro1 2019-12-20 11:12:22 +08:00
parent 094d8a4484
commit 1fd11ec05a
6 changed files with 96 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

17
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
// 使 IntelliSense
//
// 访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "启动程序",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/src/index.js"
}
]
}

22
package.json Normal file
View File

@ -0,0 +1,22 @@
{
"name": "autocommit",
"version": "1.0.0",
"description": "自动commit工具",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/OBKoro1/autoCommit.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/OBKoro1/autoCommit/issues"
},
"homepage": "https://github.com/OBKoro1/autoCommit#readme",
"dependencies": {
"moment": "^2.24.0"
}
}

47
src/index.js Normal file
View File

@ -0,0 +1,47 @@
/*
* Author : OBKoro1
* Date : 2019-12-19 20:23:57
* LastEditors : OBKoro1
* LastEditTime : 2019-12-20 11:11:29
* FilePath : /autoCommit/index.js
* Description : 自动commit
* https://github.com/OBKoro1
*/
const { execSync } = require('child_process');
const moment = require('moment');
const fs = require('fs');
class autoCommit {
constructor() {
this.init();
}
init() {
const time = moment().format('DD/MM/YYYY HH:MM:ss');
fs.writeFileSync('./test.md', time, 'utf-8');
this.commit()
}
commit() {
this.myExecSync(`git add . && git commit -m 'autoCommit' && git pull && git push`)
}
myExecSync(cmd) {
// 除了该方法直到子进程完全关闭后才返回 执行完毕 返回
try {
const res = execSync(cmd, {
encoding: 'utf8',
timeout: 0,
maxBuffer: 200 * 1024,
killSignal: 'SIGTERM',
cwd: undefined,
env: undefined
});
return res;
} catch (err) {
console.log(`执行命令出错:${cmd}`);
}
}
}
new autoCommit();

View File

@ -1,2 +1 @@
# 自动commit
20/12/2019 11:12:22

8
yarn.lock Normal file
View File

@ -0,0 +1,8 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
moment@^2.24.0:
version "2.24.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==