cluaupp 0.1.4 → 0.2.0

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 (113) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +12 -7
  3. package/bin/cluau.js +1 -1
  4. package/bin/cluaupp.js +1 -1
  5. package/docs/README.md +1 -1
  6. package/docs/architecture.md +52 -77
  7. package/docs/cli.md +29 -9
  8. package/docs/comparison.md +3 -3
  9. package/docs/config.md +6 -6
  10. package/docs/cpp-organization.md +2 -2
  11. package/docs/examples/index.md +2 -0
  12. package/docs/getting-started.md +7 -5
  13. package/docs/intellisense.md +49 -31
  14. package/docs/intro.md +2 -2
  15. package/docs/oop/file-tags.md +16 -17
  16. package/docs/oop/index.md +2 -2
  17. package/docs/oop/modules.md +3 -1
  18. package/docs/oop/services.md +7 -14
  19. package/docs/syntax.md +6 -5
  20. package/editors/vscode/extension.js +97 -146
  21. package/editors/vscode/package.json +6 -6
  22. package/examples/README.md +18 -0
  23. package/examples/game/.clangd +25 -0
  24. package/examples/game/.vscode/c_cpp_properties.json +27 -0
  25. package/examples/game/.vscode/extensions.json +5 -0
  26. package/examples/game/.vscode/settings.json +27 -0
  27. package/examples/game/Packages/.gitkeep +0 -0
  28. package/examples/game/cluaupp.config.json +6 -0
  29. package/examples/game/compile_flags.txt +6 -0
  30. package/examples/game/default.project.json +39 -0
  31. package/examples/game/package.json +9 -0
  32. package/examples/game/rokit.toml +5 -0
  33. package/examples/game/src/client/hud.client.cpp +12 -0
  34. package/{src → examples/game/src}/client/init.client.cpp +1 -0
  35. package/examples/game/src/server/combat.server.cpp +23 -0
  36. package/{src → examples/game/src}/server/leaderstats.server.cpp +1 -0
  37. package/examples/game/wally.toml +11 -0
  38. package/generated/api.js +51 -0
  39. package/generated/architecture.js +473 -0
  40. package/generated/ast.js +2 -0
  41. package/generated/cli.js +191 -0
  42. package/generated/compile.js +115 -0
  43. package/generated/editor-install.js +170 -0
  44. package/generated/emit.js +503 -0
  45. package/generated/emitter/luau-codegen.js +167 -0
  46. package/generated/emitter/translators.js +164 -0
  47. package/generated/headers.js +220 -0
  48. package/generated/index.html +49 -0
  49. package/generated/intellisense.js +277 -0
  50. package/generated/layout.js +112 -0
  51. package/generated/lex.js +146 -0
  52. package/generated/libs.js +484 -0
  53. package/generated/lsp.js +55 -0
  54. package/generated/package-info.js +11 -0
  55. package/generated/parse.js +607 -0
  56. package/generated/parser/collector.js +100 -0
  57. package/generated/parser/index.js +30 -0
  58. package/generated/preprocess.js +181 -0
  59. package/generated/system-understander.js +443 -0
  60. package/generated/transpile.js +66 -0
  61. package/generated/types.js +2 -0
  62. package/generated/understand.js +298 -0
  63. package/generated/utils/process-orchestrator.js +63 -0
  64. package/generated/utils/project.js +491 -0
  65. package/generated/utils/rojo-mapper.js +181 -0
  66. package/generated/utils/safe-paths.js +104 -0
  67. package/package.json +25 -8
  68. package/src/api.ts +53 -0
  69. package/src/{architecture.js → architecture.ts} +80 -33
  70. package/src/ast.ts +37 -0
  71. package/src/cli.ts +214 -0
  72. package/src/compile.ts +118 -0
  73. package/src/editor-install.ts +182 -0
  74. package/src/{emit.js → emit.ts} +5 -6
  75. package/src/emitter/luau-codegen.ts +187 -0
  76. package/src/emitter/translators.ts +168 -0
  77. package/src/headers.ts +233 -0
  78. package/src/intellisense.ts +286 -0
  79. package/src/{layout.js → layout.ts} +114 -129
  80. package/src/{lex.js → lex.ts} +4 -6
  81. package/src/{libs.js → libs.ts} +119 -46
  82. package/src/lsp.ts +60 -0
  83. package/src/package-info.ts +7 -0
  84. package/src/{parse.js → parse.ts} +3 -4
  85. package/src/parser/collector.ts +115 -0
  86. package/src/parser/index.ts +27 -0
  87. package/src/{preprocess.js → preprocess.ts} +64 -32
  88. package/src/system-understander.ts +501 -0
  89. package/src/transpile.ts +64 -0
  90. package/src/tree-sitter-cpp.d.ts +4 -0
  91. package/src/types.ts +81 -0
  92. package/src/{understand.js → understand.ts} +24 -213
  93. package/src/utils/process-orchestrator.ts +72 -0
  94. package/src/utils/project.ts +506 -0
  95. package/src/utils/rojo-mapper.ts +190 -0
  96. package/src/utils/safe-paths.ts +98 -0
  97. package/templates/game/.clangd +9 -0
  98. package/templates/game/.vscode/c_cpp_properties.json +1 -1
  99. package/templates/game/.vscode/extensions.json +5 -6
  100. package/templates/game/.vscode/settings.json +7 -6
  101. package/templates/game/cluaupp.config.json +2 -2
  102. package/templates/game/compile_flags.txt +1 -0
  103. package/templates/game/rokit.toml +5 -0
  104. package/templates/game/src/client/init.client.cpp +1 -0
  105. package/templates/game/src/server/leaderstats.server.cpp +1 -0
  106. package/src/api.js +0 -57
  107. package/src/cli.js +0 -481
  108. package/src/compile.js +0 -56
  109. package/src/editor-install.js +0 -218
  110. package/src/intellisense.js +0 -1368
  111. package/src/lsp.js +0 -227
  112. /package/{src → examples/game/src}/shared/config.cpp +0 -0
  113. /package/{src → examples/game/src}/shared/config.h +0 -0
@@ -1,218 +0,0 @@
1
- "use strict";
2
-
3
- const fs = require("fs");
4
- const os = require("os");
5
- const path = require("path");
6
- const https = require("https");
7
- const { spawnSync } = require("child_process");
8
-
9
- const CPPTOOLS_ID = "ms-vscode.cpptools";
10
- const GITHUB_LATEST = "https://api.github.com/repos/microsoft/vscode-cpptools/releases/latest";
11
-
12
- function which(command) {
13
- const finder = process.platform === "win32" ? "where" : "which";
14
- const result = spawnSync(finder, [command], { encoding: "utf8", windowsHide: true });
15
- if (result.status !== 0) {
16
- return null;
17
- }
18
- return String(result.stdout || "")
19
- .split(/\r?\n/)
20
- .map((line) => line.trim())
21
- .find((line) => line && !line.toLowerCase().includes("info:"));
22
- }
23
-
24
- function editorBin() {
25
- const found = which("cursor") || which("code");
26
- if (found) {
27
- return found;
28
- }
29
- const local = process.env.LOCALAPPDATA || "";
30
- const fallbacks = [
31
- path.join(local, "Programs", "cursor", "resources", "app", "bin", "cursor.cmd"),
32
- path.join(local, "Programs", "Microsoft VS Code", "bin", "code.cmd"),
33
- "/usr/bin/cursor",
34
- "/usr/local/bin/cursor",
35
- "/usr/bin/code",
36
- "/usr/local/bin/code",
37
- ];
38
- return fallbacks.find((file) => fs.existsSync(file)) || null;
39
- }
40
-
41
- function extensionHomes() {
42
- return [
43
- path.join(os.homedir(), ".cursor", "extensions"),
44
- path.join(os.homedir(), ".vscode", "extensions"),
45
- ];
46
- }
47
-
48
- function isCppToolsInstalled() {
49
- for (const home of extensionHomes()) {
50
- if (!fs.existsSync(home)) {
51
- continue;
52
- }
53
- try {
54
- if (fs.readdirSync(home).some((name) => name.startsWith(CPPTOOLS_ID + "-"))) {
55
- return true;
56
- }
57
- } catch {
58
- // ignore
59
- }
60
- }
61
- const bin = editorBin();
62
- if (!bin) {
63
- return false;
64
- }
65
- const listed = spawnSync(bin, ["--list-extensions"], { encoding: "utf8", windowsHide: true, timeout: 20000 });
66
- return String(listed.stdout || "").split(/\r?\n/).includes(CPPTOOLS_ID);
67
- }
68
-
69
- function vsixAssetName(platform = process.platform, arch = process.arch) {
70
- const cpu = arch === "arm64" ? "arm64" : "x64";
71
- if (platform === "win32") {
72
- return `cpptools-windows-${cpu}.vsix`;
73
- }
74
- if (platform === "darwin") {
75
- return `cpptools-macOS-${cpu}.vsix`;
76
- }
77
- return `cpptools-linux-${cpu}.vsix`;
78
- }
79
-
80
- function httpsJson(url) {
81
- return new Promise((resolve, reject) => {
82
- const request = https.get(
83
- url,
84
- { headers: { "User-Agent": "cluaupp", Accept: "application/vnd.github+json" } },
85
- (response) => {
86
- if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
87
- response.resume();
88
- httpsJson(response.headers.location).then(resolve, reject);
89
- return;
90
- }
91
- const chunks = [];
92
- response.on("data", (chunk) => chunks.push(chunk));
93
- response.on("end", () => {
94
- if (response.statusCode !== 200) {
95
- reject(new Error("GitHub " + response.statusCode));
96
- return;
97
- }
98
- try {
99
- resolve(JSON.parse(Buffer.concat(chunks).toString("utf8")));
100
- } catch (err) {
101
- reject(err);
102
- }
103
- });
104
- },
105
- );
106
- request.on("error", reject);
107
- });
108
- }
109
-
110
- function downloadFile(url, dest) {
111
- return new Promise((resolve, reject) => {
112
- const follow = (current) => {
113
- https
114
- .get(current, { headers: { "User-Agent": "cluaupp" } }, (response) => {
115
- if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
116
- response.resume();
117
- follow(response.headers.location);
118
- return;
119
- }
120
- if (response.statusCode !== 200) {
121
- reject(new Error("download failed " + response.statusCode));
122
- return;
123
- }
124
- const out = fs.createWriteStream(dest);
125
- response.pipe(out);
126
- out.on("finish", () => out.close(() => resolve(dest)));
127
- out.on("error", reject);
128
- })
129
- .on("error", reject);
130
- };
131
- follow(url);
132
- });
133
- }
134
-
135
- async function downloadCppToolsVsix() {
136
- const name = vsixAssetName();
137
- const dest = path.join(os.tmpdir(), name);
138
- if (fs.existsSync(dest) && fs.statSync(dest).size > 1_000_000) {
139
- return dest;
140
- }
141
- const release = await httpsJson(GITHUB_LATEST);
142
- const asset = (release.assets || []).find((item) => item.name === name);
143
- if (!asset || !asset.browser_download_url) {
144
- throw new Error("no " + name + " in vscode-cpptools " + (release.tag_name || "latest"));
145
- }
146
- console.log("cluaupp: downloading", name, release.tag_name || "");
147
- return downloadFile(asset.browser_download_url, dest);
148
- }
149
-
150
- function spawnInstall(bin, target) {
151
- const result = spawnSync(bin, ["--install-extension", target, "--force"], {
152
- encoding: "utf8",
153
- windowsHide: true,
154
- timeout: 180000,
155
- });
156
- return {
157
- ok: result.status === 0 && !/not found/i.test(String(result.stderr || "") + String(result.stdout || "")),
158
- stdout: String(result.stdout || ""),
159
- stderr: String(result.stderr || ""),
160
- status: result.status,
161
- };
162
- }
163
-
164
- async function installCppTools() {
165
- if (isCppToolsInstalled()) {
166
- return { status: "already", id: CPPTOOLS_ID };
167
- }
168
- const bin = editorBin();
169
- if (!bin) {
170
- return { status: "missing-editor", id: CPPTOOLS_ID };
171
- }
172
- console.log("cluaupp: installing", CPPTOOLS_ID);
173
- const marketplace = spawnInstall(bin, CPPTOOLS_ID);
174
- if (marketplace.ok) {
175
- return { status: "installed", id: CPPTOOLS_ID, how: "marketplace" };
176
- }
177
- try {
178
- const vsix = await downloadCppToolsVsix();
179
- const fromFile = spawnInstall(bin, vsix);
180
- if (fromFile.ok) {
181
- return { status: "installed", id: CPPTOOLS_ID, how: "vsix", file: vsix };
182
- }
183
- return { status: "failed", id: CPPTOOLS_ID, detail: fromFile.stderr || fromFile.stdout || marketplace.stderr };
184
- } catch (err) {
185
- return { status: "failed", id: CPPTOOLS_ID, detail: err.message };
186
- }
187
- }
188
-
189
- function reportCppTools(result) {
190
- if (!result) {
191
- return;
192
- }
193
- if (result.status === "already") {
194
- console.log("cluaupp: Microsoft C/C++ already installed");
195
- return;
196
- }
197
- if (result.status === "installed") {
198
- console.log("cluaupp: installed", CPPTOOLS_ID, result.how === "vsix" ? "(VSIX — Cursor marketplace does not list it)" : "");
199
- console.log("cluaupp: reload the editor (Ctrl+Shift+P → Developer: Reload Window)");
200
- return;
201
- }
202
- if (result.status === "missing-editor") {
203
- console.error("cluaupp: Cursor/VS Code CLI not found. Install ms-vscode.cpptools from the VSIX at");
204
- console.error(" https://github.com/microsoft/vscode-cpptools/releases");
205
- return;
206
- }
207
- console.error("cluaupp: could not install", CPPTOOLS_ID + ":", result.detail || "unknown error");
208
- console.error(" download https://github.com/microsoft/vscode-cpptools/releases and: cursor --install-extension cpptools-windows-x64.vsix");
209
- }
210
-
211
- module.exports = {
212
- CPPTOOLS_ID,
213
- editorBin,
214
- isCppToolsInstalled,
215
- vsixAssetName,
216
- installCppTools,
217
- reportCppTools,
218
- };