-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add CI and improve generation script (#1)
- Loading branch information
Showing
6 changed files
with
256 additions
and
215 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
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,24 @@ | ||
name: CI | ||
on: | ||
push: | ||
paths: | ||
- "**/*.json" | ||
- .github/workflows/*.yml | ||
jobs: | ||
ci: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: v1.x | ||
|
||
- name: Print version | ||
run: deno --version | ||
|
||
- name: Check hashes | ||
run: | | ||
md5sum devices.json mod.ts > hash.md5 | ||
deno run --no-check --quiet --allow-read=devices --allow-write=devices.json,mod.ts generate.ts | ||
md5sum --check hash.md5 |
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,30 +1,44 @@ | ||
import * as path from "https://deno.land/[email protected]/path/mod.ts"; | ||
|
||
async function main() { | ||
Deno.chdir(path.dirname(path.fromFileUrl(import.meta.url))); | ||
function timer() { | ||
const start = performance.now(); | ||
return function time() { | ||
return performance.now() - start; | ||
}; | ||
} | ||
|
||
async function main(dir = "devices") { | ||
const timeWriting = timer(); | ||
|
||
const readPromises = [...Deno.readDirSync(dir)] | ||
.map((entry) => entry.name) | ||
.filter((name) => name.endsWith(".json")) | ||
.sort((a, b) => a.localeCompare(b)) | ||
.map((name) => path.join(dir, name)) | ||
.map((path) => Deno.readTextFile(path)); | ||
|
||
const all: Record<string, string> = {}; | ||
const files = await Promise.all(readPromises); | ||
|
||
for await (const entry of Deno.readDir("devices")) { | ||
const string = await Deno.readTextFile(path.join("devices", entry.name)); | ||
const json = JSON.parse(string); | ||
Object.assign(all, json); | ||
} | ||
const objects = files.map((text) => JSON.parse(text)); | ||
|
||
const ids = JSON.stringify(all, null, 2); | ||
const data = Object.assign({}, ...objects); | ||
|
||
const devices = JSON.stringify(data, null, 2); | ||
|
||
// JSON is now officially a subset of ECMAScript, so this is fine. | ||
const out = ` | ||
const mod = ` | ||
// This file was generated automatically (./generate.ts) | ||
// Don't edit this file directly. | ||
export const devices = ${ids} as const; | ||
export const devices = ${devices} as const; | ||
`.trimStart(); | ||
|
||
await Promise.all([ | ||
Deno.writeTextFile("devices.json", ids), | ||
Deno.writeTextFile("mod.ts", out), | ||
Deno.writeTextFile("devices.json", devices + "\n"), | ||
Deno.writeTextFile("mod.ts", mod), | ||
]); | ||
|
||
console.log(`Generated in ${timeWriting()} ms`); | ||
} | ||
|
||
if (import.meta.main) { | ||
|
Oops, something went wrong.