Skip to content

Commit d71b4ca

Browse files
Andrey1994Gordon Preumont
andauthored
Feature/bind js (#665)
* add support for nodejs --------- Signed-off-by: Andrey Parfenov <a1994ndrey@gmail.com> Co-authored-by: Gordon Preumont <gordon.preumont@eptura.com>
1 parent 467ee1e commit d71b4ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+6970
-15
lines changed

.github/workflows/deploy.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ jobs:
3434
python -m pip install twine
3535
python -m pip install awscli
3636
shell: cmd
37+
- name: Install Node
38+
uses: actions/setup-node@v3
39+
with:
40+
node-version: 18
41+
- name: Install Typescript
42+
run: |
43+
npm install -g ts-node
44+
shell: cmd
3745
- name: Set up JDK 11
3846
uses: actions/setup-java@v1
3947
with:
@@ -102,6 +110,24 @@ jobs:
102110
env:
103111
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
104112
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
113+
- name: Prepare Node Package
114+
run: |
115+
cd $env:GITHUB_WORKSPACE\nodejs_package\
116+
Copy-Item "$env:GITHUB_WORKSPACE\linux\*" -Destination "$env:GITHUB_WORKSPACE\nodejs_package\brainflow\lib" -Recurse -Force -Filter *.*
117+
Copy-Item "$env:GITHUB_WORKSPACE\macos\*" -Destination "$env:GITHUB_WORKSPACE\nodejs_package\brainflow\lib" -Recurse -Force -Filter *.*
118+
Copy-Item "$env:GITHUB_WORKSPACE\win64\*" -Destination "$env:GITHUB_WORKSPACE\nodejs_package\brainflow\lib" -Recurse -Force -Filter *.*
119+
Copy-Item "$env:GITHUB_WORKSPACE\win32\*" -Destination "$env:GITHUB_WORKSPACE\nodejs_package\brainflow\lib" -Recurse -Force -Filter *.*
120+
ls $env:GITHUB_WORKSPACE\nodejs_package\brainflow\lib
121+
(gc .\package.json).replace('0.0.0-development', $env:VERSION) | Out-File -encoding ASCII package.json
122+
type package.json
123+
npm install
124+
npm run build
125+
npm pack
126+
aws s3 cp $env:GITHUB_WORKSPACE\nodejs_package\ s3://brainflow/$env:GITHUB_SHA/npm --recursive
127+
env:
128+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
129+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
130+
VERSION: ${{ github.event.inputs.version }}
105131
- name: Prepare Java Package
106132
run: |
107133
cd $env:GITHUB_WORKSPACE\java_package\brainflow
@@ -196,12 +222,16 @@ jobs:
196222
- name: Publish Packages
197223
if: github.event.inputs.publish == 'true'
198224
run: |
225+
cd $env:GITHUB_WORKSPACE\nodejs_package
226+
echo "//registry.npmjs.org/:_authToken=$env:NPM_TOKEN" > .npmrc
227+
npm publish
199228
cd $env:GITHUB_WORKSPACE\java_package\brainflow
200229
mvn -s $env:GITHUB_WORKSPACE\java_package\brainflow\settings.xml deploy -Dregistry=https://maven.pkg.github.com/brainflow-dev -Dtoken=$env:PUBLISH_TOKEN
201230
cd $env:GITHUB_WORKSPACE\python_package
202231
twine upload --skip-existing dist/*.whl --user Andrey1994 --password $env:PYPI_PASSWORD
203232
cd $env:GITHUB_WORKSPACE\rust_package\brainflow
204233
env:
234+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
205235
CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }}
206236
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
207237
PUBLISH_USER: ${{ secrets.PUBLISH_USER }}

.github/workflows/dockerhub.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ on:
44
workflow_dispatch:
55
inputs:
66
version:
7-
description: New Version
7+
description: Git tag to checkout
88
default: ""
9-
required: true
9+
required: false
1010
publish:
1111
description: Make Public(true or false)
1212
default: "false"
@@ -26,12 +26,18 @@ jobs:
2626
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2727
- name: Clone Repository
2828
uses: actions/checkout@v2
29-
- name: Build Docker Container
29+
- name: Build Docker Container with Tag
30+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.version != ''
3031
run: |
3132
cd Docker
3233
sudo docker build --tag brainflow/brainflow:${VERSION} --build-arg checkout_id=${VERSION} .
3334
env:
3435
VERSION: ${{ github.event.inputs.version }}
36+
- name: Build Docker Container without Tag
37+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.version == ''
38+
run: |
39+
cd Docker
40+
sudo docker build --tag brainflow/brainflow:0.0.1 .
3541
- name: Check Images
3642
run: sudo -H docker images
3743
- name: DockerHub Login

.github/workflows/run_unix.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ jobs:
3333
sudo -H apt-get install -y python3-setuptools python3-pygments libbluetooth-dev
3434
env:
3535
DEBIAN_FRONTEND: noninteractive
36+
- name: Install Node
37+
uses: actions/setup-node@v3
38+
with:
39+
node-version: 18
40+
- name: Install Typescript
41+
run: |
42+
npm install -g ts-node
3643
- name: Install Ninja
3744
if: (matrix.os == 'macos-11.0')
3845
uses: seanmiddleditch/gha-setup-ninja@master
@@ -91,6 +98,15 @@ jobs:
9198
run: |
9299
cd $GITHUB_WORKSPACE/python_package
93100
sudo -H python3 -m pip install -U .
101+
- name: Build Node Package
102+
run: |
103+
cd $GITHUB_WORKSPACE/nodejs_package/brainflow
104+
npm install
105+
npm run build
106+
- name: Install Node Tests
107+
run: |
108+
cd $GITHUB_WORKSPACE/nodejs_package/tests
109+
npm install
94110
- name: Setup Java package
95111
run: |
96112
cd $GITHUB_WORKSPACE/java_package/brainflow
@@ -305,6 +321,34 @@ jobs:
305321
mvn exec:java -Dexec.mainClass="brainflow.examples.EEGMetrics" -Dexec.args="--board-id -1"
306322
env:
307323
LD_LIBRARY_PATH: ${{ github.workspace }}/installed/lib
324+
- name: Synthetic Node
325+
run: |
326+
cd $GITHUB_WORKSPACE/nodejs_package/tests
327+
npm run brainflow_get_data
328+
- name: Signal Filters Node
329+
run: |
330+
cd $GITHUB_WORKSPACE/nodejs_package/tests
331+
npm run signal_filtering
332+
- name: Serialization Node
333+
run: |
334+
cd $GITHUB_WORKSPACE/nodejs_package/tests
335+
npm run serialization
336+
- name: Downsampling Node
337+
run: |
338+
cd $GITHUB_WORKSPACE/nodejs_package/tests
339+
npm run downsampling
340+
- name: Denoising Node
341+
run: |
342+
cd $GITHUB_WORKSPACE/nodejs_package/tests
343+
npm run denoising
344+
- name: EEG Metrics Node
345+
run: |
346+
cd $GITHUB_WORKSPACE/nodejs_package/tests
347+
npm run eeg_metrics
348+
- name: BandPowerAll Node
349+
run: |
350+
cd $GITHUB_WORKSPACE/nodejs_package/tests
351+
npm run bandpower_all
308352
# deploy started
309353
- name: Install AWS CLI
310354
run: sudo -H python3 -m pip install awscli==1.21.10

.github/workflows/run_windows.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
run: |
4646
mkdir %GITHUB_WORKSPACE%\build32
4747
cd %GITHUB_WORKSPACE%\build32
48-
cmake -DBRAINFLOW_VERSION=%BRAINFLOW_VERSION% -DBUILD_OYMOTION_SDK=ON -DBUILD_ONNX=ON -DBUILD_BLE=ON -DBUILD_BLUETOOTH=ON -DBUILD_TESTS=ON -DWARNINGS_AS_ERRORS=ON -G "Visual Studio 17 2022" -A Win32 -DCMAKE_SYSTEM_VERSION=8.1 -DCMAKE_INSTALL_PREFIX=..\installed32\ ..
48+
cmake -DBRAINFLOW_VERSION=%BRAINFLOW_VERSION% -DBUILD_OYMOTION_SDK=ON -DBUILD_ONNX=ON -DBUILD_BLE=ON -DBUILD_BLUETOOTH=ON -DWARNINGS_AS_ERRORS=ON -G "Visual Studio 17 2022" -A Win32 -DCMAKE_SYSTEM_VERSION=8.1 -DCMAKE_INSTALL_PREFIX=..\installed32\ ..
4949
cmake --build . --target install --config Release -j 2 --parallel 2
5050
env:
5151
BRAINFLOW_VERSION: ${{ steps.version.outputs.version }}
@@ -54,7 +54,7 @@ jobs:
5454
run: |
5555
mkdir %GITHUB_WORKSPACE%\build64
5656
cd %GITHUB_WORKSPACE%\build64
57-
cmake -DBRAINFLOW_VERSION=%BRAINFLOW_VERSION% -DBUILD_OYMOTION_SDK=ON -DBUILD_ONNX=ON -DBUILD_BLE=ON -DBUILD_BLUETOOTH=ON -DBUILD_TESTS=ON -DWARNINGS_AS_ERRORS=ON -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_VERSION=8.1 -DCMAKE_INSTALL_PREFIX=..\installed64\ ..
57+
cmake -DBRAINFLOW_VERSION=%BRAINFLOW_VERSION% -DBUILD_OYMOTION_SDK=ON -DBUILD_ONNX=ON -DBUILD_BLE=ON -DBUILD_BLUETOOTH=ON -DWARNINGS_AS_ERRORS=ON -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_VERSION=8.1 -DCMAKE_INSTALL_PREFIX=..\installed64\ ..
5858
cmake --build . --target install --config Release -j 2 --parallel 2
5959
env:
6060
BRAINFLOW_VERSION: ${{ steps.version.outputs.version }}
@@ -120,10 +120,6 @@ jobs:
120120
uses: julia-actions/setup-julia@v1
121121
with:
122122
version: 1.3.1
123-
# Unit testing
124-
- name: Run unit tests
125-
run: .\build\tests\Release\brainflow_tests.exe
126-
shell: cmd
127123
# BoardController testing
128124
- name: Run Julia Tests
129125
run: |

Docker/Dockerfile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ echo "deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/" | tee /etc
1313
echo "deb https://download.mono-project.com/repo/ubuntu vs-bionic main" | tee /etc/apt/sources.list.d/mono-official-vs.list && \
1414
apt-get -qq update
1515
# Installing Dependencies
16-
RUN apt-get install -yqq python3 python3-pip python3-venv openjdk-13-jdk git curl wget build-essential python3-jira r-base rustc cargo nuget nuget mono-devel mono-complete monodevelop libxml2-dev libbluetooth-dev libdbus-1-dev dotnet-sdk-6.0 dotnet-runtime-6.0 dotnet-runtime-3.1 aspnetcore-runtime-6.0
16+
RUN apt-get install -yqq python3 python3-pip python3-venv openjdk-13-jdk git curl wget build-essential python3-jira r-base rustc cargo nuget nuget mono-devel mono-complete monodevelop libxml2-dev libbluetooth-dev libdbus-1-dev dotnet-sdk-6.0 dotnet-runtime-6.0 dotnet-runtime-3.1 aspnetcore-runtime-6.0 nodejs npm
1717
RUN mkdir -p /root/local/bin
1818
WORKDIR /root/local/bin
1919
# install latest cmake
2020
RUN mkdir -p /opt/cmake && wget https://github.com/Kitware/CMake/releases/download/v3.24.3/cmake-3.24.3-linux-x86_64.sh && sh cmake-3.24.3-linux-x86_64.sh --prefix=/opt/cmake --skip-license
2121
ENV PATH=/opt/cmake/bin/:$PATH
2222
# Installing Maven and Julia
23-
RUN curl "https://miroir.univ-lorraine.fr/apache/maven/maven-3/3.9.4/binaries/apache-maven-3.9.4-bin.tar.gz" -o maven.tar.gz
23+
RUN curl "https://mirrors.estointernet.in/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz" -o maven.tar.gz
2424
RUN mkdir -p maven
2525
RUN tar xzf maven.tar.gz -C ./maven
26-
RUN export PATH=$PATH:/root/local/bin/maven/apache-maven-3.9.4/bin
26+
RUN export PATH=$PATH:/root/local/bin/maven/apache-maven-3.6.3/bin
2727
RUN wget "https://julialang-s3.julialang.org/bin/linux/x64/1.5/julia-1.5.3-linux-x86_64.tar.gz"
2828
RUN mkdir -p julia
2929
RUN tar xf julia-1.5.3-linux-x86_64.tar.gz -C ./julia
@@ -33,11 +33,11 @@ ENV PATH=$PATH:/root/local/bin/julia/julia-1.5.3/bin
3333
RUN python3 -m pip install scipy pandas matplotlib mne jupyterlab notebook opencv-python pyriemann
3434

3535
WORKDIR /root
36-
ARG checkout_id
36+
ARG checkout_id="none"
3737
# Compile
3838
RUN git clone "https://github.com/brainflow-dev/brainflow.git"
3939
WORKDIR /root/brainflow
40-
RUN if [ ! -z "${checkout_id}" ]; then git checkout "${checkout_id}"; fi
40+
RUN if [ "${checkout_id}" != "none" ]; then git checkout "${checkout_id}"; fi
4141
RUN python3 ./tools/build.py --use-openmp --bluetooth --ble
4242
ENV LD_LIBRARY_PATH=/root/brainflow/installed_linux/lib/
4343

@@ -54,7 +54,7 @@ RUN dotnet build csharp_package/brainflow/brainflow.sln
5454

5555
# Java Binding
5656
WORKDIR /root/brainflow/java_package/brainflow
57-
RUN /root/local/bin/maven/apache-maven-3.9.4/bin/mvn package
57+
RUN /root/local/bin/maven/apache-maven-3.6.3/bin/mvn package
5858

5959
# Julia Bindings
6060
WORKDIR /root/brainflow/julia_package/brainflow
@@ -67,6 +67,11 @@ RUN R --vanilla -e 'install.packages("knitr", repos="http://cran.us.r-project.or
6767
RUN R --vanilla -e 'install.packages("reticulate", repos="http://cran.us.r-project.org")'
6868
RUN R CMD build .
6969

70+
# Node JS Binding
71+
WORKDIR /root/brainflow/nodejs_binding/brainflow
72+
RUN npm install -g ts-node
73+
RUN npm install
74+
7075
# Rust Binding
7176
WORKDIR /root/brainflow/rust_package/brainflow
7277
RUN cargo build

docs/BuildBrainFlow.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ When using BrainFlow for the first time in Julia, the BrainFlow artifact contain
121121

122122
If you compile BrainFlow from source local libraries will take precedence over the artifact.
123123

124+
Typescript
125+
-----------
126+
127+
.. compound::
128+
129+
You can install BrainFlow using next command without compilation ::
130+
131+
npm install brainflow
132+
133+
.. compound::
134+
135+
If you want to install it from source files or build unreleased version from Github, you should first compile the core module (:ref:`compilation-label`). Then run ::
136+
137+
cd nodejs_package
138+
npm install --force
139+
140+
124141
Rust
125142
-------
126143

docs/Examples.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,69 @@ Rust ICA
539539
.. literalinclude:: ../rust_package/brainflow/examples/ica.rs
540540
:language: rust
541541

542+
Typescript
543+
------------
544+
545+
Typescript Get Data from a Board
546+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
547+
548+
.. literalinclude:: ../nodejs_package/tests/brainflow_get_data.ts
549+
:language: javascript
550+
551+
Typescript Markers
552+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
553+
554+
.. literalinclude:: ../nodejs_package/tests/markers.ts
555+
:language: javascript
556+
557+
Typescript Read Write File
558+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
559+
560+
.. literalinclude:: ../nodejs_package/tests/serialization.ts
561+
:language: javascript
562+
563+
Typescript Downsample Data
564+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
565+
566+
.. literalinclude:: ../nodejs_package/tests/downsampling.ts
567+
:language: javascript
568+
569+
Typescript Transforms
570+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
571+
572+
.. literalinclude:: ../nodejs_package/tests/transforms.ts
573+
:language: javascript
574+
575+
Typescript Signal Filtering
576+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
577+
578+
.. literalinclude:: ../nodejs_package/tests/signal_filtering.ts
579+
:language: javascript
580+
581+
Typescript Denoising
582+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
583+
584+
.. literalinclude:: ../nodejs_package/tests/denoising.ts
585+
:language: javascript
586+
587+
Typescript Band Power
588+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
589+
590+
.. literalinclude:: ../nodejs_package/tests/bandpower.ts
591+
:language: javascript
592+
593+
Typescript EEG Metrics
594+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
595+
596+
.. literalinclude:: ../nodejs_package/tests/eeg_metrics.ts
597+
:language: javascript
598+
599+
Typescript ICA
600+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
601+
602+
.. literalinclude:: ../nodejs_package/tests/ica.ts
603+
:language: javascript
604+
542605
Notebooks
543606
------------
544607
.. toctree::

docs/SupportedBoards.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ To create such board you need to specify the following board ID and fields of Br
730730
Initialization Example:
731731

732732
.. code-block:: python
733+
733734
params = BrainFlowInputParams()
734735
params.serial_port = "COM6"
735736
board = BoardShim(BoardIds.FREEEEG128_BOARD, params)

docs/UserAPI.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,13 @@ Example:
159159

160160
.. literalinclude:: ../rust_package/brainflow/examples/get_data.rs
161161
:language: rust
162+
163+
Typescript API Reference
164+
--------------------------
165+
166+
Typescript binding calls C/C++ code as any other binding. Use Typescript examples and API reference for other languaes as a starting point.
167+
168+
Example:
169+
170+
.. literalinclude:: ../nodejs_package/tests/brainflow_get_data.ts
171+
:language: javascript

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Pygments==2.7.4
1212
sphinxcontrib-matlabdomain==0.11.4
1313
docutils<0.17
1414
sphinx_rtd_theme==0.4.3
15+
jinja2<3.1

0 commit comments

Comments
 (0)