cpp.js 1.0.0-beta.1 → 1.0.0-beta.2

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/bin.js +56 -53
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cpp.js",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "homepage": "https://cpp.js.org",
@@ -13,7 +13,7 @@
13
13
  "@rollup/plugin-commonjs": "^26.0.1",
14
14
  "@rollup/plugin-node-resolve": "^15.2.3",
15
15
  "@rollup/plugin-virtual": "^3.0.2",
16
- "commander": "^9.4.1",
16
+ "commander": "^12.1.0",
17
17
  "glob": "^8.0.3",
18
18
  "rollup": "^4.18.0",
19
19
  "rollup-plugin-uglify": "^6.0.4"
package/src/bin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { Command, Argument } from 'commander';
3
+ import { Command, Option } from 'commander';
4
4
  import fs from 'fs';
5
5
  import glob from 'glob';
6
6
  import { createDir } from './utils/createTempDir.js';
@@ -14,30 +14,26 @@ const program = new Command();
14
14
 
15
15
  program
16
16
  .name('cpp.js')
17
- .description('Compile c++ files to webassembly.')
17
+ .description('Compile C++ files to WebAssembly and native platforms.')
18
18
  .version(packageJSON.version)
19
19
  .showHelpAfterError();
20
20
 
21
- const commandGenerate = program.command('generate')
22
- .description('Generate app or lib.')
23
- .addArgument(new Argument('<type>', 'Generation type').choices(['app', 'lib']))
24
- .option('-b, --base <base>', 'base path')
25
- .option('-p, --platform <platform>', 'platform (all)', 'all', ['all', 'wasm', 'android', 'ios'])
26
- .option('-o, --output <string>', 'Output path');
21
+ const commandBuild = program.command('build')
22
+ .description('compile the project that was set up using Cpp.js')
23
+ .addOption(new Option('-p, --platform <platform>', 'target platform').default('all').choices(['all', 'wasm', 'android', 'ios']));
27
24
 
28
25
  const commandRun = program.command('run')
29
- .description('Run docker application');
26
+ .description('run docker application');
30
27
 
31
28
  const commandPostInstall = program.command('postinstall')
32
- .description('npm postinstall');
29
+ .description('prepare the required packages for Cpp.js after installation');
33
30
 
34
31
  program.parse(process.argv);
35
32
 
