kubernetes-fluent-client 3.0.2 → 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.
Files changed (38) hide show
  1. package/.prettierignore +4 -0
  2. package/README.md +24 -0
  3. package/dist/cli.js +21 -1
  4. package/dist/fileSystem.d.ts +11 -0
  5. package/dist/fileSystem.d.ts.map +1 -0
  6. package/dist/fileSystem.js +42 -0
  7. package/dist/fileSystem.test.d.ts +2 -0
  8. package/dist/fileSystem.test.d.ts.map +1 -0
  9. package/dist/fileSystem.test.js +75 -0
  10. package/dist/generate.d.ts +71 -11
  11. package/dist/generate.d.ts.map +1 -1
  12. package/dist/generate.js +130 -117
  13. package/dist/generate.test.js +293 -346
  14. package/dist/postProcessing.d.ts +246 -0
  15. package/dist/postProcessing.d.ts.map +1 -0
  16. package/dist/postProcessing.js +497 -0
  17. package/dist/postProcessing.test.d.ts +2 -0
  18. package/dist/postProcessing.test.d.ts.map +1 -0
  19. package/dist/postProcessing.test.js +550 -0
  20. package/e2e/cli.e2e.test.ts +123 -0
  21. package/e2e/crds/policyreports.default.expected/policyreport-v1alpha1.ts +332 -0
  22. package/e2e/crds/policyreports.default.expected/policyreport-v1alpha2.ts +360 -0
  23. package/e2e/crds/policyreports.default.expected/policyreport-v1beta1.ts +360 -0
  24. package/e2e/crds/policyreports.no.post.expected/policyreport-v1alpha1.ts +331 -0
  25. package/e2e/crds/policyreports.no.post.expected/policyreport-v1alpha2.ts +360 -0
  26. package/e2e/crds/policyreports.no.post.expected/policyreport-v1beta1.ts +360 -0
  27. package/e2e/crds/test.yaml/policyreports.test.yaml +1008 -0
  28. package/e2e/crds/test.yaml/uds-podmonitors.test.yaml +1245 -0
  29. package/e2e/crds/uds-podmonitors.default.expected/podmonitor-v1.ts +1333 -0
  30. package/e2e/crds/uds-podmonitors.no.post.expected/podmonitor-v1.ts +1360 -0
  31. package/package.json +10 -9
  32. package/src/cli.ts +25 -1
  33. package/src/fileSystem.test.ts +67 -0
  34. package/src/fileSystem.ts +25 -0
  35. package/src/generate.test.ts +368 -358
  36. package/src/generate.ts +173 -154
  37. package/src/postProcessing.test.ts +742 -0
  38. 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.2",
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
  },
@@ -41,26 +42,26 @@
41
42
  "http-status-codes": "2.3.0",
42
43
  "node-fetch": "2.7.0",
43
44
  "quicktype-core": "23.0.170",
44
- "type-fest": "4.25.0",
45
+ "type-fest": "4.26.1",
45
46
  "yargs": "17.7.2"
46
47
  },
47
48
  "devDependencies": {
48
- "@commitlint/cli": "19.4.0",
49
- "@commitlint/config-conventional": "19.4.1",
49
+ "@commitlint/cli": "19.5.0",
50
+ "@commitlint/config-conventional": "19.5.0",
50
51
  "@jest/globals": "29.7.0",
51
52
  "@types/byline": "4.2.36",
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.3.0",
56
- "@typescript-eslint/parser": "8.3.0",
57
- "eslint-plugin-jsdoc": "50.2.2",
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.0",
62
+ "semantic-release": "24.1.2",
62
63
  "ts-jest": "29.2.5",
63
- "typescript": "5.5.4"
64
+ "typescript": "5.6.2"
64
65
  },
65
66
  "release": {
66
67
  "branches": [
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
- await generate(opts);
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
+ }