Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions .changeset/clean-knives-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@onflow/fcl-core": minor
"@onflow/typedefs": minor
"@onflow/sdk": minor
---

Refactored fcl-core package to TypeScript
8 changes: 8 additions & 0 deletions .changeset/fifty-seahorses-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@onflow/fcl-core": minor
"@onflow/typedefs": minor
"@onflow/fcl": minor
"@onflow/sdk": minor
---

Refactored fcl package to TypeScript
8 changes: 8 additions & 0 deletions .changeset/lemon-toes-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@onflow/fcl-react-native": minor
"@onflow/fcl-core": minor
"@onflow/typedefs": minor
"@onflow/sdk": minor
---

Refactored fcl-react-native package to TypeScript
13 changes: 13 additions & 0 deletions .changeset/strong-onions-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@onflow/fcl-ethereum-provider": minor
"@onflow/transport-http": minor
"@onflow/util-logger": minor
"@onflow/fcl-core": minor
"@onflow/typedefs": minor
"@onflow/util-rpc": minor
"@onflow/fcl-wc": minor
"@onflow/fcl": minor
"@onflow/sdk": minor
---

Converted enums to template literals
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ todo.md
.vscode/*

# type declarations
packages/*/types/
packages/*/types/

# generated documentation
/docs-generator/output/*
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
README.md
*.md
*.mdx
packages/protobuf/src/generated/
packages/protobuf/src/generated/
**/*.hbs
177 changes: 177 additions & 0 deletions docs-generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Docs Generator

This directory contains scripts to generate documentation for Flow Client Library (FCL) packages.

## Overview

The documentation generator creates Markdown files for Docusaurus v2 websites. It automatically extracts TypeScript function signatures, parameter types, return types, and JSDoc comments to create comprehensive API documentation.

## Directory Structure

- `generate-docs.js` - Main script for generating documentation for a single package
- `generate-all-docs.js` - Script to generate documentation for all packages with the generate-docs script
- `templates/` - Handlebars templates for generating documentation pages
- `output/` - Where generated files are created
- `generators/` - Function utils to generate pages from templates and data

## Features

- Automatic discovery of packages with generate-docs scripts
- Support for JSDoc comments including function descriptions, parameter info, and usage examples
- Handlebars templates for easy customization of output format
- Consistent documentation structure across all packages
- Package index page listing all available packages
- Core types documentation from the @onflow/typedefs package

### JSDoc Support

The documentation generator extracts information from JSDoc comments in code. JSDoc comments can be added to improve the generated documentation:

```javascript
/**
* This description will be used in the documentation.
*
* @param {string} param1 - This description will be used for the parameter
* @returns {number} This description will be used for the return value
* @example
* // This example will be used in the documentation
* const result = myFunction("test")
*/
export function myFunction(param1) {
// ...
}
```

## Usage

### For Individual Packages

Each package that needs documentation should include a `generate-docs` script in its `package.json`:

```json
{
"scripts": {
"generate-docs": "node ../../docs-generator/generate-docs.js"
}
}
```

To generate documentation for a single package, run:

```bash
cd packages/<package-name>
npm run generate-docs
```

### For All Packages

To generate documentation for all packages that have a `generate-docs` script:

```bash
npm run generate-docs-all
```

This will:
1. Find all packages with a `generate-docs` script
2. Run the script for each package
3. Generate documentation in the `/docs-generator/output/packages-docs/<package-name>` directory
4. Generate core types documentation in `/docs-generator/output/packages-docs/types/index.md`

## Output Structure

The generated documentation follows this structure:

```
/docs-generator/output/
└── packages-docs/ # Main folder containing
├── package-a/ # Documentation for package-a
│ ├── index.md # Main package page with installation instructions and API
│ ├── functionName1.md
│ ├── functionName2.md
│ └── ...
├── package-b/
├── types/
│ └── index.md # Type definitions page with interfaces, type aliases, and enums
└── index.md # List contents of the folder
```

Each package has a main page that includes:
- Package overview
- Installation instructions
- API reference with links to individual function documentation

