Skip to content

Commit 8effdd4

Browse files
[OV JS][DOCS] Edits in JS API docs (openvinotoolkit#26875)
### Details: - Add Node.js API contributing guide - Edits into `openvino-node` readme - Minor documentation fixes ### Tickets: - 149666 --------- Co-authored-by: Sebastian Golebiewski <sebastianx.golebiewski@intel.com>
1 parent 6526155 commit 8effdd4

8 files changed

+127
-24
lines changed

CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Choose the component your Good First Issue is related to. You can run tests to m
115115
- [C API](https://github.com/openvinotoolkit/openvino/tree/master/src/bindings/c)
116116
- [Core](https://github.com/openvinotoolkit/openvino/tree/master/src/core)
117117
- [Python API](https://github.com/openvinotoolkit/openvino/tree/master/src/bindings/python)
118+
- [Node.js API](https://github.com/openvinotoolkit/openvino/tree/master/src/bindings/js/node)
118119

119120
##### Frontends
120121
- [IR Frontend](https://github.com/openvinotoolkit/openvino/tree/master/src/frontends/ir)

src/bindings/js/docs/CODESTYLE.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# Code Style Guide
22

3+
Node.js bindings contain two parts: C++ and Typescript/JavaScript.
4+
35
This article presents the coding standards for JavaScript and TypeScript parts of **openvino-node** package. The following rules will help maintain code quality and consistency throughout the codebase.
46

7+
For C++ codestyle rules, refer to [this document](https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/coding_style.md).
8+
59
Make sure your IDE has ESLint plugin installed. Its rules are specified in the [.eslint-global.js file](../.eslintrc-global.js). Keep in mind that your PR will not be approved if it does not meet the following requirements.
610

11+
712
## General Rules
813

914
### 1. Semicolons
@@ -89,6 +94,7 @@ Make sure your IDE has ESLint plugin installed. Its rules are specified in the [
8994
- Special case for the `catch` keyword: No space after `catch`
9095
- **Enforced By**: `keyword-spacing: ['error', { overrides: { catch: { after: false } } }]`
9196

97+
9298
## Additional Resources
9399

94100
For further details on each rule, refer to the [ESLint documentation](https://eslint.org/docs/rules/).

src/bindings/js/docs/README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
## Folders
44

5-
- `./docs` - documentation
6-
- `./node` - openvino-node npm package
5+
- [./docs](../docs/) - documentation
6+
- [./node](../node/) - openvino-node npm package
77

8-
## openvino-node Package Developer Documentation
8+
## `openvino-node` Package Developer Documentation
99

1010
### Components
1111

@@ -28,7 +28,6 @@
2828
```bash
2929
cmake \
3030
-DCMAKE_BUILD_TYPE=Release \
31-
-DENABLE_FASTER_BUILD=ON \
3231
-DCPACK_GENERATOR=NPM \
3332
-DENABLE_SYSTEM_TBB=OFF -UTBB* \
3433
-DENABLE_TESTS=OFF \
@@ -75,9 +74,9 @@
7574

7675
[OpenVINO™ Node.js Bindings Examples of Usage](../../../../samples/js/node/README.md)
7776

78-
## Contribution
77+
## Contributing
7978

80-
If you want to contribute to the project, refer to the [code style rules](./CODESTYLE.md) and [contribution guide](../../../../CONTRIBUTING.md) first.
79+
Your contributions are welcome! Make sure to read the [Contribution Guide](https://github.com/openvinotoolkit/openvino/blob/master/src/bindings/js/node/CONTRIBUTING.md) to learn how you can get involved.
8180

8281
## See Also
8382

src/bindings/js/docs/code_examples.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
# How to extend the OpenVINO™ JavaScript API code
22

3-
## Build the OpenVINO™ JavaScript API
3+
## Build the OpenVINO™ JavaScript API
4+
45
For detailed build instructions, refer to the [OpenVINO™ JavaScript API documentation](./README.md).
56

7+
68
## Project's naming conventions
9+
710
When implementing the C++ sources for the JavaScript API, it is essential to adhere to the OpenVINO naming conventions described in the [OpenVINO Coding Style Guide](../../../../docs/dev/coding_style.md). In summary, the naming style employs `Snake Case` for methods, functions, and variables, while `Camel Case` is used for class names. Additionally, the naming of entities in the C++ sources should closely mirror their equivalents in the C++ API to maintain consistency.
811

912
For methods that are exposed to JavaScript, the naming convention transitions to `Camel Case`, aligning with common JavaScript practices. As an example, a method in the C++ API named `get_element_type` would be represented in the JavaScript API as `getElementType()`.
1013

14+
1115
## node-addon-api module
1216

1317
[node addon api](https://github.com/nodejs/node-addon-api) is used to create OpenVINO JavaScript API for Node.js. The quickest way to learn is to follow the official [examples](https://github.com/nodejs/node-addon-examples). It is recommended to check out the tutorial on [how to create a JavaScript object from a C++ object](https://github.com/nodejs/node-addon-examples/tree/main/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api).
1418

1519

16-
17-
18-
1920
## Adding a new class and method
21+
2022
To introduce a new `MyTensor` class that interacts with the `ov::Tensor` class, follow these steps:
2123
- The class should facilitate construction from an ov::Tensor instance and allow initialization from a JavaScript element type and shape.
2224
- It should also provide a getElementType method that retrieves the ov::Tensor element type.
@@ -25,7 +27,7 @@ Begin by creating a header file for the `MyTensor` class in the OpenVINO reposit
2527
```cpp
2628
class MyTensor : public Napi::ObjectWrap<MyTensor> {
2729
public:
28-
// Constructor for the wrapper class
30+
// Constructor for the wrapper class
2931
MyTensor(const Napi::CallbackInfo& info);
3032

3133
// It returns a JavaScript class definition
@@ -75,12 +77,15 @@ add_library(${PROJECT_NAME} SHARED
7577
)
7678
```
7779

80+
7881
### Argument validation and conversion
7982

8083
When binding JavaScript arguments with C++ functions, it is crucial to validate and convert the arguments appropriately. The template `ov::js::validate` function is a utility that facilitates this process. It is particularly useful for handling different overloads of functions and ensuring standardized error messages when arguments do not match expected signatures.
8184
Before implementing a new conversion function, such as `js_to_cpp<ov::Shape>`, review the existing [helper methods](../../node/include/helper.hpp) to see if one already meets your requirements.
8285

86+
8387
### New class initialization
88+
8489
When a new class is introduced to the `openvino-node` module, it must be initialized upon module loading. This is done in the [addon.cpp](../../src/addon.cpp) file. The initialization process registers the class with the Node.js environment so that it can be used within JavaScript code.
8590
```cpp
8691
Napi::Object init_module(Napi::Env env, Napi::Object exports) {
@@ -100,6 +105,7 @@ struct AddonData {
100105
```
101106

102107
### Document the new functionality
108+
103109
The last step is to add the TypeScript type definitions and describe the new functionality.
104110
```typescript
105111
/**
@@ -132,9 +138,9 @@ export interface NodeAddon {
132138

133139
Now that coding is finished, remember to rebuild the project and test it out.
134140

135-
To learn how to test your code, refer to the guide on [how to test OpenVINO™ JavaScript API.](./test_examples.md)
141+
To learn how to test your code, refer to the guide on [how to test OpenVINO™ JavaScript API.](./test_examples.md)
136142

137143
## See also
138144
* [OpenVINO™ README](../../../../README.md)
139145
* [OpenVINO™ bindings README](../../README.md)
140-
* [Developer documentation](../../../../docs/dev/index.md)
146+
* [Developer documentation](../../../../docs/dev/index.md)

src/bindings/js/docs/test_examples.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# How to test the OpenVINO™ JavaScript API
22

3-
## Build the OpenVINO™ JavaScript API
3+
## Build the OpenVINO™ JavaScript API
44
For detailed build instructions, refer to the [OpenVINO™ JavaScript API documentation](./README.md).
55

66

@@ -17,14 +17,14 @@ npm run test
1717

1818
To run specific test files, you can pass one or more glob patterns:
1919
```shell
20-
node --test "tests/unit/core.test.js" "tests/unit/*model.test.js"
20+
node --test "tests/unit/core.test.js" "tests/unit/*model.test.js"
2121
```
2222

2323
Before executing individual test files, a one-time setup is required. If you have not previously executed `npm run test`, initiate the setup by running the following command:
2424

2525
```shell
2626
npm run test_setup
27-
```
27+
```
2828

2929
More information on running tests from the command line can be found in the [Node.js documentation]( https://nodejs.org/docs/latest/api/test.html#running-tests-from-the-command-line).
3030

@@ -45,19 +45,20 @@ It is recommended to run the code style check each time new tests are added.
4545

4646

4747
## Writing OpenVINO™ JavaScript API tests
48+
4849
### Before start
4950
Follow and complete [Examples of OpenVINO™ JavaScript API code](./code_examples.md).
5051

5152

52-
5353
### Adding new test-case in the correct place
5454
Each new test should verify the correct behavior of the new functionality (e.g. class, method).
5555

5656
Unit test files are located in the `<openvino_repo>/src/bindings/js/node/tests/unit/` directory and their names correspond to the class/module to be tested.
5757

5858
Always add tests to the correct locations and create new files only when necessary. *Remember to include the license on top of each new file*.
5959

60-
### Test writing guidelines
60+
61+
### Test writing guidelines
6162
Each test file starts with a `describe` block to group all tests related to a specific class or module. The name of the `describe` block should match the name of the class or module being tested, for example *ov.Core tests*.
6263

6364
Within the `describe` block, individual tests are defined using `test` or `it` blocks, with the name of the test reflecting what is being tested. If multiple tests relate to the same method, they can be grouped within a nested `describe` block.

src/bindings/js/node/CONTRIBUTING.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Contributing to OpenVINO™ Node.js API
2+
3+
Your commitment to this project is greatly appreciated and the following guide is intended to help you contribute.
4+
5+
Make sure to read [main contribution guide](https://github.com/openvinotoolkit/openvino/blob/master/CONTRIBUTING.md) first. It covers most topics related to contributing to OpenVINO.
6+
7+
8+
## TLDR
9+
10+
1. Decide what you want to change.
11+
2. Create your fork of the OpenVINO repository.
12+
3. Create a branch with a meaningful name for your changes.
13+
4. Align the code style, commit the changes, and run tests.
14+
5. Create a Pull Request, which clearly describes what has been changed and why.
15+
6. Go through the Code Review.
16+
7. Get your awesome code merged!
17+
18+
Read the section below for more details.
19+
20+
21+
## How to Decide What to Change
22+
23+
In case of minor fixes, like changing variable names, additional parameter checks, etc., go to the next step.
24+
25+
However, if you want to bring significant changes, for example, the extension of architecture or a big part of functionality, that involves a large amount
26+
of source code, open [an issue](https://github.com/openvinotoolkit/openvino/issues/new?assignees=octocat&labels=enhancement%2Cfeature&projects=&template=feature_request.yml&title=%5BFeature+Request%5D%3A+) first and discuss your idea with
27+
codeowners. It will prevent you from doing extra work.
28+
29+
You can also take one of the well-described tasks from the [Good First Issue](https://github.com/orgs/openvinotoolkit/projects/3/views/14) section. It can be a great start to contributing with codeowners' support!
30+
31+
32+
## Let's code
33+
34+
Get familiar with Node.js API architecture and code samples.
35+
Refer to the [guide](../docs/code_examples.md), which will help you understand the component structure and the code style.
36+
37+
The environment setup and build instructions can be found in [Building the Node.js API](https://github.com/openvinotoolkit/openvino/blob/master/src/bindings/js/docs/README.md#openvino-node-package-developer-documentation).
38+
39+
Run tests! If you add a new functionality, make sure that it is covered by tests first.
40+
Read [the guide](../docs/test_examples.md) for more details about the tests and their runs.
41+
Many CI checks will run after getting a Code Review. Make sure that
42+
all checks have passed. CI checks are composed of both functional tests and code-style checks and may fail because of warnings/errors in both stages.
43+
44+
Remember to follow [our codestyle](../docs/CODESTYLE.md).
45+
By following the provided guide and using an automotive code style checking tool, like
46+
**eslint** and **clang-format-9**, you will save some time and help with the code review of proposed changes.
47+
48+
49+
## Description of the Pull Request
50+
51+
Append all PR titles with the `[OV JS]` tag. Provide any relevant details in the description, as it will definitely help with the review. The minimum requirement is a compact, bulleted list of proposed changes.
52+
53+
Use the following template:
54+
```
55+
*Describe what is the purpose of this PR*
56+
57+
### Details:
58+
- *Describe your changes.*
59+
- ...
60+
61+
```
62+
63+
64+
## License
65+
66+
By contributing to the OpenVINO project, you agree that your contributions will be
67+
licensed under the terms of the [LICENSE](https://github.com/openvinotoolkit/openvino/blob/master/LICENSE).

src/bindings/js/node/README.md

+25-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# OpenVINO™ Node.js Bindings
22

3-
Use OpenVINO JavaScript API for your Node.js application.
3+
Use OpenVINO to deploy deep learning models easily in Node.js applications.
44

5-
## Usage
5+
## Introduction
6+
7+
OpenVINO™ is an open-source toolkit designed for high-performance deep learning inference.
8+
Node.js API provides bindings to subset APIs from OpenVINO Runtime.
9+
The Node.js bindings enable JavaScript developers to use the capabilities of OpenVINO in their applications.
10+
11+
## Quick Start
612

713
Install the **openvino-node** package:
814
```bash
@@ -14,15 +20,21 @@ Use the **openvino-node** package:
1420
const { addon: ov } = require('openvino-node');
1521
```
1622

23+
Refer to the complete description of the `addon` API in the [documentation](https://docs.openvino.ai/2024/api/nodejs_api/addon.html).
24+
25+
See the [samples](https://github.com/openvinotoolkit/openvino/blob/master/samples/js/node/README.md) for more details on how to use it.
26+
1727
## Usage in Electron applications
1828

1929
To use the package in development of Electron applications on Windows, make sure that
2030
**Desktop development with C++** component from
2131
[Build Tools for Visual Studio](https://aka.ms/vs/17/release/vs_BuildTools.exe) is installed.
2232

23-
## Build From Sources
33+
## Supported Platforms
2434

25-
For more details, refer to the [OpenVINO™ JavaScript API Developer Documentation](https://github.com/openvinotoolkit/openvino/blob/master/src/bindings/js/docs/README.md#openvino-node-package-developer-documentation)
35+
- Windows x86
36+
- Linux x86/ARM
37+
- MacOS x86/ARM
2638

2739
## Documentation & Samples
2840

@@ -31,11 +43,19 @@ For more details, refer to the [OpenVINO™ JavaScript API Developer Documentati
3143

3244
## Live Sample
3345

34-
You can run this sample in the browser; no installation is required.
46+
You can run the following sample in the browser, no installation is required.
3547
[Codesandbox](https://codesandbox.io/) is a free online service with limited resources. For optimal performance and more control, it is recommended to run the sample locally.
3648

3749
- [hello-classification-sample](https://codesandbox.io/p/devbox/openvino-node-hello-classification-sample-djl893)
3850

51+
## Build From Sources
52+
53+
For more details, refer to the [OpenVINO™ JavaScript API Developer Documentation](https://github.com/openvinotoolkit/openvino/blob/master/src/bindings/js/docs/README.md#openvino-node-package-developer-documentation)
54+
55+
## Contributing
56+
57+
Contributions are always welcome! Read the [Contribution Guide](https://github.com/openvinotoolkit/openvino/blob/master/src/bindings/js/node/CONTRIBUTING.md) to learn how you can get involved.
58+
3959
## See Also
4060

4161
* [OpenVINO™ README](https://github.com/openvinotoolkit/openvino/blob/master/README.md)

src/bindings/js/node/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,8 @@
4848
"remote_path": "./repositories/openvino/nodejs_bindings/{version}/{platform}/",
4949
"package_name": "openvino_nodejs_bindings_{platform}_{version}_{arch}.tar.gz",
5050
"host": "https://storage.openvinotoolkit.org"
51-
}
51+
},
52+
"keywords": [
53+
"OpenVINO"
54+
]
5255
}

0 commit comments

Comments
 (0)