aboutsummaryrefslogtreecommitdiff
path: root/src/compileAndRun/index.js
diff options
context:
space:
mode:
authorjakobst1n <jakob.stendahl@outlook.com>2018-09-07 00:32:51 +0200
committerjakobst1n <jakob.stendahl@outlook.com>2018-09-07 00:32:51 +0200
commit78d7c8d75a5f55ab56dd018edc85ebce9aa033bb (patch)
tree2ad9da977667b79236cfdd827d0446a5bf9fea18 /src/compileAndRun/index.js
downloadLuxcena-Neo-78d7c8d75a5f55ab56dd018edc85ebce9aa033bb.tar.gz
Luxcena-Neo-78d7c8d75a5f55ab56dd018edc85ebce9aa033bb.zip
:construction: Add pre-v1 project
Because of some stupid mistakes with the repo, I decided to delete the git history. Create a new, fresh repo, and move all the code there. Since all this is pre-v1, everything is in a testing-phase anyways. So i do not think we are going to feel the need for any history. The old repo is renamed to Luxcena-Neo-Old, and will be there until i convince myself i won't need the history.
Diffstat (limited to 'src/compileAndRun/index.js')
-rw-r--r--src/compileAndRun/index.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/compileAndRun/index.js b/src/compileAndRun/index.js
new file mode 100644
index 0000000..6f89e44
--- /dev/null
+++ b/src/compileAndRun/index.js
@@ -0,0 +1,75 @@
+let EventEmitter = require('events');
+let fse = require("fs-extra");
+let Process = require("./process");
+let pythonSupportFiles = __dirname + "/pythonSupportFiles/";
+
+class Python extends EventEmitter {
+
+ constructor(profileFolder, usrDataFolder) {
+ super();
+ this.profileFolder = profileFolder;
+ this.usrDataFolder = usrDataFolder;
+
+ this.stdout = "";
+ this.stderr = "";
+ }
+
+ status() {
+ return {};
+ }
+
+ compile() {
+ try {
+ fse.removeSync(this.profileFolder + "/build");
+ fse.copySync(pythonSupportFiles, this.profileFolder + "/build/");
+ fse.copySync(this.profileFolder + "/script.py", this.profileFolder + "/build/script.py");
+ } catch (err) {
+ console.log(err);
+ }
+ }
+
+ run() {
+ // Setup paths and commands
+ let entryPath = this.profileFolder + "/build/entry.py";
+
+ // Spawn the new process
+ this.pyProc = new Process("python", [
+ "-u", // This makes us able to get real-time output
+ entryPath, // This is where the entry-point is located
+ this.usrDataFolder // This is required for the python-script to now where our config-files are
+ ]);
+ this.pyProc.start();
+
+ this.pyProc.proc.stdout.on("data", (_stdout) => {
+ this.emit("stdout::data", "" + _stdout);
+ });
+ this.pyProc.proc.stdout.on("end", () => {
+ this.emit("stdout::end");
+ });
+ this.pyProc.proc.stderr.on("data", (_stderr) => {
+ this.emit("stderr::data", _stderr);
+ });
+ this.pyProc.proc.stderr.on("end", () => {
+ this.emit("stderr:end");
+ });
+ this.pyProc.proc.on("close", (_code) => {
+ this.emit("close", _code);
+ });
+
+ }
+
+ compileAndRun() {
+ this.compile();
+ this.run();
+ }
+
+ stop() {
+ this.pyProc.proc.kill("SIGINT");
+ }
+
+}
+
+module.exports = {
+ Python: Python,
+ Process: Process
+};