-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add readme and method to export json (#838)
- Loading branch information
1 parent
662241f
commit 83b3540
Showing
4 changed files
with
63 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# ignore files generated by typescript | ||
dist/ | ||
**.json |
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,30 @@ | ||
# Moonbeam Types Bundle | ||
|
||
Exports npm package `moonbeam-types-bundle`, formated as per polkadot-js specification to use | ||
with the app or the api. | ||
|
||
## Exports | ||
|
||
``` | ||
export const typesBundle = { | ||
spec: { | ||
moonbeam: moonbeamDefinitions, | ||
moonbeamDefinitions, | ||
moonbase: moonbeamDefinitions, | ||
moonriver: moonbeamDefinitions, | ||
}, | ||
} as OverrideBundleType; | ||
``` | ||
|
||
`typesBundle` is of type OverrideBundleType to associate runtime names with correct definitions | ||
|
||
`moonbeamDefinitions` is of types OverrideBundleDefinition and returns a different set of type for | ||
each runtime version. | ||
|
||
## Print Types | ||
|
||
To print and save types JSON for a specific version run: | ||
`ts-node generateJSON.ts <verison number>` | ||
|
||
To print and save the latest: | ||
`ts-node generateJSON.ts latest` |
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,31 @@ | ||
import { RegistryTypes } from "@polkadot/types/types"; | ||
import fs from "fs"; | ||
import { moonbeamDefinitions } from "."; | ||
|
||
async function generateJSON() { | ||
const version = process.argv[2] || "latest"; | ||
let types: RegistryTypes; | ||
if (!moonbeamDefinitions.types) { | ||
throw new Error("missing types definitions"); | ||
} else if (version === "latest") { | ||
types = moonbeamDefinitions.types[moonbeamDefinitions.types.length - 1].types; | ||
} else if (Number(version)) { | ||
let i = 0; | ||
while ( | ||
i < moonbeamDefinitions.types.length && | ||
moonbeamDefinitions.types[i].minmax[1] && | ||
Number(moonbeamDefinitions.types[i].minmax[1]) < Number(version) | ||
) { | ||
i += 1; | ||
} | ||
types = moonbeamDefinitions.types[i].types; | ||
} else { | ||
throw new Error("parameter must be number or `latest`"); | ||
} | ||
console.log(JSON.stringify(types)); | ||
fs.appendFile("moonbeam-types-" + version + ".json", JSON.stringify(types), function (err) { | ||
if (err) throw err; | ||
console.log("Saved for version : " + version); | ||
}); | ||
} | ||
generateJSON(); |
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