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.
Co-authored-by: Harry Solovay <[email protected]> Co-authored-by: tjjfvi <[email protected]>
- Loading branch information
1 parent
997c33f
commit 7dea826
Showing
26 changed files
with
192 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,10 @@ jobs: | |
registry-url: "https://registry.npmjs.org" | ||
- name: Build NPM Package | ||
run: deno task dnt --version ${{steps.get_tag_version.outputs.tag_version}} --server ${{steps.get_tag_version.outputs.tag_version}} | ||
- run: npm pack | ||
working-directory: "./target/npm" | ||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: package | ||
path: "./target/npm/*.tgz" | ||
path: "./target/npm/artifacts/capi*.tgz" | ||
- uses: octokit/[email protected] | ||
if: startsWith(github.ref, 'refs/tags/') | ||
with: | ||
|
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 |
---|---|---|
|
@@ -6,19 +6,30 @@ import importMap from "../import_map.json" assert { type: "json" } | |
import * as nets from "../nets.ts" | ||
import { normalizePackageName } from "../util/normalize.ts" | ||
|
||
const { version: packageVersion, server: serverVersion } = flags.parse(Deno.args, { | ||
string: ["version", "server"], | ||
default: { | ||
version: "v0.0.0-local", | ||
const { | ||
version: packageVersion, | ||
server: serverVersion, | ||
examples: buildExamples, | ||
} = flags.parse( | ||
Deno.args, | ||
{ | ||
string: ["version", "server"], | ||
boolean: ["examples"], | ||
default: { | ||
version: "v0.0.0-local", | ||
}, | ||
}, | ||
}) | ||
) | ||
|
||
const server = serverVersion ? `https://capi.dev/@${serverVersion}/` : "http://localhost:4646/" | ||
const hash = new URL(importMap.imports["@capi/"]).pathname.slice(1, -1) | ||
const hash = new URL(importMap.imports["@capi/"]).pathname.split("/").at(-2)! | ||
|
||
const outDir = path.join("target", "npm") | ||
const outDir = path.join(Deno.cwd(), "target", "npm") | ||
const capiOutDir = path.join(outDir, "capi") | ||
const examplesOutDir = path.join(outDir, "capi-examples") | ||
|
||
await fs.emptyDir(outDir) | ||
await Deno.mkdir(capiOutDir) | ||
|
||
const entryPoints: EntryPoint[] = [] | ||
const mappings: Record<string, string> = {} | ||
|
@@ -47,6 +58,12 @@ for (const pathname of allFiles) { | |
} | ||
} | ||
|
||
const capiCodegenDeps = Object.fromEntries( | ||
Object.keys(nets).map((key) => normalizePackageName(key)).map(( | ||
packageName, | ||
) => [`@capi/${packageName}`, `${server}${hash}/${packageName}.tar`]), | ||
) | ||
|
||
await Promise.all([ | ||
build({ | ||
package: { | ||
|
@@ -57,12 +74,7 @@ await Promise.all([ | |
license: "Apache-2.0", | ||
repository: "github:paritytech/capi", | ||
dependencies: { | ||
...Object.fromEntries( | ||
Object.keys(nets).map((key) => { | ||
const name = normalizePackageName(key) | ||
return [`@capi/${name}`, `${server}${hash}/${name}.tar`] | ||
}), | ||
), | ||
...capiCodegenDeps, | ||
"ts-node": "^10.9.1", | ||
}, | ||
}, | ||
|
@@ -110,11 +122,12 @@ await Promise.all([ | |
"node:net": "node:net", | ||
"node:http": "node:http", | ||
"node:stream": "node:stream", | ||
"node:fs": "node:fs", | ||
"node:fs/promises": "node:fs/promises", | ||
"https://raw.githubusercontent.com/paritytech/capi-binary-builds/f5baeca/streamToFile.ts": | ||
"https://raw.githubusercontent.com/paritytech/capi-binary-builds/f5baeca/streamToFile.node.ts", | ||
}, | ||
outDir, | ||
outDir: capiOutDir, | ||
shims: { | ||
deno: true, | ||
custom: [{ | ||
|
@@ -131,25 +144,25 @@ await Promise.all([ | |
test: false, | ||
typeCheck: false, | ||
}), | ||
fs.copy("LICENSE", path.join(outDir, "LICENSE")), | ||
fs.copy("Readme.md", path.join(outDir, "Readme.md")), | ||
fs.copy("server/static/", path.join(outDir, "esm/server/static/")), | ||
fs.copy("LICENSE", path.join(capiOutDir, "LICENSE")), | ||
fs.copy("Readme.md", path.join(capiOutDir, "Readme.md")), | ||
fs.copy("server/static/", path.join(capiOutDir, "esm/server/static/")), | ||
]) | ||
|
||
await Promise.all([ | ||
fs.copy( | ||
"target/npm/src/rune/_empty.d.ts", | ||
"target/npm/types/rune/_empty.d.ts", | ||
path.join(capiOutDir, "src/rune/_empty.d.ts"), | ||
path.join(capiOutDir, "types/rune/_empty.d.ts"), | ||
{ overwrite: true }, | ||
), | ||
editFile( | ||
"target/npm/esm/main.js", | ||
path.join(capiOutDir, "esm/main.js"), | ||
(content) => | ||
content | ||
.replace(/^#!.+/, "#!/usr/bin/env -S node --loader ts-node/esm"), | ||
), | ||
editFile( | ||
"target/npm/esm/_dnt.shims.js", | ||
path.join(capiOutDir, "esm/_dnt.shims.js"), | ||
(content) => | ||
content | ||
.replace(/"@deno\/shim-deno"/g, `"./deps/shims/Deno.node.js"`), | ||
|
@@ -159,3 +172,77 @@ await Promise.all([ | |
async function editFile(path: string, modify: (content: string) => string) { | ||
await Deno.writeTextFile(path, modify(await Deno.readTextFile(path))) | ||
} | ||
|
||
await new Deno.Command("npm", { | ||
args: ["pack", "--pack-destination", outDir], | ||
cwd: capiOutDir, | ||
}).output() | ||
|
||
if (buildExamples) { | ||
const exampleEntryPoints: EntryPoint[] = [] | ||
for await ( | ||
const { path } of fs.walkSync(".", { | ||
exts: [".eg.ts"], | ||
includeDirs: false, | ||
}) | ||
) { | ||
exampleEntryPoints.push({ | ||
name: path, | ||
path: `./${path}`, | ||
}) | ||
} | ||
|
||
await build({ | ||
package: { | ||
name: "capi-examples", | ||
version: packageVersion, | ||
type: "module", | ||
devDependencies: { | ||
"ts-node": "^10.9.1", | ||
}, | ||
dependencies: { | ||
...capiCodegenDeps, | ||
capi: `file:../capi-${packageVersion}.tgz`, | ||
}, | ||
}, | ||
compilerOptions: { | ||
importHelpers: true, | ||
sourceMap: true, | ||
target: "ES2021", | ||
lib: ["es2022.error", "dom.iterable"], | ||
}, | ||
entryPoints: exampleEntryPoints, | ||
mappings: { | ||
"https://deno.land/x/[email protected]/keyring/mod.ts": { | ||
name: "@polkadot/keyring", | ||
version: "12.2.1", | ||
}, | ||
"https://deno.land/x/[email protected]/types/mod.ts": { | ||
name: "@polkadot/types", | ||
version: "10.7.2", | ||
}, | ||
}, | ||
importMap: "_tasks/dnt_examples_import_map.json", | ||
outDir: examplesOutDir, | ||
scriptModule: false, | ||
declaration: false, | ||
shims: { deno: true }, | ||
test: false, | ||
typeCheck: false, | ||
}) | ||
|
||
await Promise.all( | ||
[ | ||
fs.copy( | ||
"examples/ink/erc20.json", | ||
path.join(examplesOutDir, "esm/examples/ink/erc20.json"), | ||
{ overwrite: true }, | ||
), | ||
fs.copy( | ||
"examples/ink/erc20.wasm", | ||
path.join(examplesOutDir, "esm/examples/ink/erc20.wasm"), | ||
{ overwrite: true }, | ||
), | ||
], | ||
) | ||
} |
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,5 @@ | ||
{ | ||
"imports": { | ||
"asserts": "../deps/std/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 |
---|---|---|
|
@@ -34,7 +34,9 @@ | |
"dnt": "deno task run _tasks/dnt.ts", | ||
"test": "deno task capi serve -- deno test -A -L=info --ignore=target --parallel -r=http://localhost:4646/", | ||
"test:update": "deno task test -- --update", | ||
"test:eg": "deno task run https://deno.land/x/[email protected]/test.ts 'examples/**/*.eg.ts'", | ||
"test:eg": "deno task run https://deno.land/x/[email protected]/main.ts", | ||
"test:eg:deno": "deno task test:eg test deno 'examples/**/*.eg.ts'", | ||
"test:eg:node": "deno task test:eg test node 'target/npm/capi-examples/esm/examples/**/*.eg.js'", | ||
"moderate": "deno run -A https://deno.land/x/[email protected]/mod.ts --exclude '*.test.ts' '*.node.ts' && dprint fmt", | ||
"capi": "deno run -A main.ts", | ||
"cache": "deno task capi serve -- deno cache -r=http://localhost:4646/", | ||
|
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
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
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
Oops, something went wrong.