This is an automated email from the ASF dual-hosted git repository.
tison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pulsar-site.git
The following commit(s) were added to refs/heads/main by this push:
new 830d79e8d73 feat: js doc generator (#509)
830d79e8d73 is described below
commit 830d79e8d730e6f45577e1930b3fc85fc6ff527b
Author: tison <[email protected]>
AuthorDate: Sun Apr 9 23:31:12 2023 +0800
feat: js doc generator (#509)
Signed-off-by: tison <[email protected]>
---
tools/pytools/README.md | 10 ++++++
tools/pytools/bin/js-apidoc-generator.py | 33 ++++++++++++++++++
tools/pytools/lib/execute/typedoc_generator.py | 47 ++++++++++++++++++++++++++
3 files changed, 90 insertions(+)
diff --git a/tools/pytools/README.md b/tools/pytools/README.md
index b2001c246fa..695a33dd01d 100644
--- a/tools/pytools/README.md
+++ b/tools/pytools/README.md
@@ -59,6 +59,16 @@ poetry run bin/cpp-apidoc-generator.py <VERSION>
... where the `VERSION` is released semantic version like `2.10.2` or `3.0.0`.
+### [js-apidoc-generator](bin/js-apidoc-generator.py)
+
+This executable generates API docs for Pulsar Node.js Client using
[`typedoc`](https://typedoc.org/):
+
+```bash
+poetry run bin/js-apidoc-generator.py <VERSION>
+```
+
+... where the `VERSION` is released semantic version like `1.8.2`.
+
### [py-apidoc-generator](bin/py-apidoc-generator.py)
This executable generates API docs for Pulsar Python Client:
diff --git a/tools/pytools/bin/js-apidoc-generator.py
b/tools/pytools/bin/js-apidoc-generator.py
new file mode 100755
index 00000000000..bd261b60c4c
--- /dev/null
+++ b/tools/pytools/bin/js-apidoc-generator.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
+
+from execute import typedoc_generator
+
+if __name__ == '__main__':
+ parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
+ parser.set_defaults(func=typedoc_generator.execute)
+ parser.add_argument('version', metavar='VERSION', help='version of Pulsar
Node.js Client')
+
+ args = parser.parse_args()
+ fn = args.func
+ args = dict(vars(args))
+ del args['func']
+ fn(**args)
diff --git a/tools/pytools/lib/execute/typedoc_generator.py
b/tools/pytools/lib/execute/typedoc_generator.py
new file mode 100644
index 00000000000..7c54bcab821
--- /dev/null
+++ b/tools/pytools/lib/execute/typedoc_generator.py
@@ -0,0 +1,47 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import shutil
+import tempfile
+from pathlib import Path
+
+import semver
+
+from command import find_command, run
+from constant import site_path
+
+
+def execute(version: str):
+ git = find_command('git', msg="git is required")
+ npm = find_command('npm', msg="npm is required")
+ npx = find_command('npx', msg="npx is required")
+
+ ver = semver.VersionInfo.parse(version)
+ assert ver.compare('1.8.1') > 0
+
+ with tempfile.TemporaryDirectory() as cwd:
+ tag = f"v{ver}"
+ remote = 'https://github.com/apache/pulsar-client-node'
+ run(git, 'clone', '--depth=1', '--single-branch', f'--branch={tag}',
remote, cwd=cwd)
+
+ d = (Path(cwd) / 'pulsar-client-node').absolute()
+ run(npm, 'i', '-D', '@types/node', cwd=d)
+ run(npx, 'typedoc', cwd=d)
+
+ v = f"{ver.major}.{ver.minor}.x"
+ dst = site_path() / 'static' / 'api' / 'js' / v
+ shutil.copytree(d / 'apidocs', dst)