每小时将data文件夹中的数据推送到git仓库中
This commit is contained in:
		@@ -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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user