-
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.
- Loading branch information
Max J. Polster
committed
Mar 6, 2024
1 parent
ab4b3b2
commit ced3e82
Showing
3 changed files
with
56 additions
and
12 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
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,45 @@ | ||
import { readFile } from "node:fs/promises"; | ||
import { dirname, resolve } from "node:path"; | ||
|
||
export interface ConfigJson { | ||
extends?: string; | ||
noDuplicates?: string[]; | ||
sameVersions?: (string | string[])[]; | ||
} | ||
|
||
export interface Config { | ||
noDuplicates: string[]; | ||
sameVersions: (string | string[])[]; | ||
} | ||
|
||
export async function getConfig(context: string, json: ConfigJson | string): Promise<Config> { | ||
const config: Config = { | ||
noDuplicates: [], | ||
sameVersions: [], | ||
}; | ||
|
||
async function follow(filename: string): Promise<void> { | ||
const json = JSON.parse(await readFile(filename, "utf-8")); | ||
use(dirname(filename), json); | ||
} | ||
|
||
async function use(context: string, json: ConfigJson): Promise<void> { | ||
if (json.extends) { | ||
await follow(resolve(context, json.extends)); | ||
} | ||
if (json.noDuplicates) { | ||
config.noDuplicates?.push(...json.noDuplicates); | ||
} | ||
if (json.sameVersions) { | ||
config.sameVersions?.push(...json.sameVersions); | ||
} | ||
} | ||
|
||
if (typeof json === "string") { | ||
await follow(resolve(context, json)); | ||
} else { | ||
await use(context, json); | ||
} | ||
|
||
return config; | ||
} |
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