diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..3e634c0 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "启动程序", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}/src/index.js" + } + ] +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..9770607 --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..5c1f198 --- /dev/null +++ b/src/index.js @@ -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(); diff --git a/test.md b/test.md index 16690c9..aafb919 100644 --- a/test.md +++ b/test.md @@ -1,2 +1 @@ -# 自动commit - +20/12/2019 11:12:22 \ No newline at end of file diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..04db83b --- /dev/null +++ b/yarn.lock @@ -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==