kubernetes-fluent-client 3.0.3 → 3.0.4
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/.prettierignore +4 -0
- package/README.md +24 -0
- package/dist/cli.js +21 -1
- package/dist/fileSystem.d.ts +11 -0
- package/dist/fileSystem.d.ts.map +1 -0
- package/dist/fileSystem.js +42 -0
- package/dist/fileSystem.test.d.ts +2 -0
- package/dist/fileSystem.test.d.ts.map +1 -0
- package/dist/fileSystem.test.js +75 -0
- package/dist/generate.d.ts +71 -11
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +130 -117
- package/dist/generate.test.js +293 -346
- package/dist/postProcessing.d.ts +246 -0
- package/dist/postProcessing.d.ts.map +1 -0
- package/dist/postProcessing.js +497 -0
- package/dist/postProcessing.test.d.ts +2 -0
- package/dist/postProcessing.test.d.ts.map +1 -0
- package/dist/postProcessing.test.js +550 -0
- package/e2e/cli.e2e.test.ts +123 -0
- package/e2e/crds/policyreports.default.expected/policyreport-v1alpha1.ts +332 -0
- package/e2e/crds/policyreports.default.expected/policyreport-v1alpha2.ts +360 -0
- package/e2e/crds/policyreports.default.expected/policyreport-v1beta1.ts +360 -0
- package/e2e/crds/policyreports.no.post.expected/policyreport-v1alpha1.ts +331 -0
- package/e2e/crds/policyreports.no.post.expected/policyreport-v1alpha2.ts +360 -0
- package/e2e/crds/policyreports.no.post.expected/policyreport-v1beta1.ts +360 -0
- package/e2e/crds/test.yaml/policyreports.test.yaml +1008 -0
- package/e2e/crds/test.yaml/uds-podmonitors.test.yaml +1245 -0
- package/e2e/crds/uds-podmonitors.default.expected/podmonitor-v1.ts +1333 -0
- package/e2e/crds/uds-podmonitors.no.post.expected/podmonitor-v1.ts +1360 -0
- package/package.json +6 -5
- package/src/cli.ts +25 -1
- package/src/fileSystem.test.ts +67 -0
- package/src/fileSystem.ts +25 -0
- package/src/generate.test.ts +368 -358
- package/src/generate.ts +173 -154
- package/src/postProcessing.test.ts +742 -0
- package/src/postProcessing.ts +568 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kubernetes-fluent-client",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "A @kubernetes/client-node fluent API wrapper that leverages K8s Server Side Apply.",
|
|
5
5
|
"bin": "./dist/cli.js",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"build": "tsc",
|
|
11
11
|
"semantic-release": "semantic-release",
|
|
12
12
|
"test": "jest src --coverage",
|
|
13
|
+
"test:e2e": "jest e2e",
|
|
13
14
|
"format:check": "eslint src && prettier . --check",
|
|
14
15
|
"format:fix": "eslint --fix src && prettier . --write"
|
|
15
16
|
},
|
|
@@ -52,13 +53,13 @@
|
|
|
52
53
|
"@types/readable-stream": "4.0.15",
|
|
53
54
|
"@types/urijs": "^1.19.25",
|
|
54
55
|
"@types/yargs": "17.0.33",
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
56
|
-
"@typescript-eslint/parser": "8.
|
|
57
|
-
"eslint-plugin-jsdoc": "50.
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "8.7.0",
|
|
57
|
+
"@typescript-eslint/parser": "8.7.0",
|
|
58
|
+
"eslint-plugin-jsdoc": "50.3.0",
|
|
58
59
|
"jest": "29.7.0",
|
|
59
60
|
"nock": "13.5.5",
|
|
60
61
|
"prettier": "3.3.3",
|
|
61
|
-
"semantic-release": "24.1.
|
|
62
|
+
"semantic-release": "24.1.2",
|
|
62
63
|
"ts-jest": "29.2.5",
|
|
63
64
|
"typescript": "5.6.2"
|
|
64
65
|
},
|
package/src/cli.ts
CHANGED
|
@@ -7,6 +7,8 @@ import { hideBin } from "yargs/helpers";
|
|
|
7
7
|
import yargs from "yargs/yargs";
|
|
8
8
|
import { GenerateOptions, generate } from "./generate";
|
|
9
9
|
import { version } from "../package.json";
|
|
10
|
+
import { postProcessing } from "./postProcessing";
|
|
11
|
+
import { NodeFileSystem } from "./fileSystem"; // Import your new file system
|
|
10
12
|
|
|
11
13
|
void yargs(hideBin(process.argv))
|
|
12
14
|
.version("version", "Display version number", `kubernetes-fluent-client v${version}`)
|
|
@@ -37,14 +39,36 @@ void yargs(hideBin(process.argv))
|
|
|
37
39
|
description:
|
|
38
40
|
"the language to generate types in, see https://github.com/glideapps/quicktype#target-languages for a list of supported languages",
|
|
39
41
|
})
|
|
42
|
+
.option("noPost", {
|
|
43
|
+
alias: "x",
|
|
44
|
+
type: "boolean",
|
|
45
|
+
default: false,
|
|
46
|
+
description: "disable post-processing after generating the types",
|
|
47
|
+
})
|
|
40
48
|
.demandOption(["source", "directory"]);
|
|
41
49
|
},
|
|
42
50
|
async argv => {
|
|
43
51
|
const opts = argv as unknown as GenerateOptions;
|
|
44
52
|
opts.logFn = console.log;
|
|
45
53
|
|
|
54
|
+
// Pass the `post` flag to opts
|
|
55
|
+
opts.noPost = argv.noPost as boolean;
|
|
56
|
+
|
|
57
|
+
// Use NodeFileSystem as the file system for post-processing
|
|
58
|
+
const fileSystem = new NodeFileSystem(); // Create an instance of NodeFileSystem
|
|
59
|
+
|
|
60
|
+
if (!opts.noPost) {
|
|
61
|
+
console.log("\n✅ Post-processing has been enabled.\n");
|
|
62
|
+
}
|
|
63
|
+
|
|
46
64
|
try {
|
|
47
|
-
|
|
65
|
+
// Capture the results returned by generate
|
|
66
|
+
const allResults = await generate(opts);
|
|
67
|
+
|
|
68
|
+
// If noPost is false, run post-processing
|
|
69
|
+
if (!opts.noPost) {
|
|
70
|
+
await postProcessing(allResults, opts, fileSystem); // Pass the file system to postProcessing
|
|
71
|
+
}
|
|
48
72
|
} catch (e) {
|
|
49
73
|
console.log(`\n❌ ${e.message}`);
|
|
50
74
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
3
|
+
|
|
4
|
+
import * as fs from "fs";
|
|
5
|
+
import { NodeFileSystem } from "./fileSystem";
|
|
6
|
+
import { beforeEach, describe, expect, jest, test } from "@jest/globals";
|
|
7
|
+
|
|
8
|
+
// Mock the fs module
|
|
9
|
+
jest.mock("fs");
|
|
10
|
+
|
|
11
|
+
describe("NodeFileSystem", () => {
|
|
12
|
+
let nodeFileSystem: NodeFileSystem;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
nodeFileSystem = new NodeFileSystem();
|
|
16
|
+
jest.clearAllMocks(); // Clear all mocks before each test
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe("readFile", () => {
|
|
20
|
+
test("should call fs.readFileSync with correct arguments", () => {
|
|
21
|
+
const mockFilePath = "test-file.txt";
|
|
22
|
+
const mockFileContent = "This is a test file";
|
|
23
|
+
|
|
24
|
+
// Mock the fs.readFileSync method to return the mock file content
|
|
25
|
+
(fs.readFileSync as jest.Mock).mockReturnValue(mockFileContent);
|
|
26
|
+
|
|
27
|
+
const result = nodeFileSystem.readFile(mockFilePath);
|
|
28
|
+
|
|
29
|
+
// Assert that fs.readFileSync was called with the correct file path and encoding
|
|
30
|
+
expect(fs.readFileSync).toHaveBeenCalledWith(mockFilePath, "utf8");
|
|
31
|
+
|
|
32
|
+
// Assert that the returned content matches the mock file content
|
|
33
|
+
expect(result).toBe(mockFileContent);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("writeFile", () => {
|
|
38
|
+
test("should call fs.writeFileSync with correct arguments", () => {
|
|
39
|
+
const mockFilePath = "test-file.txt";
|
|
40
|
+
const mockFileContent = "This is a test file";
|
|
41
|
+
|
|
42
|
+
// Call the writeFile method
|
|
43
|
+
nodeFileSystem.writeFile(mockFilePath, mockFileContent);
|
|
44
|
+
|
|
45
|
+
// Assert that fs.writeFileSync was called with the correct arguments
|
|
46
|
+
expect(fs.writeFileSync).toHaveBeenCalledWith(mockFilePath, mockFileContent, "utf8");
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("readdirSync", () => {
|
|
51
|
+
test("should call fs.readdirSync with correct arguments and return file list", () => {
|
|
52
|
+
const mockDirectoryPath = "test-directory";
|
|
53
|
+
const mockFileList = ["file1.txt", "file2.txt"];
|
|
54
|
+
|
|
55
|
+
// Mock the fs.readdirSync method to return the mock file list
|
|
56
|
+
(fs.readdirSync as jest.Mock).mockReturnValue(mockFileList);
|
|
57
|
+
|
|
58
|
+
const result = nodeFileSystem.readdirSync(mockDirectoryPath);
|
|
59
|
+
|
|
60
|
+
// Assert that fs.readdirSync was called with the correct directory path
|
|
61
|
+
expect(fs.readdirSync).toHaveBeenCalledWith(mockDirectoryPath);
|
|
62
|
+
|
|
63
|
+
// Assert that the returned file list matches the mock file list
|
|
64
|
+
expect(result).toEqual(mockFileList);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
3
|
+
|
|
4
|
+
import * as fs from "fs";
|
|
5
|
+
|
|
6
|
+
export interface FileSystem {
|
|
7
|
+
readFile(filePath: string): string;
|
|
8
|
+
writeFile(filePath: string, content: string): void;
|
|
9
|
+
readdirSync(directory: string): string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/* eslint class-methods-use-this: "off" */
|
|
13
|
+
export class NodeFileSystem implements FileSystem {
|
|
14
|
+
readFile(filePath: string): string {
|
|
15
|
+
return fs.readFileSync(filePath, "utf8");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
writeFile(filePath: string, content: string): void {
|
|
19
|
+
fs.writeFileSync(filePath, content, "utf8");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
readdirSync(directory: string): string[] {
|
|
23
|
+
return fs.readdirSync(directory);
|
|
24
|
+
}
|
|
25
|
+
}
|