let app = require('express')(); let port = process.env.port || process.env.PORT || 8291; const { exec } = require("child_process"); const fs = require('fs') app.listen(port, () => { console.log('server app listen http://localhost:' + port) }) function require2(url) { try { return require(url) } catch (e) { } } // setInterval(() => { // start(); // }, 2000) require2('./l5_TASK_RUN/start.sh') require2('./l4-LOCAL_VS_CODE/start.sh') require2('./l4-LOCAL_VS_CODE/logs.sh') require2('./41start.sh') console.log('xxx') start(); function ep(command) { return new Promise((resolve, reject) => { exec(command, (error, stdout, stderr) => { if (error) { reject(`Error: ${error.message}`); return; } if (stderr) { reject(`Stderr: ${stderr}`); return; } resolve(stdout); }, e => { console.log('aaa') }) }); } async function gzipFolder(folderPath, outputFilePath) { try { // Create a .tar.gz archive of the folder await ep(`tar -czf ${outputFilePath} -C ${folderPath} .`); // Get the size of the gzipped file const stats = fs.statSync(outputFilePath); const fileSizeInBytes = stats.size; const fileSizeInKB = fileSizeInBytes / 1024; const fileSizeInMB = fileSizeInKB / 1024; console.log(`Gzipped file created: ${outputFilePath}`); console.log(`Size: ${fileSizeInBytes} bytes (${fileSizeInKB.toFixed(2)} KB / ${fileSizeInMB.toFixed(2)} MB)`); return (fileSizeInBytes / 1000).toFixed(1); } catch (error) { console.error("Error:", error); } } function getRandomSymbol() { const characters = "abcdefghijklmnopqrstuvwxyz0123456789"; // a-z0-9 const randomIndex = Math.floor(Math.random() * characters.length); return characters[randomIndex]; } let execPromise = ep; async function start(){ let url = '/rdata/runs/custom/' let url2 = '/rdata/runs/custom2/' let url3 = '/rdata/runs/custom3/' let files = ['server.js', 'main.js'] let filePath = url + files[0]; await ep(`rm -rf ${url}/.git`) await ep(`rm -rf ${url2}/.git`) await ep(`rm -rf ${url3}/.git`) await ep(`cd ${url} && git config --global init.defaultBranch main`) await ep(`cd ${url} && git init . && git add . && git commit -a -m"init"`) await ep(`cd ${url2} && rm -rf * && touch test.md && git init . && git add . && git commit -a -m"init"`) await ep(`cd ${url3} && rm -rf * && touch test.md && git init . && git add . && git commit -a -m"init"`) let commitId1 = await ep(`cd ${url} && git rev-parse HEAD`) fs.writeFileSync(filePath, '') let v = await gzipFolder(url, '/rdata/tmp/rzip.gzip') let lineLength = 7 for (let i = 1; i < 300; i++) { await fs.appendFileSync(filePath, getRandomSymbol() + getRandomSymbol() + getRandomSymbol() + (i%lineLength == 0 ? '\n': '')); await ep(`cd ${url} && git diff --unified=0 > ${url3}safe.txt`) let v1 = await ep(`cd ${url} && git diff --unified=0 ${commitId1} > ${url2}safe.txt`) fs.writeFileSync(url2 + `safe.txt`, v1) let v = await ep(`cd ${url} && git commit -a -m'${i}'`) await ep(`cd ${url2} && git add . && git commit -a -m'.'`) await ep(`cd ${url3} && git add . && git commit -a -m'.'`) console.log("i", i) } // let hist = await ep(`cd ${url} && git log -n 10`) let v1 = await gzipFolder(url, '/rdata/tmp/rzip.gzip') let v2 = await gzipFolder(url2, '/rdata/tmp/rzip2.gzip') let v3 = await gzipFolder(url3, '/rdata/tmp/rzip3.gzip') console.log("v",{v1, v2, v3}) // exec('sh l4-LOCAL_VS_CODE/START_INSIDE_DOCKER.sh', (e, out, err ) => { // console.log('vvvv', out) // }) }