-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: create integration functions and update all packages
- Loading branch information
Showing
121 changed files
with
17,122 additions
and
11,692 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
LICENSE | ||
*.xcframework.zip | ||
*.tgz | ||
.cppjs | ||
ios/build | ||
android/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import getData from '../actions/getData.js'; | ||
import loadJson from '../utils/loadJson.js'; | ||
import state from '../state/index.js'; | ||
|
||
export default function getCppJsScript(platform, bridgePath = null) { | ||
if (!platform || !state.platforms.All.includes(platform)) { | ||
throw new Error('The platform is not available!'); | ||
} | ||
const env = JSON.stringify(getData('env', platform)); | ||
const getPlatformScript = state.platforms.WebAssembly.includes(platform) ? getWebScript : getReactNativeScript; | ||
|
||
const bridgeExportFile = `${bridgePath}.exports.json`; | ||
let symbols = null; | ||
if (bridgePath) { | ||
symbols = loadJson(bridgeExportFile); | ||
} | ||
|
||
let symbolExportDefineString = ''; | ||
let symbolExportAssignString = ''; | ||
if (symbols && Array.isArray(symbols)) { | ||
symbolExportDefineString = symbols.map((s) => `export let ${s} = null;`).join('\n'); | ||
symbolExportAssignString = symbols.map((s) => `${s} = m.${s};`).join('\n'); | ||
} | ||
|
||
const scriptContent = ` | ||
AllSymbols = m; | ||
${symbolExportAssignString} | ||
`; | ||
|
||
return ` | ||
export let AllSymbols = {}; | ||
${symbolExportDefineString} | ||
${getPlatformScript(env, scriptContent)} | ||
`; | ||
} | ||
|
||
function getReactNativeScript(env, modulePrefix) { | ||
return ` | ||
import { NativeModules } from 'react-native'; | ||
import Module from '@cpp.js/core-embind-jsi'; | ||
const { RNJsiLib } = NativeModules; | ||
function setEnv() { | ||
const env = JSON.parse('${env}'); | ||
const CPPJS_DATA_PATH = Module.CppJS.getEnv('CPPJS_DATA_PATH'); | ||
Object.entries(env).forEach(([key, value]) => { | ||
Module.CppJS.setEnv(key, value.replace('_CPPJS_DATA_PATH_', CPPJS_DATA_PATH), true); | ||
}); | ||
} | ||
export function initCppJs(config = {}) { | ||
return new Promise((resolve, reject) => { | ||
if (RNJsiLib && RNJsiLib.start) { | ||
RNJsiLib.start(); | ||
setEnv(); | ||
const m = Module; | ||
${modulePrefix} | ||
resolve(Module); | ||
} else { | ||
reject('Module failed to initialise.'); | ||
} | ||
}); | ||
} | ||
`; | ||
} | ||
|
||
function getWebScript(env, modulePrefix) { | ||
const params = `{ | ||
...config, | ||
env: {...${env}, ...config.env}, | ||
paths: { | ||
wasm: 'cpp.wasm', | ||
data: 'cpp.data.txt' | ||
} | ||
}`; | ||
|
||
return ` | ||
export function initCppJs(config = {}) { | ||
return new Promise((resolve, reject) => { | ||
import(/* webpackIgnore: true */ '/cpp.js').then(n => { | ||
return window.CppJs.initCppJs(${params}); | ||
}).then(m => { | ||
${modulePrefix} | ||
resolve(m); | ||
}); | ||
}); | ||
} | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import state from '../state/index.js'; | ||
|
||
export default function getDependFilePath(source, platform) { | ||
const headerRegex = new RegExp(`\\.(${state.config.ext.header.join('|')})$`); | ||
const moduleRegex = new RegExp(`\\.(${state.config.ext.module.join('|')})$`); | ||
|
||
const dependPackage = state.config.allDependencies.find((d) => source.startsWith(d.package.name)); | ||
if (dependPackage) { | ||
const filePath = source.substring(dependPackage.package.name.length + 1); | ||
|
||
let path = `${dependPackage.paths.output}/prebuilt/${platform}/${filePath}`; | ||
if (headerRegex.test(source)) { | ||
path = `${dependPackage.paths.output}/prebuilt/${platform}/include/${filePath}`; | ||
} else if (moduleRegex.test(source)) { | ||
path = `${dependPackage.paths.output}/prebuilt/${platform}/swig/${filePath}`; | ||
} | ||
|
||
return path; | ||
} | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
*.xcframework.zip | ||
*.tgz | ||
.cppjs | ||
*.dylib | ||
dist/prebuilt/Android-arm64-v8a/lib/*.a | ||
dist/prebuilt/**/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# @cpp.js/package-expat | ||
**Precompiled expat library built with cpp.js for seamless integration in JavaScript, WebAssembly and React Native projects.** | ||
|
||
<a href="https://www.npmjs.com/package/@cpp.js/package-expat"> | ||
<img alt="NPM version" src="https://img.shields.io/npm/v/@cpp.js/package-expat?style=for-the-badge" /> | ||
</a> | ||
<a href="https://github.com/libexpat/libexpat/blob/master/COPYING"> | ||
<img alt="License" src="https://img.shields.io/npm/l/%40cpp.js%2Fpackage-expat?style=for-the-badge" /> | ||
</a> | ||
|
||
## Integration | ||
Start by installing these package with the following command: | ||
|
||
```sh | ||
npm install @cpp.js/package-expat | ||
``` | ||
|
||
To enable the library, modify the cppjs.config.js file as shown below. | ||
```diff | ||
+import expat from '@cpp.js/package-expat/cppjs.config.js'; | ||
|
||
export default { | ||
dependencies: [ | ||
+ expat | ||
] | ||
paths: { | ||
config: import.meta.url, | ||
} | ||
}; | ||
``` | ||
|
||
## Usage | ||
Below are the steps to use the expat in your C++ or JavaScript code. | ||
|
||
### Usage in C++ Code | ||
```diff | ||
+#include <expat.h> | ||
|
||
std::string Native::sample() { | ||
+ return std::string(XML_ExpatVersion()); | ||
} | ||
``` | ||
|
||
## License | ||
This project includes the precompiled expat library, which is distributed under the [MIT License](https://github.com/libexpat/libexpat/blob/master/COPYING). | ||
|
||
Expat Homepage: <https://github.com/libexpat/libexpat> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.