-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
42 changed files
with
497 additions
and
278 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license. | ||
|
||
export * as walk from "https://deno.land/std@0.211.0/fs/walk.ts"; | ||
export * as walk from "https://deno.land/std@0.212.0/fs/walk.ts"; |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license. | ||
|
||
export * as semver from "https://deno.land/std@0.211.0/semver/mod.ts"; | ||
export * as semver from "https://deno.land/std@0.212.0/semver/mod.ts"; |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license. | ||
|
||
export * as assert from "https://deno.land/std@0.211.0/assert/mod.ts"; | ||
export * as bdd from "https://deno.land/std@0.211.0/testing/bdd.ts"; | ||
export * as assert from "https://deno.land/std@0.212.0/assert/mod.ts"; | ||
export * as bdd from "https://deno.land/std@0.212.0/testing/bdd.ts"; |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license. | ||
|
||
export * as path from "https://deno.land/std@0.211.0/path/mod.ts"; | ||
export * as posix from "https://deno.land/std@0.211.0/path/posix/mod.ts"; | ||
export * as walk from "https://deno.land/std@0.211.0/fs/walk.ts"; | ||
export * as path from "https://deno.land/std@0.212.0/path/mod.ts"; | ||
export * as posix from "https://deno.land/std@0.212.0/path/posix/mod.ts"; | ||
export * as walk from "https://deno.land/std@0.212.0/fs/walk.ts"; |
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license. | ||
|
||
export * as posix from "https://deno.land/std@0.211.0/path/posix/mod.ts"; | ||
export * as posix from "https://deno.land/std@0.212.0/path/posix/mod.ts"; |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license. | ||
|
||
export * as assert from "https://deno.land/std@0.211.0/assert/mod.ts"; | ||
export * as bdd from "https://deno.land/std@0.211.0/testing/bdd.ts"; | ||
export * as mock from "https://deno.land/std@0.211.0/testing/mock.ts"; | ||
export * as assert from "https://deno.land/std@0.212.0/assert/mod.ts"; | ||
export * as bdd from "https://deno.land/std@0.212.0/testing/bdd.ts"; | ||
export * as mock from "https://deno.land/std@0.212.0/testing/mock.ts"; |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license. | ||
|
||
export * as dotenv from "https://deno.land/std@0.211.0/dotenv/mod.ts"; | ||
export * as dotenv from "https://deno.land/std@0.212.0/dotenv/mod.ts"; |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license. | ||
|
||
export * as assert from "https://deno.land/std@0.211.0/assert/mod.ts"; | ||
export * as bdd from "https://deno.land/std@0.211.0/testing/bdd.ts"; | ||
export * as mock from "https://deno.land/std@0.211.0/testing/mock.ts"; | ||
export * as assert from "https://deno.land/std@0.212.0/assert/mod.ts"; | ||
export * as bdd from "https://deno.land/std@0.212.0/testing/bdd.ts"; | ||
export * as mock from "https://deno.land/std@0.212.0/testing/mock.ts"; |
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,7 @@ | ||
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license. | ||
|
||
export * as JSONC from "https://deno.land/std@0.212.0/jsonc/mod.ts"; | ||
export * as TOML from "https://deno.land/std@0.212.0/toml/mod.ts"; | ||
export * as YAML from "https://deno.land/std@0.212.0/yaml/mod.ts"; | ||
export * as path from "https://deno.land/std@0.212.0/path/mod.ts"; | ||
export * as fs from "https://deno.land/std@0.212.0/fs/mod.ts"; |
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,92 @@ | ||
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license. | ||
|
||
import * as runtime from "../standards/runtime.ts"; | ||
import { fs, JSONC, path, TOML, YAML } from "./deps.ts"; | ||
|
||
// TODO(@eser) introduce strategy pattern for "search parents" and "recursive search" options | ||
|
||
export const locate = async ( | ||
baseDir: string, | ||
filenames: Array<string>, | ||
searchParents = false, | ||
): Promise<string | undefined> => { | ||
let dir = baseDir; | ||
|
||
while (true) { | ||
for (const name of filenames) { | ||
const filepath = path.join(dir, name); | ||
const isExists = await fs.exists(filepath, { isFile: true }); | ||
|
||
if (isExists) { | ||
return filepath; | ||
} | ||
} | ||
|
||
if (!searchParents) { | ||
break; | ||
} | ||
|
||
const parent = path.dirname(dir); | ||
if (parent === dir) { | ||
break; | ||
} | ||
|
||
dir = parent; | ||
} | ||
|
||
return undefined; | ||
}; | ||
|
||
export const parse = async <T>( | ||
filepath: string, | ||
extension?: string, | ||
): Promise<T> => { | ||
const ext = extension ?? path.extname(filepath); | ||
|
||
const file = await runtime.current.readTextFile(filepath); | ||
|
||
if (ext === ".json") { | ||
return JSON.parse(file) as T; | ||
} | ||
|
||
if (ext === ".jsonc") { | ||
return JSONC.parse(file) as T; | ||
} | ||
|
||
if (ext === ".yaml" || ext === ".yml") { | ||
return YAML.parse(file) as T; | ||
} | ||
|
||
if (ext === ".toml") { | ||
return TOML.parse(file) as T; | ||
} | ||
|
||
throw new Error(`Unsupported file extension: ${ext}`); | ||
}; | ||
|
||
export type LoadResult<T> = { | ||
content: T | undefined; | ||
path: string | undefined; | ||
}; | ||
|
||
export const load = async <T>( | ||
baseDir: string, | ||
filenames: Array<string>, | ||
searchParents = false, | ||
): Promise<LoadResult<T>> => { | ||
const filepath = await locate(baseDir, filenames, searchParents); | ||
|
||
if (filepath === undefined) { | ||
return { | ||
content: undefined, | ||
path: undefined, | ||
}; | ||
} | ||
|
||
const result = await parse<T>(filepath); | ||
|
||
return { | ||
content: result, | ||
path: filepath, | ||
}; | ||
}; |
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,4 @@ | ||
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license. | ||
|
||
export * from "./loader.ts"; | ||
export * from "./resolver.ts"; |
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 @@ | ||
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license. | ||
|
||
export const resolvePath = ( | ||
filepath: string, | ||
baseUrl: string | null = null, | ||
) => { | ||
if (baseUrl === null || filepath[0] === "/") { | ||
return filepath; | ||
} | ||
|
||
const base = baseUrl[0] === "/" ? `file://${baseUrl}/` : baseUrl; | ||
const url = new URL(filepath, base); | ||
|
||
if (url.protocol === "file:") { | ||
return url.href.substring(7); | ||
} | ||
|
||
return url.href; | ||
}; |
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
Oops, something went wrong.