Skip to content

Commit

Permalink
Jsdocs api plugins generation script
Browse files Browse the repository at this point in the history
  • Loading branch information
KhromovNikita committed Aug 5, 2024
1 parent 07665dd commit 9a44dae
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 10 deletions.
21 changes: 19 additions & 2 deletions scripts/sdkjs_common/jsdoc/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Documentation Generation Guide

This guide explains how to generate documentation for Onlyoffice API using the provided Python scripts, `generate_docs_json.py` and `generate_docs_md.py`. These scripts are used to create JSON and Markdown documentation for the `apiBuilder.js` files from the word, cell, and slide editors.
This guide explains how to generate documentation for Onlyoffice Builder/Plugins API using the provided Python scripts: `generate_docs_json.py`, `generate_docs_plugins_json.py`, `generate_docs_md.py`. These scripts are used to create JSON and Markdown documentation for the `apiBuilder.js` files from the word, cell, and slide editors.

## Prerequisites

Expand All @@ -24,7 +24,19 @@ This script generates JSON documentation based on the `apiBuilder.js` files.
```

- **Parameters**:
- `output_path` (optional): The directory where the JSON documentation will be saved. If not specified, the default path is `Onlyoffice/sdkjs/deploy/api_builder/json`.
- `output_path` (optional): The directory where the JSON documentation will be saved. If not specified, the default path is `Onlyoffice/document-builder-declarations/document-builder`.

### `generate_docs_plugins_json.py`

This script generates JSON documentation based on the `api_plugins.js` files.

- **Usage**:
```bash
python generate_docs_plugins_json.py output_path
```

- **Parameters**:
- `output_path` (optional): The directory where the JSON documentation will be saved. If not specified, the default path is `Onlyoffice/document-builder-declarations/document-builder-plugin`.

### `generate_docs_md.py`

Expand All @@ -45,6 +57,11 @@ To generate JSON documentation with the default output path:
python generate_docs_json.py /path/to/save/json
```

To generate JSON documentation with the default output path:
```bash
python generate_docs_plugins_json.py /path/to/save/json
```

