This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
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
36 changed files
with
395 additions
and
240 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
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,24 +1,24 @@ | ||
import { codegen } from "../codegen/mod.ts" | ||
import { FsCache } from "../codegen/cache.ts" | ||
import { CodegenServer } from "../codegen/serve.ts" | ||
import * as fs from "../deps/std/fs.ts" | ||
import * as path from "../deps/std/path.ts" | ||
import * as C from "../mod.ts" | ||
import * as testClients from "../test_util/clients/mod.ts" | ||
import * as U from "../util/mod.ts" | ||
|
||
const currentDir = path.dirname(path.fromFileUrl(import.meta.url)) | ||
const codegenDir = path.join(currentDir, "../codegen/_output") | ||
const cacheDir = "target/codegen" | ||
await fs.emptyDir(path.join(cacheDir, "generated")) | ||
const cache = new FsCache(cacheDir) | ||
const port = 5646 | ||
console.log(`http://localhost:${port}/`) | ||
new CodegenServer(cache).listen(port) | ||
|
||
await Deno.remove(codegenDir, { recursive: true }) | ||
await Deno.run({ | ||
cmd: [ | ||
"deno", | ||
"cache", | ||
"--import-map", | ||
"import_map_localhost.json", | ||
`--reload=http://localhost:${port}/`, | ||
"examples/mod.ts", | ||
], | ||
}).status() | ||
|
||
await Promise.all( | ||
Object.entries(testClients).map(async ([runtime, client]) => { | ||
// if (runtime !== "polkadot") return | ||
const metadata = U.throwIfError(await C.metadata(client)().run()) | ||
const outDir = path.join(codegenDir, runtime) | ||
await codegen({ | ||
importSpecifier: "../../../mod.ts", | ||
clientFile: `../../../test_util/clients/${runtime}.ts`, | ||
metadata, | ||
}) | ||
.write(outDir) | ||
}), | ||
) | ||
Deno.exit(0) |
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 @@ | ||
import * as $ from "../deps/scale.ts" | ||
import * as fs from "../deps/std/fs.ts" | ||
import * as path from "../deps/std/path.ts" | ||
import { getOrInit, WeakMemo } from "../util/mod.ts" | ||
|
||
export abstract class Cache { | ||
rawMemo = new WeakMemo<string, Uint8Array>() | ||
decodedMemo = new Map<$.AnyCodec, WeakMemo<string, object>>() | ||
abstract _getRaw(key: string, init: () => Promise<Uint8Array>): Promise<Uint8Array> | ||
|
||
getRaw(key: string, init: () => Promise<Uint8Array>): Promise<Uint8Array> { | ||
return this.rawMemo.run(key, () => this._getRaw(key, init)) | ||
} | ||
|
||
get<T extends object>(key: string, $value: $.Codec<T>, init: () => Promise<T>): Promise<T> { | ||
const memo = getOrInit(this.decodedMemo, $value, () => new WeakMemo()) as WeakMemo<string, T> | ||
return memo.run(key, async () => { | ||
let value: T | undefined | ||
const raw = await this.getRaw(key, async () => $value.encode(value = await init())) | ||
value ??= $value.decode(raw) | ||
return value | ||
}) | ||
} | ||
} | ||
|
||
export class FsCache extends Cache { | ||
constructor(readonly location: string) { | ||
super() | ||
} | ||
|
||
async _getRaw(key: string, init: () => Promise<Uint8Array>) { | ||
const file = path.join(this.location, key) | ||
try { | ||
return await Deno.readFile(file) | ||
} catch (e) { | ||
if (!(e instanceof Deno.errors.NotFound)) throw e | ||
const content = await init() | ||
await fs.ensureDir(path.dirname(file)) | ||
await Deno.writeFile(file, content) | ||
return 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
Oops, something went wrong.