diff --git a/plugins/deadlock-extension/package-lock.json b/plugins/deadlock-extension/package-lock.json index db1946e0dbd227cbd1b9e2bc208a478bb18ff29c..6f5594763143cb0e156080e59294deea259835b5 100644 --- a/plugins/deadlock-extension/package-lock.json +++ b/plugins/deadlock-extension/package-lock.json @@ -343,6 +343,11 @@ "which": "^2.0.1" } }, + "date-fns": { + "version": "2.16.1", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.16.1.tgz", + "integrity": "sha512-sAJVKx/FqrLYHAQeN7VpJrPhagZc9R4ImZIWYRFZaaohR3KzmuK88touwsSwSVT8Qcbd4zoDsnGfX4GFB4imyQ==" + }, "debug": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", @@ -1301,11 +1306,6 @@ "punycode": "^2.1.0" } }, - "uuid": { - "version": "8.3.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.1.tgz", - "integrity": "sha512-FOmRr+FmWEIG8uhZv6C2bTgEVXsHk08kE7mPlrBbEe+c3r9pjceVPgupIfNIhc4yx55H69OXANrUaSuu9eInKg==" - }, "v8-compile-cache": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz", diff --git a/plugins/deadlock-extension/package.json b/plugins/deadlock-extension/package.json index 6208de62c9fd1d4024d32dd009bd434d7127ab70..f5cdf38ffa4afeadb3120f1893452e299d3594cd 100644 --- a/plugins/deadlock-extension/package.json +++ b/plugins/deadlock-extension/package.json @@ -62,10 +62,10 @@ "dependencies": { "@types/marked": "^1.1.0", "async": "^3.2.0", + "date-fns": "^2.16.1", "keycloak-js": "^11.0.0", "marked": "^1.1.1", - "simple-git": "^2.21.0", - "uuid": "^8.3.1" + "simple-git": "^2.21.0" }, "devDependencies": { "@types/node": "^12.12.0", diff --git a/plugins/deadlock-extension/src/gitMission.ts b/plugins/deadlock-extension/src/gitMission.ts index 67f8373710bf4b346b0b040f780e465f558910d4..87d95517577a19e4beb03a39767ace8a9178f6ab 100644 --- a/plugins/deadlock-extension/src/gitMission.ts +++ b/plugins/deadlock-extension/src/gitMission.ts @@ -67,7 +67,7 @@ export default class GitMission { try { return (await this.git.remote([]) || '').replace(/(\r\n|\n|\r)/gm, ''); } catch (e) { - //ignore it, maybe the git repo does not exist + // ignore it, maybe the git repo does not exist } return ''; } diff --git a/plugins/deadlock-extension/src/recorder/command-recorder.ts b/plugins/deadlock-extension/src/recorder/command-recorder.ts index 82bc364ef1d6bac98eec7ffaf604d17a2a7d84fe..23ade5a253281efedb4a450dea653f544620a930 100644 --- a/plugins/deadlock-extension/src/recorder/command-recorder.ts +++ b/plugins/deadlock-extension/src/recorder/command-recorder.ts @@ -1,5 +1,5 @@ import GitMission from '../gitMission'; -import { error, commitAndPushCode } from './utils'; +import { error, commitAndPushCode, CommitFrom } from './utils'; const async = require("async"); // regex to match command line in ps aux @@ -50,7 +50,7 @@ export default class CommandRecorder { this.commandsInProgress.set(pid, new Command(pid, command)); try { - this.queue.push(async () => await commitAndPushCode(this.gitMission)); + this.queue.push(async () => await commitAndPushCode(this.gitMission, CommitFrom.Run)); } catch (e) { console.error('Cannot send user code to git'); console.error(e); diff --git a/plugins/deadlock-extension/src/recorder/preStop.ts b/plugins/deadlock-extension/src/recorder/preStop.ts index 9c1cf471fbdda7b913b1d6ab77168ecf27d00e27..ce1fedcfad975212dc3b4e532550735abdffaa3f 100644 --- a/plugins/deadlock-extension/src/recorder/preStop.ts +++ b/plugins/deadlock-extension/src/recorder/preStop.ts @@ -1,6 +1,6 @@ import UserConfigNode from "./userConfigNode"; import GitMission from "../gitMission"; -import { log, error, commitAndPushCode } from "./utils"; +import { log, error, commitAndPushCode, CommitFrom } from "./utils"; import { PROJECT_SRC_PATH, PROJECT_THEIA_PATH } from "../config.prod"; const util = require("util"); const exec = util.promisify(require("child_process").exec); @@ -39,7 +39,7 @@ async function containsDiff() { await userConfig.init(); const gitMission = await new GitMission(userConfig).init(); if (await containsDiff()) { - await commitAndPushCode(gitMission); + await commitAndPushCode(gitMission, CommitFrom.Auto); } } catch (e) { error("Cannot push user code at the end.."); diff --git a/plugins/deadlock-extension/src/recorder/utils.ts b/plugins/deadlock-extension/src/recorder/utils.ts index c3ff762581107435feea3f10d349fb7ee28caaf3..dfa63343229f247cbdc380b115774aac4cbdd704 100644 --- a/plugins/deadlock-extension/src/recorder/utils.ts +++ b/plugins/deadlock-extension/src/recorder/utils.ts @@ -1,7 +1,7 @@ import GitMission from "../gitMission"; import { PROJECT_SRC_PATH, PROJECT_THEIA_PATH } from "../config.prod"; import { execSync } from "child_process"; -import { v4 as uuid } from 'uuid'; +import { format } from 'date-fns'; const util = require('util'); const unlink = util.promisify(require('fs').unlink); @@ -48,15 +48,21 @@ export async function clearFilesExceptGit(path) { }); } -export async function commitAndPushCode(gitMission: GitMission) { +export enum CommitFrom { + Run = 'Run', + Auto = 'Auto' +} + +export async function commitAndPushCode(gitMission: GitMission, from: CommitFrom) { try { log(`Commit & push`); await clearFilesExceptGit(PROJECT_SRC_PATH); execSync(`rsync -r --exclude .git --exclude npm --exclude target ${PROJECT_THEIA_PATH}/* ${PROJECT_SRC_PATH} && cp ${Path.join(__dirname, '.gitignore')} ${PROJECT_SRC_PATH} && chown -R root:root /project`); + const currentDate = format(new Date(), "HH'H'mm'_'dd/LL/y"); await gitMission.addAll(); - await gitMission.commit(uuid()); + await gitMission.commit(currentDate); await gitMission.push(); log(`Commit & push done.`) } catch (e) { diff --git a/test.js b/test.js deleted file mode 100644 index f1750e4f1d1be6316d672b6eff005bca4cbe305d..0000000000000000000000000000000000000000 --- a/test.js +++ /dev/null @@ -1,47 +0,0 @@ -const child = require('child_process'); -// const watch = child.spawn('watch', ['-n', '0.5', 'ps aux']); - -const regexPsCommand = /(alex).+?([\d]+).+?([\d]+\:[\d]+).+?([\d+]\:[\d+]+) (.+)/ - -setInterval(() => { - const spawn = child.spawn('ps', ['aux']); - - spawn.stdout.setEncoding('utf8'); - spawn.stdout.on('data', function(data) { - const lines = data.toString().split('\n'); - - child.spawn('node commit.js'); - for (line of lines) { - const lineMatcher = line.match(regexPsCommand); - if (lineMatcher && lineMatcher.length > 4) { - console.log(lineMatcher[5]); - } - } - }); -}, 500); - - -// var execute = function(callback) { -// child.exec('ls', {maxBuffer: 1024 * 500}, function(error, stdout, stderr){ -// console.log('error', error); -// console.log('stdout', stdout); -// console.log('stderr', stderr); -// }); -// }; - - -// const regexTopCommand = /([\d]+) (theia).+?([\d]+\.[\d]+) +([\d]+\.[\d]+) +([\d]+\:[\d]+\.[\d]+) (.+)/ -// watch.stdout.addListener('data', (data) => { -// try { -// console.log('================='); -// console.log(data.toString()); -// } catch (e) { -// //catch anything to avoid the program exit -// console.error(e); -// } -// }); - -// watch.on('exit', function (code) { -// console.error(`exit command recorder ${code}`) -// process.exit(code); -// });