-
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.
refactor: widespread reworking (#11)
Co-authored-by: T6 <t6@t6.fyi>
- Loading branch information
1 parent
37a40fa
commit 43f3c80
Showing
32 changed files
with
428 additions
and
342 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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,3 @@ | ||
# `trun` | ||
# `egts` | ||
|
||
CLI test utility for Deno and the Browser | ||
|
||
## Flags | ||
|
||
```sh | ||
--browser # whether to run tests in the browser | ||
--browser-exec-path # path to the browser binary | ||
--concurrency # number of tests to be run in parallel | ||
--headless # whether to run the browser in headless mode | ||
--ignore # name of ignore file; should contain list of glob patterns to not match | ||
--include # glob pattern of files to match | ||
--import-map # name of deno import map file | ||
--output # name of file to output test results to | ||
--reload # passed through to deno | ||
``` | ||
Example-related utilities used in [Capi](https://github.com/paritytech/capi). |
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 @@ | ||
export * from "https://deno.land/x/case@2.1.1/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 +1 @@ | ||
export * from "https://deno.land/x/esbuild@v0.17.12/mod.js" | ||
export * from "https://deno.land/x/esbuild@v0.17.15/mod.js" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "https://deno.land/x/scale@v0.11.2/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 +1 @@ | ||
export * from "https://deno.land/std@0.180.0/testing/asserts.ts" | ||
export * from "https://deno.land/std@0.182.0/testing/asserts.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 +1 @@ | ||
export * from "https://deno.land/std@0.180.0/async/mod.ts" | ||
export * from "https://deno.land/std@0.182.0/async/deferred.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 @@ | ||
export * from "https://deno.land/std@0.182.0/datetime/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 @@ | ||
export * from "https://deno.land/std@0.182.0/encoding/hex.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 +1 @@ | ||
export * from "https://deno.land/std@0.180.0/flags/mod.ts" | ||
export * from "https://deno.land/std@0.182.0/flags/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 @@ | ||
export * from "https://deno.land/std@0.182.0/fmt/colors.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 +1 @@ | ||
export * from "https://deno.land/std@0.180.0/fs/mod.ts" | ||
export * from "https://deno.land/std@0.182.0/fs/mod.ts" |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from "https://deno.land/std@0.180.0/io/mod.ts" | ||
export * from "https://deno.land/std@0.182.0/io/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 +1 @@ | ||
export * from "https://deno.land/std@0.180.0/path/mod.ts" | ||
export * from "https://deno.land/std@0.182.0/path/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 +1 @@ | ||
export * from "https://deno.land/std@0.180.0/streams/mod.ts" | ||
export * from "https://deno.land/std@0.182.0/streams/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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!-- This file is @generated by egts --> | ||
|
||
# Example | ||
|
||
Welcome to egts. This very script is an egts. | ||
The jsdoc section above serves as frontmatter. | ||
The code serves as to-be markdown code fences. | ||
And the comments serve as ordinary lines of markdown body. | ||
|
||
Bring imports into scope. | ||
|
||
```ts | ||
import { date, description, stability, tags, title, toMarkdown } from "egts" | ||
``` | ||
|
||
Compile an egts of this very script! | ||
|
||
```ts | ||
const result = toMarkdown("basic.eg.ts", await Deno.readTextFile(new URL(import.meta.url)), { | ||
title, | ||
tags: tags(["example", "docs", "deno", "typescript"]), | ||
date: date("yyyy-MM-dd"), | ||
description, | ||
stability, | ||
}) | ||
``` | ||
|
||
Log out the typed frontmatter. | ||
|
||
```ts | ||
console.log(result.frontmatter) | ||
``` | ||
|
||
Write the result to the fs. | ||
|
||
```ts | ||
await Deno.writeTextFile( | ||
new URL(import.meta.resolve("./basic.eg.md")), | ||
`<!-- This file is @generated by egts --> | ||
# ${result.frontmatter.title} | ||
${result.content} | ||
`, | ||
) | ||
``` |
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 @@ | ||
/** | ||
* @title Example | ||
* @tags example,docs,deno,typescript | ||
* @date 2023-10-10 | ||
* @description This description can be very long and even span | ||
* multiple lines. It will be parsed as expected. | ||
* @stability experiment | ||
*/ | ||
|
||
/// Welcome to egts. This very script is an egts. | ||
/// The jsdoc section above serves as frontmatter. | ||
/// The code serves as to-be markdown code fences. | ||
/// And the comments serve as ordinary lines of markdown body. | ||
|
||
/// Bring imports into scope. | ||
import { date, description, stability, tags, title, toMarkdown } from "egts" | ||
|
||
/// Compile an egts of this very script! | ||
const result = toMarkdown("basic.eg.ts", await Deno.readTextFile(new URL(import.meta.url)), { | ||
title, | ||
tags: tags(["example", "docs", "deno", "typescript"]), | ||
date: date("yyyy-MM-dd"), | ||
description, | ||
stability, | ||
}) | ||
|
||
/// Log out the typed frontmatter. | ||
console.log(result.frontmatter) | ||
|
||
/// Write the result to the fs. | ||
await Deno.writeTextFile( | ||
new URL(import.meta.resolve("./basic.eg.md")), | ||
`<!-- This file is @generated by egts --> | ||
# ${result.frontmatter.title} | ||
${result.content} | ||
`, | ||
) |
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,43 @@ | ||
const rFrontmatterFile = /^\s*\/\*\*(?<comment>.+?)\*\/\s*(?<body>.*)$/s | ||
const rLeadingAsterisk = /^\s*(?:\* ?)?/gm | ||
const rTagStart = /^(?=@\w+)/m | ||
const rTag = /^@(?<key>\w+)(\s+(?<value>.*))?$/s | ||
|
||
export function parseFrontmatter<F extends Record<string, unknown>>( | ||
pathname: string, | ||
src: string, | ||
parsers: FrontmatterParsers<F>, | ||
): ParseFrontmatterResult<F> { | ||
const fileMatch = rFrontmatterFile.exec(src) | ||
if (!fileMatch) throw new Error(`Could not extract module comment from "${pathname}".`) | ||
const { comment = "", body = "" } = fileMatch.groups ?? {} | ||
const commentContent = comment.replace(rLeadingAsterisk, "").trim() | ||
const tagsText = commentContent.split(rTagStart) | ||
const frontmatterRaw = Object.fromEntries( | ||
tagsText.map((pairText) => { | ||
const tagMatch = rTag.exec(pairText) | ||
if (!tagMatch) throw new Error(`Error when attempting to match tag in "${pathname}"`) | ||
const { key = "", value = "" } = tagMatch.groups ?? {} | ||
return [key, value.trim()] | ||
}), | ||
) | ||
const frontmatter = {} as F | ||
for (const [key, parse] of Object.entries(parsers)) { | ||
try { | ||
frontmatter[key as keyof F] = parse(frontmatterRaw[key]) | ||
} catch (e) { | ||
throw new Error(`Failed to parse "${key}" from "${pathname}"\n${Deno.inspect(e)}`) | ||
} | ||
} | ||
return { frontmatter, body } | ||
} | ||
|
||
export type FrontmatterParsers<F extends Record<string, unknown>> = { | ||
[K in keyof F]: FrontmatterParser<F[K]> | ||
} | ||
export type FrontmatterParser<T> = (raw: string | undefined) => T | ||
|
||
export interface ParseFrontmatterResult<F extends Record<string, unknown>> { | ||
frontmatter: F | ||
body: string | ||
} |
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,35 @@ | ||
import { titleCase } from "./deps/case.ts" | ||
import * as $ from "./deps/scale.ts" | ||
import * as datetime from "./deps/std/datetime.ts" | ||
import { FrontmatterParser } from "./frontmatter.ts" | ||
|
||
export const title: FrontmatterParser<string> = (raw) => { | ||
$.assert($.str, raw) | ||
return titleCase(raw) | ||
} | ||
|
||
export const description: FrontmatterParser<string> = (raw) => { | ||
$.assert($.str, raw) | ||
return raw | ||
} | ||
|
||
const $stability = $.literalUnion(["experiment", "unstable", "nearing", "stable"]) | ||
export const stability: FrontmatterParser<$.Native<typeof $stability>> = (raw) => { | ||
$.assert($stability, raw) | ||
return raw | ||
} | ||
|
||
export function tags<T extends string>(allowed: T[]): FrontmatterParser<T[]> { | ||
return (raw) => { | ||
const tags = raw?.split(",") | ||
$.assert($.array($.literalUnion(allowed)), tags) | ||
return tags | ||
} | ||
} | ||
|
||
export function date(format: string): FrontmatterParser<Date> { | ||
return (raw) => { | ||
$.assert($.str, raw) | ||
return datetime.parse(raw, format) | ||
} | ||
} |
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 @@ | ||
{ | ||
"scopes": { | ||
"examples/": { | ||
"egts": "./mod.ts" | ||
} | ||
} | ||
} |
Oops, something went wrong.