To generate Markdown documentation and specify a custom output path:
```bash
python generate_docs_md.py /path/to/save/markdown
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions scripts/sdkjs_common/jsdoc/config/plugins/cell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"source": {
"include": ["../../../../sdkjs/cell/api_plugins.js"]
},
"plugins": ["./correct_doclets.js"],
"opts": {
"destination": "./out",
"recurse": true,
"encoding": "utf8"
},
"templates": {
"json": {
"pretty": true
}
}
}
16 changes: 16 additions & 0 deletions scripts/sdkjs_common/jsdoc/config/plugins/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"source": {
"include": ["../../../../sdkjs/common/plugins/plugin_base_api.js" ,"../../../../sdkjs/common/apiBase_plugins.js"]
},
"plugins": ["./correct_doclets.js"],
"opts": {
"destination": "./out",
"recurse": true,
"encoding": "utf8"
},
"templates": {
"json": {
"pretty": true
}
}
}
85 changes: 85 additions & 0 deletions scripts/sdkjs_common/jsdoc/config/plugins/correct_doclets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
exports.handlers = {
processingComplete: function(e) {
const filteredDoclets = [];

function checkNullProps(oDoclet) {
for (let key of Object.keys(oDoclet)) {
if (oDoclet[key] == null) {
delete oDoclet[key];
}
if (typeof(oDoclet[key]) == "object") {
checkNullProps(oDoclet[key]);
}
}
}

for (let i = 0; i < e.doclets.length; i++) {
const doclet = e.doclets[i];
if (true == doclet.undocumented || doclet.kind == 'package') {
continue;
}

const filteredDoclet = {
comment: doclet.comment,

meta: doclet.meta ? {
lineno: doclet.meta.lineno,
columnno: doclet.meta.columnno
} : doclet.meta,

kind: doclet.kind,
since: doclet.since,
name: doclet.name,
type: doclet.type ? {
names: doclet.type.names,
parsedType: doclet.type.parsedType
} : doclet.type,

description: doclet.description,
memberof: doclet.memberof,

properties: doclet.properties ? doclet.properties.map(property => ({
type: property.type ? {
names: property.type.names,
parsedType: property.type.parsedType
} : property.type,

name: property.name,
description: property.description,
optional: property.optional,
defaultvalue: property.defaultvalue
})) : doclet.properties,

longname: doclet.longname,
scope: doclet.scope,
alias: doclet.alias,

params: doclet.params ? doclet.params.map(param => ({
type: param.type ? {
names: param.type.names,
parsedType: param.type.parsedType
} : param.type,

name: param.name,
description: param.description,
optional: param.optional,
defaultvalue: param.defaultvalue
})) : doclet.params,

returns: doclet.returns ? doclet.returns.map(returnObj => ({
type: {
names: returnObj.type.names,
parsedType: returnObj.type.parsedType
}
})) : doclet.returns,
see: doclet.see
};

checkNullProps(filteredDoclet)

filteredDoclets.push(filteredDoclet);
}

e.doclets.splice(0, e.doclets.length, ...filteredDoclets);
}
};
16 changes: 16 additions & 0 deletions scripts/sdkjs_common/jsdoc/config/plugins/forms.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"source": {
"include": ["../../../../sdkjs-forms/apiPlugins.js"]
},
"plugins": ["./correct_doclets.js"],
"opts": {
"destination": "./out",
"recurse": true,
"encoding": "utf8"
},
"templates": {
"json": {
"pretty": true
}
}
}
16 changes: 16 additions & 0 deletions scripts/sdkjs_common/jsdoc/config/plugins/slide.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"source": {
"include": ["../../../../sdkjs/slide/api_plugins.js"]
},
"plugins": ["./correct_doclets.js"],
"opts": {
"destination": "./out",
"recurse": true,
"encoding": "utf8"
},
"templates": {
"json": {
"pretty": true
}
}
}
16 changes: 16 additions & 0 deletions scripts/sdkjs_common/jsdoc/config/plugins/word.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"source": {
"include": ["../../../../sdkjs/word/api_plugins.js", "../../../../sdkjs-forms/apiPlugins.js"]
},
"plugins": ["./correct_doclets.js"],
"opts": {
"destination": "./out",
"recurse": true,
"encoding": "utf8"
},
"templates": {
"json": {
"pretty": true
}
}
}
18 changes: 10 additions & 8 deletions scripts/sdkjs_common/jsdoc/generate_docs_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import argparse
import re

root = '../../../..'

# Configuration files
configs = [
"./config/word.json",
"./config/cell.json",
"./config/slide.json",
"./config/forms.json"
"./config/builder/word.json",
"./config/builder/cell.json",
"./config/builder/slide.json",
"./config/builder/forms.json"
]

editors_maps = {
Expand Down Expand Up @@ -55,7 +57,7 @@ def generate(output_dir, md=False):
else:
doclet['see'][0] = doclet['see'][0].replace('{Editor}', editor_name.title())

file_path = '../../../../' + doclet['see'][0]
file_path = f'{root}/' + doclet['see'][0]

if os.path.exists(file_path):
with open(file_path, 'r', encoding='utf-8') as see_file:
Expand Down Expand Up @@ -85,7 +87,7 @@ def generate(output_dir, md=False):
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)

print("Documentation generation completed.")
print("Documentation generation for builder completed.")

def remove_builder_lines(text):
lines = text.splitlines() # Split text into lines
Expand Down Expand Up @@ -125,11 +127,11 @@ def get_current_branch(path):
type=str,
help="Destination directory for the generated documentation",
nargs='?', # Indicates the argument is optional
default="../../../../document-builder-declarations/document-builder" # Default value
default=f"{root}/document-builder-declarations/document-builder" # Default value
)
args = parser.parse_args()

branch_name = get_current_branch("../../../../sdkjs")
branch_name = get_current_branch(f"{root}/sdkjs")
if branch_name:
args.destination = f"{args.destination}/{branch_name}"

Expand Down
Loading

0 comments on commit 9a44dae

Please sign in to comment.