node-persistent-software
Advanced tools
| service_name: travis-ci |
| language: node_js | ||
| node_js: | ||
| - "8" | ||
| script: "npm run-script tests" | ||
| sudo: false |
| { | ||
| "es6": true, | ||
| "mocha": true, | ||
| "node": true | ||
| } |
| [ | ||
| "after", | ||
| "afterEach", | ||
| "angular", | ||
| "before", | ||
| "beforeEach", | ||
| "Buffer", | ||
| "console", | ||
| "clearInterval", | ||
| "clearTimeout", | ||
| "describe", | ||
| "it", | ||
| "jQuery", | ||
| "Promise", | ||
| "Map", | ||
| "module", | ||
| "os", | ||
| "process", | ||
| "require", | ||
| "setImmediate", | ||
| "setInterval", | ||
| "setTimeout", | ||
| "__dirname", | ||
| "__filename" | ||
| ] |
| { | ||
| "for-direction": 0, | ||
| "getter-return": "error", | ||
| "no-await-in-loop": "error", | ||
| "no-compare-neg-zero": "error", | ||
| "no-cond-assign": "error", | ||
| "no-console": [ "error", { "allow": [ "info", "warn", "error" ] }], | ||
| "no-constant-condition": "error", | ||
| "no-control-regex": "error", | ||
| "no-debugger": "error", | ||
| "no-dupe-args": "error", | ||
| "no-dupe-keys": "error", | ||
| "no-duplicate-case": "error", | ||
| "no-empty": "error", | ||
| "no-empty-character-class": "error", | ||
| "no-ex-assign": "error", | ||
| "no-extra-boolean-cast": "error", | ||
| "no-extra-parens": "error", | ||
| "no-extra-semi": "error", | ||
| "no-func-assign": "error", | ||
| "no-inner-declarations": "error", | ||
| "no-invalid-regexp": "error", | ||
| "no-irregular-whitespace": "error", | ||
| "no-obj-calls": "error", | ||
| "no-prototype-builtins": "error", | ||
| "no-regex-spaces": "error", | ||
| "no-sparse-arrays": "error", | ||
| "no-template-curly-in-string": "error", | ||
| "no-unexpected-multiline": "error", | ||
| "no-unreachable": "error", | ||
| "no-unsafe-finally": "error", | ||
| "no-unsafe-negation": "error", | ||
| "use-isnan": "error", | ||
| "valid-jsdoc": "error", | ||
| "valid-typeof": "error", | ||
| "accessor-pairs": "error", | ||
| "array-callback-return": "error", | ||
| "block-scoped-var": "error", | ||
| "class-methods-use-this": "error", | ||
| "complexity": "error", | ||
| "consistent-return": "error", | ||
| "curly": "error", | ||
| "default-case": "error", | ||
| "dot-location": [ "error", "property" ], | ||
| "dot-notation": "error", | ||
| "eqeqeq": "error", | ||
| "guard-for-in": "error", | ||
| "no-alert": "error", | ||
| "no-caller": "error", | ||
| "no-case-declarations": "error", | ||
| "no-div-regex": "error", | ||
| "no-else-return": 0, | ||
| "no-empty-function": "error", | ||
| "no-empty-pattern": "error", | ||
| "no-eq-null": "error", | ||
| "no-eval": "error", | ||
| "no-extend-native": "error", | ||
| "no-extra-bind": "error", | ||
| "no-extra-label": "error", | ||
| "no-fallthrough": "error", | ||
| "no-floating-decimal": "error", | ||
| "no-global-assign": "error", | ||
| "no-implicit-coercion": "error", | ||
| "no-implicit-globals": "error", | ||
| "no-implied-eval": "error", | ||
| "no-invalid-this": "error", | ||
| "no-iterator": "error", | ||
| "no-labels": "error", | ||
| "no-lone-blocks": "error", | ||
| "no-loop-func": "error", | ||
| "no-magic-numbers": 0, | ||
| "no-multi-spaces": "error", | ||
| "no-multi-str": "error", | ||
| "no-new": "error", | ||
| "no-new-func": "error", | ||
| "no-new-wrappers": "error", | ||
| "no-octal": "error", | ||
| "no-octal-escape": "error", | ||
| "no-param-reassign": "error", | ||
| "no-proto": "error", | ||
| "no-redeclare": "error", | ||
| "no-restricted-properties": "error", | ||
| "no-return-assign": "error", | ||
| "no-return-await": "error", | ||
| "no-script-url": "error", | ||
| "no-self-assign": "error", | ||
| "no-self-compare": "error", | ||
| "no-sequences": "error", | ||
| "no-throw-literal": "error", | ||
| "no-unmodified-loop-condition": "error", | ||
| "no-unused-expressions": "error", | ||
| "no-unused-labels": "error", | ||
| "no-useless-call": "error", | ||
| "no-useless-concat": "error", | ||
| "no-useless-escape": "error", | ||
| "no-useless-return": "error", | ||
| "no-void": "error", | ||
| "no-warning-comments": "error", | ||
| "no-with": "error", | ||
| "prefer-promise-reject-errors": "error", | ||
| "radix": "error", | ||
| "require-await": "error", | ||
| "vars-on-top": "error", | ||
| "wrap-iife": "error", | ||
| "yoda": [ "error", "always" ], | ||
| "strict": [ "error", "global" ], | ||
| "init-declarations": [ "error", "always" ], | ||
| "no-catch-shadow": "error", | ||
| "no-delete-var": 0, | ||
| "no-label-var": "error", | ||
| "no-restricted-globals": "error", | ||
| "no-shadow": "error", | ||
| "no-shadow-restricted-names": "error", | ||
| "no-undef": "error", | ||
| "no-undef-init": "error", | ||
| "no-undefined": "error", | ||
| "no-unused-vars": "error", | ||
| "no-use-before-define": "error", | ||
| "callback-return": [ "error", [ "done", "send.error", "send.success" ] ], | ||
| "global-require": 0, | ||
| "handle-callback-err": "error", | ||
| "no-buffer-constructor": "error", | ||
| "no-mixed-requires": "error", | ||
| "no-new-require": "error", | ||
| "no-path-concat": "error", | ||
| "no-process-env": "error", | ||
| "no-process-exit": "error", | ||
| "no-restricted-modules": "error", | ||
| "no-sync": "error", | ||
| "array-bracket-newline": [ "error", { "multiline": true } ], | ||
| "array-bracket-spacing": [ "error", "always" ], | ||
| "array-element-newline": 0, | ||
| "block-spacing": "error", | ||
| "brace-style": [ "error", "stroustrup" ], | ||
| "camelcase": "error", | ||
| "capitalized-comments": 0, | ||
| "comma-dangle": [ "error", "never" ], | ||
| "comma-spacing": [ "error", { "before": false, "after": true } ], | ||
| "comma-style": [ "error", "last" ], | ||
| "computed-property-spacing": [ "error", "never" ], | ||
| "consistent-this": "error", | ||
| "eol-last": "error", | ||
| "func-call-spacing": "error", | ||
| "func-name-matching": "error", | ||
| "func-names": [ "error", "always" ], | ||
| "func-style": [ "error", "declaration" ], | ||
| "id-blacklist": 0, | ||
| "id-length": 0, | ||
| "id-match": 0, | ||
| "indent": 0, | ||
| "jsx-quotes": [ "error", "prefer-double" ], | ||
| "key-spacing": [ "error", { "beforeColon": false, "afterColon": true } ], | ||
| "keyword-spacing": [ "error", { "after": true, "before": true } ], | ||
| "line-comment-position": [ "error", { "position": "above" } ], | ||
| "linebreak-style": 0, | ||
| "lines-around-comment": "error", | ||
| "max-depth": 0, | ||
| "max-len": [ "error", 150 ], | ||
| "max-lines": 0, | ||
| "max-nested-callbacks": [ "error", 5 ], | ||
| "max-params": [ "error", 5 ], | ||
| "max-statements": 0, | ||
| "max-statements-per-line": [ "error", { "max": 2 } ], | ||
| "multiline-ternary": 0, | ||
| "new-cap": "error", | ||
| "new-parens": "error", | ||
| "newline-per-chained-call": 0, | ||
| "no-array-constructor": "error", | ||
| "no-bitwise": "error", | ||
| "no-continue": "error", | ||
| "no-inline-comments": "error", | ||
| "no-lonely-if": "error", | ||
| "no-mixed-operators": "error", | ||
| "no-mixed-spaces-and-tabs": "error", | ||
| "no-multi-assign": "error", | ||
| "no-multiple-empty-lines": "error", | ||
| "no-negated-condition": 0, | ||
| "no-nested-ternary": "error", | ||
| "no-new-object": "error", | ||
| "no-plusplus": 0, | ||
| "no-restricted-syntax": "error", | ||
| "no-tabs": 0, | ||
| "no-ternary": 0, | ||
| "no-trailing-spaces": "error", | ||
| "no-underscore-dangle": 0, | ||
| "no-unneeded-ternary": "error", | ||
| "no-whitespace-before-property": "error", | ||
| "nonblock-statement-body-position": [ "error", "below" ], | ||
| "object-curly-newline": [ "error", { "consistent": true } ], | ||
| "object-curly-spacing": [ "error", "always" ], | ||
| "object-property-newline": "error", | ||
| "one-var": [ "error", "never" ], | ||
| "one-var-declaration-per-line": "error", | ||
| "operator-assignment": [ "error", "always" ], | ||
| "operator-linebreak": [ "error", "after" ], | ||
| "padded-blocks": ["error", { "classes": "always", "switches": "always" } ], | ||
| "padding-line-between-statements": "error", | ||
| "quote-props": [ "error", "always" ], | ||
| "quotes": [ "error", "double" ], | ||
| "require-jsdoc": "error", | ||
| "semi": [ "error", "always" ], | ||
| "semi-spacing": [ "error", { "before": false, "after": true } ], | ||
| "semi-style": [ "error", "last" ], | ||
| "sort-keys": 0, | ||
| "sort-vars": "error", | ||
| "space-before-blocks": [ "error", "always" ], | ||
| "space-before-function-paren": [ "error", "always" ], | ||
| "space-in-parens": [ "error", "never" ], | ||
| "space-infix-ops": "error", | ||
| "space-unary-ops": "error", | ||
| "spaced-comment": [ "error", "always" ], | ||
| "switch-colon-spacing": [ "error", { "after": true, "before": false } ], | ||
| "template-tag-spacing": [ "error", "always" ], | ||
| "unicode-bom": 0, | ||
| "wrap-regex": "error", | ||
| "arrow-body-style": [ "error", "always" ], | ||
| "arrow-parens": [ "error", "always" ], | ||
| "arrow-spacing": ["error", { "before": true, "after": true } ], | ||
| "constructor-super": "error", | ||
| "generator-star-spacing": [ "error", { "before": true, "after": false } ], | ||
| "no-class-assign": "error", | ||
| "no-confusing-arrow": "error", | ||
| "no-const-assign": "error", | ||
| "no-dupe-class-members": "error", | ||
| "no-duplicate-imports": "error", | ||
| "no-new-symbol": "error", | ||
| "no-restricted-imports": 0, | ||
| "no-this-before-super": "error", | ||
| "no-useless-computed-key": "error", | ||
| "no-useless-constructor": "error", | ||
| "no-useless-rename": "error", | ||
| "no-var": "error", | ||
| "object-shorthand": "error", | ||
| "prefer-arrow-callback": "error", | ||
| "prefer-const": "error", | ||
| "prefer-destructuring": "error", | ||
| "prefer-numeric-literals": "error", | ||
| "prefer-rest-params": "error", | ||
| "prefer-spread": "error", | ||
| "prefer-template": 0, | ||
| "require-yield": "error", | ||
| "rest-spread-spacing": [ "error", "never" ], | ||
| "sort-imports": "error", | ||
| "symbol-description": "error", | ||
| "template-curly-spacing": "error", | ||
| "yield-star-spacing": [ "error", { "before": true, "after": false } ] | ||
| } |
+40
-37
@@ -16,37 +16,31 @@ | ||
| // compile | ||
| const babel = require("gulp-babel"); | ||
| require("babel-preset-es2015"); | ||
| // reports | ||
| const istanbul = require("gulp-istanbul"); | ||
| const coveralls = require("gulp-coveralls"); | ||
| // private | ||
| // consts | ||
| 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]; | ||
| const ISTRAVIS = (0, process).env.TRAVIS || false; | ||
| const APP_FILES = [ path.join(__dirname, "lib", "*.js") ]; | ||
| const UNITTESTS_FILES = [ path.join(__dirname, "tests", "**", "*.js") ]; | ||
| const ALL_FILES = [ path.join(__dirname, "gulpfile.js") ] | ||
| .concat(APP_FILES) | ||
| .concat(UNITTESTS_FILES); | ||
| // tasks | ||
| // tests | ||
| gulp.task("eslint", () => { | ||
| return gulp.src(_toTestFiles) | ||
| return gulp.src(ALL_FILES) | ||
| .pipe(plumber()) | ||
| .pipe(eslint({ | ||
| "env": require(path.join(__dirname, "gulpfile", "eslint", "env.json")), | ||
| "globals": require(path.join(__dirname, "gulpfile", "eslint", "globals.json")), | ||
| "parserOptions": { | ||
| "ecmaVersion": 6 | ||
| }, | ||
| "rules": { | ||
| "linebreak-style": 0, | ||
| "quotes": [ 1, "double" ], | ||
| "indent": 0, | ||
| // "indent": [ 2, "tab" ], | ||
| "semi": [ 2, "always" ] | ||
| }, | ||
| "env": { | ||
| "node": true, "es6": true, "mocha": true | ||
| }, | ||
| "extends": "eslint:recommended" | ||
| // http://eslint.org/docs/rules/ | ||
| "rules": require(path.join(__dirname, "gulpfile", "eslint", "rules.json")) | ||
| })) | ||
@@ -58,31 +52,40 @@ .pipe(eslint.format()) | ||
| gulp.task("mocha", ["eslint"], () => { | ||
| gulp.task("istanbul", [ "eslint" ], () => { | ||
| return gulp.src(_unitTestsFiles) | ||
| return gulp.src(APP_FILES) | ||
| .pipe(plumber()) | ||
| .pipe(mocha({reporter: "spec"})); | ||
| .pipe(istanbul({ "includeUntested": true })) | ||
| .pipe(istanbul.hookRequire()); | ||
| }); | ||
| // compile | ||
| gulp.task("mocha", [ "istanbul" ], () => { | ||
| gulp.task("babel", ["eslint"], function () { | ||
| return gulp.src(UNITTESTS_FILES) | ||
| .pipe(plumber()) | ||
| .pipe(mocha()) | ||
| .pipe(istanbul.writeReports()) | ||
| .pipe(istanbul.enforceThresholds({ "thresholds": { "global": 85 } })); | ||
| return gulp.src(_libFiles) | ||
| .pipe(babel({ | ||
| presets: ["es2015"] | ||
| })) | ||
| .pipe(gulp.dest("dist")); | ||
| }); | ||
| gulp.task("coveralls", [ "mocha" ], () => { | ||
| return gulp.src(path.join(__dirname, "coverage", "lcov.info")) | ||
| .pipe(plumber()) | ||
| .pipe(coveralls()); | ||
| }); | ||
| gulp.task("tests", [ ISTRAVIS ? "coveralls" : "mocha" ]); | ||
| // watcher | ||
| gulp.task("watch", function () { | ||
| gulp.watch(_allJSFiles, ["mocha"]); | ||
| gulp.task("watch", () => { | ||
| gulp.watch(ALL_FILES, [ "eslint" ]); | ||
| }); | ||
| // default | ||
| gulp.task("default", ["mocha"]); | ||
| gulp.task("default", [ "mocha" ]); |
+21
-15
@@ -6,9 +6,9 @@ | ||
| const spawn = require("child_process").spawn; | ||
| const { spawn } = require("child_process"); | ||
| // module | ||
| module.exports = class PersistantSoftware extends require("asynchronous-eventemitter") { | ||
| module.exports = class PersistantSoftware extends require("asynchronous-eventemitter") { | ||
| constructor(software, args, options) { | ||
| constructor (software, args, options) { | ||
@@ -18,5 +18,5 @@ super(); | ||
| this.software = software; | ||
| this.args = ("object" === typeof args && args instanceof Array) ? args : null; | ||
| this.options = ("object" === typeof options) ? options : null; | ||
| this.args = args && "object" === typeof args && args instanceof Array ? args : null; | ||
| this.options = options && "object" === typeof options ? options : null; | ||
| this.currentChildProcess = null; | ||
@@ -30,13 +30,16 @@ | ||
| max(max) { | ||
| max (max) { | ||
| this.maxCountRun = max; | ||
| this.successCountRun = 0; | ||
| return this; | ||
| } | ||
| infinite() { | ||
| infinite () { | ||
| return this.max(0); | ||
| } | ||
| start() { | ||
| start () { | ||
@@ -83,11 +86,14 @@ try { | ||
| if (0 >= this.maxCountRun || (0 < this.maxCountRun && this.successCountRun < this.maxCountRun)) { | ||
| if (0 >= this.maxCountRun) { | ||
| this.start(); | ||
| } | ||
| else if (0 < this.maxCountRun && this.successCountRun < this.maxCountRun) { | ||
| this.start(); | ||
| } | ||
| else { | ||
| this.end(); | ||
| } | ||
| } | ||
| }); | ||
@@ -98,5 +104,5 @@ | ||
| } | ||
| } | ||
| catch(e) { | ||
| catch (e) { | ||
| this.emit("error", e); | ||
@@ -109,3 +115,3 @@ } | ||
| end() { | ||
| end () { | ||
@@ -112,0 +118,0 @@ this.ended = true; |
+1
-1
@@ -1,2 +0,2 @@ | ||
| Copyright (c) 2016, Sébastien Vidal | ||
| Copyright (c) 2018, Sébastien Vidal | ||
@@ -3,0 +3,0 @@ Permission to use, copy, modify, and/or distribute this software for any |
+16
-13
| { | ||
| "name": "node-persistent-software", | ||
| "version": "1.2.0", | ||
| "version": "1.3.0", | ||
| "description": "Spawn a software and keep it running", | ||
| "main": "dist/main.js", | ||
| "main": "lib/main.js", | ||
| "scripts": { | ||
| "start": "node dist/main.js", | ||
| "test": "gulp mocha" | ||
| "start": "node lib/main.js", | ||
| "tests": "gulp tests" | ||
| }, | ||
@@ -31,14 +31,17 @@ "pre-commit": [ | ||
| "dependencies": { | ||
| "asynchronous-eventemitter": "^0.2.2" | ||
| "asynchronous-eventemitter": "0.3.0" | ||
| }, | ||
| "devDependencies": { | ||
| "gulp": "^3.9.1", | ||
| "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" | ||
| "gulp": "3.9.1", | ||
| "gulp-plumber": "1.1.0", | ||
| "gulp-eslint": "4.0.0", | ||
| "gulp-mocha": "3.0.1", | ||
| "gulp-istanbul": "1.1.2", | ||
| "gulp-coveralls": "0.1.4", | ||
| "pre-commit": "1.2.2" | ||
| }, | ||
| "homepage": "https://github.com/Psychopoulet/node-persistent-software#readme" | ||
| "homepage": "https://github.com/Psychopoulet/node-persistent-software#readme", | ||
| "engines": { | ||
| "node": ">=6.0.0" | ||
| } | ||
| } |
+5
-2
| # node-persistent-software | ||
| Spawn a software and keep it running | ||
| [](https://travis-ci.org/Psychopoulet/node-persistent-software) | ||
| [](https://coveralls.io/github/Psychopoulet/node-persistent-software) | ||
| [](https://github.com/Psychopoulet/node-persistent-software) | ||
@@ -26,3 +29,3 @@ ## Installation | ||
| * ``` constructor(string software [, array arguments [ , object options ] ] ) ``` => see [spawn documentation](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) | ||
| * ``` constructor(string software [, array arguments [, object options ] ] ) ``` => see [spawn documentation](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) | ||
@@ -103,3 +106,3 @@ ### Methods | ||
| ```bash | ||
| $ npm test | ||
| $ gulp | ||
| ``` | ||
@@ -106,0 +109,0 @@ |
+46
-76
@@ -7,4 +7,8 @@ | ||
| const assert = require("assert"); | ||
| const PersistantSoftware = require(require("path").join(__dirname, "..", "dist", "main.js")); | ||
| const PersistantSoftware = require(require("path").join(__dirname, "..", "lib", "main.js")); | ||
| // consts | ||
| const IPCONFIG = "win32" === require("os").platform() ? "ipconfig" : "ifconfig"; | ||
| // tests | ||
@@ -18,20 +22,16 @@ | ||
| let ps = new PersistantSoftware("wsdvwsdvwsdvwsdvsdv").on("error", () => { }); // there IS an error. this is the point... | ||
| // there IS an error. this is the point. | ||
| const ps = new PersistantSoftware("wsdvwsdvwsdvwsdvsdv").on("error", () => { | ||
| // nothing to do here | ||
| }); | ||
| ps.on("firststart", () => { | ||
| reject("software found"); | ||
| reject(new Error("software found")); | ||
| }).on("end", () => { | ||
| try { | ||
| assert.strictEqual(0, ps.successCountRun, "wrong count"); | ||
| assert.strictEqual(1, ps.maxCountRun, "wrong max"); | ||
| assert.strictEqual(0, ps.successCountRun, "wrong count"); | ||
| assert.strictEqual(1, ps.maxCountRun, "wrong max"); | ||
| resolve(); | ||
| resolve(); | ||
| } | ||
| catch(e) { | ||
| reject((e.message) ? e.message : e); | ||
| } | ||
| }).max(1).start(); | ||
@@ -47,5 +47,3 @@ | ||
| let ps = new PersistantSoftware("node").on("error", (err) => { | ||
| (0, console).log(err); | ||
| }); | ||
| const ps = new PersistantSoftware("node").on("error", reject); | ||
@@ -59,17 +57,10 @@ ps.on("firststart", () => { | ||
| }).on("restart", () => { | ||
| reject("restarted"); | ||
| reject(new Error("restarted")); | ||
| }).on("end", () => { | ||
| try { | ||
| assert.strictEqual(1, ps.successCountRun, "wrong count"); | ||
| assert.strictEqual(1, ps.maxCountRun, "wrong max"); | ||
| assert.strictEqual(1, ps.successCountRun, "wrong count"); | ||
| assert.strictEqual(1, ps.maxCountRun, "wrong max"); | ||
| resolve(); | ||
| resolve(); | ||
| } | ||
| catch(e) { | ||
| reject((e.message) ? e.message : e); | ||
| } | ||
| }).max(1).start(); | ||
@@ -85,5 +76,4 @@ | ||
| let version = "", ps = new PersistantSoftware( "node", [ "-v" ] ).on("error", (err) => { | ||
| (1, console).log(err); | ||
| }); | ||
| let version = ""; | ||
| const ps = new PersistantSoftware("node", [ "-v" ]).on("error", reject); | ||
@@ -98,15 +88,8 @@ ps.on("start", (process) => { | ||
| try { | ||
| assert.strictEqual(process.version, version, "wrong version"); | ||
| assert.strictEqual(2, ps.successCountRun, "wrong count"); | ||
| assert.strictEqual(2, ps.maxCountRun, "wrong max"); | ||
| assert.strictEqual(process.version, version, "wrong version"); | ||
| assert.strictEqual(2, ps.successCountRun, "wrong count"); | ||
| assert.strictEqual(2, ps.maxCountRun, "wrong max"); | ||
| resolve(); | ||
| resolve(); | ||
| } | ||
| catch(e) { | ||
| reject((e.message) ? e.message : e); | ||
| } | ||
| }).max(2).start(); | ||
@@ -122,5 +105,5 @@ | ||
| let ps = new PersistantSoftware( "node", [ "-v" ] ).on("error", (err) => { | ||
| (1, console).log(err); | ||
| }); | ||
| const ps = new PersistantSoftware("node", [ "-v" ], { | ||
| "cwd": __dirname | ||
| }).on("error", reject); | ||
@@ -131,14 +114,7 @@ ps.on("restart", () => { | ||
| try { | ||
| assert.strictEqual(2, ps.successCountRun, "wrong count"); | ||
| assert.strictEqual(0, ps.maxCountRun, "wrong max"); | ||
| assert.strictEqual(2, ps.successCountRun, "wrong count"); | ||
| assert.strictEqual(0, ps.maxCountRun, "wrong max"); | ||
| resolve(); | ||
| resolve(); | ||
| } | ||
| catch(e) { | ||
| reject((e.message) ? e.message : e); | ||
| } | ||
| }).infinite().start(); | ||
@@ -150,25 +126,18 @@ | ||
| /* | ||
| // personnal check with firefox on Windows, based on the documentation | ||
| it("should check normal running with infinite and end", () => { | ||
| return new Promise((resolve) => { | ||
| return new Promise((resolve, reject) => { | ||
| var ps = new PersistantSoftware( | ||
| "C:\\Program Files\\Mozilla Firefox\\firefox.exe", | ||
| [ "https://www.npmjs.com/package/node-persistent-software" ] | ||
| ).on("error", (msg) => { | ||
| (1, console).log(msg); | ||
| }) | ||
| let firstStarted = false; | ||
| let restarted = false; | ||
| let started = false; | ||
| .infinite() | ||
| const ps = new PersistantSoftware(IPCONFIG).on("error", reject).infinite() | ||
| .on("firststart", () => { | ||
| (1, console).log("Firefox is started for the first time !"); | ||
| firstStarted = true; | ||
| }).on("restart", () => { | ||
| (1, console).log("Firefox is started again..."); | ||
| restarted = true; | ||
| }).on("start", () => { | ||
| (1, console).log("Anyway, Firefox is started."); | ||
| started = true; | ||
| }) | ||
@@ -178,11 +147,14 @@ | ||
| (1, console).log("Firefox is stopped, trying to restart..."); | ||
| if (1 <= ps.successCountRun) { | ||
| if (2 <= ps.successCountRun) { | ||
| ps.end(); | ||
| resolve(); | ||
| } | ||
| }).on("end", () => { | ||
| (1, console).log("/!\\ Firefox is stopped and cannot be restarted /!\\"); | ||
| assert.strictEqual(firstStarted, true, "not started for the first time"); | ||
| assert.strictEqual(restarted, true, "not restarted"); | ||
| assert.strictEqual(started, true, "not started at all"); | ||
| resolve(); | ||
| }).start(); | ||
@@ -194,4 +166,2 @@ | ||
| */ | ||
| }); |
Sorry, the diff of this file is not supported yet
-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; | ||
| }(); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
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
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
22205
30.93%11
37.5%524
41.62%111
2.78%5
66.67%+ Added
- Removed