Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
feat: next-gen codegen (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjfvi authored Nov 22, 2022
1 parent 3f973a6 commit 0d6e70a
Show file tree
Hide file tree
Showing 75 changed files with 2,281 additions and 1,094 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/deno_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Deno Deploy
on: push
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@9db7f66e8e16b5699a514448ce994936c63f0d54 # v1.1.0
with:
deno-version: v1.x
- run: deno task run _tasks/gen_deploy.ts
- name: Deploy to Deno Deploy
uses: denoland/deployctl@v1
with:
project: capi-dev
entrypoint: target/deploy.ts
1 change: 1 addition & 0 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ jobs:
key: ${{ runner.os }}-deno-${{ hashFiles('lock.json', 'deps/**/*.ts') }}
- name: Setup Polkadot
uses: ./.github/actions/setup-polkadot
- run: deno task codegen
- run: deno task run ${{ matrix.example_path }}
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ jobs:
- name: Setup polkadot
uses: ./.github/actions/setup-polkadot
- run: deno task lint
- run: deno task codegen
- run: deno task star
- run: deno task test
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
},
"deno.codeLens.testArgs": ["--no-check=remote", "-A", "-L=info"],
"deno.config": "./deno.jsonc",
"deno.importMap": "./import_map_cache.json",
"deno.suggest.imports.hosts": {
"https://deno.land": true,
"https://x.nest.land": true,
"https://crux.land": true,
"http://localhost:5646": true,
"https://capi.dev": true
},
"deno.enable": true,
"deno.lint": true,
"editor.defaultFormatter": "dprint.dprint",
Expand Down
21 changes: 21 additions & 0 deletions _tasks/codegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { LocalCapiCodegenServer } from "../codegen/server/local.ts"
import * as fs from "../deps/std/fs.ts"

await fs.emptyDir("target/codegen/generated")
const port = 5646
const server = new LocalCapiCodegenServer()
server.listen(port)

await Deno.run({
cmd: [
"deno",
"cache",
"--no-lock",
"--import-map",
"import_map_localhost.json",
`--reload=http://localhost:${port}/`,
"examples/mod.ts",
],
}).status()

server.abortController.abort()
18 changes: 18 additions & 0 deletions _tasks/gen_deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { getModuleIndex, getSha } from "../codegen/server/git_utils.ts"
import { ensureDir } from "../deps/std/fs.ts"

const sha = await getSha()
const index = await getModuleIndex()

await ensureDir("target")
await Deno.writeTextFile(
"target/deploy.ts",
`
import { DenoDeployCodegenServer } from "../codegen/server/deploy.ts"
new DenoDeployCodegenServer(
"sha:${sha}",
${JSON.stringify(index)},
).listen(80)
`,
)
61 changes: 0 additions & 61 deletions codegen.ts

This file was deleted.

33 changes: 5 additions & 28 deletions codegen/Files.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
import { tsFormatter } from "../deps/dprint.ts"
import * as path from "../deps/std/path.ts"
import { S } from "./utils.ts"

export type File = { getContent: () => S }
export class Files extends Map<string, File> {
async write(outDir: string) {
const errors = []
try {
await Deno.remove(outDir, { recursive: true })
} catch (e) {
if (!(e instanceof Deno.errors.NotFound)) {
throw e
}
}
await Deno.mkdir(outDir, { recursive: true })
for (const [relativePath, file] of this.entries()) {
const outputPath = path.join(outDir, relativePath)
const content = S.toString(file.getContent())
try {
const formatted = tsFormatter.formatText("gen.ts", content)
await Deno.writeTextFile(outputPath, formatted)
} catch (e) {
await Deno.writeTextFile(outputPath, content)
errors.push(e)
}
}
if (errors.length) {
throw errors
}
export class Files extends Map<string, () => string> {
getFormatted(key: string) {
const file = this.get(key)
if (!file) return undefined
return tsFormatter.formatText(key, file())
}
}
185 changes: 0 additions & 185 deletions codegen/codecVisitor.ts

This file was deleted.

Loading

0 comments on commit 0d6e70a

Please sign in to comment.