### Auto-generation Notes

All generated files are automatically generated from the source code of FCL packages and are ignored by git (except this README).
Do not modify these files directly as they will be overwritten when documentation is regenerated.

Instead:
- Update the JSDoc comments in the source code
- Customize the templates in `docs-generator/templates/`
- Create a `docs-generator.config.js` file in the package root for custom content

## Customizing Templates

You can customize the generated documentation by editing the Handlebars templates in the `templates/` directory.

### Custom Package Documentation

Packages can provide custom documentation content by creating a `docs-generator.config.js` file in the package root directory. The following customizations are supported:

```js
module.exports = {
customData: {
displayName: `Custom Package Reference`, // Used for Docusaurus sidebar title
sections: {
overview: ``, // Custom overview section
requirements: ``, // Custom requirements section
importing: ``, // Custom importing section
},
extra: ``, // Additional content
},
};
```

All properties in the configuration are optional. If a property is not specified, default values will be used.

## Adding Documentation to a New Package

To add documentation generation to a new package:

1. Add the generate-docs script to the package's `package.json`:

```json
{
"scripts": {
"generate-docs": "node ../../docs-generator/generate-docs.js"
}
}
```

2. Ensure the code has proper JSDoc comments for better documentation.

3. Run the generate-docs script to test it.

This package will now be included when running the `generate-docs-all` command.

## Core Types Documentation

The generator also creates documentation for all types, interfaces, and enums exported from the `@onflow/typedefs` package. This documentation is generated every time you run the generate-docs script for any package, ensuring that the types documentation is always up-to-date.

The types documentation in the `types` directory includes:

- **Interfaces** - Documented with their properties and methods
- **Types** - Documented with their underlying types
- **Enums** - Documented with all their members and values

All type documentation includes JSDoc descriptions when available.

## Integration with Documentation Projects

After generating documentation, copy the `output/packages-docs` directory to the documentation project. This will maintain the folder structure and allow the documentation build system to process the files.

## Notes

- Avoid relative path linking outside of packages-docs folder to avoid docusaurus linking problems. Use only packages-docs relative links or absolute paths.
- If adding an example to a jsdoc, avoid adding backticks, it will be directly embedded into typescript backticks on pages generation.
- Don't use multiple @returns in jsdocs, they are not supported.
64 changes: 64 additions & 0 deletions docs-generator/generate-all-docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const fs = require("fs")
const path = require("path")
const {execSync} = require("child_process")

async function main() {
try {
// Get packages source directory
const sourcePackagesDir = path.resolve(__dirname, "../packages")
// Find packages with generate-docs script
console.log(`Scanning for packages in ${sourcePackagesDir}`)
const packages =
fs.readdirSync(sourcePackagesDir).filter(name => {
try {
const itemPath = path.join(sourcePackagesDir, name)
// Check if it's a directory first
if (!fs.statSync(itemPath).isDirectory()) {
return false
}

const packageJsonPath = path.join(
sourcePackagesDir,
name,
"package.json"
)
const packageJson = JSON.parse(
fs.readFileSync(packageJsonPath, "utf8")
)
return packageJson.scripts && packageJson.scripts["generate-docs"]
} catch (error) {
console.warn(`Error checking package ${name}: ${error.message}`)
return false
}
}) || []
if (packages.length === 0) {
console.warn("No packages with generate-docs script were found.")
return
}
console.log(`Found ${packages.length} packages with generate-docs script:`)
packages.forEach(pkg => console.log(`- ${pkg}`))

// Navigate to the package directory and run the generate-docs script
for (const pkg of packages) {
const pkgDir = path.join(sourcePackagesDir, pkg)
execSync(`cd ${pkgDir} && npm run generate-docs`, {
stdio: "inherit",
env: {...process.env},
})
console.log("")
}

// Report results
console.log(`All docs correctly generated.`)
} catch (error) {
console.error("Error:")
console.error(error.message || error)
process.exit(1)
}
}

main().catch(error => {
console.error("Unhandled error:")
console.error(error.message || error)
process.exit(1)
})
Loading