health-sync 0.2.1 → 0.2.3
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 +5 -2
- package/src/cli.js +45 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "health-sync",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Node.js port of health-sync",
|
|
6
6
|
"files": [
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"start": "node ./bin/health-sync.js",
|
|
17
17
|
"check": "node --check ./bin/health-sync.js && node --check ./src/cli.js",
|
|
18
|
-
"test": "node --test ./tests/*.test.js"
|
|
18
|
+
"test": "node --test ./tests/*.test.js",
|
|
19
|
+
"release:npm": "npm publish",
|
|
20
|
+
"release:clawhub": "clawhub publish clawhub/skills/health-sync --slug health-sync --name health-sync --version \"$npm_package_version\" --changelog \"Release v$npm_package_version\"",
|
|
21
|
+
"release": "npm run release:npm && npm run release:clawhub"
|
|
19
22
|
},
|
|
20
23
|
"dependencies": {
|
|
21
24
|
"@iarna/toml": "^2.2.5",
|
package/src/cli.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
1
2
|
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
2
4
|
import {
|
|
3
5
|
initConfigFile,
|
|
4
6
|
loadConfig,
|
|
@@ -10,10 +12,30 @@ import { loadProviders } from './plugins/loader.js';
|
|
|
10
12
|
import { setRequestJsonVerbose } from './util.js';
|
|
11
13
|
|
|
12
14
|
const DEFAULT_CONFIG_PATH = 'health-sync.toml';
|
|
15
|
+
const MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const PACKAGE_JSON_PATH = path.resolve(MODULE_DIR, '../package.json');
|
|
17
|
+
|
|
18
|
+
let cachedVersion = null;
|
|
19
|
+
|
|
20
|
+
function cliVersion() {
|
|
21
|
+
if (cachedVersion !== null) {
|
|
22
|
+
return cachedVersion;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const raw = JSON.parse(fs.readFileSync(PACKAGE_JSON_PATH, 'utf8'));
|
|
27
|
+
cachedVersion = raw?.version ? String(raw.version) : '0.0.0';
|
|
28
|
+
} catch {
|
|
29
|
+
cachedVersion = '0.0.0';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return cachedVersion;
|
|
33
|
+
}
|
|
13
34
|
|
|
14
35
|
function parseGlobalOptions(argv) {
|
|
15
36
|
let configPath = DEFAULT_CONFIG_PATH;
|
|
16
37
|
let dbPath = null;
|
|
38
|
+
let showVersion = false;
|
|
17
39
|
const remaining = [];
|
|
18
40
|
|
|
19
41
|
for (let i = 0; i < argv.length; i += 1) {
|
|
@@ -42,10 +64,14 @@ function parseGlobalOptions(argv) {
|
|
|
42
64
|
dbPath = arg.slice('--db='.length);
|
|
43
65
|
continue;
|
|
44
66
|
}
|
|
67
|
+
if (arg === '--version' || arg === '-V') {
|
|
68
|
+
showVersion = true;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
45
71
|
remaining.push(arg);
|
|
46
72
|
}
|
|
47
73
|
|
|
48
|
-
return { configPath, dbPath, remaining };
|
|
74
|
+
return { configPath, dbPath, showVersion, remaining };
|
|
49
75
|
}
|
|
50
76
|
|
|
51
77
|
function parseAuthArgs(args) {
|
|
@@ -160,6 +186,18 @@ function parseArgs(argv) {
|
|
|
160
186
|
const global = parseGlobalOptions(argv);
|
|
161
187
|
const [command, ...rest] = global.remaining;
|
|
162
188
|
|
|
189
|
+
if (global.showVersion) {
|
|
190
|
+
if (command) {
|
|
191
|
+
throw new Error('--version cannot be combined with a command');
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
command: 'version',
|
|
195
|
+
configPath: global.configPath,
|
|
196
|
+
dbPath: global.dbPath,
|
|
197
|
+
options: {},
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
163
201
|
if (!command) {
|
|
164
202
|
return {
|
|
165
203
|
command: null,
|
|
@@ -223,6 +261,7 @@ function enableHint(providerId) {
|
|
|
223
261
|
function usage() {
|
|
224
262
|
return [
|
|
225
263
|
'Usage: health-sync [--config path] [--db path] <command> [options]',
|
|
264
|
+
' health-sync --version',
|
|
226
265
|
'',
|
|
227
266
|
'Commands:',
|
|
228
267
|
' init Initialize config file and database',
|
|
@@ -485,6 +524,11 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
485
524
|
return 1;
|
|
486
525
|
}
|
|
487
526
|
|
|
527
|
+
if (parsed.command === 'version') {
|
|
528
|
+
console.log(cliVersion());
|
|
529
|
+
return 0;
|
|
530
|
+
}
|
|
531
|
+
|
|
488
532
|
if (parsed.command === 'init') {
|
|
489
533
|
return await cmdInit(parsed);
|
|
490
534
|
}
|