๐Ÿ“ฆ himself65 / create-addon

Create node.js addon CLI

โ˜… 5 stars โ‘‚ 0 forks ๐Ÿ‘ 5 watching
๐Ÿ“ฅ Clone https://github.com/himself65/create-addon.git
HTTPS git clone https://github.com/himself65/create-addon.git
SSH git clone git@github.com:himself65/create-addon.git
CLI gh repo clone himself65/create-addon
Alex Yang Alex Yang ci: fix (#1) 3a61e9e 6 months ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ .github
๐Ÿ“ src
๐Ÿ“ templates
๐Ÿ“„ .gitignore
๐Ÿ“„ .npmignore
๐Ÿ“„ .prettierignore
๐Ÿ“„ CLAUDE.md
๐Ÿ“„ package.json
๐Ÿ“„ pnpm-lock.yaml
๐Ÿ“„ README.md
๐Ÿ“„ tsconfig.json
๐Ÿ“„ README.md

create-addon

๐Ÿš€ Create Node.js native addons with ease

A modern CLI tool for scaffolding Node.js native addon projects with an interactive interface. Generate boilerplate code for C++, Objective-C, and Swift addons with platform-specific templates.

Features

  • ๐ŸŽฏ Interactive CLI - Beautiful terminal UI built with React and Ink
  • ๐Ÿ—๏ธ Multiple Templates - Support for C++, Objective-C, and Swift
  • ๐Ÿ”ง Platform-Specific - Templates optimized for Linux, Windows, and macOS
  • โšก Modern N-API - Uses node-addon-api for modern native bindings
  • ๐ŸŽจ EventEmitter Pattern - Built-in event system for native-to-JS communication
  • ๐Ÿ“ฆ Ready to Build - Pre-configured with node-gyp and build scripts

Installation

npm install -g create-addon

Or use directly with npx:

npx create-addon my-project

Quick Start

Interactive Mode

Launch the interactive CLI to create a new project:

create-addon

Semi-Interactive Mode

Provide a project name and select a template interactively:

create-addon my-awesome-addon

Non-Interactive Mode

Create a project with all options specified:

create-addon my-awesome-addon --template cpp-linux

Templates

๐Ÿง cpp-linux

C++ addon optimized for Linux platforms with GTK+ integration.

Features:

  • GTK+ GUI components
  • Event-driven architecture
  • Todo management functionality
  • Platform detection and safety checks

๐ŸชŸ cpp-win32

C++ addon designed for Windows platforms.

Features:

  • Windows-specific APIs
  • Native Win32 integration
  • Event system for UI interactions
  • Build configuration for Windows

๐ŸŽ objective-c

Objective-C addon for macOS with native Cocoa integration.

Features:

  • Native macOS UI components
  • Todo management with Objective-C classes
  • Bridge between Objective-C and JavaScript
  • macOS-specific functionality

๐Ÿฆ‰ swift

Swift addon for macOS with modern Swift integration.

Features:

  • Modern Swift code
  • Native Swift-to-JavaScript bridge
  • Event-driven communication
  • macOS platform optimization

Usage Examples

Creating Different Types of Addons

# Create a C++ addon for Linux
create-addon my-cpp-addon --template cpp-linux

# Create a Swift addon for macOS
create-addon my-swift-addon --template swift

# Create an Objective-C addon
create-addon my-objc-addon --template objective-c

# Create a Windows C++ addon
create-addon my-win-addon --template cpp-win32

Skip Dependency Installation

create-addon my-project --skip-install

Command Line Options

create-addon [project-name] [options]

Options:
  -t, --template <template>  Template to use (cpp-linux, cpp-win32, objective-c, swift)
  --skip-install            Skip installing dependencies
  -h, --help               Show help

Generated Project Structure

Each generated project includes:

my-project/
โ”œโ”€โ”€ binding.gyp          # node-gyp build configuration
โ”œโ”€โ”€ package.json         # Project configuration and scripts
โ”œโ”€โ”€ src/                 # Native source code
โ”‚   โ”œโ”€โ”€ addon.cc         # Main addon implementation
โ”‚   โ””โ”€โ”€ ...              # Additional source files
โ”œโ”€โ”€ include/             # Header files
โ”‚   โ””โ”€โ”€ *.h              # Platform-specific headers
โ””โ”€โ”€ js/
    โ””โ”€โ”€ index.js         # JavaScript wrapper with EventEmitter

Building Your Addon

After creating your project:

cd my-project

# Install dependencies
npm install

# Build the native addon
npm run build

# Clean build artifacts
npm run clean

# Build for Electron (if needed)
npm run build-electron

Using Your Addon

Generated addons follow a consistent EventEmitter pattern:

const addon = require("./js/index.js");

// Basic usage
console.log(addon.helloWorld("Hello from Node.js!"));

// GUI interaction (platform-specific)
addon.helloGui();

// Event handling
addon.on("todoAdded", (todo) => {
  console.log("New todo:", todo);
});

addon.on("todoUpdated", (todo) => {
  console.log("Updated todo:", todo);
});

addon.on("todoDeleted", (todo) => {
  console.log("Deleted todo:", todo);
});

Development

Prerequisites

  • Node.js 16+
  • Python 3.x (for node-gyp)
  • Platform-specific build tools:
  • Linux: build-essential, GTK+ development libraries
  • Windows: Visual Studio Build Tools
  • macOS: Xcode Command Line Tools

Building the CLI

# Clone the repository
git clone https://github.com/himself65/create-addon.git
cd create-addon

# Install dependencies
pnpm install

# Build the CLI
pnpm run build

# Test locally
node dist/bin.js

Development Mode

# Build with watch mode
pnpm run dev

Contributing

We welcome contributions! Please feel free to submit a Pull Request.

Development Setup

  • Fork the repository
  • Create your feature branch (git checkout -b feature/amazing-feature)
  • Make your changes
  • Build and test (pnpm run build)
  • Commit your changes (git commit -m 'Add some amazing feature')
  • Push to the branch (git push origin feature/amazing-feature)
  • Open a Pull Request

License

MIT ยฉ himself65

Credits to the Felix electron-native-code-demos for inspiration and initial templates.