36
33
  switch (program.args[0]) {
37
- case 'generate': {
38
- const type = commandGenerate.args[0];
39
- const { output, platform, base } = commandGenerate.opts();
40
- generate(type, platform, output, base);
34
+ case 'build': {
35
+ const { platform } = commandBuild.opts();
36
+ build(platform);
41
37
  break;
42
38
  }
43
39
  case 'run': {
@@ -55,7 +51,15 @@ switch (program.args[0]) {
55
51
 
56
52
  function postInstall() {
57
53
  const projectPath = process.env.PWD;
58
- if (!fs.existsSync(`${projectPath}/cppjs.config.js`) && !fs.existsSync(`${projectPath}/cppjs.config.cjs`) && !fs.existsSync(`${projectPath}/cppjs.config.mjs`)) {
54
+ const isDarwin = process.platform === 'darwin';
55
+ if (
56
+ !isDarwin
57
+ || (
58
+ !fs.existsSync(`${projectPath}/cppjs.config.js`)
59
+ && !fs.existsSync(`${projectPath}/cppjs.config.cjs`)
60
+ && !fs.existsSync(`${projectPath}/cppjs.config.mjs`)
61
+ )
62
+ ) {
59
63
  return;
60
64
  }
61
65
 
@@ -78,49 +82,48 @@ function postInstall() {
78
82
 
79
83
  function run(programName, params) {
80
84
  const compiler = new CppjsCompiler();
81
- compiler.run(programName, params);
85
+ compiler.run(programName, params, { console: true });
82
86
  }
83
87
 
84
- function generate(type, platform) {
88
+ function build(platform) {
85
89
  const compiler2 = new CppjsCompiler();
86
- if (type === 'lib') {
87
- const modules = [];
88
- compiler2.config.paths.module.forEach((modulePath) => {
89
- modules.push(...glob.sync('**/*.i', { absolute: true, cwd: modulePath }));
90
- modules.push(...glob.sync('*.i', { absolute: true, cwd: modulePath }));
91
- });
92
-
93
- if (platform === 'all' || platform === 'wasm') {
94
- if (!fs.existsSync(`${compiler2.config.paths.output}/prebuilt/Emscripten-x86_64`)) {
95
- generateWasmLib();
96
- modules.forEach((modulePath) => {
97
- const fileName = modulePath.split('/').at(-1);
98
- createDir('prebuilt/Emscripten-x86_64/swig', compiler2.config.paths.output);
99
- fs.copyFileSync(modulePath, `${compiler2.config.paths.output}/prebuilt/Emscripten-x86_64/swig/${fileName}`);
100
- });
101
- }
90
+
91
+ const modules = [];
92
+ compiler2.config.paths.module.forEach((modulePath) => {
93
+ modules.push(...glob.sync('**/*.i', { absolute: true, cwd: modulePath }));
94
+ modules.push(...glob.sync('*.i', { absolute: true, cwd: modulePath }));
95
+ });
96
+
97
+ if (platform === 'all' || platform === 'wasm') {
98
+ if (!fs.existsSync(`${compiler2.config.paths.output}/prebuilt/Emscripten-x86_64`)) {
99
+ buildWasm();
100
+ modules.forEach((modulePath) => {
101
+ const fileName = modulePath.split('/').at(-1);
102
+ createDir('prebuilt/Emscripten-x86_64/swig', compiler2.config.paths.output);
103
+ fs.copyFileSync(modulePath, `${compiler2.config.paths.output}/prebuilt/Emscripten-x86_64/swig/${fileName}`);
104
+ });
102
105
  }
106
+ }
103
107
 
104
- if (platform === 'wasm') return;
105
- const platforms = {
106
- all: ['Android-arm64-v8a', 'iOS-iphoneos', 'iOS-iphonesimulator'],
107
- android: ['Android-arm64-v8a'],
108
- ios: ['iOS-iphoneos', 'iOS-iphonesimulator'],
109
- };
110
- platforms[platform].forEach((p) => {
111
- if (!fs.existsSync(`${compiler2.config.paths.output}/prebuilt/${p}`)) {
112
- const compiler = new CppjsCompiler(p);
113
- compiler.createLib();
114
- modules.forEach((modulePath) => {
115
- const fileName = modulePath.split('/').at(-1);
116
- createDir(`prebuilt/${p}/swig`, compiler2.config.paths.output);
117
- fs.copyFileSync(modulePath, `${compiler2.config.paths.output}/prebuilt/${p}/swig/${fileName}`);
118
- });
119
- }
120
- });
121
- if (platform === 'all' || platform === 'ios') {
122
- compiler2.finishBuild();
108
+ if (platform === 'wasm') return;
109
+ const platforms = {
110
+ all: ['Android-arm64-v8a', 'iOS-iphoneos', 'iOS-iphonesimulator'],
111
+ android: ['Android-arm64-v8a'],
112
+ ios: ['iOS-iphoneos', 'iOS-iphonesimulator'],
113
+ };
114
+ platforms[platform].forEach((p) => {
115
+ if (!fs.existsSync(`${compiler2.config.paths.output}/prebuilt/${p}`)) {
116
+ const compiler = new CppjsCompiler(p);
117
+ compiler.createLib();
118
+ modules.forEach((modulePath) => {
119
+ const fileName = modulePath.split('/').at(-1);
120
+ createDir(`prebuilt/${p}/swig`, compiler2.config.paths.output);
121
+ fs.copyFileSync(modulePath, `${compiler2.config.paths.output}/prebuilt/${p}/swig/${fileName}`);
122
+ });
123
123
  }
124
+ });
125
+ if (platform === 'all' || platform === 'ios') {
126
+ compiler2.finishBuild();
124
127
  }
125
128
 
126
129
  const distCmakeContent = fs.readFileSync(`${compiler2.config.paths.cli}/assets/dist.cmake`, { encoding: 'utf8', flag: 'r' })
@@ -128,7 +131,7 @@ function generate(type, platform) {
128
131
  fs.writeFileSync(`${compiler2.config.paths.output}/prebuilt/CMakeLists.txt`, distCmakeContent);
129
132
  }
130
133
 
131
- async function generateWasmLib() {
134
+ async function buildWasm() {
132
135
  let headers = [];
133
136
 
134
137
  const compiler = new CppjsCompiler();