Code Monkey home page Code Monkey logo

node-addon's Introduction

Templ Node.js Addon

Node.js CI

Hits Contributions welcome

JSCPD

Sonarcloud Status Code Smells Maintainability Rating Reliability Rating Security Rating

Lines of Code SonarCloud Coverage SonarCloud Bugs Technical Debt SonarCloud Vulnerabilities

Donate to this project using Patreon Donate to this project using Paypal

JavaScript Logo

Any fool can write code that a computer can understand. Good programmers write code that humans can understand. โ€“ Martin Fowler

nodejs-addon is a template project for developing Node.js addons using C/C++. It includes support for formatting and linting both C/C++ and JavaScript code, tools for assuring code quality as well as instructions to code further using two of the most popular IDEs on the market. It can also be configured to use any of the three C/C++ APIs provided by Node.js.

Please download it and adapt it as you see fit.

Warning! This template is provided as is. If you feel you do not have enough documentation, you are always free to read its code. We are developers after all and we are forced daily to read other people's code.

Getting Started

Project Description

The template is trying to cover multiple build systems as

Linters, Code Analysis, Formatters

Javascript
C++
Generic
  • jscpd for code analisys as copy paste detector
  • dependency-checker (designed by OWASP) for code analisys, will check dependencies & security

Git Hooks

Git hooks are configured using husky

pre-commit

Found in .husky/pre-commit, script will run

  • .scripts/configure.js script, keeping your configuration stable, as well as
  • ca and test scripts from package.json.

Please take a look in the package.json file and follow the two mentioned scripts to understand what they do and how they are called.

commit-msg

Found in .husky/commit-msg, script will run a commitlint check. Please read more on the official page on how to customize commitlint config.

Prerequisites / Dependencies

For Linux
  • git, gcc/g++, make
  • clang-formatter && clang-tidy
  • Python 3.6 or above.
  • Depending on the build system, please install:
    • NodeGyp: All requirements are set as default in the above list.
    • CMake: make, cmake
    • XMake: make, xmake

Do not forget NodeGyp is the main build system, so you need its requirements installed whatsoever.

# i.e ubuntu
PY_SUBVER=6 \
  sudo apt-get install -y \
    build-essential git make \
    python3.$PY_SUBVER \
    clang-format clang-tidy
# for CMake
sudo apt-get install cmake
# for XMake (see https://xmake.io/#/guide/installation)
bash <(curl -fsSL https://xmake.io/shget.text)
For MacOS
brew install git
brew install llvm && \
  ln -s "$(brew --prefix llvm)/bin/clang-format" "/usr/local/bin/clang-format" && \
  ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy" && \
  ln -s "$(brew --prefix llvm)/bin/clang-apply-replacements" "/usr/local/bin/clang-apply-replacements"
# for CMake
brew install cmake
# for XMake (see https://xmake.io/#/guide/installation)
bash <(curl -fsSL https://xmake.io/shget.text)
For Windows
choco install git make python
# Visual Studio needs manual installation
choco install llvm
# for CMake
choco install cmake
# for XMake (see https://xmake.io/#/guide/installation)
Invoke-Expression (Invoke-Webrequest 'https://xmake.io/psget.text' -UseBasicParsing).Content

Known Issues / Troubleshooting

  1. Note that node-gyp doesn't support Python 2.7 anymore, so you'll need to install Python 3.6 or above.
  2. #2 xmake is still under development and not compiling properly in debug mode

Installation

git clone https://github.com/templ-project/nodejs-addon your_project
cd your_project
rm -rf .git
git init
git add remote origin https://url/to/your/project/repository
git add .
git commit -am "init"
git push origin master
npm install
node .scripts/configure -a node-addon-api -x gyp -e vscode -ucl

Configure Command

Read about the configure command, integrated build systems, supported IDEs and NodeJs APIs.

Development

Requirements

Please install:

Testing

Testing is done using mocha and chai.

Run unit tests using npm run test.

Testing is currently set to use unittest.

We will try to provide a Jest implementation in the future. If you wish us to rush into it, please submit a ticket.

Single Tests

Run single unit tests file, by calling npm run test:single -- test/path/to/file.test.js

npm test:single -- test/index.test.js

Deployment

Please check release-it for making releases to npmjs.com or any other repository tool, then run:

npm run release

Authors

Issues / Support

Add a set of links to the issues page/website, so people can know where to add issues/bugs or ask for support.

License

(If the package is public, add licence) This project is licensed under the MIT License - see the LICENSE.md file for details

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.