puppyperpetual 1.2.5 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,59 +1,57 @@
1
- # puppyperpetual
2
-
3
- node script to run things... perpetually. adapted from [legacyshell](https://github.com/onlypuppy7/LegacyShell)
4
-
5
- [On npm @ https://www.npmjs.com/package/puppyperpetual](https://www.npmjs.com/package/puppyperpetual)
6
-
7
- [And GitHub @ https://github.com/onlypuppy7/perpetual](https://github.com/onlypuppy7/perpetual)
8
-
9
- ## usage (as an npm package)
10
-
11
- you can use it to run your node stuff perpetually:
12
-
13
- ```js
14
- import Perpetual from '../index.js';
15
-
16
- const perpetual = new Perpetual('test_process', {
17
- process_cmd: 'node ./src/test/test_process.js',
18
- });
19
- await perpetual.run();
20
- ```
21
-
22
- or anything really:
23
-
24
- ```js
25
- import Perpetual from '../index.js';
26
-
27
- const perpetual = new Perpetual('test_process', {
28
- process_cmd: 'cd . && git pull && date',
29
- });
30
- await perpetual.run();
31
- ```
32
-
33
- ## usage (as a node app thing)
34
-
35
- note: on windows unless you spawn as worker, perpetual expects `C:\Program Files\Git\bin\bash.exe` to exist.
36
-
37
- as per tradition for my projects, simple installation!
38
-
39
- 1. `npm i`
40
-
41
- then run once to create config
42
-
43
- - `npm run start`
44
-
45
- then customise it in `store/config.yaml`, making a new entry for every thing
46
-
47
- then run like this:
48
-
49
- - `node .\perpetual.js --default`
50
-
51
- alternatively, just pass in your command:
52
-
53
- - `node .\perpetual.js "cd . && echo date"`
54
-
55
- then you dont need to mess around with the horrible yaml. dont worry, i hate doing it too.
56
-
57
- ## it doesnt work?
58
-
1
+ # puppyperpetual
2
+
3
+ node script to run things... perpetually. adapted from [legacyshell](https://github.com/onlypuppy7/LegacyShell)
4
+
5
+ [On npm @ https://www.npmjs.com/package/puppyperpetual](https://www.npmjs.com/package/puppyperpetual)
6
+
7
+ [And GitHub @ https://github.com/onlypuppy7/perpetual](https://github.com/onlypuppy7/perpetual)
8
+
9
+ ## usage (as an npm package)
10
+
11
+ you can use it to run your node stuff perpetually:
12
+
13
+ ```js
14
+ import Perpetual from '../index.js';
15
+
16
+ const perpetual = new Perpetual('test_process', {
17
+ process_cmd: 'node ./src/test/test_process.js',
18
+ });
19
+ await perpetual.run();
20
+ ```
21
+
22
+ or anything really:
23
+
24
+ ```js
25
+ import Perpetual from '../index.js';
26
+
27
+ const perpetual = new Perpetual('test_process', {
28
+ process_cmd: 'cd . && git pull && date',
29
+ });
30
+ await perpetual.run();
31
+ ```
32
+
33
+ ## usage (as a node app thing)
34
+
35
+ as per tradition for my projects, simple installation!
36
+
37
+ 1. `npm i`
38
+
39
+ then run once to create config
40
+
41
+ - `npm run start`
42
+
43
+ then customise it in `store/config.yaml`, making a new entry for every thing
44
+
45
+ then run like this:
46
+
47
+ - `node .\perpetual.js --default`
48
+
49
+ alternatively, just pass in your command:
50
+
51
+ - `node .\perpetual.js "cd . && echo date"`
52
+
53
+ then you dont need to mess around with the horrible yaml. dont worry, i hate doing it too.
54
+
55
+ ## it doesnt work?
56
+
59
57
  i dont care. i use this for my own stuff. i know that it works on linux and thats all i need.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "puppyperpetual",
3
3
  "type": "module",
4
4
  "types": "./src/index.d.ts",
5
- "version": "1.2.5",
5
+ "version": "1.2.7",
6
6
  "description": "Run stuff FOREVER! PERPETUALLY!",
7
7
  "main": "./src/index.js",
8
8
  "exports": {
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { spawn } from 'node:child_process';
3
+ import { spawn, exec } from 'node:child_process';
4
4
  import { Worker } from 'node:worker_threads';
5
5
  import { getTimestamp } from 'puppymisc';
6
6
 
@@ -27,6 +27,15 @@ export class ProcessManager {
27
27
  this.logger.logSend(`Failed to stop previous process via .terminate: ${err.message} ${this.runningProcess}`);
28
28
  }
29
29
  } else {
30
+ // if (process.platform === 'win32') {
31
+ // try {
32
+ // exec(`taskkill /pid ${this.runningProcess.pid} /T /F`);
33
+ // this.logger.logSend(`Stopped previous process via taskkill: ${this.runningProcess.pid}`);
34
+ // } catch (error) {
35
+ // this.logger.logSend(`Failed to stop previous process via taskkill: ${error.message} ${this.runningProcess}`);
36
+ // }
37
+ // }
38
+
30
39
  try {
31
40
  this.runningProcess.kill('SIGINT');
32
41
  this.logger.logSend(`Stopped previous process via .kill: ${this.runningProcess.pid}`);
@@ -45,7 +54,7 @@ export class ProcessManager {
45
54
  this.logger.logSend(`Starting process: ${this.options.process_cmd}`);
46
55
 
47
56
  const useWorkerThreads = this.options.useWorkerThreads ?? false;
48
- const isNodeScript = this.options.process_cmd.startsWith('node ') || this.options.isNode;
57
+ const isNodeScript = this.options.process_cmd.startsWith('node ') || this.options.isNodeScript;
49
58
  let scriptPath = this.options.process_cmd;
50
59
 
51
60
  if (isNodeScript && useWorkerThreads) {
@@ -88,14 +97,14 @@ export class ProcessManager {
88
97
  this.runningProcess.on('exit', (code, signal) => {
89
98
  code = code === 57 ? 1337 : code;
90
99
  if (signal === 'SIGINT') {
91
- this.logger.logSend(`Process terminated manually.`);
100
+ this.logger.logSend(`Worker process terminated manually.`);
92
101
  return;
93
102
  }
94
103
 
95
104
  const pingUser = this.options.webhook_ping_user ? ` <@${this.options.webhook_ping_user}>` : "";
96
105
  const pingRole = this.options.webhook_ping_role ? ` <@&${this.options.webhook_ping_role}>` : "";
97
106
 
98
- this.logger.logSend(`Process exited with code ${code}, signal ${signal}. ${(code === 1337 || this.runningProcess.purposefulStop) ? "No ping, intended restart" : `Restarting...${pingUser}${pingRole}`}`);
107
+ this.logger.logSend(`Worker process exited with code ${code}, signal ${signal}. ${(code === 1337 || this.runningProcess.purposefulStop) ? "No ping, intended restart" : `Restarting...${pingUser}${pingRole}`}`);
99
108
 
100
109
  setTimeout(() => {
101
110
  this.runningProcess = null;
@@ -105,12 +114,18 @@ export class ProcessManager {
105
114
 
106
115
  } else {
107
116
  let bash = 'bash';
117
+ let options = ['-c', 'export FORCE_COLOR=3; exec ' + scriptPath];
108
118
  if (process.platform === 'win32') {
109
119
  bash = this.options.winBashPath || 'C:\\Program Files\\Git\\bin\\bash.exe';
120
+ if (isNodeScript) {
121
+ bash = 'node';
122
+ options = scriptPath.replace(/^node\s+/, '').trim().split(' ');
123
+ // options.push("FORCE_COLOR=3");
124
+ }
110
125
  }
111
- this.runningProcess = spawn(bash, ['-c', 'export FORCE_COLOR=3; ' + scriptPath], {
126
+ this.runningProcess = spawn(bash, options, {
112
127
  stdio: ['inherit', 'pipe', 'pipe'],
113
- env: { ...process.env },
128
+ env: { ...process.env, FORCE_COLOR: '3' },
114
129
  detached: process.platform !== 'win32',
115
130
  });
116
131