node-persistent-software
Advanced tools
+135
| "use strict"; | ||
| // deps | ||
| var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
| var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
| function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
| var spawn = require("child_process").spawn, | ||
| events = require("asynchronous-eventemitter"); | ||
| // module | ||
| module.exports = function () { | ||
| function PersistantSoftware(software, args, options) { | ||
| var _this = this; | ||
| _classCallCheck(this, PersistantSoftware); | ||
| this.software = software; | ||
| this.args = "object" === (typeof args === "undefined" ? "undefined" : _typeof(args)) && args instanceof Array ? args : null; | ||
| this.options = "object" === (typeof options === "undefined" ? "undefined" : _typeof(options)) ? options : null; | ||
| this.currentChildProcess = null; | ||
| this.ended = false; | ||
| this.infinite(); | ||
| this.eventEmitter = new events().on("eventerror", function (err) { | ||
| _this.eventEmitter.emit("error", err); | ||
| }); | ||
| } | ||
| _createClass(PersistantSoftware, [{ | ||
| key: "on", | ||
| value: function on(eventName, listener) { | ||
| this.eventEmitter.on(eventName, listener); | ||
| return this; | ||
| } | ||
| }, { | ||
| key: "max", | ||
| value: function max(_max) { | ||
| this.maxCountRun = _max; | ||
| this.successCountRun = 0; | ||
| return this; | ||
| } | ||
| }, { | ||
| key: "infinite", | ||
| value: function infinite() { | ||
| return this.max(0); | ||
| } | ||
| }, { | ||
| key: "start", | ||
| value: function start() { | ||
| var _this2 = this; | ||
| try { | ||
| if (!this.ended) { | ||
| if (!this.args) { | ||
| this.currentChildProcess = spawn(this.software); | ||
| } else if (!this.options) { | ||
| this.currentChildProcess = spawn(this.software, this.args); | ||
| } else { | ||
| this.currentChildProcess = spawn(this.software, this.args, this.options); | ||
| } | ||
| this.currentChildProcess.on("error", function (err) { | ||
| _this2.eventEmitter.emit("error", err); | ||
| }); | ||
| if (!this.currentChildProcess || !this.currentChildProcess.pid) { | ||
| this.end(); | ||
| } else { | ||
| ++this.successCountRun; | ||
| if (1 < this.successCountRun) { | ||
| this.eventEmitter.emit("restart"); | ||
| } else { | ||
| this.eventEmitter.emit("firststart"); | ||
| } | ||
| this.eventEmitter.emit("start", this.currentChildProcess); | ||
| this.currentChildProcess.on("exit", function () { | ||
| _this2.eventEmitter.emit("stop"); | ||
| if (!_this2.ended) { | ||
| if (0 >= _this2.maxCountRun || 0 < _this2.maxCountRun && _this2.successCountRun < _this2.maxCountRun) { | ||
| _this2.start(); | ||
| } else { | ||
| _this2.end(); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } catch (e) { | ||
| this.eventEmitter.emit("error", e.message ? e.message : e); | ||
| } | ||
| return this; | ||
| } | ||
| }, { | ||
| key: "end", | ||
| value: function end() { | ||
| this.ended = true; | ||
| if (this.currentChildProcess && this.currentChildProcess.pid) { | ||
| try { | ||
| process.kill(this.currentChildProcess.pid); | ||
| this.eventEmitter.emit("stop"); | ||
| } catch (e) { | ||
| // nothing to do here | ||
| } | ||
| } | ||
| this.eventEmitter.emit("end"); | ||
| return this; | ||
| } | ||
| }]); | ||
| return PersistantSoftware; | ||
| }(); |
+42
-15
@@ -6,27 +6,42 @@ | ||
| const path = require("path"), | ||
| const path = require("path"); | ||
| gulp = require("gulp"), | ||
| eslint = require("gulp-eslint"), | ||
| excludeGitignore = require("gulp-exclude-gitignore"), | ||
| mocha = require("gulp-mocha"), | ||
| plumber = require("gulp-plumber"); | ||
| // gulp | ||
| const gulp = require("gulp"); | ||
| const plumber = require("gulp-plumber"); | ||
| // tests | ||
| const eslint = require("gulp-eslint"); | ||
| const mocha = require("gulp-mocha"); | ||
| // compile | ||
| const babel = require("gulp-babel"); | ||
| require("babel-preset-es2015"); | ||
| // private | ||
| var _gulpFile = path.join(__dirname, "gulpfile.js"), | ||
| _libFiles = path.join(__dirname, "lib", "**", "*.js"), | ||
| _unitTestsFiles = path.join(__dirname, "tests", "**", "*.js"), | ||
| _allJSFiles = [_gulpFile, _libFiles, _unitTestsFiles]; | ||
| var _gulpFile = path.join(__dirname, "gulpfile.js"); | ||
| var _libFiles = path.join(__dirname, "lib", "*.js"); | ||
| var _dirFiles = path.join(__dirname, "dir", "*.js"); | ||
| var _unitTestsFiles = path.join(__dirname, "tests", "*.js"); | ||
| var _toTestFiles = [_gulpFile, _libFiles, _unitTestsFiles]; | ||
| // tasks | ||
| gulp.task("eslint", function () { | ||
| // tests | ||
| return gulp.src(_allJSFiles) | ||
| gulp.task("eslint", () => { | ||
| return gulp.src(_toTestFiles) | ||
| .pipe(plumber()) | ||
| .pipe(excludeGitignore()) | ||
| .pipe(eslint({ | ||
| "parserOptions": { | ||
| "ecmaVersion": 6 | ||
| }, | ||
| "rules": { | ||
| "indent": 0 | ||
| "linebreak-style": 0, | ||
| "quotes": [ 1, "double" ], | ||
| "indent": 0, | ||
| // "indent": [ 2, "tab" ], | ||
| "semi": [ 2, "always" ] | ||
| }, | ||
@@ -43,3 +58,3 @@ "env": { | ||
| gulp.task("mocha", ["eslint"], function () { | ||
| gulp.task("mocha", ["eslint"], () => { | ||
@@ -52,2 +67,14 @@ return gulp.src(_unitTestsFiles) | ||
| // compile | ||
| gulp.task("babel", ["eslint"], function () { | ||
| return gulp.src(_libFiles) | ||
| .pipe(babel({ | ||
| presets: ["es2015"] | ||
| })) | ||
| .pipe(gulp.dest("dist")); | ||
| }); | ||
| // watcher | ||
@@ -54,0 +81,0 @@ |
+2
-2
@@ -26,3 +26,3 @@ | ||
| this.eventEmitter = new events().on("eventerror", (err) => { | ||
| this.eventEmitter.emit("error", (err.message) ? err.message : err); | ||
| this.eventEmitter.emit("error", err); | ||
| }); | ||
@@ -64,3 +64,3 @@ | ||
| this.currentChildProcess.on("error", (err) => { | ||
| this.eventEmitter.emit("error", (err.message) ? err.message : err); | ||
| this.eventEmitter.emit("error", err); | ||
| }); | ||
@@ -67,0 +67,0 @@ |
+27
-13
| { | ||
| "name": "node-persistent-software", | ||
| "version": "1.0.1", | ||
| "version": "1.1.0", | ||
| "description": "Spawn a software and keep it running", | ||
| "main": "lib/main.js", | ||
| "main": "dist/main.js", | ||
| "scripts": { | ||
| "start": "node lib/main.js", | ||
| "test": "gulp" | ||
| "start": "node dist/main.js", | ||
| "test": "gulp mocha" | ||
| }, | ||
| "pre-commit": [ | ||
| "test" | ||
| ], | ||
| "repository": { | ||
@@ -15,3 +18,8 @@ "type": "git", | ||
| "keywords": [ | ||
| "spawn", "forever", "keep", "software", "exe", "run" | ||
| "spawn", | ||
| "forever", | ||
| "keep", | ||
| "software", | ||
| "exe", | ||
| "run" | ||
| ], | ||
@@ -24,13 +32,19 @@ "author": "Sébastien VIDAL", | ||
| "dependencies": { | ||
| "asynchronous-eventemitter": "^0.1.0" | ||
| "asynchronous-eventemitter": "^0.2.2" | ||
| }, | ||
| "devDependencies": { | ||
| "gulp": "^3.9.1", | ||
| "gulp-eslint": "^2.1.0", | ||
| "gulp-exclude-gitignore": "^1.0.0", | ||
| "gulp-mocha": "^2.2.0", | ||
| "gulp-plumber": "^1.1.0" | ||
| "gulp-plumber": "^1.1.0", | ||
| "gulp-eslint": "^3.0.1", | ||
| "gulp-mocha": "^4.3.1", | ||
| "pre-commit": "^1.2.2", | ||
| "gulp-babel": "^6.1.2", | ||
| "babel-preset-es2015": "^6.24.1" | ||
| }, | ||
| "homepage": "https://github.com/Psychopoulet/node-persistent-software#readme", | ||
| "engines" : { "node" : ">=4.0.0" } | ||
| } | ||
| "homepage": "https://github.com/Psychopoulet/node-persistent-software#readme" | ||
| } |
+1
-1
@@ -103,3 +103,3 @@ # node-persistent-software | ||
| ```bash | ||
| $ gulp | ||
| $ npm test | ||
| ``` | ||
@@ -106,0 +106,0 @@ |
+5
-4
@@ -7,3 +7,3 @@ | ||
| const assert = require("assert"), | ||
| PersistantSoftware = require(require("path").join(__dirname, "..", "lib", "main.js")); | ||
| PersistantSoftware = require(require("path").join(__dirname, "..", "dist", "main.js")); | ||
@@ -149,3 +149,3 @@ // tests | ||
| return new Promise(() => { | ||
| return new Promise((resolve) => { | ||
@@ -166,3 +166,3 @@ var ps = new PersistantSoftware( | ||
| }).on("start", () => { | ||
| (1, console).log("anyway, Firefox is started."); | ||
| (1, console).log("Anyway, Firefox is started."); | ||
| }) | ||
@@ -176,2 +176,3 @@ | ||
| ps.end(); | ||
| resolve(); | ||
| } | ||
@@ -185,3 +186,3 @@ | ||
| }).timeout(1 * 1000); | ||
| }).timeout(5 * 1000); | ||
@@ -188,0 +189,0 @@ */ |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
16912
34.01%8
14.29%370
49.19%7
40%2
100%+ Added
- Removed