Skip to content

Commit

Permalink
ci: add auto-generator for readme
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed May 20, 2024
1 parent 69e85fb commit 580acd0
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 209 deletions.
65 changes: 65 additions & 0 deletions .github/deno_readme.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<ul data-for="bundle">
<li>Lint, minify, license CSS code and check features compatibility against MDN data for each browser</li>
<li>Bundle, minify, anonymize local file paths and license TypeScript code</li>
<li>Compile Rust projects to Web assembly, hot-patch source in base64 and minify output</li>
<li><a href="#-cli-utilities">CLI utilities</a></li>
</ul>
<ul data-for="crypto">
<li>Encrypt and decrypt data using a seed-salt derived private key</li>
<li>Generate time-based OTP secret key and verify tokens validity</li>
</ul>
<ul data-for="diff">
<li>Compute unified patch between two string</li>
</ul>
<ul data-for="logger">
<li>
Simple logger library with configurable log level
<ul>
<li>Support date, time and delta stamps</li>
<li>Support caller info (file, name, line) using internal V8's <code>Error.prepareStackTrace</code> API</li>
</ul>
</li>
<li>Automatically reads <code>LOG_LEVEL</code> environment variable (if available)</li>
</ul>
<ul data-for="qrcode">
<li>Generate QR codes without external dependencies</li>
<li>Support console, array and SVG output (with customizable colors)</li>
</ul>
<ul data-for="reactive">
<li>Create observable contexts to track get, set, delete and call operations</li>
<li>Support inherited contexts</li>
</ul>
<ul data-for="testing">
<li>
Cross-runtime testing framework
<ul>
<li>Support <a href="https://deno.com">deno</a> natively</li>
<li>Support <a href="https://nodejs.org">Node.js</a> through <code>npx tsx --test</code></li>
<li>Support <a href="https://bun.sh">bun</a> through <code>bun test</code></li>
<li><i>Note: although tests are run on multiple runtimes, this library <b>must</b> be run on deno</i></li>
</ul>
</li>
<li>Automatically skip test cases when runtime is not available on current platform</li>
</ul>
<ul data-for="typing">
<li>Utility types such as <code>Promisable</code>, <code>Nullable</code>, <code>MapKey</code>, <code>MapValue</code>, <code>SetValue</code>, etc.</li>
</ul>
<ul data-for="xml">
<li>
Parse XML to JavaScript object
<ul>
<li>Support cleaning options to remove attributes, comments, XML doctype and processing instructions from output</li>
<li>Support flatten options to flatten node content when only attributes, text or nothing is present</li>
<li>Support reviving options to trim text, replace XML entities, revive booleans and numbers</li>
<li>Also support custom reviving function</li>
</ul>
</li>
<li>
Stringify JavaScript object to XML
<ul>
<li>Support formatting options to configure indentation and text break lines</li>
<li>Support replacing options to replace XML entities</li>
<li>Also support custom replacing function</li>
</ul>
</li>
</ul>
37 changes: 37 additions & 0 deletions .github/deno_readme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Imports
import { expandGlob } from "jsr:@std/fs"
import { basename, dirname, fromFileUrl, resolve } from "jsr:@std/path"
import * as JSONC from "jsr:@std/jsonc"
import { DOMParser } from "https://deno.land/x/[email protected]/deno-dom-wasm.ts"
import { Logger } from "@libs/logger"

// Load local configurations
const logger = new Logger({ level: Logger.level.debug })
const root = fromFileUrl(import.meta.resolve("../"))
const document = new DOMParser().parseFromString(await Deno.readTextFile(fromFileUrl(import.meta.resolve("./deno_readme.html"))), "text/html")!
let table = "<table><!-- Generated by deno_readme.ts, do not edit manually -->"
for await (const { path } of expandGlob(`*/deno.jsonc`, { root })) {
const { icon, supported = [], playground } = JSONC.parse(await Deno.readTextFile(path)) as Record<string, unknown>
const name = basename(dirname(path))
const log = logger.with({ name, icon, supported, playground })
const features = document.querySelector(`[data-for="${name}"]`)?.outerHTML!
log.info()
log.debug(features)
table += `
<tr><th colspan="3"><h2><a href="https://jsr.io/@libs/${name}"><code>${icon} @libs/${name}</code></a></h2></th></tr>
<tr><th colspan="2">Metadata and compatibility</th><th>Features</th></tr>
<tr>
<th><a href="https://jsr.io/@libs/${name}"><img src="https://jsr.io/badges/@libs/${name}"></a></th>
<th rowspan="3">${(supported as string[]).map((platform) => `<img height="18px" src="https://jsr.io/logos/${platform}.svg">`).join("")}</th>
<td rowspan="3">${features}</td>
</tr>
<tr><th>${playground ? `<a href="${playground}"><img src="https://img.shields.io/badge/Playground--black?style=flat&logo=deno&labelColor=black"></a>` : ""}</th></tr>
<tr><th><a href="https://libs-coverage.lecoq.io/${name}"><img src="https://libs-coverage.lecoq.io/${name}/badge.svg"></a></th></tr>`.trim()
}
table += "</table>"

// Update README.md
let readme = await Deno.readTextFile(resolve(root, "README.md"))
readme = readme.replace(/<table>[\s\S]*<\/table>/, table)
await Deno.writeTextFile(resolve(root, "README.md"), readme)
logger.info("Updated README.md")
Loading

0 comments on commit 580acd0

Please sign in to comment.