@needle-tools/needle-component-compiler 3.0.0-alpha.2.b3c6deb → 3.0.0-alpha.4
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 +32 -0
- package/dist/Compiler.js +10 -0
- package/dist/impl/blender-compiler.js +10 -3
- package/dist/impl/csharp-compiler.js +1 -1
- package/package.json +4 -4
package/Readme.md
CHANGED
|
@@ -2,10 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
Compiles TypeScript component definitions into **Unity C#** component stubs and **Blender** Python component schemas for Needle Engine.
|
|
4
4
|
|
|
5
|
+
### CLI Usage
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npx @needle-tools/needle-component-compiler <target> <output_dir> <input_files...>
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- `target`: `csharp` or `blender`
|
|
12
|
+
- `output_dir`: directory for generated files
|
|
13
|
+
- `input_files`: one or more `.ts` source files
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Generate C# component stubs
|
|
17
|
+
npx @needle-tools/needle-component-compiler csharp ./codegen ./src/MyComponent.ts
|
|
18
|
+
|
|
19
|
+
# Generate Blender component schemas
|
|
20
|
+
npx @needle-tools/needle-component-compiler blender ./codegen ./src/MyComponent.ts
|
|
21
|
+
|
|
22
|
+
# Print version
|
|
23
|
+
npx @needle-tools/needle-component-compiler --version
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Programmatic API
|
|
27
|
+
|
|
5
28
|
```
|
|
6
29
|
npm install @needle-tools/needle-component-compiler
|
|
7
30
|
```
|
|
8
31
|
|
|
32
|
+
```ts
|
|
33
|
+
import { Compiler, CSharpWriter, FileSink } from "@needle-tools/needle-component-compiler";
|
|
34
|
+
|
|
35
|
+
const sink = new FileSink("./output");
|
|
36
|
+
const writer = new CSharpWriter(sink);
|
|
37
|
+
const compiler = new Compiler();
|
|
38
|
+
compiler.compile(writer, code, "MyComponent.ts");
|
|
39
|
+
```
|
|
40
|
+
|
|
9
41
|
### Supported TypeScript Features
|
|
10
42
|
|
|
11
43
|
- Classes extending `Behaviour`, `MonoBehaviour`, or implementing `IComponent`
|
package/dist/Compiler.js
CHANGED
|
@@ -106,6 +106,16 @@ var Compiler = /** @class */ (function () {
|
|
|
106
106
|
this.debugLog("[COMPILER] CLASS END", name, "\n");
|
|
107
107
|
};
|
|
108
108
|
Compiler.prototype.visitPropertyDeclaration = function (node, writer) {
|
|
109
|
+
// Skip static and abstract properties — they don't map to serialized fields
|
|
110
|
+
if (node.modifiers) {
|
|
111
|
+
for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) {
|
|
112
|
+
var modifier = _a[_i];
|
|
113
|
+
if (modifier.kind === ts.SyntaxKind.StaticKeyword ||
|
|
114
|
+
modifier.kind === ts.SyntaxKind.AbstractKeyword) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
109
119
|
var name = node.name.getText();
|
|
110
120
|
var type = this.resolveType(node.type, writer);
|
|
111
121
|
var visibility = this.getVisibility(node);
|
|
@@ -97,6 +97,8 @@ var BlenderWriter = /** @class */ (function (_super) {
|
|
|
97
97
|
return typeName;
|
|
98
98
|
};
|
|
99
99
|
BlenderWriter.prototype.startNewType = function (filePath, typeName, baseTypes, comments) {
|
|
100
|
+
if (comments === null || comments === void 0 ? void 0 : comments.includes("@dont-generate-component"))
|
|
101
|
+
return false;
|
|
100
102
|
var isSupportedType = false;
|
|
101
103
|
for (var i = 0; i < knownBaseTypes.length; i++) {
|
|
102
104
|
if (baseTypes.includes(knownBaseTypes[i])) {
|
|
@@ -104,12 +106,9 @@ var BlenderWriter = /** @class */ (function (_super) {
|
|
|
104
106
|
break;
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
|
-
// console.log(baseTypes, knownBaseTypes, isSupportedType)
|
|
108
109
|
if (!isSupportedType)
|
|
109
110
|
return false;
|
|
110
111
|
this.writer.beginBlock("{");
|
|
111
|
-
if (comments)
|
|
112
|
-
console.log(comments);
|
|
113
112
|
this.writer.beginBlock("\"" + typeName + "\": {");
|
|
114
113
|
};
|
|
115
114
|
BlenderWriter.prototype.endNewType = function (filePath, typeName) {
|
|
@@ -120,6 +119,14 @@ var BlenderWriter = /** @class */ (function (_super) {
|
|
|
120
119
|
BlenderWriter.prototype.writeMember = function (visibility, name, isArray, type, initialValue, comments) {
|
|
121
120
|
if (visibility !== base_compiler_1.Visibility.Public)
|
|
122
121
|
return;
|
|
122
|
+
// @nonSerialized → skip entirely
|
|
123
|
+
if (comments === null || comments === void 0 ? void 0 : comments.some(function (c) { return c.startsWith("@nonSerialized"); }))
|
|
124
|
+
return;
|
|
125
|
+
// @type override
|
|
126
|
+
var typeOverride = comments === null || comments === void 0 ? void 0 : comments.find(function (c) { return c.startsWith("@type "); });
|
|
127
|
+
if (typeOverride) {
|
|
128
|
+
type = typeOverride.substring("@type ".length).trim();
|
|
129
|
+
}
|
|
123
130
|
// Check if type is a registered TypeScript enum
|
|
124
131
|
var enumMembers = this._enumRegistry.get(type);
|
|
125
132
|
if (enumMembers && enumMembers.length > 0) {
|
|
@@ -273,7 +273,7 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
273
273
|
: "void";
|
|
274
274
|
if (contextMenu)
|
|
275
275
|
this.writer.writeLine("[UnityEngine.ContextMenu(\"".concat(contextMenu, "\")]"));
|
|
276
|
-
this.writer.writeLine("public
|
|
276
|
+
this.writer.writeLine("public ".concat(csReturnType, " ").concat(methodName, "(").concat(paramList, ") {}"));
|
|
277
277
|
};
|
|
278
278
|
CSharpWriter.prototype.writeNewTypeExpression = function (typeName, args) {
|
|
279
279
|
// no-op for C# output
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/needle-component-compiler",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.4",
|
|
4
4
|
"description": "Compile Editor components for Needle Engine for C# and Blender",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"url": "git+https://github.com/needle-tools/needle-tiny-component-compiler.git"
|
|
58
58
|
},
|
|
59
59
|
"publishConfig": {
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
"access": "public",
|
|
61
|
+
"registry": "https://registry.npmjs.org/"
|
|
62
62
|
}
|
|
63
|
-
}
|
|
63
|
+
}
|