@needle-tools/needle-component-compiler 3.0.10 → 3.0.12
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/Changelog.md +4 -0
- package/dist/BaseWriter.js +4 -1
- package/dist/Compiler.d.ts +2 -1
- package/dist/Compiler.js +65 -35
- package/dist/base-compiler.js +3 -2
- package/dist/cli.js +17 -8
- package/dist/impl/blender-compiler.js +2 -1
- package/dist/impl/csharp-compiler.js +3 -2
- package/dist/log.d.ts +8 -0
- package/dist/log.js +30 -0
- package/dist/register-types.js +2 -1
- package/dist/watcher.js +9 -8
- package/package.json +1 -1
package/Changelog.md
CHANGED
|
@@ -4,6 +4,10 @@ All notable changes to this package will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [3.0.12] - 2026-03-23
|
|
8
|
+
### Fixed
|
|
9
|
+
- Fix nullable array types (`Texture[] | null`, `Array<Texture> | null`, `Array<Texture | null>`) not emitting as arrays in C# and Blender output
|
|
10
|
+
|
|
7
11
|
## [3.0.5] - 2026-03-15
|
|
8
12
|
### Added
|
|
9
13
|
- `--types <path>` CLI flag to load external type mappings from a JSON file (e.g. Unity's `Types.json`)
|
package/dist/BaseWriter.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.BaseWriter = void 0;
|
|
|
4
4
|
var fs_1 = require("fs");
|
|
5
5
|
var base_compiler_1 = require("./base-compiler");
|
|
6
6
|
var commands_1 = require("./commands");
|
|
7
|
+
var log_1 = require("./log");
|
|
7
8
|
var BaseWriter = /** @class */ (function () {
|
|
8
9
|
function BaseWriter(_sink) {
|
|
9
10
|
this._sink = _sink;
|
|
@@ -38,7 +39,9 @@ var BaseWriter = /** @class */ (function () {
|
|
|
38
39
|
};
|
|
39
40
|
BaseWriter.prototype.end = function (filePath) {
|
|
40
41
|
var results = this._currentlyProcessingFiles[filePath];
|
|
41
|
-
|
|
42
|
+
if (results === null || results === void 0 ? void 0 : results.length) {
|
|
43
|
+
log_1.logger.log(" Schemes:", results.map(function (r) { return r.componentName; }).join(", "));
|
|
44
|
+
}
|
|
42
45
|
if (results) {
|
|
43
46
|
var previousResultsFromThisFile = this._createdSchemesPerFile[filePath];
|
|
44
47
|
if (previousResultsFromThisFile) {
|
package/dist/Compiler.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export declare class Compiler {
|
|
|
6
6
|
private visitEnumDeclaration;
|
|
7
7
|
private visit;
|
|
8
8
|
private visitClassDeclaration;
|
|
9
|
+
/** Format a structured log line for a member */
|
|
10
|
+
private logMember;
|
|
9
11
|
private visitPropertyDeclaration;
|
|
10
12
|
private hasSerializableDecorator;
|
|
11
13
|
/** Track accessor names already emitted per class to avoid duplicates when both getter and setter have @serializable() */
|
|
@@ -13,7 +15,6 @@ export declare class Compiler {
|
|
|
13
15
|
private visitAccessorDeclaration;
|
|
14
16
|
private visitMethodDeclaration;
|
|
15
17
|
private resolveParameters;
|
|
16
|
-
private debugLog;
|
|
17
18
|
private getComments;
|
|
18
19
|
/** Strip markdown/code/images/URLs/JSDoc tags to produce a plain-text tooltip */
|
|
19
20
|
private static sanitizeJsdocForTooltip;
|
package/dist/Compiler.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Compiler = void 0;
|
|
4
4
|
var ts = require("typescript");
|
|
5
5
|
var base_compiler_1 = require("./base-compiler");
|
|
6
|
+
var log_1 = require("./log");
|
|
6
7
|
/** Typescript Walker */
|
|
7
8
|
var Compiler = /** @class */ (function () {
|
|
8
9
|
function Compiler() {
|
|
@@ -17,7 +18,7 @@ var Compiler = /** @class */ (function () {
|
|
|
17
18
|
};
|
|
18
19
|
Compiler.prototype.run = function (prog, writer, sourceFile, filePath) {
|
|
19
20
|
var _this = this;
|
|
20
|
-
|
|
21
|
+
log_1.logger.log("Compiling", filePath);
|
|
21
22
|
writer.begin(filePath);
|
|
22
23
|
// Pre-scan: collect enum declarations so type resolution works for class fields
|
|
23
24
|
ts.forEachChild(sourceFile, function (node) {
|
|
@@ -62,7 +63,7 @@ var Compiler = /** @class */ (function () {
|
|
|
62
63
|
}
|
|
63
64
|
members.push({ name: memberName, value: value });
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
+
log_1.logger.log(" enum", name, "(" + members.length + " members)");
|
|
66
67
|
writer.registerEnum(name, members);
|
|
67
68
|
};
|
|
68
69
|
Compiler.prototype.visit = function (filePath, node, writer) {
|
|
@@ -102,10 +103,10 @@ var Compiler = /** @class */ (function () {
|
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
|
-
|
|
106
|
+
log_1.logger.log(" class " + name + (baseTypes.length ? " extends " + baseTypes.join(", ") : ""));
|
|
106
107
|
var res = writer.startNewType(filePath, name, baseTypes, this.getComments(node));
|
|
107
108
|
if (res === false) {
|
|
108
|
-
|
|
109
|
+
log_1.logger.log(" (skipped)");
|
|
109
110
|
return;
|
|
110
111
|
}
|
|
111
112
|
this._emittedAccessors.clear();
|
|
@@ -113,13 +114,23 @@ var Compiler = /** @class */ (function () {
|
|
|
113
114
|
_this.visit(filePath, node, writer);
|
|
114
115
|
});
|
|
115
116
|
writer.endNewType(filePath, name);
|
|
116
|
-
|
|
117
|
+
};
|
|
118
|
+
/** Format a structured log line for a member */
|
|
119
|
+
Compiler.prototype.logMember = function (kind, visibility, name, type, initialValue, flags) {
|
|
120
|
+
var parts = [];
|
|
121
|
+
parts.push(base_compiler_1.Visibility[visibility].toLowerCase());
|
|
122
|
+
if (flags && flags.length)
|
|
123
|
+
parts.push.apply(parts, flags);
|
|
124
|
+
var detail = parts.length ? " (" + parts.join(", ") + ")" : "";
|
|
125
|
+
var valStr = initialValue !== undefined && initialValue !== null ? " = " + initialValue : "";
|
|
126
|
+
log_1.logger.log(" " + kind + " " + name + ": " + (type || "?") + valStr + detail);
|
|
117
127
|
};
|
|
118
128
|
Compiler.prototype.visitPropertyDeclaration = function (node, writer) {
|
|
129
|
+
var _a;
|
|
119
130
|
// Skip static and abstract properties — they don't map to serialized fields
|
|
120
131
|
if (node.modifiers) {
|
|
121
|
-
for (var _i = 0,
|
|
122
|
-
var modifier =
|
|
132
|
+
for (var _i = 0, _b = node.modifiers; _i < _b.length; _i++) {
|
|
133
|
+
var modifier = _b[_i];
|
|
123
134
|
if (modifier.kind === ts.SyntaxKind.StaticKeyword ||
|
|
124
135
|
modifier.kind === ts.SyntaxKind.AbstractKeyword) {
|
|
125
136
|
return;
|
|
@@ -134,10 +145,22 @@ var Compiler = /** @class */ (function () {
|
|
|
134
145
|
if (!type && node.initializer) {
|
|
135
146
|
type = this.tryResolveTypeFromExpression(node.initializer, writer);
|
|
136
147
|
}
|
|
137
|
-
this.debugLog("[COMPILER] PROPERTY", base_compiler_1.Visibility[visibility], name, isArray, type, initialValue);
|
|
138
148
|
if (!type)
|
|
139
149
|
return; // cannot determine type — skip the field
|
|
140
|
-
|
|
150
|
+
var comments = (_a = this.getComments(node)) !== null && _a !== void 0 ? _a : [];
|
|
151
|
+
// If the property has a @serializable() decorator, ensure it's in the comments
|
|
152
|
+
// so the writer emits private/protected fields with [SerializeField]
|
|
153
|
+
var hasSerialized = this.hasSerializableDecorator(node);
|
|
154
|
+
if (hasSerialized && !comments.some(function (c) { return c.startsWith("@serializable"); })) {
|
|
155
|
+
comments.push("@serializable");
|
|
156
|
+
}
|
|
157
|
+
var flags = [];
|
|
158
|
+
if (isArray)
|
|
159
|
+
flags.push("array");
|
|
160
|
+
if (hasSerialized)
|
|
161
|
+
flags.push("@serializable");
|
|
162
|
+
this.logMember("+", visibility, name, type, initialValue, flags);
|
|
163
|
+
writer.writeMember(visibility, name, isArray, type, initialValue, comments);
|
|
141
164
|
};
|
|
142
165
|
Compiler.prototype.hasSerializableDecorator = function (node) {
|
|
143
166
|
var _a;
|
|
@@ -167,7 +190,6 @@ var Compiler = /** @class */ (function () {
|
|
|
167
190
|
typeNode = (_b = (_a = node.parameters) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type;
|
|
168
191
|
}
|
|
169
192
|
type = this.resolveType(typeNode, writer);
|
|
170
|
-
this.debugLog("[COMPILER] ACCESSOR (serializable)", name, type);
|
|
171
193
|
if (!type)
|
|
172
194
|
return;
|
|
173
195
|
var isArray = typeNode ? this.isArrayType(typeNode) : false;
|
|
@@ -177,6 +199,10 @@ var Compiler = /** @class */ (function () {
|
|
|
177
199
|
if (!comments.some(function (c) { return c.startsWith("@serializable"); })) {
|
|
178
200
|
comments.push("@serializable");
|
|
179
201
|
}
|
|
202
|
+
var flags = ["accessor", "@serializable"];
|
|
203
|
+
if (isArray)
|
|
204
|
+
flags.push("array");
|
|
205
|
+
this.logMember("+", visibility, name, type, undefined, flags);
|
|
180
206
|
writer.writeMember(visibility, name, isArray, type, undefined, comments);
|
|
181
207
|
};
|
|
182
208
|
Compiler.prototype.visitMethodDeclaration = function (node, writer) {
|
|
@@ -198,7 +224,8 @@ var Compiler = /** @class */ (function () {
|
|
|
198
224
|
if ((_a = node.parameters) === null || _a === void 0 ? void 0 : _a.length) {
|
|
199
225
|
args = this.resolveParameters(node.parameters, writer);
|
|
200
226
|
}
|
|
201
|
-
|
|
227
|
+
var argsStr = (args === null || args === void 0 ? void 0 : args.length) ? "(" + args.map(function (a) { return (a.type || "?") + " " + a.name; }).join(", ") + ")" : "()";
|
|
228
|
+
this.logMember("+", visibility, name + argsStr, returnType || "void");
|
|
202
229
|
writer.writeMethod(visibility, name, returnType, args, this.getComments(node));
|
|
203
230
|
};
|
|
204
231
|
Compiler.prototype.resolveParameters = function (parameters, writer) {
|
|
@@ -213,13 +240,6 @@ var Compiler = /** @class */ (function () {
|
|
|
213
240
|
}
|
|
214
241
|
return result;
|
|
215
242
|
};
|
|
216
|
-
Compiler.prototype.debugLog = function () {
|
|
217
|
-
var args = [];
|
|
218
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
219
|
-
args[_i] = arguments[_i];
|
|
220
|
-
}
|
|
221
|
-
console.log.apply(console, args);
|
|
222
|
-
};
|
|
223
243
|
Compiler.prototype.getComments = function (node) {
|
|
224
244
|
var commentRanges = ts.getLeadingCommentRanges(node.getFullText(), 0);
|
|
225
245
|
if (commentRanges) {
|
|
@@ -305,19 +325,15 @@ var Compiler = /** @class */ (function () {
|
|
|
305
325
|
}
|
|
306
326
|
// Infer type from literal initializers (no explicit type annotation)
|
|
307
327
|
if (ts.isNumericLiteral(exp)) {
|
|
308
|
-
// e.g. speed = 5 or ratio = 5.5 → number → float
|
|
309
328
|
return this.resolveTypeFromString("number", write);
|
|
310
329
|
}
|
|
311
330
|
if (ts.isStringLiteral(exp)) {
|
|
312
|
-
// e.g. label = "hello" → string
|
|
313
331
|
return this.resolveTypeFromString("string", write);
|
|
314
332
|
}
|
|
315
333
|
if (exp.kind === ts.SyntaxKind.TrueKeyword || exp.kind === ts.SyntaxKind.FalseKeyword) {
|
|
316
|
-
// e.g. active = true → boolean → bool
|
|
317
334
|
return this.resolveTypeFromString("boolean", write);
|
|
318
335
|
}
|
|
319
336
|
if (ts.isPrefixUnaryExpression(exp) && ts.isNumericLiteral(exp.operand)) {
|
|
320
|
-
// e.g. speed = -5 or ratio = -1.5 → number → float
|
|
321
337
|
return this.resolveTypeFromString("number", write);
|
|
322
338
|
}
|
|
323
339
|
};
|
|
@@ -326,6 +342,17 @@ var Compiler = /** @class */ (function () {
|
|
|
326
342
|
return undefined;
|
|
327
343
|
// check if its an array
|
|
328
344
|
if (this.isArrayType(typeNode)) {
|
|
345
|
+
// Unwrap union types (e.g. Texture[] | null) to find the array member
|
|
346
|
+
if (ts.isUnionTypeNode(typeNode)) {
|
|
347
|
+
for (var _i = 0, _a = typeNode.types; _i < _a.length; _i++) {
|
|
348
|
+
var member = _a[_i];
|
|
349
|
+
if (member.kind !== ts.SyntaxKind.NullKeyword &&
|
|
350
|
+
member.kind !== ts.SyntaxKind.UndefinedKeyword &&
|
|
351
|
+
member.kind !== ts.SyntaxKind.VoidKeyword) {
|
|
352
|
+
return this.resolveType(member, writer);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
329
356
|
if (typeNode.kind === ts.SyntaxKind.ArrayType) {
|
|
330
357
|
var arrayType = typeNode;
|
|
331
358
|
return this.resolveType(arrayType.elementType, writer);
|
|
@@ -361,18 +388,12 @@ var Compiler = /** @class */ (function () {
|
|
|
361
388
|
}
|
|
362
389
|
}
|
|
363
390
|
}
|
|
364
|
-
|
|
365
|
-
// if (typeNode.kind === ts.SyntaxKind.TypeReference) {
|
|
366
|
-
// const typeReference = typeNode as ts.TypeReferenceNode;
|
|
367
|
-
// const typeArgument = typeReference.typeArguments && typeReference.typeArguments[0];
|
|
368
|
-
// return this.resolveType(typeArgument, writer);
|
|
369
|
-
// }
|
|
370
|
-
console.error("!!!!! ----- Unknown array type", typeNode.getText());
|
|
391
|
+
log_1.logger.warn("Unknown array type:", typeNode.getText());
|
|
371
392
|
}
|
|
372
393
|
// Union types: Object3D | null | undefined → resolve the first concrete member
|
|
373
394
|
if (ts.isUnionTypeNode(typeNode)) {
|
|
374
|
-
for (var
|
|
375
|
-
var member =
|
|
395
|
+
for (var _b = 0, _c = typeNode.types; _b < _c.length; _b++) {
|
|
396
|
+
var member = _c[_b];
|
|
376
397
|
if (member.kind !== ts.SyntaxKind.NullKeyword &&
|
|
377
398
|
member.kind !== ts.SyntaxKind.UndefinedKeyword &&
|
|
378
399
|
member.kind !== ts.SyntaxKind.VoidKeyword) {
|
|
@@ -400,6 +421,18 @@ var Compiler = /** @class */ (function () {
|
|
|
400
421
|
Compiler.prototype.isArrayType = function (typeNode) {
|
|
401
422
|
if (!typeNode)
|
|
402
423
|
return false;
|
|
424
|
+
// Unwrap union types (e.g. Texture[] | null → Texture[])
|
|
425
|
+
if (ts.isUnionTypeNode(typeNode)) {
|
|
426
|
+
for (var _i = 0, _a = typeNode.types; _i < _a.length; _i++) {
|
|
427
|
+
var member = _a[_i];
|
|
428
|
+
if (member.kind !== ts.SyntaxKind.NullKeyword &&
|
|
429
|
+
member.kind !== ts.SyntaxKind.UndefinedKeyword &&
|
|
430
|
+
member.kind !== ts.SyntaxKind.VoidKeyword) {
|
|
431
|
+
return this.isArrayType(member);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
403
436
|
// check if its an array
|
|
404
437
|
if (typeNode.kind === ts.SyntaxKind.ArrayType) {
|
|
405
438
|
return true;
|
|
@@ -499,14 +532,11 @@ var Compiler = /** @class */ (function () {
|
|
|
499
532
|
else if (ts.isNewExpression(node)) {
|
|
500
533
|
var typeName = this.resolveTypeFromString(node.expression.getText(), writer);
|
|
501
534
|
if (typeName) {
|
|
502
|
-
console.log("TODO: new expression");
|
|
503
535
|
var args = node.arguments.map(function (a) { return _this.resolveExpression(a, writer); }).filter(function (a) { return a; });
|
|
504
|
-
// writer.writeNewTypeExpression(typeName, args);
|
|
505
|
-
// return;
|
|
506
536
|
return "new " + typeName + "(" + args.join(", ") + ")";
|
|
507
537
|
}
|
|
508
538
|
}
|
|
509
|
-
|
|
539
|
+
log_1.logger.warn("Unknown expression:", ts.SyntaxKind[node.kind], node.getText());
|
|
510
540
|
};
|
|
511
541
|
return Compiler;
|
|
512
542
|
}());
|
package/dist/base-compiler.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.runFromFile = runFromFile;
|
|
|
6
6
|
var fs_1 = require("fs");
|
|
7
7
|
var fs = require("fs");
|
|
8
8
|
var commands_1 = require("./commands");
|
|
9
|
+
var log_1 = require("./log");
|
|
9
10
|
var Compiler_1 = require("./Compiler");
|
|
10
11
|
var Visibility;
|
|
11
12
|
(function (Visibility) {
|
|
@@ -21,7 +22,7 @@ var FileSink = /** @class */ (function () {
|
|
|
21
22
|
if (!fs.existsSync(this.directory)) {
|
|
22
23
|
fs.mkdirSync(this.directory, { recursive: true });
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
+
log_1.logger.log(" → Writing " + id);
|
|
25
26
|
var fullPath = this.directory + "/" + id;
|
|
26
27
|
// If the file already exists and contains codegen fences,
|
|
27
28
|
// preserve content outside the fences
|
|
@@ -172,7 +173,7 @@ function handleDeletedFile(filePath, types) {
|
|
|
172
173
|
}
|
|
173
174
|
function runFromFile(writer, path) {
|
|
174
175
|
if (!fs.existsSync(path)) {
|
|
175
|
-
|
|
176
|
+
log_1.logger.error("File not found", path);
|
|
176
177
|
return;
|
|
177
178
|
}
|
|
178
179
|
var code = (0, fs_1.readFileSync)(path).toString();
|
package/dist/cli.js
CHANGED
|
@@ -7,6 +7,7 @@ var Compiler_1 = require("./Compiler");
|
|
|
7
7
|
var base_compiler_1 = require("./base-compiler");
|
|
8
8
|
var csharp_compiler_1 = require("./impl/csharp-compiler");
|
|
9
9
|
var blender_compiler_1 = require("./impl/blender-compiler");
|
|
10
|
+
var log_1 = require("./log");
|
|
10
11
|
var pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf-8"));
|
|
11
12
|
var rawArgs = process.argv.slice(2);
|
|
12
13
|
if (rawArgs.includes("--version") || rawArgs.includes("-v")) {
|
|
@@ -26,6 +27,7 @@ if (rawArgs.includes("--help") || rawArgs.includes("-h") || rawArgs.length < 3)
|
|
|
26
27
|
console.log(" --types <path> path to Types.json with extra type mappings");
|
|
27
28
|
console.log("");
|
|
28
29
|
console.log("Flags:");
|
|
30
|
+
console.log(" --silent, -s only output errors and CMD: lines");
|
|
29
31
|
console.log(" --version, -v print version");
|
|
30
32
|
console.log(" --help, -h print this help");
|
|
31
33
|
if (rawArgs.length < 3 && !rawArgs.includes("--help") && !rawArgs.includes("-h")) {
|
|
@@ -33,42 +35,49 @@ if (rawArgs.includes("--help") || rawArgs.includes("-h") || rawArgs.length < 3)
|
|
|
33
35
|
}
|
|
34
36
|
process.exit(0);
|
|
35
37
|
}
|
|
36
|
-
// Extract
|
|
38
|
+
// Extract flags from anywhere in the args
|
|
37
39
|
var typesPath;
|
|
40
|
+
var silent = false;
|
|
38
41
|
var positionalArgs = [];
|
|
39
42
|
for (var i = 0; i < rawArgs.length; i++) {
|
|
40
43
|
if (rawArgs[i] === "--types" && i + 1 < rawArgs.length) {
|
|
41
44
|
typesPath = rawArgs[++i];
|
|
42
45
|
}
|
|
46
|
+
else if (rawArgs[i] === "--silent" || rawArgs[i] === "-s") {
|
|
47
|
+
silent = true;
|
|
48
|
+
}
|
|
43
49
|
else {
|
|
44
50
|
positionalArgs.push(rawArgs[i]);
|
|
45
51
|
}
|
|
46
52
|
}
|
|
53
|
+
if (silent) {
|
|
54
|
+
log_1.logger.silent = true;
|
|
55
|
+
}
|
|
47
56
|
var target = positionalArgs[0];
|
|
48
57
|
var outputDir = positionalArgs[1];
|
|
49
58
|
var inputFiles = positionalArgs.slice(2);
|
|
50
59
|
if (target !== "csharp" && target !== "blender") {
|
|
51
|
-
|
|
60
|
+
log_1.logger.error("Error: unknown target \"".concat(target, "\". Use \"csharp\" or \"blender\"."));
|
|
52
61
|
process.exit(1);
|
|
53
62
|
}
|
|
63
|
+
log_1.logger.log("needle-component-compiler v".concat(pkg.version));
|
|
54
64
|
// Load external types if provided
|
|
55
65
|
var externalTypes;
|
|
56
66
|
if (typesPath) {
|
|
57
67
|
if (!fs.existsSync(typesPath)) {
|
|
58
|
-
|
|
68
|
+
log_1.logger.warn("Warning: types file not found: ".concat(typesPath));
|
|
59
69
|
}
|
|
60
70
|
else {
|
|
61
71
|
try {
|
|
62
72
|
externalTypes = JSON.parse(fs.readFileSync(typesPath, "utf-8"));
|
|
63
|
-
|
|
73
|
+
log_1.logger.log("Loaded ".concat(Object.keys(externalTypes).length, " external type mappings from ").concat(typesPath));
|
|
64
74
|
}
|
|
65
75
|
catch (e) {
|
|
66
|
-
|
|
76
|
+
log_1.logger.error("Error reading types file: ".concat(e));
|
|
67
77
|
process.exit(1);
|
|
68
78
|
}
|
|
69
79
|
}
|
|
70
80
|
}
|
|
71
|
-
console.log("needle-component-compiler v".concat(pkg.version));
|
|
72
81
|
var sink = new base_compiler_1.FileSink(outputDir);
|
|
73
82
|
var writer = target === "csharp" ? new csharp_compiler_1.CSharpWriter(sink, externalTypes) : new blender_compiler_1.BlenderWriter(sink);
|
|
74
83
|
var compiler = new Compiler_1.Compiler();
|
|
@@ -77,7 +86,7 @@ for (var _i = 0, inputFiles_1 = inputFiles; _i < inputFiles_1.length; _i++) {
|
|
|
77
86
|
var filePath = inputFiles_1[_i];
|
|
78
87
|
try {
|
|
79
88
|
if (!fs.existsSync(filePath)) {
|
|
80
|
-
|
|
89
|
+
log_1.logger.error("Error: file not found: ".concat(filePath));
|
|
81
90
|
hasErrors = true;
|
|
82
91
|
continue;
|
|
83
92
|
}
|
|
@@ -85,7 +94,7 @@ for (var _i = 0, inputFiles_1 = inputFiles; _i < inputFiles_1.length; _i++) {
|
|
|
85
94
|
compiler.compile(writer, code, filePath);
|
|
86
95
|
}
|
|
87
96
|
catch (e) {
|
|
88
|
-
|
|
97
|
+
log_1.logger.error("Error processing ".concat(filePath, ": ").concat(e));
|
|
89
98
|
hasErrors = true;
|
|
90
99
|
}
|
|
91
100
|
}
|
|
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.BlenderWriter = void 0;
|
|
19
19
|
var base_compiler_1 = require("../base-compiler");
|
|
20
20
|
var BaseWriter_1 = require("../BaseWriter");
|
|
21
|
+
var log_1 = require("../log");
|
|
21
22
|
var supportedTypes = ["string", "float", "int", "bool", "col", "obj", "evt", "fn", "vec2", "vec3", "comp"];
|
|
22
23
|
var knownBaseTypes = ["Behaviour", "IComponent"];
|
|
23
24
|
var BlenderWriter = /** @class */ (function (_super) {
|
|
@@ -187,7 +188,7 @@ var BlenderWriter = /** @class */ (function (_super) {
|
|
|
187
188
|
this.writer.endBlock("},");
|
|
188
189
|
};
|
|
189
190
|
BlenderWriter.prototype.writeNewTypeExpression = function (typeName, args) {
|
|
190
|
-
|
|
191
|
+
log_1.logger.log("new type:", typeName);
|
|
191
192
|
};
|
|
192
193
|
return BlenderWriter;
|
|
193
194
|
}(BaseWriter_1.BaseWriter));
|
|
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.CSharpWriter = void 0;
|
|
19
19
|
var base_compiler_1 = require("../base-compiler");
|
|
20
20
|
var BaseWriter_1 = require("../BaseWriter");
|
|
21
|
+
var log_1 = require("../log");
|
|
21
22
|
var allowDebugLogs = false;
|
|
22
23
|
/** Inline type dictionary: TypeScript type name → fully-qualified C# type name */
|
|
23
24
|
var TYPE_MAP = {
|
|
@@ -209,7 +210,7 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
209
210
|
CSharpWriter.prototype.writeMember = function (visibility, name, isArray, type, initialValue, comments) {
|
|
210
211
|
var _a;
|
|
211
212
|
if (allowDebugLogs)
|
|
212
|
-
|
|
213
|
+
log_1.logger.log("[CSharp] writeMember", name, type, comments);
|
|
213
214
|
// @nonSerialized → skip entirely
|
|
214
215
|
if (comments === null || comments === void 0 ? void 0 : comments.some(function (c) { return c.startsWith("@nonSerialized"); }))
|
|
215
216
|
return;
|
|
@@ -290,7 +291,7 @@ var CSharpWriter = /** @class */ (function (_super) {
|
|
|
290
291
|
var _this = this;
|
|
291
292
|
var _a, _b;
|
|
292
293
|
if (allowDebugLogs)
|
|
293
|
-
|
|
294
|
+
log_1.logger.log("[CSharp] writeMethod", name, returnType);
|
|
294
295
|
// @nonSerialized → skip entirely
|
|
295
296
|
if (comments === null || comments === void 0 ? void 0 : comments.some(function (c) { return c.startsWith("@nonSerialized"); }))
|
|
296
297
|
return;
|
package/dist/log.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Simple logger that can be silenced via the `silent` flag.
|
|
2
|
+
* Errors and CMD: lines are always emitted regardless of silent mode. */
|
|
3
|
+
export declare const logger: {
|
|
4
|
+
silent: boolean;
|
|
5
|
+
log(...args: any[]): void;
|
|
6
|
+
warn(...args: any[]): void;
|
|
7
|
+
error(...args: any[]): void;
|
|
8
|
+
};
|
package/dist/log.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = void 0;
|
|
4
|
+
/** Simple logger that can be silenced via the `silent` flag.
|
|
5
|
+
* Errors and CMD: lines are always emitted regardless of silent mode. */
|
|
6
|
+
exports.logger = {
|
|
7
|
+
silent: false,
|
|
8
|
+
log: function () {
|
|
9
|
+
var args = [];
|
|
10
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
11
|
+
args[_i] = arguments[_i];
|
|
12
|
+
}
|
|
13
|
+
if (!this.silent)
|
|
14
|
+
console.log.apply(console, args);
|
|
15
|
+
},
|
|
16
|
+
warn: function () {
|
|
17
|
+
var args = [];
|
|
18
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
19
|
+
args[_i] = arguments[_i];
|
|
20
|
+
}
|
|
21
|
+
console.warn.apply(console, args);
|
|
22
|
+
},
|
|
23
|
+
error: function () {
|
|
24
|
+
var args = [];
|
|
25
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
26
|
+
args[_i] = arguments[_i];
|
|
27
|
+
}
|
|
28
|
+
console.error.apply(console, args);
|
|
29
|
+
},
|
|
30
|
+
};
|
package/dist/register-types.js
CHANGED
|
@@ -4,8 +4,9 @@ exports.writeTypeRegistry = writeTypeRegistry;
|
|
|
4
4
|
var fs_1 = require("fs");
|
|
5
5
|
var path = require("path");
|
|
6
6
|
var base_compiler_1 = require("./base-compiler");
|
|
7
|
+
var log_1 = require("./log");
|
|
7
8
|
function writeTypeRegistry(types, registerTypesPath) {
|
|
8
|
-
|
|
9
|
+
log_1.logger.log("Writing type registry to", registerTypesPath);
|
|
9
10
|
var directory = path.dirname(registerTypesPath);
|
|
10
11
|
if (!(0, fs_1.existsSync)(directory)) {
|
|
11
12
|
(0, fs_1.mkdirSync)(directory);
|
package/dist/watcher.js
CHANGED
|
@@ -7,6 +7,7 @@ var Compiler_1 = require("./Compiler");
|
|
|
7
7
|
var blender_compiler_1 = require("./impl/blender-compiler");
|
|
8
8
|
var chokidar = require("chokidar");
|
|
9
9
|
var commands_1 = require("./commands");
|
|
10
|
+
var log_1 = require("./log");
|
|
10
11
|
var register_types_1 = require("./register-types");
|
|
11
12
|
// https://github.com/paulmillr/chokidar
|
|
12
13
|
var DirectoryWatcher = /** @class */ (function () {
|
|
@@ -21,26 +22,26 @@ var DirectoryWatcher = /** @class */ (function () {
|
|
|
21
22
|
try {
|
|
22
23
|
switch (event) {
|
|
23
24
|
case "add":
|
|
24
|
-
|
|
25
|
+
log_1.logger.log("File added:", path);
|
|
25
26
|
_this.compiler.compile(writer, fs.readFileSync(path).toString(), path);
|
|
26
27
|
_this._typesChanged = true;
|
|
27
28
|
break;
|
|
28
29
|
case "change":
|
|
29
|
-
|
|
30
|
+
log_1.logger.log("File changed:", path);
|
|
30
31
|
_this.compiler.compile(writer, fs.readFileSync(path).toString(), path);
|
|
31
32
|
_this._typesChanged = true;
|
|
32
33
|
break;
|
|
33
34
|
case "unlink":
|
|
34
|
-
|
|
35
|
+
log_1.logger.log("File removed:", path);
|
|
35
36
|
(0, base_compiler_1.handleDeletedFile)(path, writer.outputInfo);
|
|
36
37
|
_this._typesChanged = true;
|
|
37
38
|
break;
|
|
38
39
|
default:
|
|
39
|
-
|
|
40
|
+
log_1.logger.log("File unhandled event:", event, path);
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
catch (err) {
|
|
43
|
-
|
|
44
|
+
log_1.logger.error(err);
|
|
44
45
|
}
|
|
45
46
|
});
|
|
46
47
|
// call reload cmd
|
|
@@ -61,19 +62,19 @@ process.on('exit', function () {
|
|
|
61
62
|
});
|
|
62
63
|
var args = process.argv.slice(2);
|
|
63
64
|
if (args.length < 3) {
|
|
64
|
-
|
|
65
|
+
log_1.logger.error("Missing arguments, usage: node watcher.js <directory> <output> <registerTypesPath>");
|
|
65
66
|
process.exit(1);
|
|
66
67
|
}
|
|
67
68
|
var directoryToWatch = args[0].replace("\"", "");
|
|
68
69
|
var outputDirectory = args[1].replace("\"", "");
|
|
69
70
|
var registerTypesPath = args[2].replace("\"", "");
|
|
70
71
|
if (!fs.existsSync(directoryToWatch)) {
|
|
71
|
-
|
|
72
|
+
log_1.logger.error("Directory to watch does not exist");
|
|
72
73
|
process.exit(1);
|
|
73
74
|
}
|
|
74
75
|
if (fs.existsSync(outputDirectory))
|
|
75
76
|
fs.rmSync(outputDirectory, { recursive: true });
|
|
76
|
-
|
|
77
|
+
log_1.logger.log("Watch:", directoryToWatch, "→", outputDirectory);
|
|
77
78
|
var watcher = new DirectoryWatcher();
|
|
78
79
|
var sink = new base_compiler_1.FileSink(outputDirectory);
|
|
79
80
|
watcher.startWatching(directoryToWatch, new blender_compiler_1.BlenderWriter(sink), registerTypesPath);
|