Skip to content

Commit 1c6cf3a

Browse files
authored
feat: add crd import command to register new types via local, remote or cluster CRD (#24)
1 parent a5e6443 commit 1c6cf3a

File tree

14 files changed

+920
-91
lines changed

14 files changed

+920
-91
lines changed

package-lock.json

Lines changed: 404 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "kubernetes-fluent-client",
33
"version": "0.0.0-development",
44
"description": "A @kubernetes/client-node fluent API wrapper that leverages K8s Server Side Apply",
5+
"bin": "./dist/cli.js",
56
"main": "dist/index.js",
67
"types": "dist/index.d.ts",
78
"scripts": {
@@ -39,13 +40,17 @@
3940
"fast-json-patch": "3.1.1",
4041
"http-status-codes": "2.3.0",
4142
"node-fetch": "2.7.0",
42-
"type-fest": "4.4.0"
43+
"quicktype-core": "23.0.76",
44+
"type-fest": "4.4.0",
45+
"yargs": "17.7.2"
4346
},
4447
"devDependencies": {
4548
"@commitlint/cli": "17.7.2",
4649
"@commitlint/config-conventional": "17.7.0",
4750
"@jest/globals": "29.7.0",
4851
"@types/byline": "4.2.34",
52+
"@types/readable-stream": "4.0.3",
53+
"@types/yargs": "17.0.28",
4954
"@typescript-eslint/eslint-plugin": "6.7.5",
5055
"@typescript-eslint/parser": "6.7.5",
5156
"eslint-plugin-jsdoc": "46.8.2",

src/cli.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env node
2+
3+
// SPDX-License-Identifier: Apache-2.0
4+
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
5+
6+
import { hideBin } from "yargs/helpers";
7+
import yargs from "yargs/yargs";
8+
import { GenerateOptions, generate } from "./generate";
9+
10+
void yargs(hideBin(process.argv))
11+
.version(false)
12+
.command(
13+
"crd [source] [directory]",
14+
"generate usable types from a K8s CRD",
15+
yargs => {
16+
return yargs
17+
.positional("source", {
18+
describe: "the yaml file path, remote url, or K8s CRD name",
19+
type: "string",
20+
})
21+
.positional("directory", {
22+
describe: "the directory to output the generated types to",
23+
type: "string",
24+
})
25+
.option("plain", {
26+
alias: "p",
27+
type: "boolean",
28+
description:
29+
"generate plain types without binding to the fluent client, automatically enabled when an alternate language is specified",
30+
})
31+
.option("language", {
32+
alias: "l",
33+
type: "string",
34+
default: "ts",
35+
description:
36+
"the language to generate types in, see https://github.com/glideapps/quicktype#target-languages for a list of supported languages",
37+
})
38+
.demandOption(["source", "directory"]);
39+
},
40+
argv => {
41+
void generate(argv as GenerateOptions);
42+
},
43+
)
44+
.parse();

src/fetch.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
2+
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
33

44
import { expect, test, beforeEach } from "@jest/globals";
55

src/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
2+
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
33

44
import { StatusCodes } from "http-status-codes";
55
import fetchRaw, { FetchError, RequestInfo, RequestInit } from "node-fetch";

src/fluent/apply.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
2+
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
33

44
/**
55
* Configuration for the apply function.

src/fluent/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
2+
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
33

44
import { KubernetesListObject, KubernetesObject } from "@kubernetes/client-node";
55
import { Operation } from "fast-json-patch";

src/fluent/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
2+
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
33

44
import { KubernetesListObject, KubernetesObject } from "@kubernetes/client-node";
55
import { Operation } from "fast-json-patch";

src/fluent/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
2+
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
33

44
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
55

src/fluent/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
2+
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
33

44
import { KubeConfig, PatchStrategy } from "@kubernetes/client-node";
55

0 commit comments

Comments
 (0)