jm2 0.1.0 → 0.1.2
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/package.json +2 -2
- package/src/cli/index.js +5 -1
- package/src/ipc/server.js +2 -1
- package/src/utils/paths.js +48 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jm2",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Job Manager 2 - A simple yet powerful job scheduler combining cron and at functionality",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/cli/index.js",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"sideEffects": false,
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"better-sqlite3": "^
|
|
50
|
+
"better-sqlite3": "^12.6.2",
|
|
51
51
|
"chalk": "^5.4.1",
|
|
52
52
|
"cli-table3": "^0.6.5",
|
|
53
53
|
"commander": "^14.0.2",
|
package/src/cli/index.js
CHANGED
|
@@ -63,7 +63,11 @@ export async function runCli() {
|
|
|
63
63
|
program
|
|
64
64
|
.name('jm2')
|
|
65
65
|
.description('JM2 (Job Manager 2) - A simple yet powerful job scheduler')
|
|
66
|
-
.version(getVersion(), '-v, --version', 'Display version number')
|
|
66
|
+
.version(getVersion(), '-v, --version', 'Display version number')
|
|
67
|
+
.showHelpAfterError()
|
|
68
|
+
.action(() => {
|
|
69
|
+
program.help();
|
|
70
|
+
});
|
|
67
71
|
|
|
68
72
|
// Daemon management commands
|
|
69
73
|
program
|
package/src/ipc/server.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { createServer } from 'node:net';
|
|
6
6
|
import { unlinkSync, existsSync } from 'node:fs';
|
|
7
|
-
import { getSocketPath, ensureDataDir } from '../utils/paths.js';
|
|
7
|
+
import { getSocketPath, ensureDataDir, ensureRuntimeDir } from '../utils/paths.js';
|
|
8
8
|
import { MessageType, createErrorResponse, createPongResponse } from './protocol.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -22,6 +22,7 @@ export function startIpcServer(options = {}) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
ensureDataDir();
|
|
25
|
+
ensureRuntimeDir();
|
|
25
26
|
|
|
26
27
|
const server = createServer(socket => {
|
|
27
28
|
let buffer = '';
|
package/src/utils/paths.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Provides consistent paths for data directory, config files, logs, etc.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { homedir } from 'node:os';
|
|
6
|
+
import { homedir, tmpdir } from 'node:os';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
8
|
import { mkdirSync, existsSync } from 'node:fs';
|
|
9
9
|
|
|
@@ -12,6 +12,36 @@ import { mkdirSync, existsSync } from 'node:fs';
|
|
|
12
12
|
*/
|
|
13
13
|
const DATA_DIR_NAME = '.jm2';
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Get the runtime directory for sockets
|
|
17
|
+
* Uses platform-specific standard locations:
|
|
18
|
+
* - Linux: /run/user/<uid>/jm2/ (XDG standard)
|
|
19
|
+
* - macOS: ~/Library/Caches/jm2/
|
|
20
|
+
* - Others: ~/.jm2/
|
|
21
|
+
* @returns {string} The runtime directory path
|
|
22
|
+
*/
|
|
23
|
+
function getRuntimeDir() {
|
|
24
|
+
// Allow explicit override
|
|
25
|
+
if (process.env.JM2_RUNTIME_DIR) {
|
|
26
|
+
return process.env.JM2_RUNTIME_DIR;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (process.platform === 'linux') {
|
|
30
|
+
// XDG Base Directory Specification - user-specific runtime
|
|
31
|
+
const uid = process.getuid?.() || 0;
|
|
32
|
+
const xdgRuntimeDir = process.env.XDG_RUNTIME_DIR || `/run/user/${uid}`;
|
|
33
|
+
return join(xdgRuntimeDir, 'jm2');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (process.platform === 'darwin') {
|
|
37
|
+
// macOS standard - use Library/Caches for runtime files
|
|
38
|
+
return join(homedir(), 'Library', 'Caches', 'jm2');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Fallback to data directory for other platforms
|
|
42
|
+
return getDataDir();
|
|
43
|
+
}
|
|
44
|
+
|
|
15
45
|
/**
|
|
16
46
|
* Get the base data directory path (~/.jm2/)
|
|
17
47
|
* Can be overridden via JM2_DATA_DIR environment variable for testing
|
|
@@ -75,7 +105,8 @@ export function getJobLogFile(jobName) {
|
|
|
75
105
|
|
|
76
106
|
/**
|
|
77
107
|
* Get the IPC socket path
|
|
78
|
-
* On
|
|
108
|
+
* On Linux: /run/user/<uid>/jm2/daemon.sock
|
|
109
|
+
* On macOS: ~/Library/Caches/jm2/daemon.sock
|
|
79
110
|
* On Windows: \\.\pipe\jm2-daemon
|
|
80
111
|
* @returns {string} The socket path
|
|
81
112
|
*/
|
|
@@ -83,7 +114,20 @@ export function getSocketPath() {
|
|
|
83
114
|
if (process.platform === 'win32') {
|
|
84
115
|
return '\\\\.\\pipe\\jm2-daemon';
|
|
85
116
|
}
|
|
86
|
-
return join(
|
|
117
|
+
return join(getRuntimeDir(), 'daemon.sock');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Ensure the runtime directory exists
|
|
122
|
+
* Creates platform-specific runtime directory if it doesn't exist
|
|
123
|
+
* @returns {string} The runtime directory path
|
|
124
|
+
*/
|
|
125
|
+
export function ensureRuntimeDir() {
|
|
126
|
+
const runtimeDir = getRuntimeDir();
|
|
127
|
+
if (!existsSync(runtimeDir)) {
|
|
128
|
+
mkdirSync(runtimeDir, { recursive: true });
|
|
129
|
+
}
|
|
130
|
+
return runtimeDir;
|
|
87
131
|
}
|
|
88
132
|
|
|
89
133
|
/**
|
|
@@ -159,6 +203,7 @@ export default {
|
|
|
159
203
|
getHistoryDbFile,
|
|
160
204
|
ensureDataDir,
|
|
161
205
|
ensureLogsDir,
|
|
206
|
+
ensureRuntimeDir,
|
|
162
207
|
dataDirExists,
|
|
163
208
|
pidFileExists,
|
|
164
209
|
};
|