-
Notifications
You must be signed in to change notification settings - Fork 3
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
13 changed files
with
283 additions
and
6 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 |
---|---|---|
|
@@ -23,4 +23,6 @@ postcss.config.js | |
LICENSE | ||
README.md | ||
CHANGELOG.md | ||
.licenserc.json | ||
.licenserc.json | ||
|
||
*json_export_index* |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* @license Copyright 2024 @polkadot-ui/library authors & contributors | ||
SPDX-License-Identifier: MIT */ | ||
|
||
export const POLKADOT_NETWORK_URL = | ||
"https://raw.githubusercontent.com/polkadot-cloud/polkadot_network_directory/master/chain_info/"; | ||
|
||
export const NETWORKS = [ | ||
"Acala", | ||
"Ajuna", | ||
"Aleph_Zero", | ||
"Aleph_Zero_Testnet", | ||
"Astar", | ||
"Bajun", | ||
"Basilisk", | ||
"Bifrost", | ||
"Bifrost_Kusama", | ||
"Contracts", | ||
"HydraDX", | ||
"Idiyanale_Testnet", | ||
"Karura", | ||
"Khala", | ||
"Kusama", | ||
"Kusama_Asset_Hub", | ||
"Kusama_BridgeHub", | ||
"Moonbase_Alpha", | ||
"Moonbase_Relay", | ||
"Moonbeam", | ||
"Moonriver", | ||
"Phala", | ||
"Polkadot", | ||
"Polkadot_Asset_Hub", | ||
"Polkadot_BridgeHub", | ||
"Polkadot_Collectives", | ||
"Rococo", | ||
"Rococo_Asset_Hub", | ||
"Rococo_BridgeHub", | ||
"Shibuya", | ||
"Shiden", | ||
"Tangle", | ||
"Tinkernet", | ||
"Tokyo", | ||
"Watr", | ||
"Westend", | ||
"Westend_Asset_Hub", | ||
"Westend_BridgeHub", | ||
"Westend_Collectives", | ||
]; |
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,75 @@ | ||
/* @license Copyright 2024 @polkadot-ui/library authors & contributors | ||
SPDX-License-Identifier: MIT */ | ||
|
||
import fs from "fs"; | ||
import http from "https"; | ||
import { parse } from "yaml"; | ||
|
||
import { POLKADOT_NETWORK_URL, NETWORKS } from "./config.js"; | ||
|
||
const EXTERNAL_DIR = "./lib/external/"; | ||
const YAML_DIR = EXTERNAL_DIR + "yaml/"; | ||
const JSON_DIR = EXTERNAL_DIR + "json/"; | ||
const dirs = [YAML_DIR, JSON_DIR]; | ||
|
||
fs.rmSync(JSON_DIR, { recursive: true, force: true }); | ||
fs.rmSync(YAML_DIR, { recursive: true, force: true }); | ||
|
||
dirs.forEach((dir) => { | ||
if (!fs.existsSync(dir)) { | ||
fs.mkdirSync(dir); | ||
} | ||
}); | ||
|
||
const writeStream = fs.createWriteStream(EXTERNAL_DIR + "index.ts"); | ||
writeStream.write(`export * from "./json/index";`); | ||
writeStream.write(`export * from "./types";`); | ||
writeStream.end(); | ||
|
||
const generateFiles = (f) => { | ||
const yamlFile = f + ".yaml"; | ||
const jsonFile = f + ".json"; | ||
const downloadFile = fs.createWriteStream(YAML_DIR + yamlFile); | ||
http.get(POLKADOT_NETWORK_URL + yamlFile, (response) => { | ||
response.pipe(downloadFile); | ||
// after download completed, convert to JSON and close filestream | ||
downloadFile.on("finish", () => { | ||
const ymlFile = fs.readFileSync(YAML_DIR + yamlFile, "utf8"); | ||
fs.writeFileSync( | ||
`./lib/external/json/${jsonFile}`, | ||
JSON.stringify(parse(ymlFile)) | ||
); | ||
downloadFile.close(); | ||
}); | ||
}); | ||
}; | ||
|
||
for (const f of NETWORKS) { | ||
generateFiles(f); | ||
} | ||
|
||
const createIndexFile = () => { | ||
const exportArray = []; | ||
const indexFile = fs.createWriteStream(JSON_DIR + "index.tsx", { | ||
flags: "a", | ||
}); | ||
indexFile.write( | ||
`/* @license Copyright 2024 @polkadot-ui/library authors & contributors\n` | ||
); | ||
indexFile.write(`SPDX-License-Identifier: MIT */\n`); | ||
indexFile.write(`import { NetworkInformation } from "../types";\n`); | ||
|
||
for (const f of NETWORKS) { | ||
const f_lower = f.toLowerCase(); | ||
indexFile.write(`import ${f_lower + "Json"} from "./${f}.json";\n`); | ||
indexFile.write( | ||
`const ${f_lower}: NetworkInformation = ${f_lower + "Json"};\n` | ||
); | ||
exportArray.push(f_lower); | ||
} | ||
|
||
indexFile.write(`export { ${exportArray.join(", ")} };\n`); | ||
indexFile.end(); | ||
}; | ||
|
||
createIndexFile(); |
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,77 @@ | ||
export interface NetworkInformation { | ||
name: string; | ||
network_type: string; | ||
// TODO, add type guard for string | ||
// | "mainnet" | ||
// | "testnet" | ||
// | "canarynet" | ||
// | "solo_mainnet" | ||
// | "solo_testnet"; | ||
chain: Chain; | ||
chainspec: Chainspec; | ||
goals: string[]; | ||
repository: string; | ||
validators: string[]; | ||
release_cycle: string; | ||
specs: Specs; | ||
contacts: Contact[]; | ||
faucet?: null | string; | ||
rpc_endpoints: RpcEndpoint[]; | ||
api_endpoints: ApiEndpoint[]; | ||
bootnodes: Bootnode[]; | ||
documentation: string[]; | ||
expectations: string[]; | ||
features: string[]; | ||
notes?: string[]; | ||
} | ||
|
||
export interface Chain { | ||
type: string; | ||
// TODO, add type guard for string | ||
// | "relaychain" | ||
// | "parachain" | ||
// | "testnet" | ||
// | "solo_mainnet" | ||
// | "solo_testnet"; | ||
parent?: string; | ||
// TODO, add type guard for string | ||
// | "Polkadot" | ||
// | "Kusama" | ||
// | "Westend" | ||
// | "Rococo" | ||
// | "Moonbase Relay" | ||
// | "Tokyo"; | ||
consensus: string; | ||
// TODO, add type guard for string | ||
// "PoS" | "PoA" | "Aura"; | ||
sudo: boolean; | ||
para_id?: number; | ||
} | ||
|
||
export interface Chainspec { | ||
http_url: string; | ||
} | ||
|
||
export interface Specs { | ||
block_time: number; | ||
decimals: number; | ||
token: string; | ||
ss58_format: number; | ||
ed?: number; | ||
lease_period?: number; | ||
era?: number | null; | ||
} | ||
|
||
export interface Contact { | ||
type: string; | ||
contact: string; | ||
} | ||
|
||
export interface Endpoint { | ||
name: string; | ||
url: string; | ||
} | ||
|
||
export type RpcEndpoint = Endpoint; | ||
export type ApiEndpoint = Endpoint; | ||
export type Bootnode = Endpoint; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5768,6 +5768,11 @@ gulp-livereload@^4.0.2: | |
tiny-lr "^1.1.1" | ||
vinyl "^2.2.0" | ||
|
||
gulp-rename@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/gulp-rename/-/gulp-rename-2.0.0.tgz#9bbc3962b0c0f52fc67cd5eaff6c223ec5b9cf6c" | ||
integrity sha512-97Vba4KBzbYmR5VBs9mWmK+HwIf5mj+/zioxfZhOKeXtx5ZjBk57KFlePf5nxq9QsTtFl0ejnHE3zTC9MHXqyQ== | ||
|
||
gulp-replace@^1.1.4: | ||
version "1.1.4" | ||
resolved "https://registry.yarnpkg.com/gulp-replace/-/gulp-replace-1.1.4.tgz#06a0e9ee36f30e343c1e0a2dd760ec32c8a3d3b2" | ||
|
@@ -11284,6 +11289,7 @@ [email protected]: | |
integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw== | ||
|
||
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: | ||
name wrap-ansi-cjs | ||
version "7.0.0" | ||
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" | ||
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== | ||
|