-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: helper for parsing bundle yaml
- Loading branch information
Tim Smart
committed
Apr 22, 2022
1 parent
a35b387
commit 17e6206
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters