@needle-tools/needle-component-compiler 2.4.1-pre → 3.0.0-68ab237
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 +183 -88
- package/Readme.md +134 -19
- package/dist/BaseWriter.d.ts +23 -0
- package/dist/BaseWriter.js +91 -0
- package/dist/Compiler.d.ts +22 -0
- package/{src/base-compiler.js → dist/Compiler.js} +461 -507
- package/dist/base-compiler.d.ts +56 -0
- package/dist/base-compiler.js +182 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +63 -0
- package/dist/commands.d.ts +3 -0
- package/{src → dist}/commands.js +15 -15
- package/dist/impl/blender-compiler.d.ts +14 -0
- package/dist/impl/blender-compiler.js +195 -0
- package/dist/impl/csharp-compiler.d.ts +16 -0
- package/dist/impl/csharp-compiler.js +307 -0
- package/dist/impl/react-three-fiber-compiler.d.ts +20 -0
- package/{src → dist/impl}/react-three-fiber-compiler.js +36 -34
- package/dist/index.d.ts +5 -0
- package/dist/index.js +16 -0
- package/dist/register-types.d.ts +8 -0
- package/{src → dist}/register-types.js +34 -34
- package/dist/watcher.d.ts +6 -0
- package/{src → dist}/watcher.js +79 -78
- package/package.json +63 -49
- package/src/blender-compiler.js +0 -190
- package/src/component-compiler.js +0 -699
- package/src/csharp-compiler.js +0 -58
- package/src/test.js +0 -194
- package/src/types.js +0 -51
- package/test/component.basic.test.js +0 -26
- package/test/component.methods.test.js +0 -82
- package/test/component.nonserialized.test.js +0 -20
- package/test/component.primitives.test.js +0 -47
- package/test/helpers.js +0 -54
package/{src → dist}/watcher.js
RENAMED
|
@@ -1,78 +1,79 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DirectoryWatcher = void 0;
|
|
4
|
-
var fs = require("fs");
|
|
5
|
-
var base_compiler_1 = require("./base-compiler");
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
_this.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
_this.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
(0,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
process
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
var
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var
|
|
78
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DirectoryWatcher = void 0;
|
|
4
|
+
var fs = require("fs");
|
|
5
|
+
var base_compiler_1 = require("./base-compiler");
|
|
6
|
+
var Compiler_1 = require("./Compiler");
|
|
7
|
+
var blender_compiler_1 = require("./impl/blender-compiler");
|
|
8
|
+
var chokidar = require("chokidar");
|
|
9
|
+
var commands_1 = require("./commands");
|
|
10
|
+
var register_types_1 = require("./register-types");
|
|
11
|
+
// https://github.com/paulmillr/chokidar
|
|
12
|
+
var DirectoryWatcher = /** @class */ (function () {
|
|
13
|
+
function DirectoryWatcher() {
|
|
14
|
+
this.compiler = new Compiler_1.Compiler();
|
|
15
|
+
this._typesChanged = false;
|
|
16
|
+
}
|
|
17
|
+
DirectoryWatcher.prototype.startWatching = function (dir, writer, registerTypesPath) {
|
|
18
|
+
var _this = this;
|
|
19
|
+
// console.log("Start watching", dir);
|
|
20
|
+
chokidar.watch(dir + "/**/*.ts").on('all', function (event, path) {
|
|
21
|
+
try {
|
|
22
|
+
switch (event) {
|
|
23
|
+
case "add":
|
|
24
|
+
console.log("File", path, "has been added");
|
|
25
|
+
_this.compiler.compile(writer, fs.readFileSync(path).toString(), path);
|
|
26
|
+
_this._typesChanged = true;
|
|
27
|
+
break;
|
|
28
|
+
case "change":
|
|
29
|
+
console.log("File", path, "has been changed");
|
|
30
|
+
_this.compiler.compile(writer, fs.readFileSync(path).toString(), path);
|
|
31
|
+
_this._typesChanged = true;
|
|
32
|
+
break;
|
|
33
|
+
case "unlink":
|
|
34
|
+
console.log("File", path, "has been removed");
|
|
35
|
+
(0, base_compiler_1.handleDeletedFile)(path, writer.outputInfo);
|
|
36
|
+
_this._typesChanged = true;
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
console.log("File unhandled event", event, path);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
console.error(err);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
// call reload cmd
|
|
47
|
+
setInterval(function () {
|
|
48
|
+
if (_this._typesChanged) {
|
|
49
|
+
_this._typesChanged = false;
|
|
50
|
+
(0, commands_1.sendReloadCommand)();
|
|
51
|
+
(0, register_types_1.writeTypeRegistry)(writer.outputInfo, registerTypesPath);
|
|
52
|
+
}
|
|
53
|
+
}, 2000);
|
|
54
|
+
};
|
|
55
|
+
return DirectoryWatcher;
|
|
56
|
+
}());
|
|
57
|
+
exports.DirectoryWatcher = DirectoryWatcher;
|
|
58
|
+
// listen to process exit
|
|
59
|
+
process.on('exit', function () {
|
|
60
|
+
// console.log('Bye node');
|
|
61
|
+
});
|
|
62
|
+
var args = process.argv.slice(2);
|
|
63
|
+
if (args.length < 3) {
|
|
64
|
+
console.error("Missing arguments, usage: node watcher.js <directory> <output> <registerTypesPath>");
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
var directoryToWatch = args[0].replace("\"", "");
|
|
68
|
+
var outputDirectory = args[1].replace("\"", "");
|
|
69
|
+
var registerTypesPath = args[2].replace("\"", "");
|
|
70
|
+
if (!fs.existsSync(directoryToWatch)) {
|
|
71
|
+
console.error("Directory to watch does not exist");
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
if (fs.existsSync(outputDirectory))
|
|
75
|
+
fs.rmSync(outputDirectory, { recursive: true });
|
|
76
|
+
console.log("Watch: " + directoryToWatch + " and output to: " + outputDirectory);
|
|
77
|
+
var watcher = new DirectoryWatcher();
|
|
78
|
+
var sink = new base_compiler_1.FileSink(outputDirectory);
|
|
79
|
+
watcher.startWatching(directoryToWatch, new blender_compiler_1.BlenderWriter(sink), registerTypesPath);
|
package/package.json
CHANGED
|
@@ -1,49 +1,63 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@needle-tools/needle-component-compiler",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Compile
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
},
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@needle-tools/needle-component-compiler",
|
|
3
|
+
"version": "3.0.0-68ab237",
|
|
4
|
+
"description": "Compile Editor components for Needle Engine for C# and Blender",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"needle-component-compiler": "dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"tsc": "tsc",
|
|
11
|
+
"dev": "npm-watch compile",
|
|
12
|
+
"compile": "tsc",
|
|
13
|
+
"prepublishOnly": "npm run compile",
|
|
14
|
+
"test": "npm run test:csharp && npm run test:blender",
|
|
15
|
+
"test:csharp": "mocha -r ts-node/register 'test/csharp/**/*.test.ts'",
|
|
16
|
+
"test:blender": "mocha -r ts-node/register 'test/blender/**/*.test.ts'",
|
|
17
|
+
"test:single": "mocha"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"Readme.md",
|
|
21
|
+
"Changelog.md",
|
|
22
|
+
"package.json",
|
|
23
|
+
"dist/**/*"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"chokidar": "^3.5.3",
|
|
27
|
+
"typescript": "^4.5.5"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/chai": "^4.3.3",
|
|
31
|
+
"@types/mocha": "^9.1.1",
|
|
32
|
+
"@types/node": "^18.7.18",
|
|
33
|
+
"chai": "^4.3.6",
|
|
34
|
+
"mocha": "^10.0.0",
|
|
35
|
+
"npm-watch": "^0.11.0",
|
|
36
|
+
"ts-node": "^10.9.1"
|
|
37
|
+
},
|
|
38
|
+
"watch": {
|
|
39
|
+
"compile": {
|
|
40
|
+
"patterns": [
|
|
41
|
+
"src/**/*.ts",
|
|
42
|
+
"test/*/*.ts",
|
|
43
|
+
"test/*.ts"
|
|
44
|
+
],
|
|
45
|
+
"ignore": "src/test.ts",
|
|
46
|
+
"extensions": "ts",
|
|
47
|
+
"quiet": false
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"author": {
|
|
51
|
+
"name": "Needle",
|
|
52
|
+
"email": "help@needle.tools",
|
|
53
|
+
"url": "https://needle.tools/"
|
|
54
|
+
},
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "git+https://github.com/needle-tools/needle-tiny-component-compiler.git"
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public",
|
|
61
|
+
"registry": "https://registry.npmjs.org/"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/blender-compiler.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BlenderWriter = void 0;
|
|
4
|
-
var fs_1 = require("fs");
|
|
5
|
-
var base_compiler_1 = require("./base-compiler");
|
|
6
|
-
var commands_1 = require("./commands");
|
|
7
|
-
var supportedTypes = ["string", "float", "int", "bool", "col", "obj", "evt", "fn", "vec2", "vec3", "comp"];
|
|
8
|
-
var knownBaseTypes = ["Behaviour", "IComponent"];
|
|
9
|
-
var BlenderWriter = /** @class */ (function () {
|
|
10
|
-
function BlenderWriter(_sink) {
|
|
11
|
-
this._sink = _sink;
|
|
12
|
-
this.writer = new base_compiler_1.CodeTextWriter();
|
|
13
|
-
this._createdSchemesPerFile = {};
|
|
14
|
-
this._currentlyProcessingFiles = {};
|
|
15
|
-
}
|
|
16
|
-
Object.defineProperty(BlenderWriter.prototype, "outputInfo", {
|
|
17
|
-
get: function () {
|
|
18
|
-
return this._createdSchemesPerFile;
|
|
19
|
-
},
|
|
20
|
-
enumerable: false,
|
|
21
|
-
configurable: true
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(BlenderWriter.prototype, "sink", {
|
|
24
|
-
get: function () {
|
|
25
|
-
return this._sink;
|
|
26
|
-
},
|
|
27
|
-
enumerable: false,
|
|
28
|
-
configurable: true
|
|
29
|
-
});
|
|
30
|
-
BlenderWriter.prototype.resolveTypeName = function (typeName, comments) {
|
|
31
|
-
typeName = typeName.toLocaleLowerCase();
|
|
32
|
-
if (typeName.startsWith("three."))
|
|
33
|
-
typeName = typeName.substring("three.".length);
|
|
34
|
-
switch (typeName) {
|
|
35
|
-
case "number":
|
|
36
|
-
return "float";
|
|
37
|
-
case "int":
|
|
38
|
-
return "int";
|
|
39
|
-
case "boolean":
|
|
40
|
-
return "bool";
|
|
41
|
-
case "string":
|
|
42
|
-
return "string";
|
|
43
|
-
case "void":
|
|
44
|
-
return "void";
|
|
45
|
-
case "vector2":
|
|
46
|
-
return "vec2";
|
|
47
|
-
case "vector3":
|
|
48
|
-
return "vec3";
|
|
49
|
-
case "vector4":
|
|
50
|
-
return "vec4";
|
|
51
|
-
case "quaternion":
|
|
52
|
-
return "quat";
|
|
53
|
-
case "euler":
|
|
54
|
-
return "vec3";
|
|
55
|
-
case "color":
|
|
56
|
-
return "col";
|
|
57
|
-
case "eventlist":
|
|
58
|
-
return "evt";
|
|
59
|
-
case "behaviour":
|
|
60
|
-
return "comp";
|
|
61
|
-
case "texture":
|
|
62
|
-
return "tex";
|
|
63
|
-
case "image":
|
|
64
|
-
return "img";
|
|
65
|
-
case "object3d":
|
|
66
|
-
return "obj";
|
|
67
|
-
case "material":
|
|
68
|
-
return "mat";
|
|
69
|
-
case "animationclip":
|
|
70
|
-
return "anim";
|
|
71
|
-
}
|
|
72
|
-
return typeName;
|
|
73
|
-
};
|
|
74
|
-
BlenderWriter.prototype.begin = function (filePath) {
|
|
75
|
-
if (!this._currentlyProcessingFiles[filePath]) {
|
|
76
|
-
this._currentlyProcessingFiles[filePath] = [];
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
BlenderWriter.prototype.end = function (filePath) {
|
|
80
|
-
var results = this._currentlyProcessingFiles[filePath];
|
|
81
|
-
console.log("Writing schemes for", filePath, results);
|
|
82
|
-
if (results) {
|
|
83
|
-
var previousResultsFromThisFile = this._createdSchemesPerFile[filePath];
|
|
84
|
-
if (previousResultsFromThisFile) {
|
|
85
|
-
for (var _i = 0, previousResultsFromThisFile_1 = previousResultsFromThisFile; _i < previousResultsFromThisFile_1.length; _i++) {
|
|
86
|
-
var previouslyCreated = previousResultsFromThisFile_1[_i];
|
|
87
|
-
var foundInAny = false;
|
|
88
|
-
for (var _a = 0, results_1 = results; _a < results_1.length; _a++) {
|
|
89
|
-
var res = results_1[_a];
|
|
90
|
-
if (res.filePath === previouslyCreated.filePath) {
|
|
91
|
-
foundInAny = true;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (!foundInAny) {
|
|
96
|
-
for (var sourcePath in this._createdSchemesPerFile) {
|
|
97
|
-
if (foundInAny)
|
|
98
|
-
break;
|
|
99
|
-
if (sourcePath === filePath)
|
|
100
|
-
continue;
|
|
101
|
-
var otherSourceSchemes = this._createdSchemesPerFile[sourcePath];
|
|
102
|
-
if (otherSourceSchemes.includes(previouslyCreated)) {
|
|
103
|
-
// the file was moved to another source file
|
|
104
|
-
foundInAny = true;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (!foundInAny && (0, fs_1.existsSync)(previouslyCreated.filePath)) {
|
|
109
|
-
(0, fs_1.unlinkSync)(previouslyCreated.filePath);
|
|
110
|
-
(0, commands_1.sendFileDeletedCommand)(previouslyCreated.filePath);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
this._createdSchemesPerFile[filePath] = results;
|
|
115
|
-
}
|
|
116
|
-
delete this._currentlyProcessingFiles[filePath];
|
|
117
|
-
};
|
|
118
|
-
BlenderWriter.prototype.startNewType = function (filePath, typeName, baseTypes, comments) {
|
|
119
|
-
var isSupportedType = false;
|
|
120
|
-
for (var i = 0; i < knownBaseTypes.length; i++) {
|
|
121
|
-
if (baseTypes.includes(knownBaseTypes[i])) {
|
|
122
|
-
isSupportedType = true;
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
// console.log(baseTypes, knownBaseTypes, isSupportedType)
|
|
127
|
-
if (!isSupportedType)
|
|
128
|
-
return false;
|
|
129
|
-
this.writer.beginBlock("{");
|
|
130
|
-
if (comments)
|
|
131
|
-
console.log(comments);
|
|
132
|
-
this.writer.beginBlock("\"" + typeName + "\": {");
|
|
133
|
-
};
|
|
134
|
-
BlenderWriter.prototype.endNewType = function (filePath, typeName) {
|
|
135
|
-
this.writer.endBlock("},");
|
|
136
|
-
this.writer.endBlock("}");
|
|
137
|
-
this.writeScheme(filePath, typeName);
|
|
138
|
-
};
|
|
139
|
-
BlenderWriter.prototype.writeMember = function (visibility, name, isArray, type, initialValue, comments) {
|
|
140
|
-
if (visibility !== base_compiler_1.Visibility.Public)
|
|
141
|
-
return;
|
|
142
|
-
// if (!supportedTypes.includes(type)) {
|
|
143
|
-
// console.log("-- unsupported type:", type);
|
|
144
|
-
// return;
|
|
145
|
-
// }
|
|
146
|
-
this.writer.beginBlock("\"" + name + "\": {");
|
|
147
|
-
this.writer.writeLine("\"type\": \"" + type + "\",");
|
|
148
|
-
if (initialValue && !isArray) {
|
|
149
|
-
if (initialValue.startsWith("new "))
|
|
150
|
-
initialValue = undefined;
|
|
151
|
-
switch (type) {
|
|
152
|
-
case "bool":
|
|
153
|
-
initialValue = initialValue.toLowerCase();
|
|
154
|
-
break;
|
|
155
|
-
case "string":
|
|
156
|
-
initialValue = "\"" + initialValue + "\"";
|
|
157
|
-
}
|
|
158
|
-
if (initialValue)
|
|
159
|
-
this.writer.writeLine("\"value\": " + initialValue);
|
|
160
|
-
}
|
|
161
|
-
if (isArray) {
|
|
162
|
-
this.writer.writeLine("\"value\": []");
|
|
163
|
-
}
|
|
164
|
-
this.writer.endBlock("},");
|
|
165
|
-
};
|
|
166
|
-
BlenderWriter.prototype.writeMethod = function (visibility, name, returnType, args, comments) {
|
|
167
|
-
if (visibility !== base_compiler_1.Visibility.Public)
|
|
168
|
-
return;
|
|
169
|
-
this.writer.beginBlock("\"" + name + "\": {");
|
|
170
|
-
this.writer.writeLine("\"type\": \"fn\",");
|
|
171
|
-
this.writer.endBlock("},");
|
|
172
|
-
};
|
|
173
|
-
BlenderWriter.prototype.writeNewTypeExpression = function (typeName, args) {
|
|
174
|
-
console.log("new type:", typeName);
|
|
175
|
-
};
|
|
176
|
-
BlenderWriter.prototype.writeScheme = function (processingFilePath, component) {
|
|
177
|
-
var res = this.sink.flush(component + ".component.json", this.writer.flush());
|
|
178
|
-
// if an output path is returned it means a file has been written to that path
|
|
179
|
-
if (res && (0, fs_1.existsSync)(res)) {
|
|
180
|
-
(0, commands_1.sendFileWrittenCommand)(res);
|
|
181
|
-
// add the scheme to the list of created schemes
|
|
182
|
-
if (processingFilePath && this._currentlyProcessingFiles[processingFilePath]) {
|
|
183
|
-
this._currentlyProcessingFiles[processingFilePath].push({ componentName: component, filePath: res });
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
return BlenderWriter;
|
|
188
|
-
}());
|
|
189
|
-
exports.BlenderWriter = BlenderWriter;
|
|
190
|
-
// runFromFile(new BlenderWriter("dist"), "src\\test.ts");
|