Skip to content

Commit

Permalink
Merge pull request #857 from MoralisWeb3/readme-generator
Browse files Browse the repository at this point in the history
docs: readme generator
  • Loading branch information
ErnoW authored Nov 30, 2022
2 parents da0fa39 + 17c31c2 commit 1310a8b
Show file tree
Hide file tree
Showing 34 changed files with 666 additions and 35 deletions.
84 changes: 53 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<!--
CAUTION: This file is automatically generated. Do not edit it manually!
To adjust it, change the sdk-readme code generator or its template
-->
<div align="center">
<a align="center" href="https://moralis.io" target="_blank">
<img src="./assets/moralis-logo.svg" alt="Moralis JS SDK" height=200/>
<img src="https://github.com/MoralisWeb3/Moralis-JS-SDK/raw/main/assets/moralis-logo.svg" alt="Moralis JS SDK" height=200/>
</a>
<h1 align="center">Moralis SDK (JavaScript / TypeScript)</h1>
<a href="https://discord.gg/moralis" target="_blank">
Expand Down Expand Up @@ -99,10 +103,6 @@ If you need help with setting up the boilerplate or have other questions - don't
- [👩‍🔬 Advanced setup](#-advanced-setup)
- [1. Install the dependencies](#1-install-the-dependencies)
- [📦 Packages](#-packages)
- [Umbrella package](#umbrella-package)
- [Core module](#core-module)
- [API modules](#api-modules)
- [Other](#other)
- [🧙‍♂️ Community](#️-community)

# ⚙️ Configuration
Expand Down Expand Up @@ -181,43 +181,65 @@ Moralis.EvmApi.block.getBlock();

# 📦 Packages

## Umbrella package
## Main modules

| package | Changelog | Description |
| --------------------------------- | ---------------------------------------------------- | ---------------------------------------------------------------- |
| [moralis](./packages/moralis) | [CHANGELOG.md](./packages/moralis/CHANGELOG.md) | Umbrella package that includes all packages and initialises them |
The main modules of the SDK

## Core module
| package | changelog | description |
| ------------------------------------- | -------------------------------------- | ------------------------------------------------------------------------------------------- |
| [moralis](packages/moralis/README.md) | [2.8.0](packages/moralis/CHANGELOG.md) | The main package of Moralis containing all features. You probably are looking for this one. |

The core module is required in all applications. It will handle global dependencies and communications between other packages.
## Integrations

| package | Changelog | Description |
| -------------------------------------------------- |------------------------------------------------------ | -------------------------------------------------------------------------------------- |
| [@moralisweb3/common-core](./packages/common/core) | [CHANGELOG.md](./packages/common/core/CHANGELOG.md) | Core logic, responsible for core logic and sharing state and events between packages |
Integrations with frameworks and services

| package | changelog | description |
| ----------------------------------------------------------- | ------------------------------------------ | -------------------------------------- |
| [@moralisweb3/next](packages/next/README.md) | [2.8.0](packages/next/CHANGELOG.md) | Integration of Moralis in NextJs |
| [@moralisweb3/parse-server](packages/parseServer/README.md) | [2.8.0](packages/parseServer/CHANGELOG.md) | Integration of Moralis in parse-server |

## Utilities
| package | Changelog | Description |
| ----------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------ |
| [@moralisweb3/common-evm-utils](./packages/common/evmUtils) | [CHANGELOG.md](./packages/common/evmApi/CHANGELOG.md) | Utility functions and datatypes for EVM chains. |
| [@moralisweb3/common-sol-utils](./packages/common/solUtils) | [CHANGELOG.md](./packages/solApi/CHANGELOG.md) | Utility functions and datatypes for Solana networks. |
| [@moralisweb3/api-utils](./packages/apiUtils) | [CHANGELOG.md](./packages/apiUtils/CHANGELOG.md) | Generic functions, used in all api logic within the SDK. |
## Features

Feature modules. Only use these directly for advanced use-cases, the prefered way is to use these features via the umbrella package &quot;moralis&quot;

## Moralis functionalities
| package | changelog | description |
| -------------------------------------------------- | -------------------------------------- | ----------------------------------------------------------- |
| [@moralisweb3/auth](packages/auth/README.md) | [2.8.0](packages/auth/CHANGELOG.md) | Authenticate via web3 |
| [@moralisweb3/evm-api](packages/evmApi/README.md) | [2.8.0](packages/evmApi/CHANGELOG.md) | Make calls to the Evm blockchain via Moralis Evm Apis |
| [@moralisweb3/sol-api](packages/solApi/README.md) | [2.8.0](packages/solApi/CHANGELOG.md) | Make calls to the Solana blockchain via Moralis Solana Apis |
| [@moralisweb3/streams](packages/streams/README.md) | [2.8.0](packages/streams/CHANGELOG.md) | Subscribe to realtime data from the blockchain |

| package | Changelog | Description |
| ---------------------------------------------------- | --------------------------------------------------- | --------------------------------------- |
| [@moralisweb3/evm-api](./packages/evmApi) | [CHANGELOG.md](./packages/evmApi/CHANGELOG.md) | Fetch data from an EVM chain |
| [@moralisweb3/sol-api](./packages/solApi) | [CHANGELOG.md](./packages/solApi/CHANGELOG.md) | Fetch data from a Solana network |
| [@moralisweb3/auth](./packages/auth) | [CHANGELOG.md](./packages/auth/CHANGELOG.md) | Handle authentication |
| [@moralisweb3/streams](./packages/streams) | [CHANGELOG.md](./packages/streams/CHANGELOG.md) | Listen EVM blockchains |
## Core modules

## Other
Core modules are the building blocks of Moralis.

| package | changelog | description |
| ---------------------------------------------------------- | ------------------------------------------ | --------------------------------- |
| [@moralisweb3/common-core](packages/common/core/README.md) | [2.8.0](packages/common/core/CHANGELOG.md) | All core logic related to the SDK |

## Utilities

Utilities, types, operations and datatypes related used by other modules.

| package | changelog | description |
| --------------------------------------------------------------------------- | -------------------------------------------------- | ------------------------------------------------------------- |
| [@moralisweb3/api-utils](packages/apiUtils/README.md) | [2.8.0](packages/apiUtils/CHANGELOG.md) | Utilities and types to handle logic for api calls |
| [@moralisweb3/client-api-utils](packages/client/apiUtils/README.md) | [2.8.0](packages/client/apiUtils/CHANGELOG.md) | Client-side utilities for api calls |
| [@moralisweb3/client-evm-api](packages/client/evmApi/README.md) | [2.8.0](packages/client/evmApi/CHANGELOG.md) | Client-side logic for making Evm Api calls |
| [@moralisweb3/client-sol-api](packages/client/solApi/README.md) | [2.8.0](packages/client/solApi/CHANGELOG.md) | Client-side logic for making Solana Api calls |
| [@moralisweb3/common-auth-utils](packages/common/authUtils/README.md) | [2.8.0](packages/common/authUtils/CHANGELOG.md) | Utilities, operations, datatypes, and types related to Auth |
| [@moralisweb3/common-evm-utils](packages/common/evmUtils/README.md) | [2.8.0](packages/common/evmUtils/CHANGELOG.md) | Utilities, operations, datatypes and types related to Evm |
| [@moralisweb3/common-sol-utils](packages/common/solUtils/README.md) | [2.8.0](packages/common/solUtils/CHANGELOG.md) | Utilities, operations, datatypes and types related to Solana |
| [@moralisweb3/common-streams-utils](packages/common/streamsUtils/README.md) | [2.8.0](packages/common/streamsUtils/CHANGELOG.md) | Utilities, operations, datatypes and types related to Streams |

## Tools

Stand-alone tools and utilities

| package | changelog | description |
| ------------------------------------------------------------- | ------------------------------------------- | --------------------------------------------------------------- |
| [@moralisweb3/eslint-config](packages/eslintConfig/README.md) | [1.0.1](packages/eslintConfig/CHANGELOG.md) | Eslint rules, used within the Moralis SDK and its demo projects |

| package | Changelog | Description |
| ----------------------------------------------------- | ---------- | ----------------------------------------------------------- |
| [@moralisweb3/eslint-config](./packages/eslintConfig) | - | Eslint configuration that is used within Moralis |


# 🧙‍♂️ Community
Expand Down
6 changes: 6 additions & 0 deletions packages/apiUtils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"sideEffects": false,
"moralis": {
"name": "Api Utilities",
"type": "utils",
"scope": "server",
"description": "Utilities and types to handle logic for api calls"
},
"files": [
"lib/*"
],
Expand Down
6 changes: 6 additions & 0 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"sideEffects": false,
"moralis": {
"name": "Auth",
"type": "feature",
"scope": "server",
"description": "Authenticate via web3"
},
"files": [
"lib/*"
],
Expand Down
6 changes: 6 additions & 0 deletions packages/client/apiUtils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"sideEffects": false,
"moralis": {
"name": "Api Utilities for client-side",
"type": "utils",
"scope": "client",
"description": "Client-side utilities for api calls"
},
"files": [
"lib/*"
],
Expand Down
6 changes: 6 additions & 0 deletions packages/client/evmApi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"sideEffects": false,
"moralis": {
"name": "Evm Api logic for client-side",
"type": "utils",
"scope": "client",
"description": "Client-side logic for making Evm Api calls"
},
"files": [
"lib/*"
],
Expand Down
6 changes: 6 additions & 0 deletions packages/client/solApi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"sideEffects": false,
"moralis": {
"name": "Solana Api logic for client-side",
"type": "utils",
"scope": "client",
"description": "Client-side logic for making Solana Api calls"
},
"files": [
"lib/*"
],
Expand Down
7 changes: 6 additions & 1 deletion packages/codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@
"scripts": {
"lint": "eslint . --ext .js,.ts,.tsx,jsx",
"format": "prettier --write 'src/**/*.{js,ts}'",
"generate": "yarn esmo src/index.ts"
"generate": "yarn esmo src/index.ts",
"debug": "yarn esmo src/test.ts"
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
"@types/glob": "^8.0.0",
"@types/inquirer-autocomplete-prompt": "^1.3.3",
"@types/markdown-table": "^3.0.0",
"@types/minimist": "^1.2.2",
"esmo": "^0.14.1",
"glob": "^8.0.3",
"handlebars": "^4.7.7",
"inquirer-autocomplete-prompt": "^2.0.0",
"lodash": "^4.17.21",
"markdown-table": "^3.0.2",
"plop": "3.1.1",
"ts-morph": "16.0.0"
}
Expand Down
2 changes: 2 additions & 0 deletions packages/codegen/src/plopfile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NodePlopAPI } from 'plop';
import autocompletePrompt from 'inquirer-autocomplete-prompt';
import setNextGenerators from './next/generators';
import setSdkGenerators from './sdk/generators';

// == Types ================================================================

Expand All @@ -12,4 +13,5 @@ export default function (plop: NodePlopAPI) {
plop.setPrompt('autocomplete', autocompletePrompt);

setNextGenerators(plop);
setSdkGenerators(plop);
}
6 changes: 6 additions & 0 deletions packages/codegen/src/sdk/generators/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { NodePlopAPI } from 'plop';
import SdkReadmeGenerator from './readme';

export default function setNextGenerators(plop: NodePlopAPI) {
SdkReadmeGenerator(plop);
}
101 changes: 101 additions & 0 deletions packages/codegen/src/sdk/generators/readme/ReadmeGenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* eslint-disable no-console */
import { ActionType } from 'node-plop';
import { paths } from './constants';
import path from 'node:path';
import { PackageData, PackageInfo } from 'packages/codegen/src/utils/PackageInfo';
import { markdownTable } from 'markdown-table';
import { packageTypeTitles } from './config';

const FALLBACK_TYPE = 'other';

const isSupportedPackageType = (pkg: PackageData) => {
const isValid = pkg.type && Object.keys(packageTypeTitles).includes(pkg.type);
if (!isValid) {
console.warn(`Package ${pkg.name} omitted as the type "${pkg.type}" is not implemented`);
}
return isValid;
};
const isActivePackage = (pkg: PackageData) => pkg.isPublishable && !pkg.isDeprecated;
const hasMoralisMetadata = (pkg: PackageData) => pkg.moralis !== undefined;
const sortByPackageType = (typeA: string, typeB: string) =>
Object.keys(packageTypeTitles).indexOf(typeA) - Object.keys(packageTypeTitles).indexOf(typeB);

const createMarkdownLink = (title: string, url: string) => `[${title}](${url})`;

export class ReadmeGenerator {
private packageInfo: PackageInfo;

constructor() {
this.packageInfo = PackageInfo.create();
}

get packagesByType() {
return this.packageInfo.packages
.filter(isActivePackage)
.filter(hasMoralisMetadata)
.filter(isSupportedPackageType)
.reduce<Record<string, PackageData[]>>((acc, pkg) => {
const type = pkg.type ?? FALLBACK_TYPE;

return {
...acc,
[type]: [...(acc[type] ?? []), pkg],
};
}, {});
}

generatePackageTable = (packageType: string, rootPath: string) => {
const packages = this.packagesByType[packageType];

return `\
## ${packageTypeTitles[packageType].title}
${packageTypeTitles[packageType].description}
${markdownTable([
['package', 'changelog', 'description'],
...packages.map((pck) => [
createMarkdownLink(pck.name, path.relative(rootPath, path.join(pck.fullPath, 'README.md'))),
pck.changelog
? createMarkdownLink(pck.version, path.relative(rootPath, path.join(pck.fullPath, 'CHANGELOG.md')))
: pck.version,
pck.description,
]),
])}
`;
};

getAllPackagesTables({ rootPath }: { rootPath: string }) {
const packageTypes = Object.keys(this.packagesByType);

return `\
${packageTypes
.sort(sortByPackageType)
.map((pkg) => this.generatePackageTable(pkg, rootPath))
.join('\n')}
`;
}

public get actions(): ActionType[] {
return [
{
type: 'add',
templateFile: path.join(paths.templates, 'README.md.hbs'),
path: path.join(paths.root, 'README.md'),
force: true,
data: {
packagesTables: this.getAllPackagesTables({ rootPath: paths.root }),
},
},
{
type: 'add',
templateFile: path.join(paths.templates, 'README.md.hbs'),
path: path.join(paths.umbrellaPackage, 'README.md'),
force: true,
data: {
packagesTables: this.getAllPackagesTables({ rootPath: paths.umbrellaPackage }),
},
},
];
}
}
19 changes: 19 additions & 0 deletions packages/codegen/src/sdk/generators/readme/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// We only show package types that are defined in this list
export const packageTypeTitles: Record<string, { title: string; description: string }> = {
main: { title: 'Main modules', description: 'The main modules of the SDK' },
integration: { title: 'Integrations', description: 'Integrations with frameworks and services' },
feature: {
title: 'Features',
description:
'Feature modules. Only use these directly for advanced use-cases, the prefered way is to use these features via the umbrella package "moralis"',
},
core: { title: 'Core modules', description: 'Core modules are the building blocks of Moralis.' },
utils: {
title: 'Utilities',
description: 'Utilities, types, operations and datatypes related used by other modules.',
},
tools: {
title: 'Tools',
description: 'Stand-alone tools and utilities',
},
};
13 changes: 13 additions & 0 deletions packages/codegen/src/sdk/generators/readme/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { fileURLToPath } from 'node:url';
import path from 'node:path';

const dirname = path.dirname(fileURLToPath(import.meta.url));

const root = path.join(dirname, '../../../../../..');

export const paths = {
root,
packages: path.join(root, 'packages'),
templates: path.join(dirname, './templates'),
umbrellaPackage: path.join(root, 'packages/moralis'),
};
10 changes: 10 additions & 0 deletions packages/codegen/src/sdk/generators/readme/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NodePlopAPI } from 'plop';
import { ReadmeGenerator } from './ReadmeGenerator';

export default function NextReadmeGenerator(plop: NodePlopAPI) {
plop.setGenerator('sdk-readme', {
description: 'readme the whole SDK',
prompts: [],
actions: () => new ReadmeGenerator().actions,
});
}
Loading

1 comment on commit 1310a8b

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 25%
26.34% (49/186) 19.14% (9/47) 22.85% (8/35)
auth Coverage: 90%
92.77% (77/83) 81.81% (18/22) 90% (18/20)
evm-api Coverage: 100%
100% (79/79) 66.66% (6/9) 100% (47/47)
common-evm-utils Coverage: 64%
65% (938/1443) 19.93% (123/617) 35.89% (201/560)
sol-api Coverage: 96%
96.66% (29/30) 66.66% (6/9) 91.66% (11/12)
common-sol-utils Coverage: 74%
73.77% (135/183) 60% (12/20) 65.67% (44/67)
common-streams-utils Coverage: 93%
93.13% (787/845) 85.96% (196/228) 84.14% (276/328)
streams Coverage: 87%
86.71% (398/459) 67.14% (47/70) 84.52% (71/84)

Please sign in to comment.