Skip to content

Commit

Permalink
feat: helper for parsing bundle yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Smart committed Apr 22, 2022
1 parent a35b387 commit 17e6206
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/k8s/src/bundles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { loadAll } from "js-yaml";
import { readFileSync } from "fs";
import { IResource } from "./resources";

export const bundleFromFile = (file: string, prefix = 10) => {
const content = readFileSync(file, { encoding: "utf8" });
const decoded = loadAll(content) as IResource[];
let counter = prefix;

return decoded.reduce((acc, resource) => {
const suffix = resource.kind?.toLowerCase() ?? "bundle";
const name = `${counter++}-${suffix}`;

return {
...acc,
[name]: resource,
};
}, {} as Record<string, unknown>);
};
1 change: 1 addition & 0 deletions packages/k8s/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./bundles";
export * from "./common";
export * from "./configmaps";
export * from "./containers";
Expand Down

0 comments on commit 17e6206

Please sign in to comment.