1
0
Code Issues Pull Requests Projects Releases Wiki Activity GitHub Gitee

每小时将data文件夹中的数据推送到git仓库中

This commit is contained in:
2022-07-24 01:01:23 +08:00
parent da446224eb
commit a2af3be807
2 changed files with 45 additions and 14 deletions

View File

@@ -1,24 +1,18 @@
'use strict';
const path = require('path');
const child_process = require('child_process');
const iconv = require("iconv-lite");
const encoding = "cp936";
const bufferEncoding = "binary";
const DATA_FOLDER = path.join(path.dirname(__dirname), process.env.DATA_FOLDER ?? 'data');
var cmds = [
'dir',
'git status',
];
async function main() {
async function execute(rootPath, cmds) {
let outputs = [];
for (let cmd of cmds) {
let result = await new Promise(function (resolve) {
// refer: https://www.webhek.com/post/execute-a-command-line-binary-with-node-js/
child_process.exec(cmd, {
cwd: DATA_FOLDER, // 脚本执行目录
cwd: rootPath, // 脚本执行目录
encoding: bufferEncoding
}, function (err, stdout, stderr) {
if (err) {
@@ -38,7 +32,9 @@ async function main() {
}
});
});
console.log(result);
outputs.push(result);
}
return outputs;
}
main();
exports.execute = execute;