-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Including the bundle system to parse the based configuration file and…
… including find-up as a dependency
- Loading branch information
Showing
5 changed files
with
261 additions
and
59 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,39 @@ | ||
import { findUp } from 'find-up' | ||
import { readJSON } from 'fs-extra/esm' | ||
import { bundle } from '@based/bundle' | ||
|
||
export type Project = { | ||
cluster?: string | ||
project?: string | ||
org?: string | ||
env?: string | ||
apiKey?: string | ||
} | ||
|
||
export const getBasedFile = async (file: string[]): Promise<Project | null> => { | ||
if (!file || !file.length) { | ||
throw new Error() | ||
} | ||
|
||
const basedFile = await findUp(file) | ||
let basedFileContent: Project = {} | ||
const basedProject: Project = {} | ||
|
||
if (basedFile) { | ||
if (basedFile.endsWith('.json')) { | ||
basedFileContent = await readJSON(basedFile) | ||
} else { | ||
const bundled = await bundle({ | ||
entryPoints: [basedFile], | ||
}) | ||
const compiled = bundled.require() | ||
|
||
basedFileContent = compiled.default || compiled | ||
} | ||
|
||
Object.assign(basedProject, basedFileContent) | ||
return basedProject | ||
} else { | ||
throw new Error() | ||
} | ||
} |
Oops, something went wrong.