cluaupp 0.1.5 → 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 (101) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +6 -1
  3. package/bin/cluau.js +1 -1
  4. package/bin/cluaupp.js +1 -1
  5. package/docs/architecture.md +26 -1
  6. package/docs/cli.md +27 -6
  7. package/docs/examples/index.md +2 -0
  8. package/docs/getting-started.md +5 -4
  9. package/docs/intellisense.md +49 -31
  10. package/docs/intro.md +1 -1
  11. package/editors/vscode/extension.js +97 -146
  12. package/editors/vscode/package.json +6 -6
  13. package/examples/README.md +18 -0
  14. package/examples/game/.clangd +25 -0
  15. package/examples/game/.vscode/c_cpp_properties.json +27 -0
  16. package/examples/game/.vscode/extensions.json +5 -0
  17. package/examples/game/.vscode/settings.json +27 -0
  18. package/examples/game/Packages/.gitkeep +0 -0
  19. package/examples/game/cluaupp.config.json +6 -0
  20. package/examples/game/compile_flags.txt +6 -0
  21. package/examples/game/default.project.json +39 -0
  22. package/examples/game/package.json +9 -0
  23. package/examples/game/rokit.toml +5 -0
  24. package/examples/game/src/client/hud.client.cpp +12 -0
  25. package/{src → examples/game/src}/client/init.client.cpp +1 -0
  26. package/examples/game/src/server/combat.server.cpp +23 -0
  27. package/{src → examples/game/src}/server/leaderstats.server.cpp +1 -0
  28. package/examples/game/wally.toml +11 -0
  29. package/generated/api.js +51 -0
  30. package/generated/architecture.js +473 -0
  31. package/generated/ast.js +2 -0
  32. package/generated/cli.js +191 -0
  33. package/generated/compile.js +115 -0
  34. package/generated/editor-install.js +170 -0
  35. package/generated/emit.js +503 -0
  36. package/generated/emitter/luau-codegen.js +167 -0
  37. package/generated/emitter/translators.js +164 -0
  38. package/generated/headers.js +220 -0
  39. package/generated/index.html +49 -0
  40. package/generated/intellisense.js +277 -0
  41. package/generated/layout.js +112 -0
  42. package/generated/lex.js +146 -0
  43. package/generated/libs.js +484 -0
  44. package/generated/lsp.js +55 -0
  45. package/generated/package-info.js +11 -0
  46. package/generated/parse.js +607 -0
  47. package/generated/parser/collector.js +100 -0
  48. package/generated/parser/index.js +30 -0
  49. package/generated/preprocess.js +181 -0
  50. package/generated/system-understander.js +443 -0
  51. package/generated/transpile.js +66 -0
  52. package/generated/types.js +2 -0
  53. package/generated/understand.js +298 -0
  54. package/generated/utils/process-orchestrator.js +63 -0
  55. package/generated/utils/project.js +491 -0
  56. package/generated/utils/rojo-mapper.js +181 -0
  57. package/generated/utils/safe-paths.js +104 -0
  58. package/package.json +25 -8
  59. package/src/api.ts +53 -0
  60. package/src/{architecture.js → architecture.ts} +9 -10
  61. package/src/ast.ts +37 -0
  62. package/src/cli.ts +214 -0
  63. package/src/compile.ts +118 -0
  64. package/src/editor-install.ts +182 -0
  65. package/src/{emit.js → emit.ts} +4 -5
  66. package/src/emitter/luau-codegen.ts +187 -0
  67. package/src/emitter/translators.ts +168 -0
  68. package/src/{headers.js → headers.ts} +4 -5
  69. package/src/intellisense.ts +286 -0
  70. package/src/{layout.js → layout.ts} +114 -129
  71. package/src/{lex.js → lex.ts} +4 -6
  72. package/src/{libs.js → libs.ts} +9 -4
  73. package/src/lsp.ts +60 -0
  74. package/src/package-info.ts +7 -0
  75. package/src/{parse.js → parse.ts} +3 -4
  76. package/src/parser/collector.ts +115 -0
  77. package/src/parser/index.ts +27 -0
  78. package/src/{preprocess.js → preprocess.ts} +22 -37
  79. package/src/system-understander.ts +501 -0
  80. package/src/transpile.ts +64 -0
  81. package/src/tree-sitter-cpp.d.ts +4 -0
  82. package/src/types.ts +81 -0
  83. package/src/{understand.js → understand.ts} +19 -210
  84. package/src/utils/process-orchestrator.ts +72 -0
  85. package/src/utils/project.ts +506 -0
  86. package/src/utils/rojo-mapper.ts +190 -0
  87. package/src/utils/safe-paths.ts +98 -0
  88. package/templates/game/.clangd +9 -0
  89. package/templates/game/.vscode/c_cpp_properties.json +1 -1
  90. package/templates/game/.vscode/extensions.json +5 -6
  91. package/templates/game/.vscode/settings.json +7 -6
  92. package/templates/game/compile_flags.txt +1 -0
  93. package/templates/game/rokit.toml +5 -0
  94. package/src/api.js +0 -57
  95. package/src/cli.js +0 -473
  96. package/src/compile.js +0 -110
  97. package/src/editor-install.js +0 -218
  98. package/src/intellisense.js +0 -1368
  99. package/src/lsp.js +0 -227
  100. /package/{src → examples/game/src}/shared/config.cpp +0 -0
  101. /package/{src → examples/game/src}/shared/config.h +0 -0
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.compileSource = compileSource;
7
+ exports.compileService = compileService;
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const parse_js_1 = require("./parse.js");
10
+ const emit_js_1 = require("./emit.js");
11
+ const preprocess_js_1 = require("./preprocess.js");
12
+ const libs_js_1 = require("./libs.js");
13
+ const architecture_js_1 = require("./architecture.js");
14
+ const headers_js_1 = require("./headers.js");
15
+ function shouldAttachRequires(name, contents) {
16
+ const file = String(name || "").replace(/\\/g, "/");
17
+ if (/\.json$/i.test(file) || /\.meta\.json$/i.test(file)) {
18
+ return false;
19
+ }
20
+ const trimmed = String(contents || "").trim();
21
+ if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
22
+ return false;
23
+ }
24
+ return true;
25
+ }
26
+ function attachRequires(contents, source, ast, options, outName) {
27
+ if (!shouldAttachRequires(outName, contents)) {
28
+ return contents;
29
+ }
30
+ const libraries = String(contents).includes("CluauppLibs") ? [] : (0, libs_js_1.collectLibraries)(source, ast);
31
+ return (0, libs_js_1.insertPreamble)(contents, options.moduleIncludes || [], libraries, outName);
32
+ }
33
+ function posixRel(from, file) {
34
+ return node_path_1.default.relative(from, file).replace(/\\/g, "/");
35
+ }
36
+ function wireHeaderImpl(ast, fileName, options) {
37
+ const headerPath = options.filePath || null;
38
+ const impl = headerPath ? (0, preprocess_js_1.siblingImplementation)(headerPath) : null;
39
+ if (!impl) {
40
+ return;
41
+ }
42
+ const typeName = (0, headers_js_1.primaryHeaderName)(ast, options.relativeName || fileName);
43
+ const implRel = options.srcDir ? posixRel(options.srcDir, impl) : node_path_1.default.basename(impl).replace(/\\/g, "/");
44
+ const implOut = (0, preprocess_js_1.implOutName)(implRel);
45
+ options.headerImplName = `${typeName}Module`;
46
+ options.moduleIncludes = options.moduleIncludes || [];
47
+ if (!options.moduleIncludes.some((spec) => spec.name === options.headerImplName)) {
48
+ options.moduleIncludes.push({
49
+ name: options.headerImplName,
50
+ outRel: implOut,
51
+ exports: { consts: [], structs: [] },
52
+ });
53
+ }
54
+ }
55
+ function compileHeader(source, fileName, options, ast) {
56
+ wireHeaderImpl(ast, fileName, options);
57
+ const rel = (options.relativeName || fileName || "header.h").replace(/\\/g, "/");
58
+ const outName = (0, preprocess_js_1.toLuauPath)(rel);
59
+ const luau = attachRequires((0, headers_js_1.emitHeaderModule)(ast, options), source, ast, options, outName);
60
+ return {
61
+ kind: "module",
62
+ plan: { kind: "module", strict: options.strict === true },
63
+ files: [{ name: outName, contents: luau }],
64
+ stale: [],
65
+ };
66
+ }
67
+ function compileSource(source, fileName, options = {}) {
68
+ const opts = options;
69
+ opts.moduleIncludes = opts.moduleIncludes || [];
70
+ const prepared = (0, preprocess_js_1.preprocess)(source, opts.filePath || null, opts);
71
+ const ast = (0, parse_js_1.parse)(prepared, fileName || "input.cpp");
72
+ if ((0, preprocess_js_1.isHeaderFile)(fileName || "") || (0, preprocess_js_1.isHeaderFile)(opts.filePath || "")) {
73
+ return compileHeader(source, fileName || "header.h", opts, ast).files[0].contents;
74
+ }
75
+ const luau = (0, emit_js_1.emit)(ast, opts);
76
+ return attachRequires(luau, source, ast, opts, opts.outName || fileName || "input.cpp");
77
+ }
78
+ function compileService(source, fileName, options = {}) {
79
+ const opts = options;
80
+ opts.moduleIncludes = opts.moduleIncludes || [];
81
+ const prepared = (0, preprocess_js_1.preprocess)(source, opts.filePath || null, opts);
82
+ const ast = (0, parse_js_1.parse)(prepared, fileName || "input.cpp");
83
+ if ((0, preprocess_js_1.isHeaderFile)(fileName || "") || (0, preprocess_js_1.isHeaderFile)(opts.filePath || "") || (0, preprocess_js_1.isHeaderFile)(opts.relativeName || "")) {
84
+ return compileHeader(source, fileName || "header.h", opts, ast);
85
+ }
86
+ const implHeader = opts.filePath ? (0, preprocess_js_1.siblingHeader)(opts.filePath) : null;
87
+ if (implHeader) {
88
+ opts.skipInit = true;
89
+ }
90
+ const planned = (0, architecture_js_1.planOutput)(ast, fileName || "input.cpp", {
91
+ ...opts,
92
+ relativeName: opts.relativeName || fileName,
93
+ source: prepared,
94
+ siblingHeader: implHeader,
95
+ });
96
+ if (planned.files) {
97
+ return {
98
+ ...planned,
99
+ files: planned.files.map((file) => ({
100
+ ...file,
101
+ contents: attachRequires(file.contents, source, ast, opts, file.name),
102
+ })),
103
+ };
104
+ }
105
+ const luau = attachRequires((0, emit_js_1.emit)(ast, opts), source, ast, opts, planned.outName || opts.outName || fileName || "input.cpp");
106
+ const name = planned.outName ||
107
+ opts.outName ||
108
+ String(fileName || "input.cpp").replace(/\.(cpp|cc|cxx|c|h|hpp|hh)$/i, ".luau");
109
+ return {
110
+ kind: planned.kind || "flat",
111
+ plan: planned.plan,
112
+ files: [{ name, contents: luau }],
113
+ stale: planned.stale || [],
114
+ };
115
+ }
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CLANGD_ID = void 0;
7
+ exports.editorBin = editorBin;
8
+ exports.isExtensionInstalled = isExtensionInstalled;
9
+ exports.findClangPlusPlus = findClangPlusPlus;
10
+ exports.ensureLlvm = ensureLlvm;
11
+ exports.installMarketplaceExtension = installMarketplaceExtension;
12
+ exports.reportInstall = reportInstall;
13
+ const node_fs_1 = __importDefault(require("node:fs"));
14
+ const node_os_1 = __importDefault(require("node:os"));
15
+ const node_path_1 = __importDefault(require("node:path"));
16
+ const node_child_process_1 = require("node:child_process");
17
+ exports.CLANGD_ID = "llvm-vs-code-extensions.vscode-clangd";
18
+ function which(command) {
19
+ const finder = process.platform === "win32" ? "where" : "which";
20
+ const result = (0, node_child_process_1.spawnSync)(finder, [command], { encoding: "utf8", windowsHide: true });
21
+ if (result.status !== 0) {
22
+ return null;
23
+ }
24
+ return String(result.stdout || "")
25
+ .split(/\r?\n/)
26
+ .map((line) => line.trim())
27
+ .find((line) => line && !line.toLowerCase().includes("info:")) || null;
28
+ }
29
+ function editorBin() {
30
+ const found = which("cursor") || which("code");
31
+ if (found) {
32
+ return found;
33
+ }
34
+ const local = process.env.LOCALAPPDATA || "";
35
+ const fallbacks = [
36
+ node_path_1.default.join(local, "Programs", "cursor", "resources", "app", "bin", "cursor.cmd"),
37
+ node_path_1.default.join(local, "Programs", "Microsoft VS Code", "bin", "code.cmd"),
38
+ "/usr/bin/cursor",
39
+ "/usr/local/bin/cursor",
40
+ "/usr/bin/code",
41
+ "/usr/local/bin/code",
42
+ ];
43
+ return fallbacks.find((file) => node_fs_1.default.existsSync(file)) || null;
44
+ }
45
+ function extensionHomes() {
46
+ return [node_path_1.default.join(node_os_1.default.homedir(), ".cursor", "extensions"), node_path_1.default.join(node_os_1.default.homedir(), ".vscode", "extensions")];
47
+ }
48
+ function isExtensionInstalled(id) {
49
+ for (const home of extensionHomes()) {
50
+ if (!node_fs_1.default.existsSync(home)) {
51
+ continue;
52
+ }
53
+ try {
54
+ if (node_fs_1.default.readdirSync(home).some((name) => name.startsWith(`${id}-`))) {
55
+ return true;
56
+ }
57
+ }
58
+ catch {
59
+ // ignore
60
+ }
61
+ }
62
+ const bin = editorBin();
63
+ if (!bin) {
64
+ return false;
65
+ }
66
+ const listed = (0, node_child_process_1.spawnSync)(bin, ["--list-extensions"], { encoding: "utf8", windowsHide: true, timeout: 20000 });
67
+ return String(listed.stdout || "").split(/\r?\n/).includes(id);
68
+ }
69
+ function llvmCandidates() {
70
+ if (process.platform === "win32") {
71
+ return [
72
+ "C:/Program Files/LLVM/bin/clang++.exe",
73
+ "C:/Program Files (x86)/LLVM/bin/clang++.exe",
74
+ node_path_1.default.join(process.env.ProgramFiles || "C:/Program Files", "LLVM", "bin", "clang++.exe"),
75
+ "C:/msys64/ucrt64/bin/clang++.exe",
76
+ "C:/msys64/mingw64/bin/clang++.exe",
77
+ ];
78
+ }
79
+ return ["/usr/bin/clang++", "/usr/local/bin/clang++", "/opt/homebrew/bin/clang++"];
80
+ }
81
+ function findClangPlusPlus() {
82
+ for (const candidate of llvmCandidates()) {
83
+ if (candidate && node_fs_1.default.existsSync(candidate)) {
84
+ return candidate.replace(/\\/g, "/");
85
+ }
86
+ }
87
+ return which("clang++");
88
+ }
89
+ function ensureLlvm() {
90
+ const found = findClangPlusPlus();
91
+ if (found) {
92
+ return { status: "already", path: found };
93
+ }
94
+ if (process.platform === "win32" && which("winget")) {
95
+ console.log("cluaupp: installing LLVM.LLVM (clang++ / clangd) via winget");
96
+ const result = (0, node_child_process_1.spawnSync)("winget", ["install", "--id", "LLVM.LLVM", "-e", "--accept-package-agreements", "--accept-source-agreements"], { encoding: "utf8", windowsHide: true, timeout: 300000 });
97
+ const after = findClangPlusPlus();
98
+ if (after) {
99
+ return { status: "installed", path: after, how: "winget" };
100
+ }
101
+ return {
102
+ status: "missing",
103
+ detail: String(result.stderr || result.stdout || "").trim() || "winget did not install LLVM",
104
+ hint: "winget install --id LLVM.LLVM -e",
105
+ };
106
+ }
107
+ const hint = process.platform === "darwin"
108
+ ? "brew install llvm"
109
+ : process.platform === "win32"
110
+ ? "winget install --id LLVM.LLVM -e"
111
+ : "sudo apt install clang";
112
+ return { status: "missing", hint };
113
+ }
114
+ function spawnInstall(bin, target) {
115
+ const result = (0, node_child_process_1.spawnSync)(bin, ["--install-extension", target, "--force"], {
116
+ encoding: "utf8",
117
+ windowsHide: true,
118
+ timeout: 180000,
119
+ });
120
+ return {
121
+ ok: result.status === 0 && !/not found/i.test(String(result.stderr || "") + String(result.stdout || "")),
122
+ stdout: String(result.stdout || ""),
123
+ stderr: String(result.stderr || ""),
124
+ status: result.status,
125
+ };
126
+ }
127
+ async function installMarketplaceExtension(id, label) {
128
+ if (isExtensionInstalled(id)) {
129
+ return { status: "already", id };
130
+ }
131
+ const bin = editorBin();
132
+ if (!bin) {
133
+ return { status: "missing-editor", id };
134
+ }
135
+ console.log("cluaupp: installing", label || id);
136
+ const marketplace = spawnInstall(bin, id);
137
+ if (marketplace.ok) {
138
+ return { status: "installed", id, how: "marketplace" };
139
+ }
140
+ return { status: "failed", id, detail: marketplace.stderr || marketplace.stdout };
141
+ }
142
+ function reportInstall(result, label, extraMissing) {
143
+ if (!result) {
144
+ return;
145
+ }
146
+ const name = label || result.id;
147
+ if (result.status === "already") {
148
+ console.log("cluaupp:", name, "already installed");
149
+ return;
150
+ }
151
+ if (result.status === "installed") {
152
+ console.log("cluaupp: installed", name, result.how ? `(${result.how})` : "");
153
+ return;
154
+ }
155
+ if (result.status === "missing-editor") {
156
+ console.error("cluaupp: Cursor/VS Code CLI not found. Install", name, "from the marketplace.");
157
+ return;
158
+ }
159
+ if (result.status === "missing") {
160
+ console.error("cluaupp: LLVM clang++ not found.", result.hint || extraMissing || "");
161
+ if (result.detail) {
162
+ console.error(" ", result.detail.split(/\r?\n/)[0]);
163
+ }
164
+ return;
165
+ }
166
+ console.error("cluaupp: could not install", name + ":", result.detail || "unknown error");
167
+ if (extraMissing) {
168
+ console.error(" ", extraMissing);
169
+ }
170
+ }