@quangnv13/nonstop 1.0.11 → 1.0.13
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/dist/index.js +19 -0
- package/package.json +5 -2
- package/scripts/preinstall.js +35 -0
package/dist/index.js
CHANGED
|
@@ -5,12 +5,31 @@ const config_js_1 = require("./config.js");
|
|
|
5
5
|
const logger_js_1 = require("./logger.js");
|
|
6
6
|
const runtime_js_1 = require("./runtime.js");
|
|
7
7
|
const ui_js_1 = require("./ui.js");
|
|
8
|
+
const runtime_manager_js_1 = require("./runtime-manager.js");
|
|
8
9
|
async function main() {
|
|
9
10
|
(0, config_js_1.ensureEnvExampleFile)();
|
|
10
11
|
const args = new Set(process.argv.slice(2));
|
|
11
12
|
const isBackground = args.has('--background');
|
|
13
|
+
const isStop = args.has('--stop');
|
|
12
14
|
const config = (0, config_js_1.loadConfigFromDisk)();
|
|
13
15
|
(0, config_js_1.applyConfigToProcessEnv)(config);
|
|
16
|
+
if (isStop) {
|
|
17
|
+
const status = (0, runtime_manager_js_1.getRuntimeStatus)();
|
|
18
|
+
if (status.running && status.snapshot) {
|
|
19
|
+
try {
|
|
20
|
+
const msg = (0, runtime_manager_js_1.stopBackgroundRuntime)(status.snapshot);
|
|
21
|
+
console.log(msg);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
25
|
+
process.exitCode = 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
console.log('nonstop background runtime is not running.');
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
14
33
|
if (isBackground) {
|
|
15
34
|
const missingFields = (0, config_js_1.getMissingConfigFields)(config);
|
|
16
35
|
if (missingFields.length > 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quangnv13/nonstop",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"preferGlobal": true,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"files": [
|
|
30
30
|
"dist",
|
|
31
31
|
"images",
|
|
32
|
+
"scripts",
|
|
32
33
|
"README.md",
|
|
33
34
|
"README.vi.md"
|
|
34
35
|
],
|
|
@@ -39,7 +40,9 @@
|
|
|
39
40
|
"dev": "tsx watch src/index.ts",
|
|
40
41
|
"build": "tsc -p tsconfig.json",
|
|
41
42
|
"start": "node dist/index.js",
|
|
42
|
-
"test": "node --import tsx --test src/*.test.ts"
|
|
43
|
+
"test": "node --import tsx --test src/*.test.ts",
|
|
44
|
+
"preinstall": "node scripts/preinstall.js",
|
|
45
|
+
"preuninstall": "node scripts/preinstall.js"
|
|
43
46
|
},
|
|
44
47
|
"dependencies": {
|
|
45
48
|
"boxen": "^5.1.2",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { execSync } = require('child_process');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
|
|
5
|
+
function killOldProcesses() {
|
|
6
|
+
const platform = os.platform();
|
|
7
|
+
console.log(`[nonstop] Pre-install hook: Checking for running nonstop processes on ${platform}...`);
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
if (platform === 'win32') {
|
|
11
|
+
// Windows PowerShell command to find and kill node processes running nonstop background
|
|
12
|
+
const cmd = `powershell -NoProfile -Command "Get-CimInstance Win32_Process -Filter \\"name = 'node.exe'\\" | Where-Object { $_.CommandLine -like '*nonstop*' -and $_.CommandLine -like '*--background*' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force; Write-Host 'Killed nonstop background process PID' $_.ProcessId }"`;
|
|
13
|
+
const output = execSync(cmd, { encoding: 'utf8' });
|
|
14
|
+
if (output.trim()) {
|
|
15
|
+
console.log(output.trim());
|
|
16
|
+
} else {
|
|
17
|
+
console.log('[nonstop] No running nonstop background processes found on Windows.');
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
// Unix/Linux/macOS command
|
|
21
|
+
try {
|
|
22
|
+
const cmd = `pkill -9 -f "node.*nonstop.*--background"`;
|
|
23
|
+
execSync(cmd);
|
|
24
|
+
console.log('[nonstop] Killed running nonstop background processes on Unix.');
|
|
25
|
+
} catch (err) {
|
|
26
|
+
// pkill exits with 1 if no processes match
|
|
27
|
+
console.log('[nonstop] No running nonstop background processes found on Unix.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.warn('[nonstop] Warning during pre-install check:', error.message);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
killOldProcesses();
|