@lovrabet/cli-framework 1.0.2 → 1.0.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/lib/framework/output.d.ts +14 -1
- package/lib/framework/output.js +25 -20
- package/lib/index.d.ts +8 -1
- package/lib/index.js +3 -1
- package/lib/utils/jq-sidecar.d.ts +11 -0
- package/lib/utils/jq-sidecar.js +28 -0
- package/package.json +5 -3
- package/sidecar/jq/README.md +24 -0
- package/sidecar/jq/darwin-arm64/jq +0 -0
- package/sidecar/jq/darwin-x64/jq +0 -0
- package/sidecar/jq/linux-arm64/jq +0 -0
- package/sidecar/jq/linux-x64/jq +0 -0
- package/sidecar/jq/win32-x64/jq.exe +0 -0
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* resolved from `JQ_PATH` or the system `PATH`.
|
|
11
11
|
*/
|
|
12
12
|
import type { CommandResult, OutputFormat, Risk } from "./types.js";
|
|
13
|
+
import { type JqBinaryResolverOptions } from "../utils/apply-jq-filter.js";
|
|
14
|
+
import { type CliErrorsShape } from "../errors.js";
|
|
13
15
|
/** Shared options passed through every internal print function. */
|
|
14
16
|
interface OutputOptions {
|
|
15
17
|
/** Full command label (e.g. `"api list"`). */
|
|
@@ -23,6 +25,15 @@ interface OutputOptions {
|
|
|
23
25
|
/** Optional jq expression for post-filtering (json/compress modes only). */
|
|
24
26
|
jqFilter?: string;
|
|
25
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Options for constructing a CLI-specific output formatter.
|
|
30
|
+
*/
|
|
31
|
+
export interface CreateFormatOutputOptions {
|
|
32
|
+
/** Error factory used when jq execution fails. */
|
|
33
|
+
cliErrors?: Pick<CliErrorsShape, "validation">;
|
|
34
|
+
/** jq binary resolution strategy for this concrete CLI. */
|
|
35
|
+
jqBinaryResolverOptions?: JqBinaryResolverOptions;
|
|
36
|
+
}
|
|
26
37
|
/**
|
|
27
38
|
* Central formatting entry point used by the runner adapter.
|
|
28
39
|
*
|
|
@@ -41,5 +52,7 @@ interface OutputOptions {
|
|
|
41
52
|
* formatOutput({ ok: true, data: { id: 1 } }, { command: "app list", risk: "read", format: "compress" });
|
|
42
53
|
* ```
|
|
43
54
|
*/
|
|
44
|
-
export declare function
|
|
55
|
+
export declare function createFormatOutput(options?: CreateFormatOutputOptions): <T>(result: CommandResult<T>, outputOptions: OutputOptions) => void;
|
|
56
|
+
/** Default framework formatter using `JQ_PATH` / `PATH` resolution only. */
|
|
57
|
+
export declare const formatOutput: <T>(result: CommandResult<T>, outputOptions: OutputOptions) => void;
|
|
45
58
|
export {};
|
package/lib/framework/output.js
CHANGED
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
import chalk from "chalk";
|
|
13
13
|
import { createJqFilter } from "../utils/apply-jq-filter.js";
|
|
14
14
|
import { createCliErrors } from "../errors.js";
|
|
15
|
-
const
|
|
15
|
+
const DEFAULT_CLI_ERRORS = createCliErrors({
|
|
16
16
|
cliBinName: "cli",
|
|
17
17
|
authRequiredHint: "",
|
|
18
18
|
configMissingHint: "",
|
|
19
19
|
notInProjectHint: "",
|
|
20
|
-
})
|
|
20
|
+
});
|
|
21
21
|
/**
|
|
22
22
|
* Central formatting entry point used by the runner adapter.
|
|
23
23
|
*
|
|
@@ -36,20 +36,25 @@ const applyJqFilter = createJqFilter(createCliErrors({
|
|
|
36
36
|
* formatOutput({ ok: true, data: { id: 1 } }, { command: "app list", risk: "read", format: "compress" });
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
export function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
export function createFormatOutput(options = {}) {
|
|
40
|
+
const applyJqFilter = createJqFilter(options.cliErrors ?? DEFAULT_CLI_ERRORS, options.jqBinaryResolverOptions);
|
|
41
|
+
return function formatOutput(result, outputOptions) {
|
|
42
|
+
switch (outputOptions.format) {
|
|
43
|
+
case "json":
|
|
44
|
+
printJson(result, outputOptions, applyJqFilter);
|
|
45
|
+
break;
|
|
46
|
+
case "compress":
|
|
47
|
+
printCompress(result, outputOptions, applyJqFilter);
|
|
48
|
+
break;
|
|
49
|
+
case "pretty":
|
|
50
|
+
default:
|
|
51
|
+
printPretty(result, outputOptions);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
52
55
|
}
|
|
56
|
+
/** Default framework formatter using `JQ_PATH` / `PATH` resolution only. */
|
|
57
|
+
export const formatOutput = createFormatOutput();
|
|
53
58
|
/**
|
|
54
59
|
* Wraps the command result in an {@link OutputEnvelope} by merging the
|
|
55
60
|
* command metadata from `options` and the result data / error.
|
|
@@ -81,8 +86,8 @@ function buildEnvelope(result, options) {
|
|
|
81
86
|
* @param result - The command result to serialize.
|
|
82
87
|
* @param options - Output options including jq filter.
|
|
83
88
|
*/
|
|
84
|
-
function printJson(result, options) {
|
|
85
|
-
writeJsonWithOptionalJq(`${JSON.stringify(buildEnvelope(result, options), null, 2)}\n`, options);
|
|
89
|
+
function printJson(result, options, applyJqFilter) {
|
|
90
|
+
writeJsonWithOptionalJq(`${JSON.stringify(buildEnvelope(result, options), null, 2)}\n`, options, applyJqFilter);
|
|
86
91
|
}
|
|
87
92
|
/**
|
|
88
93
|
* Formats and prints the result as single-line (compact) JSON.
|
|
@@ -91,8 +96,8 @@ function printJson(result, options) {
|
|
|
91
96
|
* @param result - The command result to serialize.
|
|
92
97
|
* @param options - Output options including jq filter.
|
|
93
98
|
*/
|
|
94
|
-
function printCompress(result, options) {
|
|
95
|
-
writeJsonWithOptionalJq(`${JSON.stringify(buildEnvelope(result, options))}\n`, options);
|
|
99
|
+
function printCompress(result, options, applyJqFilter) {
|
|
100
|
+
writeJsonWithOptionalJq(`${JSON.stringify(buildEnvelope(result, options))}\n`, options, applyJqFilter);
|
|
96
101
|
}
|
|
97
102
|
/**
|
|
98
103
|
* Writes a JSON string to stdout, optionally piping it through `jq`.
|
|
@@ -100,7 +105,7 @@ function printCompress(result, options) {
|
|
|
100
105
|
* @param jsonLine - Complete JSON line (must end with `\n`).
|
|
101
106
|
* @param options - Output options carrying the jq expression.
|
|
102
107
|
*/
|
|
103
|
-
function writeJsonWithOptionalJq(jsonLine, options) {
|
|
108
|
+
function writeJsonWithOptionalJq(jsonLine, options, applyJqFilter) {
|
|
104
109
|
const expr = options.jqFilter?.trim();
|
|
105
110
|
if (!expr) {
|
|
106
111
|
process.stdout.write(jsonLine);
|
package/lib/index.d.ts
CHANGED
|
@@ -205,5 +205,12 @@ Paging,
|
|
|
205
205
|
* @description List response wrapper with records and optional paging.
|
|
206
206
|
*/
|
|
207
207
|
ListResponse, } from "./framework/response.js";
|
|
208
|
-
export { formatOutput } from "./framework/output.js";
|
|
208
|
+
export { createFormatOutput, formatOutput } from "./framework/output.js";
|
|
209
|
+
export type {
|
|
210
|
+
/**
|
|
211
|
+
* @see ./framework/output.ts
|
|
212
|
+
* @description Options for constructing a CLI-specific output formatter.
|
|
213
|
+
*/
|
|
214
|
+
CreateFormatOutputOptions, } from "./framework/output.js";
|
|
215
|
+
export { resolveBundledJqPaths } from "./utils/jq-sidecar.js";
|
|
209
216
|
export { createJqFilter } from "./utils/apply-jq-filter.js";
|
package/lib/index.js
CHANGED
|
@@ -47,6 +47,8 @@ extractList,
|
|
|
47
47
|
/** @see ./framework/response.ts */
|
|
48
48
|
extractPaging, } from "./framework/response.js";
|
|
49
49
|
// ─── Output Formatting ─────────────────────────────────────────────────────────
|
|
50
|
-
export { formatOutput } from "./framework/output.js";
|
|
50
|
+
export { createFormatOutput, formatOutput } from "./framework/output.js";
|
|
51
|
+
// ─── Bundled jq Sidecar ────────────────────────────────────────────────────────
|
|
52
|
+
export { resolveBundledJqPaths } from "./utils/jq-sidecar.js";
|
|
51
53
|
// ─── JQ Filter ────────────────────────────────────────────────────────────────
|
|
52
54
|
export { createJqFilter } from "./utils/apply-jq-filter.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves bundled jq candidate paths for the current runtime platform.
|
|
3
|
+
*
|
|
4
|
+
* The result is ordered from most preferred to least preferred. Callers should
|
|
5
|
+
* test the paths in order and use the first one that exists.
|
|
6
|
+
*
|
|
7
|
+
* @param platform - Node.js platform, defaults to `process.platform`.
|
|
8
|
+
* @param arch - Node.js architecture, defaults to `process.arch`.
|
|
9
|
+
* @returns Candidate absolute paths to bundled jq executables.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveBundledJqPaths(platform?: NodeJS.Platform, arch?: NodeJS.Architecture): string[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
/** Supported bundled jq targets keyed by `platform:arch`. */
|
|
4
|
+
const JQ_TARGETS = {
|
|
5
|
+
"darwin:arm64": ["darwin-arm64", "darwin-x64"],
|
|
6
|
+
"darwin:x64": ["darwin-x64"],
|
|
7
|
+
"linux:arm64": ["linux-arm64"],
|
|
8
|
+
"linux:x64": ["linux-x64"],
|
|
9
|
+
"win32:arm64": ["win32-x64"],
|
|
10
|
+
"win32:x64": ["win32-x64"],
|
|
11
|
+
};
|
|
12
|
+
const CURRENT_FILE = fileURLToPath(import.meta.url);
|
|
13
|
+
const PACKAGE_ROOT = path.resolve(path.dirname(CURRENT_FILE), "../..");
|
|
14
|
+
const SIDECAR_ROOT = path.join(PACKAGE_ROOT, "sidecar", "jq");
|
|
15
|
+
/**
|
|
16
|
+
* Resolves bundled jq candidate paths for the current runtime platform.
|
|
17
|
+
*
|
|
18
|
+
* The result is ordered from most preferred to least preferred. Callers should
|
|
19
|
+
* test the paths in order and use the first one that exists.
|
|
20
|
+
*
|
|
21
|
+
* @param platform - Node.js platform, defaults to `process.platform`.
|
|
22
|
+
* @param arch - Node.js architecture, defaults to `process.arch`.
|
|
23
|
+
* @returns Candidate absolute paths to bundled jq executables.
|
|
24
|
+
*/
|
|
25
|
+
export function resolveBundledJqPaths(platform = process.platform, arch = process.arch) {
|
|
26
|
+
const targetDirs = JQ_TARGETS[`${platform}:${arch}`] ?? [];
|
|
27
|
+
return targetDirs.map((dir) => path.join(SIDECAR_ROOT, dir, platform === "win32" ? "jq.exe" : "jq"));
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lovrabet/cli-framework",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -11,13 +11,15 @@
|
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
|
-
"lib"
|
|
14
|
+
"lib",
|
|
15
|
+
"sidecar"
|
|
15
16
|
],
|
|
16
17
|
"publishConfig": {
|
|
17
18
|
"access": "public"
|
|
18
19
|
},
|
|
19
20
|
"scripts": {
|
|
20
21
|
"build": "rm -rf lib && tsc && echo 'cli-framework build done'",
|
|
22
|
+
"update:jq-sidecar": "node scripts/update-jq-sidecar.mjs",
|
|
21
23
|
"beta-release": "sh scripts/update-beta-version.sh && bun run build && git push && git push origin --tag && bun publish --tag beta",
|
|
22
24
|
"release": "sh scripts/update-latest-version.sh && bun run build && git push && git push origin --tag && bun publish",
|
|
23
25
|
"typecheck": "tsc --noEmit",
|
|
@@ -28,7 +30,7 @@
|
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
30
32
|
"@types/node": "^24.5.2",
|
|
31
|
-
"typescript": "
|
|
33
|
+
"typescript": "5.9.3",
|
|
32
34
|
"vitest": "^4.1.2"
|
|
33
35
|
}
|
|
34
36
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
This directory vendors jq binaries that ship with `@lovrabet/cli-framework`.
|
|
2
|
+
|
|
3
|
+
Consumer CLIs such as `@lovrabet/rabetbase-cli` and `@lovrabet/lovrabet-cli`
|
|
4
|
+
resolve these binaries through the framework package.
|
|
5
|
+
|
|
6
|
+
- Upstream project: `jqlang/jq`
|
|
7
|
+
- Version: `jq-1.8.1`
|
|
8
|
+
- License: `MIT`
|
|
9
|
+
- Release source: `https://github.com/jqlang/jq/releases/tag/jq-1.8.1`
|
|
10
|
+
|
|
11
|
+
Bundled targets:
|
|
12
|
+
|
|
13
|
+
- `darwin-arm64/jq`
|
|
14
|
+
- `darwin-x64/jq`
|
|
15
|
+
- `linux-arm64/jq`
|
|
16
|
+
- `linux-x64/jq`
|
|
17
|
+
- `win32-x64/jq.exe`
|
|
18
|
+
|
|
19
|
+
Update policy:
|
|
20
|
+
|
|
21
|
+
1. Download binaries only from the official jq release assets.
|
|
22
|
+
2. Keep file names stable (`jq` / `jq.exe`) so runtime resolution stays simple.
|
|
23
|
+
3. Refresh the sidecar with `npm run update:jq-sidecar -- jq-<version>` when the bundled jq version changes.
|
|
24
|
+
4. Update this README when the bundled jq version changes.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|