cpp.js 1.0.0-beta.21 → 1.0.0-beta.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cpp.js",
3
- "version": "1.0.0-beta.21",
3
+ "version": "1.0.0-beta.22",
4
4
  "license": "MIT",
5
5
  "homepage": "https://cpp.js.org",
6
6
  "repository": "https://github.com/bugra9/cpp.js.git",
package/src/index.js CHANGED
@@ -9,5 +9,5 @@ export { default as getCmakeParameters } from './actions/getCmakeParameters.js';
9
9
  export { default as createXCFramework } from './actions/createXCFramework.js';
10
10
  export { default as getAllBridges } from './actions/getAllBridges.js';
11
11
  export { default as run } from './actions/run.js';
12
- export { default as exportWeb } from './export/web.js';
13
- export { default as exportReactNative } from './export/react-native.js';
12
+ export { default as getCppJsScript } from './integration/getCppJsScript.js';
13
+ export { default as getDependFilePath } from './integration/getDependFilePath.js';
@@ -0,0 +1,90 @@
1
+ import getData from '../actions/getData.js';
2
+ import loadJson from '../utils/loadJson.js';
3
+ import state from '../state/index.js';
4
+
5
+ export default function getCppJsScript(platform, bridgePath = null) {
6
+ if (!platform || !state.platforms.All.includes(platform)) {
7
+ throw new Error('The platform is not available!');
8
+ }
9
+ const env = JSON.stringify(getData('env', platform));
10
+ const getPlatformScript = state.platforms.WebAssembly.includes(platform) ? getWebScript : getReactNativeScript;
11
+
12
+ const bridgeExportFile = `${bridgePath}.exports.json`;
13
+ let symbols = null;
14
+ if (bridgePath) {
15
+ symbols = loadJson(bridgeExportFile);
16
+ }
17
+
18
+ let symbolExportDefineString = '';
19
+ let symbolExportAssignString = '';
20
+ if (symbols && Array.isArray(symbols)) {
21
+ symbolExportDefineString = symbols.map((s) => `export let ${s} = null;`).join('\n');
22
+ symbolExportAssignString = symbols.map((s) => `${s} = m.${s};`).join('\n');
23
+ }
24
+
25
+ const scriptContent = `
26
+ AllSymbols = m;
27
+ ${symbolExportAssignString}
28
+ `;
29
+
30
+ return `
31
+ export let AllSymbols = {};
32
+ ${symbolExportDefineString}
33
+
34
+ export function initCppJs(config = {}) {
35
+ ${getPlatformScript(env, scriptContent)}
36
+ }
37
+ `;
38
+ }
39
+
40
+ function getReactNativeScript(env, modulePrefix) {
41
+ return `
42
+ import { NativeModules } from 'react-native';
43
+ import Module from '@cpp.js/core-embind-jsi';
44
+
45
+ const { RNJsiLib } = NativeModules;
46
+
47
+ function setEnv() {
48
+ const env = JSON.parse('${env}');
49
+ const CPPJS_DATA_PATH = Module.CppJS.getEnv('CPPJS_DATA_PATH');
50
+
51
+ Object.entries(env).forEach(([key, value]) => {
52
+ Module.CppJS.setEnv(key, value.replace('_CPPJS_DATA_PATH_', CPPJS_DATA_PATH), true);
53
+ });
54
+ }
55
+
56
+ return new Promise((resolve, reject) => {
57
+ if (RNJsiLib && RNJsiLib.start) {
58
+ RNJsiLib.start();
59
+ setEnv();
60
+ const m = Module;
61
+ ${modulePrefix}
62
+ resolve(Module);
63
+ } else {
64
+ reject('Module failed to initialise.');
65
+ }
66
+ });
67
+ `;
68
+ }
69
+
70
+ function getWebScript(env, modulePrefix) {
71
+ const params = `{
72
+ ...config,
73
+ env: {...${env}, ...config.env},
74
+ paths: {
75
+ wasm: 'cpp.wasm',
76
+ data: 'cpp.data.txt'
77
+ }
78
+ }`;
79
+
80
+ return `
81
+ return new Promise((resolve, reject) => {
82
+ import('/cpp.js').then(n => {
83
+ return window.CppJs.initCppJs(${params});
84
+ }).then(m => {
85
+ ${modulePrefix}
86
+ resolve(m);
87
+ });
88
+ });
89
+ `;
90
+ }
@@ -0,0 +1,22 @@
1
+ import state from '../state/index.js';
2
+
3
+ export default function getDependFilePath(source, platform) {
4
+ const headerRegex = new RegExp(`\\.(${state.config.ext.header.join('|')})$`);
5
+ const moduleRegex = new RegExp(`\\.(${state.config.ext.module.join('|')})$`);
6
+
7
+ const dependPackage = state.config.allDependencies.find((d) => source.startsWith(d.package.name));
8
+ if (dependPackage) {
9
+ const filePath = source.substring(dependPackage.package.name.length + 1);
10
+
11
+ let path = `${dependPackage.paths.output}/prebuilt/${platform}/${filePath}`;
12
+ if (headerRegex.test(source)) {
13
+ path = `${dependPackage.paths.output}/prebuilt/${platform}/include/${filePath}`;
14
+ } else if (moduleRegex.test(source)) {
15
+ path = `${dependPackage.paths.output}/prebuilt/${platform}/swig/${filePath}`;
16
+ }
17
+
18
+ return path;
19
+ }
20
+
21
+ return null;
22
+ }
@@ -3,7 +3,7 @@ import { execFileSync } from 'child_process';
3
3
  let isDockerImageAvailable = false;
4
4
 
5
5
  export function getDockerImage() {
6
- return 'bugra9/cpp.js:0.2.6';
6
+ return 'bugra9/cpp.js:0.2.7';
7
7
  }
8
8
 
9
9
  export default function pullDockerImage() {
File without changes
File without changes