cpp.js 1.0.0-beta.3 → 1.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -0
- package/package.json +1 -1
- package/src/bin.js +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://cpp.js.org">
|
|
3
|
+
<picture>
|
|
4
|
+
<img alt="Next.js logo" src="https://cpp.js.org/img/logo.png" height="128">
|
|
5
|
+
</picture>
|
|
6
|
+
</a>
|
|
7
|
+
<h1>Cpp.js</h1>
|
|
8
|
+
<p align="center">
|
|
9
|
+
<strong>Bind C++ to JavaScript with no extra code.</strong><br>
|
|
10
|
+
WebAssembly & React Native
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<a href="https://www.npmjs.com/package/cpp.js"><img alt="NPM version" src="https://img.shields.io/npm/v/cpp.js?style=for-the-badge" /></a>
|
|
14
|
+
<a href="https://github.com/bugra9/cpp.js/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/bugra9/cpp.js?style=for-the-badge" /></a>
|
|
15
|
+
<a href=""><img alt="Discussions" src="https://img.shields.io/github/discussions/bugra9/cpp.js?style=for-the-badge" /></a>
|
|
16
|
+
<a href=""><img alt="Discussions" src="https://img.shields.io/github/issues/bugra9/cpp.js?style=for-the-badge" /></a>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<h3 align="center">
|
|
20
|
+
<a href="https://cpp.js.org/docs/guide/getting-started/prerequisites">Getting Started</a>
|
|
21
|
+
<span> · </span>
|
|
22
|
+
<a href="https://cpp.js.org/docs/guide/integrate-into-existing-project/overview">Integrate Into Existing Project</a>
|
|
23
|
+
<span> · </span>
|
|
24
|
+
<a href="https://cpp.js.org/docs/api/cpp-bindings/overview">C++ Bindings</a>
|
|
25
|
+
<span> · </span>
|
|
26
|
+
<a href="https://cpp.js.org/showcase">Showcase</a>
|
|
27
|
+
</h3>
|
|
28
|
+
|
|
29
|
+
## Basic Usage
|
|
30
|
+
**src/index.js**
|
|
31
|
+
```js
|
|
32
|
+
import { initCppJs } from './native/Factorial.h';
|
|
33
|
+
|
|
34
|
+
const { Factorial } = await initCppJs();
|
|
35
|
+
const factorial = new Factorial(99999);
|
|
36
|
+
const result = factorial.calculate();
|
|
37
|
+
console.log(result);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**src/native/Factorial.h**
|
|
41
|
+
```c++
|
|
42
|
+
class Factorial {
|
|
43
|
+
private:
|
|
44
|
+
int number;
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
Factorial(int num) : number(num) {}
|
|
48
|
+
|
|
49
|
+
int calculate() {
|
|
50
|
+
if (number < 0) return -1;
|
|
51
|
+
|
|
52
|
+
int result = 1;
|
|
53
|
+
for (int i = 2; i <= number; i++) {
|
|
54
|
+
result *= i;
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Prerequisites
|
|
62
|
+
To begin building your project with Cpp.js, you’ll first need to install a few dependencies:
|
|
63
|
+
|
|
64
|
+
- Docker
|
|
65
|
+
- Node.js version 18 or higher
|
|
66
|
+
- CMake version 3.28 or higher (only required for Mobile development)
|
|
67
|
+
- Xcode (only required for iOS development)
|
|
68
|
+
- Cocoapods (only required for iOS development)
|
|
69
|
+
|
|
70
|
+
## Create a New Project
|
|
71
|
+
To set up a new cpp.js project with a minimal starter structure, execute the following command in your terminal:
|
|
72
|
+
```sh
|
|
73
|
+
npm create cpp.js@latest
|
|
74
|
+
```
|
|
75
|
+
## Integrate Into Existing Project
|
|
76
|
+
Integrate cpp.js seamlessly into your existing projects using the appropriate packages for your development needs. Refer to the documentation links for detailed integration guides.
|
|
77
|
+
|
|
78
|
+
| Platform | Package(s) | Documentation |
|
|
79
|
+
| -------- | ---------- | ------------- |
|
|
80
|
+
| Standalone | [cpp.js](https://www.npmjs.com/package/cpp.js) | [Learn](https://cpp.js.org/docs/guide/integrate-into-existing-project/standalone) |
|
|
81
|
+
| Webpack | [cppjs-webpack-plugin](https://www.npmjs.com/package/cppjs-webpack-plugin), [cppjs-loader](https://www.npmjs.com/package/cppjs-loader) | [Learn](https://cpp.js.org/docs/guide/integrate-into-existing-project/webpack) |
|
|
82
|
+
| Rollup | [rollup-plugin-cppjs](https://www.npmjs.com/package/rollup-plugin-cppjs) | [Learn](https://cpp.js.org/docs/guide/integrate-into-existing-project/rollup) |
|
|
83
|
+
| Vite | [vite-plugin-cppjs](https://www.npmjs.com/package/vite-plugin-cppjs) | [Learn](https://cpp.js.org/docs/guide/integrate-into-existing-project/vite) |
|
|
84
|
+
| Rspack | [cppjs-webpack-plugin](https://www.npmjs.com/package/cppjs-webpack-plugin), [cppjs-loader](https://www.npmjs.com/package/cppjs-loader) | [Learn](https://cpp.js.org/docs/guide/integrate-into-existing-project/rspack) |
|
|
85
|
+
| Create React App (CRA) | [cppjs-webpack-plugin](https://www.npmjs.com/package/cppjs-webpack-plugin), [cppjs-loader](https://www.npmjs.com/package/cppjs-loader) | [Learn](https://cpp.js.org/docs/guide/integrate-into-existing-project/create-react-app) |
|
|
86
|
+
| React Native | [cppjs-plugin-react-native](https://www.npmjs.com/package/cppjs-plugin-react-native), [cppjs-plugin-react-native-ios-helper](https://www.npmjs.com/package/cppjs-plugin-react-native-ios-helper), [cppjs-core-rn-embind](https://www.npmjs.com/package/cppjs-core-rn-embind) | [Learn](https://cpp.js.org/docs/guide/integrate-into-existing-project/react-native) |
|
|
87
|
+
| Expo | [cppjs-plugin-react-native](https://www.npmjs.com/package/cppjs-plugin-react-native), [cppjs-plugin-react-native-ios-helper](https://www.npmjs.com/package/cppjs-plugin-react-native-ios-helper), [cppjs-core-rn-embind](https://www.npmjs.com/package/cppjs-core-rn-embind) | [Learn](https://cpp.js.org/docs/guide/integrate-into-existing-project/expo) |
|
|
88
|
+
| Node.js | [cpp.js](https://www.npmjs.com/package/cpp.js) | [Learn](https://cpp.js.org/docs/guide/integrate-into-existing-project/nodejs) |
|
|
89
|
+
| Cloudflare Workers | [cpp.js](https://www.npmjs.com/package/cpp.js) | [Learn](https://cpp.js.org/docs/guide/integrate-into-existing-project/cloudflare-worker) |
|
|
90
|
+
|
|
91
|
+
## Features
|
|
92
|
+
- [Calling C++ from JavaScript](https://cpp.js.org/docs/guide/features/calling-cpp-from-javascript)
|
|
93
|
+
- [Packages](https://cpp.js.org/docs/guide/features/packages)
|
|
94
|
+
- [Plugins](https://cpp.js.org/docs/guide/features/plugins)
|
|
95
|
+
- [Assets](https://cpp.js.org/docs/guide/features/assets)
|
|
96
|
+
- [Working with a Monorepo](https://cpp.js.org/docs/guide/features/monorepo)
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
[MIT](https://github.com/bugra9/cpp.js/blob/main/LICENSE)
|
|
100
|
+
|
|
101
|
+
Copyright (c) 2024, Buğra Sarı
|
package/package.json
CHANGED
package/src/bin.js
CHANGED
|
@@ -13,7 +13,7 @@ const packageJSON = JSON.parse(fs.readFileSync(new URL('../package.json', import
|
|
|
13
13
|
const program = new Command();
|
|
14
14
|
|
|
15
15
|
program
|
|
16
|
-
.name('
|
|
16
|
+
.name('cppjs')
|
|
17
17
|
.description('Compile C++ files to WebAssembly and native platforms.')
|
|
18
18
|
.version(packageJSON.version)
|
|
19
19
|
.showHelpAfterError();
|