Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4x clean docs #6582

Merged
merged 25 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ yarn-error.log*

# Don't include auto generated docs of current version
docs/api

docs/libdocs
1 change: 1 addition & 0 deletions docs/docs/libdocs/.nojekyll
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
5 changes: 5 additions & 0 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ const config = {
{
to: '/',
activeBasePath: '/',
label: 'Guides & Tutorials',
position: 'left',
},
{
to: 'libdocs',
label: 'Documentation',
position: 'left',
},
Expand Down
1 change: 1 addition & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
const sidebars = {
guidesSidebar: [{ type: 'autogenerated', dirName: 'guides' }],
docSidebar: [{ type: 'autogenerated', dirName: 'libdocs' }],
glossarySidebar: [{ type: 'autogenerated', dirName: 'glossary' }],
apiSidebar: [
{
Expand Down
368 changes: 194 additions & 174 deletions docs/yarn.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"build:esm": "lerna run build:esm --stream",
"build:web": "lerna run build:web --stream",
"build:web:analyze": "lerna run build:web:analyze --stream",
"build:docs": "cd docs && yarn install && yarn build",
"generate:docs": "node ./scripts/docshelper/generatedoc.js",
"build:docs": "yarn generate:docs && cd docs && yarn install && yarn build",
"changelog": "ts-node -P scripts/changelog/tsconfig.json scripts/changelog/src/index.ts",
"clean": "lerna run clean --stream --parallel",
"ganache:start": "WEB3_SYSTEM_TEST_BACKEND=ganache && ./scripts/ganache.sh start",
Expand Down Expand Up @@ -119,10 +120,12 @@
"ts-jest": "^28.0.7",
"ts-loader": "^9.3.1",
"ts-node": "^10.9.1",
"typedoc": "^0.23.9",
"typedoc": "^0.25.3",
"typedoc-monorepo-link-types": "^0.0.4",
"typedoc-plugin-extras": "^2.2.5",
"typedoc-plugin-markdown": "^3.17.0",
"typedoc-plugin-mdn-links": "^2.0.0",
"typedoc-plugin-merge-modules": "^5.1.0",
"typescript": "^4.7.4",
"utf-8-validate": "^5.0.9",
"webpack": "^5.73.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/web3-eth-accounts/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* @module Accounts
*/

import {
decrypt as createDecipheriv,
encrypt as createCipheriv,
Expand Down Expand Up @@ -70,6 +74,7 @@ import type {
SignResult,
} from './types.js';


/**
* Get the private key Uint8Array after the validation
*/
Expand Down
1 change: 1 addition & 0 deletions packages/web3-eth-contract/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export type ContractMethodsInterface<Abi extends ContractAbi> = {
} & { [key: string]: ContractBoundMethod<any> };

/**
* @hidden
* The event object can be accessed from `myContract.events.myEvent`.
*
* \> Remember: To subscribe to an event, your provider must have support for subscriptions.
Expand Down
7 changes: 5 additions & 2 deletions packages/web3-eth-personal/src/personal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { Address, EthPersonalAPI, HexString, Transaction } from 'web3-types';

import * as rpcWrappers from './rpc_method_wrappers.js';

/**
* Eth Personal allows you to interact with the Ethereum node’s accounts.
*/
export class Personal extends Web3Context<EthPersonalAPI> {
/**
*Returns a list of accounts the node controls by using the provider and calling the RPC method personal_listAccounts. Using `web3.eth.accounts.create()` will not add accounts into this list. For that use `web3.eth.personal.newAccount()`.
Expand Down Expand Up @@ -143,9 +146,9 @@ export class Personal extends Web3Context<EthPersonalAPI> {
/**
* Signs a transaction. This account needs to be unlocked.
* **_NOTE:_** Sending your account password over an unsecured HTTP RPC connection is highly unsecure.
* @param tx - The transaction data to sign. See {@link sendTransaction} for more information.
* @param tx - The transaction data to sign. See sendTransaction for more information.
* @param passphrase - The password of the `from` account, to sign the transaction with.
* @returns - The RLP encoded transaction. The `raw` property can be used to send the transaction using {@link sendSignedTransaction}.
* @returns - The RLP encoded transaction. The `raw` property can be used to send the transaction using sendSignedTransaction.
* @example
* ```ts
* const tx = personal
Expand Down
6 changes: 5 additions & 1 deletion packages/web3-eth/src/web3_eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export const registeredSubscriptions = {
newBlockHeaders: NewHeadsSubscription, // the same as newHeads. just for support API like in version 1.x
};

/**
*
* The Web3Eth allows you to interact with an Ethereum blockchain.
*/
export class Web3Eth extends Web3Context<Web3EthExecutionAPI, RegisteredSubscription> {
public constructor(
providerOrContext?: SupportedProviders<any> | Web3ContextInitOptions | string,
Expand All @@ -95,7 +99,7 @@ export class Web3Eth extends Web3Context<Web3EthExecutionAPI, RegisteredSubscrip
super({
...(providerOrContext as Web3ContextInitOptions),
registeredSubscriptions,
});
});
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/web3-net/src/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import { DataFormat, DEFAULT_RETURN_FORMAT, Web3NetAPI } from 'web3-types';

import * as rpcMethodsWrappers from './rpc_method_wrappers.js';

/**
* Net class allows you to interact with an Ethereum node’s network properties.
*/
export class Net extends Web3Context<Web3NetAPI> {
/**
* Gets the current network ID
Expand Down
4 changes: 4 additions & 0 deletions packages/web3-utils/src/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* @module Utils
*/

import { keccak256 } from 'ethereum-cryptography/keccak.js';
import { bytesToUtf8, utf8ToBytes as ecUtf8ToBytes } from 'ethereum-cryptography/utils.js';
import { Address, Bytes, HexString, Numbers, ValueTypes } from 'web3-types';
Expand Down
5 changes: 5 additions & 0 deletions packages/web3-utils/src/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* @module Utils
*/

import { keccak256 } from 'ethereum-cryptography/keccak.js';
import { utf8ToBytes } from 'ethereum-cryptography/utils.js';
import {
Expand Down Expand Up @@ -46,6 +50,7 @@ import {
} from './converters.js';
import { leftPad, rightPad, toTwosComplement } from './string_manipulation.js';


const SHA3_EMPTY_BYTES = '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470';

/**
Expand Down
59 changes: 59 additions & 0 deletions scripts/docshelper/base.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module.exports = {
entryPointStrategy: "expand",
out: "./docs/docs/libdocs/",

// "exclude": [
// "**/*.test.ts"
// ],
plugin: [
"typedoc-plugin-markdown",
"typedoc-plugin-merge-modules"
],

mergeModulesRenameDefaults: true, // NEW option of TypeDoc added by typedoc-plugin-merge-modules plugin

hideInPageTOC: true,
hideBreadcrumbs: true,
hidePageTitle: true,

//publicPath: "https://docs.web3js.org/libdocs/",
//filenameSeparator : "-",
//indexTitle: "",
//preserveAnchorCasing: true,

excludeExternals: true,
excludeReferences: true,
tsconfig: "./docs/tsconfig.docs.json",
excludeNotDocumented: true,

excludeNotDocumentedKinds: [
"Namespace",
"Enum",
"EnumMember",
"Variable",
"Function",
"Class",
"Interface",
"Constructor",
"Property",
"Method",
"CallSignature",
"IndexSignature",
"ConstructorSignature",
"Accessor",
"GetSignature",
"SetSignature",
"TypeAlias",
"Reference"
],
excludeInternal: true,
excludePrivate: true,
excludeProtected: true,

visibilityFilters: {
"protected": false,
"private": false,
"inherited": false,
"external": false
}
};
20 changes: 20 additions & 0 deletions scripts/docshelper/classesdoc.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const baseDocConfig = require('./base.config.js');

module.exports = {
... baseDocConfig,

entryPoints: [
"./packages/web3-eth/src/web3_eth.ts",
"./packages/web3-eth-accounts/src/wallet.ts",
"./packages/web3-eth-accounts/src/account.ts",
"./packages/web3-eth-contract/src/contract.ts",
"./packages/web3-eth-ens/src/ens.ts",
"./packages/web3-eth-iban/src/iban.ts",
"./packages/web3-eth-personal/src/personal.ts",
"./packages/web3-net/src/net.ts",
],

excludeCategories: "ContractEvent", // for exluding being in module.md file and invalid link in contract.md
mergeModulesMergeMode: "project", // NEW option of TypeDoc added by typedoc-plugin-merge-modules plugin

};
17 changes: 17 additions & 0 deletions scripts/docshelper/functionsdoc.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

const baseConfig = require('./base.config.js');

module.exports = {
... baseConfig,

entryPoints: [
"./packages/web3-eth-accounts/src/account.ts",
//utils
"./packages/web3-utils/src/converters.ts",
"./packages/web3-utils/src/hash.ts"
],

mergeModulesMergeMode: "module", // NEW option of TypeDoc added by typedoc-plugin-merge-modules plugin
cleanOutputDir: false,

};
120 changes: 120 additions & 0 deletions scripts/docshelper/generatedoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
const TypeDoc = require("typedoc");
const fs = require('fs');
const path = require('path');

const functionsDocConfig = require("./functionsdoc.config.js");
const classesDocsConfig = require("./classesdoc.config.js");


async function run() {
await generateDocs(classesDocsConfig);
postProcessClassesDocs(classesDocsConfig);

await generateDocs(functionsDocConfig);
postProcessFunctionsDocs(functionsDocConfig);

if (fs.existsSync(classesDocsConfig.out + "/modules.md")) {
fs.unlinkSync(classesDocsConfig.out + "/modules.md");
}
}

run().catch(console.log);

///// Post process docs
function postProcessClassesDocs(configOptions) {

const packagesPath = configOptions.out + '/classes/';

copyDir(packagesPath, configOptions.out);
cleanDir(packagesPath);

try {
const files = fs.readdirSync(configOptions.out);
files.forEach(function (file) {
const filePath = path.join(configOptions.out, file);
const data = fs.readFileSync(filePath, 'utf8');
const replacedData = data.replace(/\.md/g, '');
fs.writeFileSync(filePath, replacedData, 'utf8');
});
} catch (err) {
console.log('Error getting directory information.');
}

}

function postProcessFunctionsDocs(configOptions) {

const packagesPath = configOptions.out + '/modules/';
//post process functions

copyDir(packagesPath, configOptions.out);
cleanDir(packagesPath);

}

///// utils
async function generateDocs(config) {
const app = await TypeDoc.Application.bootstrapWithPlugins(config);

const project = await app.convert();

if (project) {
await app.generateDocs(project, config.out);
}
}

function copyDir(src, dest) {
// Create the destination folder if it doesn't exist
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest);
}

// Read the source directory
const files = fs.readdirSync(src);

// Loop through all the files in the source directory
for (let file of files) {
// Get the full path of the file
const srcPath = path.join(src, file);
const destPath = path.join(dest, file);

// Get the file's stats
const stats = fs.statSync(srcPath);

// If the file is a directory, recursively copy it
if (stats.isDirectory()) {
copyDir(srcPath, destPath);
} else {
// If the file is a file, copy it
fs.copyFileSync(srcPath, destPath);
}
}
}

function cleanDir(dirPath) {
// Check if the directory exists
if (fs.existsSync(dirPath)) {
// Get all the files and subdirectories in the directory
const files = fs.readdirSync(dirPath);

// Loop through all the files and subdirectories
for (let file of files) {
// Get the full path of the file or subdirectory
const filePath = path.join(dirPath, file);

// Check if it's a file or a subdirectory
const stats = fs.statSync(filePath);
if (stats.isFile()) {
// If it's a file, delete it
fs.unlinkSync(filePath);
} else {
// If it's a subdirectory, recursively delete it
cleanDir(filePath);
}
}

// Finally, delete the directory itself
fs.rmdirSync(dirPath);
}
}

Loading
Loading