breeze-bindgen 1.1.0 → 1.1.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.
- package/README.md +17 -8
- package/dist/cli.mjs +13 -14
- package/dist/core.cjs +8 -7
- package/dist/core.mjs +8 -7
- package/package.json +1 -1
package/README.md
CHANGED
@@ -39,14 +39,23 @@ breeze-bindgen -i <input_header_file> [options]
|
|
39
39
|
|
40
40
|
**Options:**
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
42
|
+
--version Show version number [boolean]
|
43
|
+
-i, --input Path to the input C++ header file to process.
|
44
|
+
[string] [required]
|
45
|
+
-o, --output Directory where the generated binding.h and
|
46
|
+
definition.d.ts files will be saved. [string]
|
47
|
+
--clang Optional path to the clang++ executable.[string]
|
48
|
+
--cppBindingOutputFile Name of the generated C++ binding file.
|
49
|
+
[string] [default: "binding_qjs.h"]
|
50
|
+
--tsDefinitionOutputFile Name of the generated TypeScript definition
|
51
|
+
file. [string] [default: "binding_types.d.ts"]
|
52
|
+
--tsModuleName Name of the TypeScript module.
|
53
|
+
[string] [default: "BreezeJS"]
|
54
|
+
--extTypesPath Path to additional type definitions.
|
55
|
+
[string] [default: ""]
|
56
|
+
--nameFilter Clang AST dump filter for names (e.g.,
|
57
|
+
"breeze::js"). [string] [default: "breeze::js"]
|
58
|
+
-h, --help Show help [boolean]
|
50
59
|
|
51
60
|
**Example:**
|
52
61
|
|
package/dist/cli.mjs
CHANGED
@@ -195,7 +195,7 @@ function parseFunctionQualType(type) {
|
|
195
195
|
if (state !== 2 /* Done */) throw new Error("Invalid function type");
|
196
196
|
return { returnType, args };
|
197
197
|
}
|
198
|
-
function processAstAndGenerateCode(astArr, originalCppFilePath, nameFilter, additionalTypes) {
|
198
|
+
function processAstAndGenerateCode(astArr, originalCppFilePath, nameFilter, additionalTypes, tsModuleName) {
|
199
199
|
const origFileContent = readFileSync(originalCppFilePath, "utf-8").split("\n").map((v) => v.trim());
|
200
200
|
const structNames = [];
|
201
201
|
const resolveUnderPath = (path, resolveName) => {
|
@@ -214,11 +214,11 @@ function processAstAndGenerateCode(astArr, originalCppFilePath, nameFilter, addi
|
|
214
214
|
const parsed = parser2.parse(type, (name) => resolveUnderPath(path, name));
|
215
215
|
return parser2.formatToC(parsed);
|
216
216
|
};
|
217
|
-
let binding = `// This file is generated by bindgen
|
217
|
+
let binding = `// This file is generated by Breeze.JS Bindgen (https://github.com/breeze-shell/breeze-js-bindgen)
|
218
218
|
// Do not modify this file manually!
|
219
219
|
|
220
220
|
#pragma once
|
221
|
-
#include "binding_types.h"
|
221
|
+
#include "binding_types.h"
|
222
222
|
#include "quickjs.h"
|
223
223
|
#include "quickjspp.hpp"
|
224
224
|
|
@@ -230,7 +230,7 @@ struct js_bind {
|
|
230
230
|
let typescriptDef = `// This file is generated by bindgen
|
231
231
|
// Do not modify this file manually!
|
232
232
|
|
233
|
-
declare module '
|
233
|
+
declare module '${tsModuleName}' {
|
234
234
|
`;
|
235
235
|
const generateForRecordDecl = (node_struct, path) => {
|
236
236
|
if (node_struct.kind !== "CXXRecordDecl") throw new Error("Node is not a RecordDecl");
|
@@ -391,7 +391,7 @@ export class ${tsClassName}${bases.length > 0 ? ` extends ${bases.map((base) =>
|
|
391
391
|
if (tsNamespace) typescriptDef += `
|
392
392
|
}`;
|
393
393
|
};
|
394
|
-
const enumerateStructDecls = (node, callback, path = ["
|
394
|
+
const enumerateStructDecls = (node, callback, path = [nameFilter.split("::")[0]]) => {
|
395
395
|
if (node.kind === "CXXRecordDecl" && node.name && node.inner) {
|
396
396
|
callback(node, path);
|
397
397
|
}
|
@@ -436,7 +436,8 @@ function generateBindingsAndDefinitions(config) {
|
|
436
436
|
cppBindingOutputFile = DEFAULT_CPP_BINDING_OUTPUT_FILE,
|
437
437
|
tsDefinitionOutputFile = DEFAULT_TS_DEFINITION_OUTPUT_FILE,
|
438
438
|
additionalTypes = "",
|
439
|
-
nameFilter = DEFAULT_NAME_FILTER
|
439
|
+
nameFilter = DEFAULT_NAME_FILTER,
|
440
|
+
tsModuleName = "mshell"
|
440
441
|
} = config;
|
441
442
|
const absoluteCppFilePath = resolvePath(cppFilePath);
|
442
443
|
const absoluteOutputDir = resolvePath(outputDir);
|
@@ -482,7 +483,7 @@ ${clangProcess.stderr}`);
|
|
482
483
|
if (!astArr || astArr.length === 0) {
|
483
484
|
log.warn(`No AST data was parsed. This might mean the ast-dump-filter ("${nameFilter.slice(0, -2)}") didn't match anything, or the input file is empty or has no relevant declarations.`);
|
484
485
|
}
|
485
|
-
const { cppBinding, tsDefinitions } = processAstAndGenerateCode(astArr, absoluteCppFilePath, nameFilter, additionalTypes);
|
486
|
+
const { cppBinding, tsDefinitions } = processAstAndGenerateCode(astArr, absoluteCppFilePath, nameFilter, additionalTypes, tsModuleName);
|
486
487
|
if (!existsSync(absoluteOutputDir)) {
|
487
488
|
try {
|
488
489
|
mkdirSync(absoluteOutputDir, { recursive: true });
|
@@ -5178,7 +5179,6 @@ async function main() {
|
|
5178
5179
|
alias: "o",
|
5179
5180
|
type: "string",
|
5180
5181
|
description: "Directory where the generated binding.h and definition.d.ts files will be saved."
|
5181
|
-
// Default will be set later based on input file if not provided
|
5182
5182
|
}).option("clang", {
|
5183
5183
|
type: "string",
|
5184
5184
|
description: "Optional path to the clang++ executable."
|
@@ -5190,10 +5190,10 @@ async function main() {
|
|
5190
5190
|
type: "string",
|
5191
5191
|
description: "Name of the generated TypeScript definition file.",
|
5192
5192
|
default: "binding_types.d.ts"
|
5193
|
-
}).option("
|
5193
|
+
}).option("tsModuleName", {
|
5194
5194
|
type: "string",
|
5195
|
-
description: "
|
5196
|
-
default: "
|
5195
|
+
description: "Name of the TypeScript module.",
|
5196
|
+
default: "BreezeJS"
|
5197
5197
|
}).option("extTypesPath", {
|
5198
5198
|
type: "string",
|
5199
5199
|
description: "Path to additional type definitions.",
|
@@ -5202,7 +5202,6 @@ async function main() {
|
|
5202
5202
|
type: "string",
|
5203
5203
|
description: 'Clang AST dump filter for names (e.g., "breeze::js").',
|
5204
5204
|
default: "breeze::js"
|
5205
|
-
// Note: core.ts adds "::" internally
|
5206
5205
|
}).help().alias("h", "help").parse();
|
5207
5206
|
try {
|
5208
5207
|
const inputFile = resolvePath2(argv.input);
|
@@ -5227,8 +5226,8 @@ async function main() {
|
|
5227
5226
|
cppBindingOutputFile: argv.cppBindingOutputFile,
|
5228
5227
|
tsDefinitionOutputFile: argv.tsDefinitionOutputFile,
|
5229
5228
|
additionalTypes: argv.extTypesPath ? readFileSync5(resolvePath2(argv.extTypesPath), "utf-8") : "",
|
5230
|
-
nameFilter: argv.nameFilter + "::"
|
5231
|
-
|
5229
|
+
nameFilter: argv.nameFilter + "::",
|
5230
|
+
tsModuleName: argv.tsModuleName
|
5232
5231
|
});
|
5233
5232
|
log2("Binding generation finished successfully.");
|
5234
5233
|
} catch (error) {
|
package/dist/core.cjs
CHANGED
@@ -406,7 +406,7 @@ function parseFunctionQualType(type) {
|
|
406
406
|
if (state !== 2 /* Done */) throw new Error("Invalid function type");
|
407
407
|
return { returnType, args };
|
408
408
|
}
|
409
|
-
function processAstAndGenerateCode(astArr, originalCppFilePath, nameFilter, additionalTypes) {
|
409
|
+
function processAstAndGenerateCode(astArr, originalCppFilePath, nameFilter, additionalTypes, tsModuleName) {
|
410
410
|
const origFileContent = (0, import_node_fs.readFileSync)(originalCppFilePath, "utf-8").split("\n").map((v) => v.trim());
|
411
411
|
const structNames = [];
|
412
412
|
const resolveUnderPath = (path, resolveName) => {
|
@@ -425,11 +425,11 @@ function processAstAndGenerateCode(astArr, originalCppFilePath, nameFilter, addi
|
|
425
425
|
const parsed = parser.parse(type, (name) => resolveUnderPath(path, name));
|
426
426
|
return parser.formatToC(parsed);
|
427
427
|
};
|
428
|
-
let binding = `// This file is generated by bindgen
|
428
|
+
let binding = `// This file is generated by Breeze.JS Bindgen (https://github.com/breeze-shell/breeze-js-bindgen)
|
429
429
|
// Do not modify this file manually!
|
430
430
|
|
431
431
|
#pragma once
|
432
|
-
#include "binding_types.h"
|
432
|
+
#include "binding_types.h"
|
433
433
|
#include "quickjs.h"
|
434
434
|
#include "quickjspp.hpp"
|
435
435
|
|
@@ -441,7 +441,7 @@ struct js_bind {
|
|
441
441
|
let typescriptDef = `// This file is generated by bindgen
|
442
442
|
// Do not modify this file manually!
|
443
443
|
|
444
|
-
declare module '
|
444
|
+
declare module '${tsModuleName}' {
|
445
445
|
`;
|
446
446
|
const generateForRecordDecl = (node_struct, path) => {
|
447
447
|
if (node_struct.kind !== "CXXRecordDecl") throw new Error("Node is not a RecordDecl");
|
@@ -602,7 +602,7 @@ export class ${tsClassName}${bases.length > 0 ? ` extends ${bases.map((base) =>
|
|
602
602
|
if (tsNamespace) typescriptDef += `
|
603
603
|
}`;
|
604
604
|
};
|
605
|
-
const enumerateStructDecls = (node, callback, path = ["
|
605
|
+
const enumerateStructDecls = (node, callback, path = [nameFilter.split("::")[0]]) => {
|
606
606
|
if (node.kind === "CXXRecordDecl" && node.name && node.inner) {
|
607
607
|
callback(node, path);
|
608
608
|
}
|
@@ -647,7 +647,8 @@ function generateBindingsAndDefinitions(config) {
|
|
647
647
|
cppBindingOutputFile = DEFAULT_CPP_BINDING_OUTPUT_FILE,
|
648
648
|
tsDefinitionOutputFile = DEFAULT_TS_DEFINITION_OUTPUT_FILE,
|
649
649
|
additionalTypes = "",
|
650
|
-
nameFilter = DEFAULT_NAME_FILTER
|
650
|
+
nameFilter = DEFAULT_NAME_FILTER,
|
651
|
+
tsModuleName = "mshell"
|
651
652
|
} = config;
|
652
653
|
const absoluteCppFilePath = (0, import_node_path.resolve)(cppFilePath);
|
653
654
|
const absoluteOutputDir = (0, import_node_path.resolve)(outputDir);
|
@@ -693,7 +694,7 @@ ${clangProcess.stderr}`);
|
|
693
694
|
if (!astArr || astArr.length === 0) {
|
694
695
|
import_fancy_log.default.warn(`No AST data was parsed. This might mean the ast-dump-filter ("${nameFilter.slice(0, -2)}") didn't match anything, or the input file is empty or has no relevant declarations.`);
|
695
696
|
}
|
696
|
-
const { cppBinding, tsDefinitions } = processAstAndGenerateCode(astArr, absoluteCppFilePath, nameFilter, additionalTypes);
|
697
|
+
const { cppBinding, tsDefinitions } = processAstAndGenerateCode(astArr, absoluteCppFilePath, nameFilter, additionalTypes, tsModuleName);
|
697
698
|
if (!(0, import_node_fs.existsSync)(absoluteOutputDir)) {
|
698
699
|
try {
|
699
700
|
(0, import_node_fs.mkdirSync)(absoluteOutputDir, { recursive: true });
|
package/dist/core.mjs
CHANGED
@@ -401,7 +401,7 @@ function parseFunctionQualType(type) {
|
|
401
401
|
if (state !== 2 /* Done */) throw new Error("Invalid function type");
|
402
402
|
return { returnType, args };
|
403
403
|
}
|
404
|
-
function processAstAndGenerateCode(astArr, originalCppFilePath, nameFilter, additionalTypes) {
|
404
|
+
function processAstAndGenerateCode(astArr, originalCppFilePath, nameFilter, additionalTypes, tsModuleName) {
|
405
405
|
const origFileContent = readFileSync(originalCppFilePath, "utf-8").split("\n").map((v) => v.trim());
|
406
406
|
const structNames = [];
|
407
407
|
const resolveUnderPath = (path, resolveName) => {
|
@@ -420,11 +420,11 @@ function processAstAndGenerateCode(astArr, originalCppFilePath, nameFilter, addi
|
|
420
420
|
const parsed = parser.parse(type, (name) => resolveUnderPath(path, name));
|
421
421
|
return parser.formatToC(parsed);
|
422
422
|
};
|
423
|
-
let binding = `// This file is generated by bindgen
|
423
|
+
let binding = `// This file is generated by Breeze.JS Bindgen (https://github.com/breeze-shell/breeze-js-bindgen)
|
424
424
|
// Do not modify this file manually!
|
425
425
|
|
426
426
|
#pragma once
|
427
|
-
#include "binding_types.h"
|
427
|
+
#include "binding_types.h"
|
428
428
|
#include "quickjs.h"
|
429
429
|
#include "quickjspp.hpp"
|
430
430
|
|
@@ -436,7 +436,7 @@ struct js_bind {
|
|
436
436
|
let typescriptDef = `// This file is generated by bindgen
|
437
437
|
// Do not modify this file manually!
|
438
438
|
|
439
|
-
declare module '
|
439
|
+
declare module '${tsModuleName}' {
|
440
440
|
`;
|
441
441
|
const generateForRecordDecl = (node_struct, path) => {
|
442
442
|
if (node_struct.kind !== "CXXRecordDecl") throw new Error("Node is not a RecordDecl");
|
@@ -597,7 +597,7 @@ export class ${tsClassName}${bases.length > 0 ? ` extends ${bases.map((base) =>
|
|
597
597
|
if (tsNamespace) typescriptDef += `
|
598
598
|
}`;
|
599
599
|
};
|
600
|
-
const enumerateStructDecls = (node, callback, path = ["
|
600
|
+
const enumerateStructDecls = (node, callback, path = [nameFilter.split("::")[0]]) => {
|
601
601
|
if (node.kind === "CXXRecordDecl" && node.name && node.inner) {
|
602
602
|
callback(node, path);
|
603
603
|
}
|
@@ -642,7 +642,8 @@ function generateBindingsAndDefinitions(config) {
|
|
642
642
|
cppBindingOutputFile = DEFAULT_CPP_BINDING_OUTPUT_FILE,
|
643
643
|
tsDefinitionOutputFile = DEFAULT_TS_DEFINITION_OUTPUT_FILE,
|
644
644
|
additionalTypes = "",
|
645
|
-
nameFilter = DEFAULT_NAME_FILTER
|
645
|
+
nameFilter = DEFAULT_NAME_FILTER,
|
646
|
+
tsModuleName = "mshell"
|
646
647
|
} = config;
|
647
648
|
const absoluteCppFilePath = resolvePath(cppFilePath);
|
648
649
|
const absoluteOutputDir = resolvePath(outputDir);
|
@@ -688,7 +689,7 @@ ${clangProcess.stderr}`);
|
|
688
689
|
if (!astArr || astArr.length === 0) {
|
689
690
|
import_fancy_log.default.warn(`No AST data was parsed. This might mean the ast-dump-filter ("${nameFilter.slice(0, -2)}") didn't match anything, or the input file is empty or has no relevant declarations.`);
|
690
691
|
}
|
691
|
-
const { cppBinding, tsDefinitions } = processAstAndGenerateCode(astArr, absoluteCppFilePath, nameFilter, additionalTypes);
|
692
|
+
const { cppBinding, tsDefinitions } = processAstAndGenerateCode(astArr, absoluteCppFilePath, nameFilter, additionalTypes, tsModuleName);
|
692
693
|
if (!existsSync(absoluteOutputDir)) {
|
693
694
|
try {
|
694
695
|
mkdirSync(absoluteOutputDir, { recursive: true });
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
|
3
3
|
"name": "breeze-bindgen",
|
4
|
-
"version": "1.1.
|
4
|
+
"version": "1.1.2",
|
5
5
|
"main": "dist/index.cjs",
|
6
6
|
"module": "dist/index.mjs",
|
7
7
|
"types": "dist/index.d.ts",
|