Skip to content

Commit

Permalink
Merge pull request #13 from initia-labs/feat/registry-package
Browse files Browse the repository at this point in the history
fix: add .npmignore, fix package.json
  • Loading branch information
ALPAC-4 authored Mar 19, 2024
2 parents dca478b + 35d3744 commit 46c3200
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 231 deletions.
5 changes: 5 additions & 0 deletions _package/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist
node_modules

# MacOS
.DS_Store
4 changes: 4 additions & 0 deletions _package/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
src
types
zods
tsconfig*
29 changes: 26 additions & 3 deletions package/package-lock.json → _package/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions package/package.json → _package/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
"name": "@initia/initia-registry",
"version": "0.0.1",
"name": "@initia/initia-registry-types",
"version": "0.0.3",
"description": "The package provides TypeScript type definitions and Zod integration for initia-registry.",
"type": "module",
"types": "./dist/types/index.d.ts",
"exports": {
".": "./dist/types/index.js",
"./zod": "./zods/index.ts"
"./zod": "./dist/zods/index.js"
},
"files": [
"dist/types/*",
"dist/zods/*"
],
"scripts": {
"build": "tsc -p tsconfig.prod.json --module commonjs",
"generate": "rm -rf ./types && rm -rf ./zods && ts-node src/generate.ts"
"build": "tsc --module commonjs",
"generate": "rm -rf ./src/types && rm -rf ./src/zods && ts-node src/generate.ts"
},
"repository": {
"type": "git",
Expand All @@ -23,12 +26,12 @@
},
"homepage": "https://github.com/initia-labs/initia-registry#readme",
"dependencies": {
"json-schema-to-typescript": "^13.1.2",
"json-schema-to-zod": "^1.2.0",
"json5": "^2.2.3",
"zod": "^3.22.4"
},
"devDependencies": {
"json-schema-to-typescript": "^13.1.2",
"json-schema-to-zod": "^1.2.0",
"json5": "^2.2.3",
"ts-node": "^10.9.2",
"typescript": "^5.2.2"
}
Expand Down
60 changes: 60 additions & 0 deletions _package/src/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { compile } from "json-schema-to-typescript";
import { jsonSchemaToZodDereffed } from "json-schema-to-zod";
import * as fs from "fs";
import * as json5 from "json5";

const schemata: Record<string, string> = {
assetlist: "AssetList",
chain: "Chain",
ibc_data: "IBCData",
};

const schemaTitle: Record<string, string> = {
assetlist: "AssetLists",
chain: "CosmosChain",
ibc_data: "IBCData",
};

async function main() {
fs.mkdirSync("./src/types");
fs.mkdirSync("./src/zods");

Object.keys(schemata).map((schema) => generateTypeAndZod(schema));
}

main();

async function generateTypeAndZod(key: string) {
if (!fs.existsSync("./src/types/index.ts")) {
fs.writeFileSync("./src/types/index.ts", "");
}
if (!fs.existsSync("./src/zods/index.ts")) {
fs.writeFileSync("./src/zods/index.ts", "");
}

const schema = json5.parse(
fs.readFileSync(`../${key}.schema.json`).toString()
);

compile(schema, schemata[key]).then((ts) => {
ts = ts.replace(schemaTitle[key], schemata[key]);
fs.writeFileSync(`./src/types/${schemata[key]}.ts`, ts);
});

fs.appendFileSync(
"./src/types/index.ts",
`export * from "./${schemata[key]}"\n`
);

const zod = await jsonSchemaToZodDereffed(schema, {
module: "esm",
name: schemata[key] + "Schema",
});

fs.appendFileSync(
"./src/zods/index.ts",
`export * from "./${schemata[key]}"\n`
);

fs.writeFileSync(`./src/zods/${schemata[key]}.ts`, zod);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Asset lists are a similar mechanism to allow frontends and other UIs to fetch metadata associated with Cosmos SDK denoms, especially for assets sent over IBC.
*/
export interface AssetLists {
export interface AssetList {
$schema?: string;
chain_name: string;
assets: Asset[];
Expand Down
2 changes: 1 addition & 1 deletion package/types/Chain.ts → _package/src/types/Chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type Amount = string;
/**
* Cosmos Chain.json is a metadata file that contains information about a cosmos sdk based chain.
*/
export interface CosmosChain {
export interface Chain {
$schema?: string;
chain_name: string;
chain_id: string;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion package/types/index.ts → _package/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./Assetlist"
export * from "./AssetList"
export * from "./Chain"
export * from "./IBCData"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";

export const AssetlistSchema = z
export const AssetListSchema = z
.object({
$schema: z
.string()
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion package/zods/index.ts → _package/src/zods/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./IBCData"
export * from "./Assetlist"
export * from "./AssetList"
export * from "./Chain"
27 changes: 27 additions & 0 deletions _package/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"lib": ["es2019", "esnext"],
"sourceMap": true,
"baseUrl": "./",
"incremental": true,
"strict": true,
"noImplicitAny": true,
"alwaysStrict": true,
"strictNullChecks": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"outDir": "dist"
},
"include": ["src"],
"exclude": ["node_modules"]
}
111 changes: 0 additions & 111 deletions package/.gitignore

This file was deleted.

Loading

0 comments on commit 46c3200

Please sign in to comment.