@luaward/cli 0.0.0-stage → 0.2.1
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/LICENSE +21 -0
- package/README.md +60 -2
- package/action.yml +46 -0
- package/dist/cli.js +1641 -0
- package/dist/cli.js.map +7 -0
- package/package.json +48 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,1641 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/commands.ts
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, watch, writeFileSync as writeFileSync2 } from "node:fs";
|
|
6
|
+
import { basename, dirname as dirname2, join as join2, resolve as resolve2 } from "node:path";
|
|
7
|
+
|
|
8
|
+
// src/client.ts
|
|
9
|
+
var CliApiError = class extends Error {
|
|
10
|
+
constructor(status, code, message, retryAfterSec = null) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.retryAfterSec = retryAfterSec;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var READ_ONLY_ACTIONS = /* @__PURE__ */ new Set([
|
|
18
|
+
"workspace",
|
|
19
|
+
"script.source",
|
|
20
|
+
"script.buildStatus",
|
|
21
|
+
"debug.poll",
|
|
22
|
+
"keys.recent",
|
|
23
|
+
"errors.list"
|
|
24
|
+
]);
|
|
25
|
+
function parseRetryAfterSeconds(header) {
|
|
26
|
+
if (!header) return null;
|
|
27
|
+
const n = Number(header.trim());
|
|
28
|
+
if (Number.isFinite(n) && n > 0) return Math.min(n, 30);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
function parseIdeJson(rawText) {
|
|
32
|
+
if (!rawText) return null;
|
|
33
|
+
try {
|
|
34
|
+
const parsed = JSON.parse(rawText);
|
|
35
|
+
return parsed && typeof parsed === "object" ? parsed : null;
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function enrichApiMessage(status, code, fallback) {
|
|
41
|
+
if (status === 403 && code === "FORBIDDEN") {
|
|
42
|
+
return `${fallback} (\u0E1A\u0E31\u0E0D\u0E0A\u0E35/\u0E42\u0E17\u0E40\u0E04\u0E19\u0E19\u0E35\u0E49\u0E44\u0E21\u0E48\u0E21\u0E35\u0E2A\u0E34\u0E17\u0E18\u0E34\u0E4C\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19 \u0E2B\u0E23\u0E37\u0E2D\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E2D\u0E22\u0E39\u0E48\u0E43\u0E19\u0E23\u0E32\u0E22\u0E01\u0E32\u0E23 Early Access)`;
|
|
43
|
+
}
|
|
44
|
+
if (code === "TWO_FACTOR_REQUIRED") {
|
|
45
|
+
return "\u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E34\u0E14\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E15\u0E31\u0E27\u0E15\u0E19 2 \u0E02\u0E31\u0E49\u0E19\u0E15\u0E2D\u0E19 (2FA) \u0E43\u0E19\u0E1A\u0E31\u0E0D\u0E0A\u0E35 Luaward \u0E01\u0E48\u0E2D\u0E19\u0E08\u0E36\u0E07\u0E08\u0E30\u0E40\u0E1B\u0E34\u0E14\u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01\u0E0B\u0E2D\u0E23\u0E4C\u0E2A\u0E42\u0E04\u0E49\u0E14\u0E1A\u0E19\u0E40\u0E0B\u0E34\u0E23\u0E4C\u0E1F\u0E40\u0E27\u0E2D\u0E23\u0E4C\u0E44\u0E14\u0E49 (\u0E41\u0E01\u0E49\u0E44\u0E02\u0E44\u0E14\u0E49\u0E43\u0E19\u0E2B\u0E19\u0E49\u0E32 \u0E15\u0E31\u0E49\u0E07\u0E04\u0E48\u0E32\u0E04\u0E27\u0E32\u0E21\u0E1B\u0E25\u0E2D\u0E14\u0E20\u0E31\u0E22)";
|
|
46
|
+
}
|
|
47
|
+
if (code === "SOURCE_NOT_STORED") {
|
|
48
|
+
return "\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C\u0E19\u0E35\u0E49\u0E43\u0E0A\u0E49\u0E42\u0E2B\u0E21\u0E14 Zero-Retention (\u0E44\u0E21\u0E48\u0E40\u0E01\u0E47\u0E1A\u0E0B\u0E2D\u0E23\u0E4C\u0E2A\u0E42\u0E04\u0E49\u0E14\u0E1A\u0E19\u0E40\u0E0B\u0E34\u0E23\u0E4C\u0E1F\u0E40\u0E27\u0E2D\u0E23\u0E4C) \u0E08\u0E36\u0E07\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E14\u0E36\u0E07\u0E0B\u0E2D\u0E23\u0E4C\u0E2A\u0E2B\u0E23\u0E37\u0E2D\u0E04\u0E2D\u0E21\u0E44\u0E1E\u0E25\u0E4C\u0E43\u0E2B\u0E21\u0E48\u0E42\u0E14\u0E22\u0E44\u0E21\u0E48\u0E2D\u0E31\u0E1B\u0E42\u0E2B\u0E25\u0E14\u0E42\u0E04\u0E49\u0E14\u0E43\u0E2B\u0E21\u0E48\u0E44\u0E14\u0E49 \u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E31\u0E19 `luaward push` \u0E1E\u0E23\u0E49\u0E2D\u0E21\u0E44\u0E1F\u0E25\u0E4C\u0E15\u0E49\u0E19\u0E09\u0E1A\u0E31\u0E1A";
|
|
49
|
+
}
|
|
50
|
+
if (status === 409 && code === "APPROVAL_PENDING") {
|
|
51
|
+
return `${fallback} - \u0E42\u0E1B\u0E23\u0E14\u0E2D\u0E19\u0E38\u0E21\u0E31\u0E15\u0E34\u0E04\u0E33\u0E02\u0E2D\u0E43\u0E19\u0E2B\u0E19\u0E49\u0E32 Test in Game / AI & MCP \u0E2B\u0E23\u0E37\u0E2D\u0E43\u0E0A\u0E49\u0E42\u0E17\u0E40\u0E04\u0E19\u0E42\u0E2B\u0E21\u0E14 Runs at once`;
|
|
52
|
+
}
|
|
53
|
+
return fallback;
|
|
54
|
+
}
|
|
55
|
+
var LuawardCliClient = class {
|
|
56
|
+
constructor(apiUrl, token, options = {}) {
|
|
57
|
+
this.apiUrl = apiUrl;
|
|
58
|
+
this.token = token;
|
|
59
|
+
this.timeoutMs = options.timeoutMs ?? 35e3;
|
|
60
|
+
this.maxRetries = options.maxRetries ?? 2;
|
|
61
|
+
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
62
|
+
}
|
|
63
|
+
timeoutMs;
|
|
64
|
+
maxRetries;
|
|
65
|
+
fetchImpl;
|
|
66
|
+
async call(payload) {
|
|
67
|
+
const base = this.apiUrl.replace(/\/+$/, "");
|
|
68
|
+
const action = typeof payload.action === "string" ? payload.action : "";
|
|
69
|
+
const isReadOnly = READ_ONLY_ACTIONS.has(action);
|
|
70
|
+
let attempt = 0;
|
|
71
|
+
while (true) {
|
|
72
|
+
attempt += 1;
|
|
73
|
+
const controller = new AbortController();
|
|
74
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
75
|
+
let res;
|
|
76
|
+
try {
|
|
77
|
+
res = await this.fetchImpl(`${base}/api/ide`, {
|
|
78
|
+
method: "POST",
|
|
79
|
+
headers: {
|
|
80
|
+
"content-type": "application/json",
|
|
81
|
+
authorization: `Bearer ${this.token}`
|
|
82
|
+
},
|
|
83
|
+
body: JSON.stringify(payload),
|
|
84
|
+
signal: controller.signal
|
|
85
|
+
});
|
|
86
|
+
} catch (err) {
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
if (isReadOnly && attempt <= this.maxRetries) {
|
|
89
|
+
await new Promise((r) => setTimeout(r, 300 * attempt));
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const reason = err instanceof Error && err.name === "AbortError" ? `\u0E2B\u0E21\u0E14\u0E40\u0E27\u0E25\u0E32\u0E23\u0E2D\u0E04\u0E33\u0E15\u0E2D\u0E1A\u0E08\u0E32\u0E01\u0E40\u0E0B\u0E34\u0E23\u0E4C\u0E1F\u0E40\u0E27\u0E2D\u0E23\u0E4C (${this.timeoutMs}ms)` : `\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D ${base} \u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08: ${err instanceof Error ? err.message : String(err)}`;
|
|
93
|
+
throw new CliApiError(0, "NETWORK_ERROR", reason);
|
|
94
|
+
} finally {
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
}
|
|
97
|
+
const retryAfter = parseRetryAfterSeconds(res.headers.get("retry-after"));
|
|
98
|
+
const rawText = await res.text();
|
|
99
|
+
const body = parseIdeJson(rawText);
|
|
100
|
+
if (res.ok && body?.ok) {
|
|
101
|
+
return body.data;
|
|
102
|
+
}
|
|
103
|
+
const shouldRetry = attempt <= this.maxRetries && (res.status === 429 || isReadOnly && (res.status === 502 || res.status === 503 || res.status === 504));
|
|
104
|
+
if (shouldRetry) {
|
|
105
|
+
const waitMs = (retryAfter ?? 0.5 * attempt) * 1e3;
|
|
106
|
+
await new Promise((r) => setTimeout(r, waitMs));
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const code = body && !body.ok && body.error ? body.error : `HTTP_${res.status}`;
|
|
110
|
+
const rawMsg = body && !body.ok && body.message ? body.message : body === null && rawText ? `\u0E04\u0E33\u0E15\u0E2D\u0E1A\u0E44\u0E21\u0E48\u0E43\u0E0A\u0E48 JSON (HTTP ${res.status})` : `Request failed (${res.status})`;
|
|
111
|
+
throw new CliApiError(res.status, code, enrichApiMessage(res.status, code, rawMsg), retryAfter);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
workspace() {
|
|
115
|
+
return this.call({ action: "workspace" });
|
|
116
|
+
}
|
|
117
|
+
pullSource(scriptId) {
|
|
118
|
+
return this.call({ action: "script.source", scriptId });
|
|
119
|
+
}
|
|
120
|
+
deployScript(input) {
|
|
121
|
+
return this.call({ action: "script.deploy", ...input });
|
|
122
|
+
}
|
|
123
|
+
buildStatus(scriptId, buildId) {
|
|
124
|
+
return this.call({ action: "script.buildStatus", scriptId, buildId });
|
|
125
|
+
}
|
|
126
|
+
toggleScript(input) {
|
|
127
|
+
return this.call({ action: "script.toggle", ...input });
|
|
128
|
+
}
|
|
129
|
+
runLocal(input) {
|
|
130
|
+
return this.call({ action: "debug.runLocal", ...input });
|
|
131
|
+
}
|
|
132
|
+
pollDebug(input) {
|
|
133
|
+
return this.call({ action: "debug.poll", ...input });
|
|
134
|
+
}
|
|
135
|
+
execSnippet(sid, code) {
|
|
136
|
+
return this.call({ action: "debug.exec", sid, code });
|
|
137
|
+
}
|
|
138
|
+
stopDebug(sid) {
|
|
139
|
+
return this.call({ action: "debug.stop", sid });
|
|
140
|
+
}
|
|
141
|
+
ensurePairCommand() {
|
|
142
|
+
return this.call({ action: "debug.ensurePair" });
|
|
143
|
+
}
|
|
144
|
+
recentKeys(projectId, limit = 10) {
|
|
145
|
+
return this.call({ action: "keys.recent", projectId, limit });
|
|
146
|
+
}
|
|
147
|
+
createQuickKey(input) {
|
|
148
|
+
return this.call({ action: "keys.createQuick", ...input });
|
|
149
|
+
}
|
|
150
|
+
resetHwid(keyOrId, projectId) {
|
|
151
|
+
return this.call({ action: "keys.resetHwid", keyOrId, projectId });
|
|
152
|
+
}
|
|
153
|
+
listErrors(scriptId, status = "open") {
|
|
154
|
+
return this.call({ action: "errors.list", scriptId, status });
|
|
155
|
+
}
|
|
156
|
+
resolveError(id, status = "resolved") {
|
|
157
|
+
return this.call({ action: "errors.resolve", id, status });
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// src/config.ts
|
|
162
|
+
import { randomBytes } from "node:crypto";
|
|
163
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
164
|
+
import { createServer } from "node:http";
|
|
165
|
+
import { homedir } from "node:os";
|
|
166
|
+
import { dirname, join, resolve } from "node:path";
|
|
167
|
+
import { URL } from "node:url";
|
|
168
|
+
var CLI_VERSION = "0.2.1";
|
|
169
|
+
var TOKEN_SHAPE = /^lwm_[0-9a-f]{48}$/;
|
|
170
|
+
var HEX32_RE = /^[0-9a-f]{32}$/i;
|
|
171
|
+
var DISCORD_ID_RE = /^\d{15,22}$/;
|
|
172
|
+
var MANIFEST_FILE = "luaward.json";
|
|
173
|
+
var DEFAULT_API_URL = "https://luaward.com";
|
|
174
|
+
function isValidPreset(value) {
|
|
175
|
+
return value === "fast" || value === "balanced" || value === "max";
|
|
176
|
+
}
|
|
177
|
+
function isHex32(value) {
|
|
178
|
+
return HEX32_RE.test(value.trim());
|
|
179
|
+
}
|
|
180
|
+
function isValidDiscordId(value) {
|
|
181
|
+
return DISCORD_ID_RE.test(value.trim());
|
|
182
|
+
}
|
|
183
|
+
function getCredentialsPath() {
|
|
184
|
+
const base = process.env.LUAWARD_CONFIG_DIR || join(homedir(), ".config", "luaward");
|
|
185
|
+
return join(base, "credentials.json");
|
|
186
|
+
}
|
|
187
|
+
function readCredentials() {
|
|
188
|
+
const p = getCredentialsPath();
|
|
189
|
+
if (!existsSync(p)) return null;
|
|
190
|
+
try {
|
|
191
|
+
const raw = JSON.parse(readFileSync(p, "utf8"));
|
|
192
|
+
if (!raw.token || !TOKEN_SHAPE.test(raw.token)) return null;
|
|
193
|
+
return {
|
|
194
|
+
token: raw.token,
|
|
195
|
+
apiUrl: (raw.apiUrl || DEFAULT_API_URL).replace(/\/+$/, ""),
|
|
196
|
+
updatedAt: raw.updatedAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
197
|
+
};
|
|
198
|
+
} catch {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function writeCredentials(token, apiUrl = DEFAULT_API_URL) {
|
|
203
|
+
const p = getCredentialsPath();
|
|
204
|
+
mkdirSync(dirname(p), { recursive: true, mode: 448 });
|
|
205
|
+
const payload = {
|
|
206
|
+
token: token.trim(),
|
|
207
|
+
apiUrl: apiUrl.replace(/\/+$/, ""),
|
|
208
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
209
|
+
};
|
|
210
|
+
writeFileSync(p, `${JSON.stringify(payload, null, 2)}
|
|
211
|
+
`, { mode: 384 });
|
|
212
|
+
try {
|
|
213
|
+
chmodSync(p, 384);
|
|
214
|
+
} catch {
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function clearCredentials() {
|
|
218
|
+
const p = getCredentialsPath();
|
|
219
|
+
if (!existsSync(p)) return false;
|
|
220
|
+
rmSync(p, { force: true });
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
function findManifestDir(startDir = process.cwd()) {
|
|
224
|
+
let dir = resolve(startDir);
|
|
225
|
+
while (true) {
|
|
226
|
+
if (existsSync(join(dir, MANIFEST_FILE))) return dir;
|
|
227
|
+
const parent = dirname(dir);
|
|
228
|
+
if (parent === dir) return null;
|
|
229
|
+
dir = parent;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function readManifest(cwd = process.cwd()) {
|
|
233
|
+
const p = resolve(cwd, MANIFEST_FILE);
|
|
234
|
+
if (!existsSync(p)) return null;
|
|
235
|
+
const raw = JSON.parse(readFileSync(p, "utf8"));
|
|
236
|
+
if (!raw || typeof raw !== "object" || typeof raw.projectId !== "string" || !raw.scripts) {
|
|
237
|
+
throw new Error(`\u0E44\u0E1F\u0E25\u0E4C ${MANIFEST_FILE} \u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07 (\u0E15\u0E49\u0E2D\u0E07\u0E23\u0E30\u0E1A\u0E38 projectId \u0E41\u0E25\u0E30 scripts)`);
|
|
238
|
+
}
|
|
239
|
+
return raw;
|
|
240
|
+
}
|
|
241
|
+
function findManifest(startDir = process.cwd()) {
|
|
242
|
+
const dir = findManifestDir(startDir);
|
|
243
|
+
if (!dir) return null;
|
|
244
|
+
const manifest = readManifest(dir);
|
|
245
|
+
return manifest ? { dir, manifest } : null;
|
|
246
|
+
}
|
|
247
|
+
function writeManifest(manifest, cwd = process.cwd()) {
|
|
248
|
+
const p = resolve(cwd, MANIFEST_FILE);
|
|
249
|
+
writeFileSync(p, `${JSON.stringify(manifest, null, 2)}
|
|
250
|
+
`, "utf8");
|
|
251
|
+
return p;
|
|
252
|
+
}
|
|
253
|
+
function resolveAuth(cwd = process.cwd(), flags = {}) {
|
|
254
|
+
const manifest = findManifest(cwd)?.manifest ?? null;
|
|
255
|
+
const creds = readCredentials();
|
|
256
|
+
const token = flags.token?.trim() || process.env.LUAWARD_TOKEN?.trim() || creds?.token || null;
|
|
257
|
+
const apiUrl = (flags.apiUrl?.trim() || process.env.LUAWARD_API_URL?.trim() || manifest?.apiUrl?.trim() || creds?.apiUrl || DEFAULT_API_URL).replace(/\/+$/, "");
|
|
258
|
+
return { token, apiUrl };
|
|
259
|
+
}
|
|
260
|
+
var CLI_CALLBACK_HTML = `<!doctype html>
|
|
261
|
+
<html lang="th">
|
|
262
|
+
<head>
|
|
263
|
+
<meta charset="utf-8" />
|
|
264
|
+
<title>Luaward CLI - \u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08</title>
|
|
265
|
+
<style>
|
|
266
|
+
body {
|
|
267
|
+
margin: 0;
|
|
268
|
+
min-height: 100vh;
|
|
269
|
+
display: grid;
|
|
270
|
+
place-items: center;
|
|
271
|
+
background: #050506;
|
|
272
|
+
color: #f4f4f6;
|
|
273
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
274
|
+
}
|
|
275
|
+
.card {
|
|
276
|
+
background: #0e0e12;
|
|
277
|
+
border: 1px solid rgba(255,255,255,0.09);
|
|
278
|
+
border-radius: 20px;
|
|
279
|
+
padding: 32px 36px;
|
|
280
|
+
max-width: 420px;
|
|
281
|
+
text-align: center;
|
|
282
|
+
}
|
|
283
|
+
.badge {
|
|
284
|
+
width: 48px;
|
|
285
|
+
height: 48px;
|
|
286
|
+
border-radius: 14px;
|
|
287
|
+
margin: 0 auto 16px;
|
|
288
|
+
display: grid;
|
|
289
|
+
place-items: center;
|
|
290
|
+
background: rgba(39, 209, 127, 0.14);
|
|
291
|
+
color: #27d17f;
|
|
292
|
+
font-size: 24px;
|
|
293
|
+
font-weight: 800;
|
|
294
|
+
}
|
|
295
|
+
h1 { margin: 0 0 8px; font-size: 20px; }
|
|
296
|
+
p { margin: 0; font-size: 14px; color: rgba(255,255,255,0.62); }
|
|
297
|
+
</style>
|
|
298
|
+
</head>
|
|
299
|
+
<body>
|
|
300
|
+
<div class="card">
|
|
301
|
+
<div class="badge">\u2713</div>
|
|
302
|
+
<h1>\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D Luaward CLI \u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08\u0E41\u0E25\u0E49\u0E27</h1>
|
|
303
|
+
<p>\u0E04\u0E38\u0E13\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E1B\u0E34\u0E14\u0E41\u0E17\u0E47\u0E1A\u0E19\u0E35\u0E49\u0E41\u0E25\u0E30\u0E01\u0E25\u0E31\u0E1A\u0E44\u0E1B\u0E17\u0E35\u0E48 Terminal \u0E44\u0E14\u0E49\u0E17\u0E31\u0E19\u0E17\u0E35</p>
|
|
304
|
+
</div>
|
|
305
|
+
</body>
|
|
306
|
+
</html>`;
|
|
307
|
+
async function startCliLoopbackAuth(baseUrl, timeoutMs = 18e4) {
|
|
308
|
+
const state = randomBytes(16).toString("hex");
|
|
309
|
+
let resolveToken;
|
|
310
|
+
let rejectToken;
|
|
311
|
+
let settled = false;
|
|
312
|
+
const waitForToken = new Promise((resolve3, reject) => {
|
|
313
|
+
resolveToken = resolve3;
|
|
314
|
+
rejectToken = reject;
|
|
315
|
+
});
|
|
316
|
+
const server = createServer((req, res) => {
|
|
317
|
+
const reqUrl = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
318
|
+
if (req.method !== "GET" || reqUrl.pathname !== "/callback") {
|
|
319
|
+
res.writeHead(404, { "cache-control": "no-store" });
|
|
320
|
+
res.end("Not found");
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const returnedState = reqUrl.searchParams.get("state") ?? "";
|
|
324
|
+
const token = reqUrl.searchParams.get("token") ?? "";
|
|
325
|
+
if (returnedState !== state || !TOKEN_SHAPE.test(token)) {
|
|
326
|
+
res.writeHead(400, { "cache-control": "no-store" });
|
|
327
|
+
res.end("Invalid state or token");
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
res.writeHead(200, {
|
|
331
|
+
"content-type": "text/html; charset=utf-8",
|
|
332
|
+
"cache-control": "no-store"
|
|
333
|
+
});
|
|
334
|
+
res.end(CLI_CALLBACK_HTML);
|
|
335
|
+
settled = true;
|
|
336
|
+
cleanup();
|
|
337
|
+
resolveToken(token);
|
|
338
|
+
});
|
|
339
|
+
await new Promise((resolveListen, rejectListen) => {
|
|
340
|
+
server.once("error", rejectListen);
|
|
341
|
+
server.listen(0, "127.0.0.1", () => resolveListen());
|
|
342
|
+
});
|
|
343
|
+
const port = server.address().port;
|
|
344
|
+
const timer = setTimeout(() => {
|
|
345
|
+
if (settled) return;
|
|
346
|
+
settled = true;
|
|
347
|
+
cleanup();
|
|
348
|
+
rejectToken(new Error("\u0E2B\u0E21\u0E14\u0E40\u0E27\u0E25\u0E32\u0E23\u0E2D\u0E01\u0E32\u0E23\u0E2D\u0E19\u0E38\u0E0D\u0E32\u0E15\u0E08\u0E32\u0E01\u0E40\u0E1A\u0E23\u0E32\u0E27\u0E4C\u0E40\u0E0B\u0E2D\u0E23\u0E4C"));
|
|
349
|
+
}, timeoutMs);
|
|
350
|
+
timer.unref?.();
|
|
351
|
+
function cleanup() {
|
|
352
|
+
clearTimeout(timer);
|
|
353
|
+
try {
|
|
354
|
+
server.closeAllConnections?.();
|
|
355
|
+
server.close();
|
|
356
|
+
} catch {
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const cleanBase = baseUrl.replace(/\/+$/, "");
|
|
360
|
+
const authorizeUrl = `${cleanBase}/dashboard/ai?ide_port=${port}&ide_state=${state}&ide_name=${encodeURIComponent("Luaward CLI")}`;
|
|
361
|
+
return {
|
|
362
|
+
authorizeUrl,
|
|
363
|
+
port,
|
|
364
|
+
state,
|
|
365
|
+
waitForToken,
|
|
366
|
+
cancel: () => {
|
|
367
|
+
if (settled) return;
|
|
368
|
+
settled = true;
|
|
369
|
+
cleanup();
|
|
370
|
+
rejectToken(new Error("\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01\u0E01\u0E32\u0E23\u0E25\u0E47\u0E2D\u0E01\u0E2D\u0E34\u0E19"));
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/commands.ts
|
|
376
|
+
var c = {
|
|
377
|
+
red: (s) => `\x1B[38;2;229;9;20m${s}\x1B[0m`,
|
|
378
|
+
green: (s) => `\x1B[38;2;39;209;127m${s}\x1B[0m`,
|
|
379
|
+
yellow: (s) => `\x1B[38;2;242;176;60m${s}\x1B[0m`,
|
|
380
|
+
blue: (s) => `\x1B[38;2;138;180;255m${s}\x1B[0m`,
|
|
381
|
+
dim: (s) => `\x1B[2m${s}\x1B[0m`,
|
|
382
|
+
bold: (s) => `\x1B[1m${s}\x1B[0m`
|
|
383
|
+
};
|
|
384
|
+
function slugify(name) {
|
|
385
|
+
return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "main";
|
|
386
|
+
}
|
|
387
|
+
function openBrowser(url) {
|
|
388
|
+
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
389
|
+
const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
|
|
390
|
+
try {
|
|
391
|
+
const child = spawn(cmd, args, { stdio: "ignore", detached: true });
|
|
392
|
+
child.unref();
|
|
393
|
+
} catch {
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function makeOutput(options) {
|
|
397
|
+
const rawLog = options.log ?? console.log;
|
|
398
|
+
return {
|
|
399
|
+
log: options.json ? () => {
|
|
400
|
+
} : rawLog,
|
|
401
|
+
writeJson: (data) => rawLog(JSON.stringify(data, null, 2))
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
function getWorkspaceContext(startCwd) {
|
|
405
|
+
const cwd = resolve2(startCwd ?? process.cwd());
|
|
406
|
+
const found = findManifest(cwd);
|
|
407
|
+
return {
|
|
408
|
+
cwd,
|
|
409
|
+
workspaceDir: found?.dir ?? cwd,
|
|
410
|
+
manifest: found?.manifest ?? null
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
function selectProject(projects, projectRef) {
|
|
414
|
+
if (projects.length === 0) {
|
|
415
|
+
throw new Error("\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35\u0E42\u0E1B\u0E23\u0E40\u0E08\u0E01\u0E15\u0E4C\u0E43\u0E19\u0E40\u0E27\u0E34\u0E23\u0E4C\u0E01\u0E2A\u0E40\u0E1B\u0E0B \u0E01\u0E23\u0E38\u0E13\u0E32\u0E2A\u0E23\u0E49\u0E32\u0E07\u0E42\u0E1B\u0E23\u0E40\u0E08\u0E01\u0E15\u0E4C\u0E1A\u0E19\u0E41\u0E14\u0E0A\u0E1A\u0E2D\u0E23\u0E4C\u0E14\u0E01\u0E48\u0E2D\u0E19");
|
|
416
|
+
}
|
|
417
|
+
if (!projectRef) return projects[0];
|
|
418
|
+
const match = projects.find(
|
|
419
|
+
(p) => p.id === projectRef || p.name.toLowerCase() === projectRef.toLowerCase()
|
|
420
|
+
);
|
|
421
|
+
if (!match) {
|
|
422
|
+
const available = projects.map((p) => `${p.name} (${p.id})`).join(", ");
|
|
423
|
+
throw new Error(`\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E42\u0E1B\u0E23\u0E40\u0E08\u0E01\u0E15\u0E4C "${projectRef}" (\u0E17\u0E35\u0E48\u0E21\u0E35\u0E43\u0E19\u0E40\u0E27\u0E34\u0E23\u0E4C\u0E01\u0E2A\u0E40\u0E1B\u0E0B: ${available})`);
|
|
424
|
+
}
|
|
425
|
+
return match;
|
|
426
|
+
}
|
|
427
|
+
async function resolveProjectId(client, manifest, projectRef) {
|
|
428
|
+
if (projectRef) {
|
|
429
|
+
if (isHex32(projectRef)) return projectRef.toLowerCase();
|
|
430
|
+
const ws2 = await client.workspace();
|
|
431
|
+
return selectProject(ws2.projects, projectRef).id;
|
|
432
|
+
}
|
|
433
|
+
if (manifest?.projectId) return manifest.projectId;
|
|
434
|
+
const ws = await client.workspace();
|
|
435
|
+
if (ws.projects.length === 1 && ws.projects[0]) return ws.projects[0].id;
|
|
436
|
+
throw new Error("\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38 --project <id-or-name> \u0E2B\u0E23\u0E37\u0E2D\u0E23\u0E31\u0E19\u0E43\u0E19\u0E42\u0E1F\u0E25\u0E40\u0E14\u0E2D\u0E23\u0E4C\u0E17\u0E35\u0E48\u0E21\u0E35 luaward.json");
|
|
437
|
+
}
|
|
438
|
+
function matchManifestEntries(manifest, workspaceDir, cwd, target) {
|
|
439
|
+
const entries = Object.entries(manifest.scripts);
|
|
440
|
+
if (!target) return entries;
|
|
441
|
+
const targetAbs = resolve2(cwd, target);
|
|
442
|
+
const targetLower = target.toLowerCase();
|
|
443
|
+
return entries.filter(
|
|
444
|
+
([alias, item]) => alias === target || item.id === target || item.file === target || item.name?.toLowerCase() === targetLower || resolve2(workspaceDir, item.file) === targetAbs
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
async function resolveScriptTarget(client, ctx, target) {
|
|
448
|
+
if (ctx.manifest) {
|
|
449
|
+
const matched = matchManifestEntries(ctx.manifest, ctx.workspaceDir, ctx.cwd, target);
|
|
450
|
+
if (target && matched.length === 1 && matched[0]) {
|
|
451
|
+
const [alias, item] = matched[0];
|
|
452
|
+
if (!item.id) {
|
|
453
|
+
throw new Error(
|
|
454
|
+
`\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C "${alias}" \u0E43\u0E19 ${MANIFEST_FILE} \u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35 id - \u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E31\u0E19 \`luaward push ${alias}\` \u0E01\u0E48\u0E2D\u0E19`
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
return { id: item.id, name: item.name ?? alias, alias };
|
|
458
|
+
}
|
|
459
|
+
if (!target) {
|
|
460
|
+
const linked = matched.filter(([, item]) => Boolean(item.id));
|
|
461
|
+
if (linked.length === 1 && linked[0]) {
|
|
462
|
+
const [alias, item] = linked[0];
|
|
463
|
+
return { id: item.id, name: item.name ?? alias, alias };
|
|
464
|
+
}
|
|
465
|
+
if (linked.length > 1) {
|
|
466
|
+
const names = linked.map(([alias]) => alias).join(", ");
|
|
467
|
+
throw new Error(`\u0E21\u0E35\u0E2B\u0E25\u0E32\u0E22\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C\u0E43\u0E19 ${MANIFEST_FILE} \u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E0A\u0E37\u0E48\u0E2D\u0E2B\u0E23\u0E37\u0E2D alias (\u0E40\u0E0A\u0E48\u0E19 ${names})`);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
if (target && isHex32(target)) {
|
|
472
|
+
return { id: target.toLowerCase(), name: target.toLowerCase() };
|
|
473
|
+
}
|
|
474
|
+
const ws = await client.workspace();
|
|
475
|
+
if (target) {
|
|
476
|
+
const lower = target.toLowerCase();
|
|
477
|
+
const found = ws.scripts.filter((s) => s.id === target || s.name.toLowerCase() === lower);
|
|
478
|
+
if (found.length === 1 && found[0]) {
|
|
479
|
+
return { id: found[0].id, name: found[0].name };
|
|
480
|
+
}
|
|
481
|
+
if (found.length > 1) {
|
|
482
|
+
throw new Error(
|
|
483
|
+
`\u0E1E\u0E1A\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C\u0E0A\u0E37\u0E48\u0E2D "${target}" \u0E21\u0E32\u0E01\u0E01\u0E27\u0E48\u0E32 1 \u0E23\u0E32\u0E22\u0E01\u0E32\u0E23 \u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38 script ID \u0E41\u0E17\u0E19: ${found.map((s) => s.id).join(", ")}`
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
throw new Error(`\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C "${target}" \u0E43\u0E19 ${MANIFEST_FILE} \u0E2B\u0E23\u0E37\u0E2D\u0E40\u0E27\u0E34\u0E23\u0E4C\u0E01\u0E2A\u0E40\u0E1B\u0E0B`);
|
|
487
|
+
}
|
|
488
|
+
if (ws.scripts.length === 1 && ws.scripts[0]) {
|
|
489
|
+
return { id: ws.scripts[0].id, name: ws.scripts[0].name };
|
|
490
|
+
}
|
|
491
|
+
throw new Error("\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E0A\u0E37\u0E48\u0E2D\u0E44\u0E1F\u0E25\u0E4C alias \u0E2B\u0E23\u0E37\u0E2D script ID");
|
|
492
|
+
}
|
|
493
|
+
function resolveSession(ws, sid) {
|
|
494
|
+
if (ws.sessions.length === 0) {
|
|
495
|
+
const pairHint = ws.pairCommand ? `
|
|
496
|
+
\u0E27\u0E32\u0E07\u0E04\u0E33\u0E2A\u0E31\u0E48\u0E07\u0E19\u0E35\u0E49\u0E43\u0E19 Executor \u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E40\u0E01\u0E21:
|
|
497
|
+
${c.blue(ws.pairCommand)}` : "\n \u0E23\u0E31\u0E19 `luaward pair` \u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E23\u0E31\u0E1A\u0E04\u0E33\u0E2A\u0E31\u0E48\u0E07\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E40\u0E01\u0E21";
|
|
498
|
+
throw new Error(`\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35\u0E40\u0E01\u0E21 Roblox \u0E17\u0E35\u0E48\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E2D\u0E22\u0E39\u0E48\u0E43\u0E19\u0E02\u0E13\u0E30\u0E19\u0E35\u0E49${pairHint}`);
|
|
499
|
+
}
|
|
500
|
+
if (!sid) return ws.sessions[0];
|
|
501
|
+
const exact = ws.sessions.find((s) => s.sid === sid || s.sid.startsWith(sid));
|
|
502
|
+
if (!exact) {
|
|
503
|
+
const active = ws.sessions.map((s) => `${s.sid} (${s.game})`).join(", ");
|
|
504
|
+
throw new Error(`\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E40\u0E0B\u0E2A\u0E0A\u0E31\u0E19 "${sid}" (\u0E40\u0E0B\u0E2A\u0E0A\u0E31\u0E19\u0E17\u0E35\u0E48\u0E01\u0E33\u0E25\u0E31\u0E07\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E2D\u0E22\u0E39\u0E48: ${active})`);
|
|
505
|
+
}
|
|
506
|
+
return exact;
|
|
507
|
+
}
|
|
508
|
+
async function waitForBuildReady(client, scriptId, buildId, name, options) {
|
|
509
|
+
const timeoutMs = options.timeoutMs ?? 12e4;
|
|
510
|
+
const pollIntervalMs = options.pollIntervalMs ?? 1200;
|
|
511
|
+
const deadline = Date.now() + timeoutMs;
|
|
512
|
+
let lastStatus = "queued";
|
|
513
|
+
let lastVersion = 0;
|
|
514
|
+
while (true) {
|
|
515
|
+
const b = await client.buildStatus(scriptId, buildId);
|
|
516
|
+
lastStatus = b.status;
|
|
517
|
+
lastVersion = b.version;
|
|
518
|
+
if (b.status === "ready") {
|
|
519
|
+
const kb = b.sizeBytes ? ` (${(b.sizeBytes / 1024).toFixed(1)} KB)` : "";
|
|
520
|
+
options.log(`${c.green("\u2713")} Build ${c.bold(name)} v${b.version} \u0E1E\u0E23\u0E49\u0E2D\u0E21\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19\u0E41\u0E25\u0E49\u0E27${kb}`);
|
|
521
|
+
return { version: b.version, status: "ready", sizeBytes: b.sizeBytes };
|
|
522
|
+
}
|
|
523
|
+
if (b.status === "failed") {
|
|
524
|
+
throw new Error(`\u0E01\u0E32\u0E23\u0E04\u0E2D\u0E21\u0E44\u0E1E\u0E25\u0E4C ${name} v${b.version} \u0E25\u0E49\u0E21\u0E40\u0E2B\u0E25\u0E27: ${b.error ?? "Unknown error"}`);
|
|
525
|
+
}
|
|
526
|
+
if (Date.now() >= deadline) {
|
|
527
|
+
const secs = Math.round(timeoutMs / 1e3);
|
|
528
|
+
throw new Error(
|
|
529
|
+
`\u0E23\u0E2D\u0E1C\u0E25\u0E04\u0E2D\u0E21\u0E44\u0E1E\u0E25\u0E4C ${name} v${lastVersion} \u0E40\u0E01\u0E34\u0E19 ${secs} \u0E27\u0E34\u0E19\u0E32\u0E17\u0E35 (\u0E2A\u0E16\u0E32\u0E19\u0E30\u0E25\u0E48\u0E32\u0E2A\u0E38\u0E14: ${lastStatus}) - \u0E15\u0E23\u0E27\u0E08\u0E15\u0E48\u0E2D\u0E44\u0E14\u0E49\u0E1A\u0E19\u0E41\u0E14\u0E0A\u0E1A\u0E2D\u0E23\u0E4C\u0E14\u0E2B\u0E23\u0E37\u0E2D\u0E43\u0E0A\u0E49 --no-wait`
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
await new Promise((r) => setTimeout(r, pollIntervalMs));
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
function getAuthenticatedClient(cwd = process.cwd(), flags = {}) {
|
|
536
|
+
const { token, apiUrl } = resolveAuth(cwd, flags);
|
|
537
|
+
if (!token) {
|
|
538
|
+
throw new Error("\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E44\u0E14\u0E49\u0E40\u0E02\u0E49\u0E32\u0E2A\u0E39\u0E48\u0E23\u0E30\u0E1A\u0E1A \u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E31\u0E19 `luaward login` \u0E2B\u0E23\u0E37\u0E2D\u0E15\u0E31\u0E49\u0E07\u0E04\u0E48\u0E32\u0E15\u0E31\u0E27\u0E41\u0E1B\u0E23\u0E41\u0E27\u0E14\u0E25\u0E49\u0E2D\u0E21 `LUAWARD_TOKEN=lwm_\u2026`");
|
|
539
|
+
}
|
|
540
|
+
return new LuawardCliClient(apiUrl, token);
|
|
541
|
+
}
|
|
542
|
+
async function cmdLogin(options = {}) {
|
|
543
|
+
const { log, writeJson } = makeOutput(options);
|
|
544
|
+
const ctx = getWorkspaceContext(options.cwd);
|
|
545
|
+
const apiUrl = (options.apiUrl?.trim() || process.env.LUAWARD_API_URL?.trim() || ctx.manifest?.apiUrl?.trim() || DEFAULT_API_URL).replace(/\/+$/, "");
|
|
546
|
+
let token = options.token?.trim();
|
|
547
|
+
if (!token) {
|
|
548
|
+
const session = await startCliLoopbackAuth(apiUrl);
|
|
549
|
+
log(`${c.red("\u26A1 Luaward CLI")} \u0E40\u0E1B\u0E34\u0E14\u0E40\u0E1A\u0E23\u0E32\u0E27\u0E4C\u0E40\u0E0B\u0E2D\u0E23\u0E4C\u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E2A\u0E34\u0E17\u0E18\u0E34\u0E4C (1-Click Allow):`);
|
|
550
|
+
log(` ${c.blue(session.authorizeUrl)}`);
|
|
551
|
+
openBrowser(session.authorizeUrl);
|
|
552
|
+
token = await session.waitForToken;
|
|
553
|
+
}
|
|
554
|
+
if (!TOKEN_SHAPE.test(token)) {
|
|
555
|
+
throw new Error("\u0E23\u0E39\u0E1B\u0E41\u0E1A\u0E1A\u0E42\u0E17\u0E40\u0E04\u0E19\u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07 (\u0E15\u0E49\u0E2D\u0E07\u0E02\u0E36\u0E49\u0E19\u0E15\u0E49\u0E19\u0E14\u0E49\u0E27\u0E22 lwm_ \u0E15\u0E32\u0E21\u0E14\u0E49\u0E27\u0E22\u0E40\u0E25\u0E02\u0E10\u0E32\u0E19\u0E2A\u0E34\u0E1A\u0E2B\u0E01 48 \u0E15\u0E31\u0E27)");
|
|
556
|
+
}
|
|
557
|
+
const client = new LuawardCliClient(apiUrl, token);
|
|
558
|
+
const ws = await client.workspace();
|
|
559
|
+
writeCredentials(token, apiUrl);
|
|
560
|
+
if (options.json) {
|
|
561
|
+
writeJson({ ok: true, apiUrl, org: ws.org });
|
|
562
|
+
} else {
|
|
563
|
+
log(`${c.green("\u2713")} \u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E01\u0E31\u0E1A\u0E40\u0E27\u0E34\u0E23\u0E4C\u0E01\u0E2A\u0E40\u0E1B\u0E0B ${c.bold(ws.org.name)} (${ws.org.planName}) \u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08!`);
|
|
564
|
+
}
|
|
565
|
+
return { token, orgName: ws.org.name, apiUrl };
|
|
566
|
+
}
|
|
567
|
+
function cmdLogout(options = {}) {
|
|
568
|
+
const opts = typeof options === "function" ? { log: options } : options;
|
|
569
|
+
const { log, writeJson } = makeOutput(opts);
|
|
570
|
+
const removed = clearCredentials();
|
|
571
|
+
if (opts.json) {
|
|
572
|
+
writeJson({ ok: true, removed });
|
|
573
|
+
} else {
|
|
574
|
+
log(removed ? `${c.green("\u2713")} \u0E25\u0E1A\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E01\u0E32\u0E23\u0E40\u0E02\u0E49\u0E32\u0E2A\u0E39\u0E48\u0E23\u0E30\u0E1A\u0E1A\u0E40\u0E23\u0E35\u0E22\u0E1A\u0E23\u0E49\u0E2D\u0E22\u0E41\u0E25\u0E49\u0E27` : "\u0E44\u0E21\u0E48\u0E44\u0E14\u0E49\u0E40\u0E02\u0E49\u0E32\u0E2A\u0E39\u0E48\u0E23\u0E30\u0E1A\u0E1A\u0E44\u0E27\u0E49");
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
async function cmdStatus(options = {}) {
|
|
578
|
+
const { log, writeJson } = makeOutput(options);
|
|
579
|
+
const client = getAuthenticatedClient(options.cwd, options);
|
|
580
|
+
const ws = await client.workspace();
|
|
581
|
+
if (options.json) {
|
|
582
|
+
writeJson(ws);
|
|
583
|
+
return ws;
|
|
584
|
+
}
|
|
585
|
+
log(`${c.red("Luaward")} v${CLI_VERSION} \xB7 ${c.bold(ws.org.name)} (${ws.org.planName})`);
|
|
586
|
+
log(` \u0E42\u0E1B\u0E23\u0E40\u0E08\u0E01\u0E15\u0E4C: ${ws.projects.length} \xB7 \u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C: ${ws.scripts.length} \xB7 \u0E40\u0E01\u0E21\u0E17\u0E35\u0E48\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E2D\u0E22\u0E39\u0E48: ${ws.sessions.length}`);
|
|
587
|
+
if (ws.sessions.length > 0) {
|
|
588
|
+
log(`
|
|
589
|
+
${c.bold("\u0E40\u0E01\u0E21\u0E17\u0E35\u0E48\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E2D\u0E22\u0E39\u0E48 (Test in Game):")}`);
|
|
590
|
+
for (const s of ws.sessions) {
|
|
591
|
+
log(` ${c.green("\u25CF")} ${s.game} (@${s.user}) \xB7 ${s.executor} \xB7 sid=${c.dim(s.sid)}`);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
if (ws.scripts.length > 0) {
|
|
595
|
+
log(`
|
|
596
|
+
${c.bold("\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C\u0E43\u0E19\u0E40\u0E27\u0E34\u0E23\u0E4C\u0E01\u0E2A\u0E40\u0E1B\u0E0B:")}`);
|
|
597
|
+
for (const s of ws.scripts) {
|
|
598
|
+
const st = !s.enabled ? c.yellow("PAUSED") : c.green(`v${s.version} (${s.preset})`);
|
|
599
|
+
log(` - ${c.bold(s.name)} [${st}] \xB7 id=${c.dim(s.id)} \xB7 \u0E42\u0E1B\u0E23\u0E40\u0E08\u0E01\u0E15\u0E4C ${s.projectName}`);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return ws;
|
|
603
|
+
}
|
|
604
|
+
async function cmdInit(options = {}) {
|
|
605
|
+
const cwd = resolve2(options.cwd ?? process.cwd());
|
|
606
|
+
const { log, writeJson } = makeOutput(options);
|
|
607
|
+
const manifestPath = join2(cwd, MANIFEST_FILE);
|
|
608
|
+
const existing = existsSync2(manifestPath) ? readManifest(cwd) : null;
|
|
609
|
+
if (existing && !options.force && !options.merge) {
|
|
610
|
+
throw new Error(
|
|
611
|
+
`\u0E1E\u0E1A\u0E44\u0E1F\u0E25\u0E4C ${MANIFEST_FILE} \u0E2D\u0E22\u0E39\u0E48\u0E41\u0E25\u0E49\u0E27\u0E43\u0E19\u0E42\u0E1F\u0E25\u0E40\u0E14\u0E2D\u0E23\u0E4C\u0E19\u0E35\u0E49 - \u0E43\u0E0A\u0E49 --merge \u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E40\u0E1E\u0E34\u0E48\u0E21\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C\u0E43\u0E2B\u0E21\u0E48\u0E42\u0E14\u0E22\u0E04\u0E07\u0E04\u0E48\u0E32\u0E40\u0E14\u0E34\u0E21 \u0E2B\u0E23\u0E37\u0E2D --force \u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E2A\u0E23\u0E49\u0E32\u0E07\u0E17\u0E31\u0E1A`
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
const client = getAuthenticatedClient(cwd, options);
|
|
615
|
+
const ws = await client.workspace();
|
|
616
|
+
const chosenProject = selectProject(
|
|
617
|
+
ws.projects,
|
|
618
|
+
options.project ?? (options.merge ? existing?.projectId : void 0)
|
|
619
|
+
);
|
|
620
|
+
const projectScripts = ws.scripts.filter((s) => s.projectId === chosenProject.id);
|
|
621
|
+
const scriptsMap = options.merge && existing ? { ...existing.scripts } : {};
|
|
622
|
+
const usedAliases = new Set(Object.keys(scriptsMap));
|
|
623
|
+
const mappedIds = new Set(
|
|
624
|
+
Object.values(scriptsMap).map((entry) => entry.id).filter((id) => Boolean(id))
|
|
625
|
+
);
|
|
626
|
+
let addedCount = 0;
|
|
627
|
+
for (const s of projectScripts) {
|
|
628
|
+
if (mappedIds.has(s.id)) continue;
|
|
629
|
+
let alias = slugify(s.name);
|
|
630
|
+
let idx = 2;
|
|
631
|
+
while (usedAliases.has(alias)) {
|
|
632
|
+
alias = `${slugify(s.name)}-${idx++}`;
|
|
633
|
+
}
|
|
634
|
+
usedAliases.add(alias);
|
|
635
|
+
mappedIds.add(s.id);
|
|
636
|
+
scriptsMap[alias] = {
|
|
637
|
+
id: s.id,
|
|
638
|
+
name: s.name,
|
|
639
|
+
file: `src/${alias}.luau`,
|
|
640
|
+
preset: s.preset
|
|
641
|
+
};
|
|
642
|
+
addedCount++;
|
|
643
|
+
}
|
|
644
|
+
if (Object.keys(scriptsMap).length === 0) {
|
|
645
|
+
scriptsMap.main = {
|
|
646
|
+
name: "Main Script",
|
|
647
|
+
file: "src/main.luau",
|
|
648
|
+
preset: "balanced"
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
const manifest = {
|
|
652
|
+
...existing?.apiUrl ? { apiUrl: existing.apiUrl } : {},
|
|
653
|
+
projectId: chosenProject.id,
|
|
654
|
+
projectName: chosenProject.name,
|
|
655
|
+
scripts: scriptsMap
|
|
656
|
+
};
|
|
657
|
+
const filePath = writeManifest(manifest, cwd);
|
|
658
|
+
const summaryVerb = options.merge ? `\u0E2D\u0E31\u0E1B\u0E40\u0E14\u0E15 ${MANIFEST_FILE} (+${addedCount} \u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C\u0E43\u0E2B\u0E21\u0E48)` : `\u0E2A\u0E23\u0E49\u0E32\u0E07\u0E44\u0E1F\u0E25\u0E4C ${MANIFEST_FILE}`;
|
|
659
|
+
log(
|
|
660
|
+
`${c.green("\u2713")} ${summaryVerb} \u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A\u0E42\u0E1B\u0E23\u0E40\u0E08\u0E01\u0E15\u0E4C ${c.bold(chosenProject.name)} (\u0E23\u0E27\u0E21 ${Object.keys(scriptsMap).length} \u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C) \u0E17\u0E35\u0E48 ${filePath}`
|
|
661
|
+
);
|
|
662
|
+
if (options.pull) {
|
|
663
|
+
await cmdPull({ ...options, cwd, json: false });
|
|
664
|
+
}
|
|
665
|
+
if (options.json) {
|
|
666
|
+
writeJson({ filePath, merged: Boolean(options.merge), addedCount, manifest });
|
|
667
|
+
}
|
|
668
|
+
return manifest;
|
|
669
|
+
}
|
|
670
|
+
async function cmdPull(options = {}) {
|
|
671
|
+
const ctx = getWorkspaceContext(options.cwd);
|
|
672
|
+
const { log, writeJson } = makeOutput(options);
|
|
673
|
+
const client = getAuthenticatedClient(ctx.cwd, options);
|
|
674
|
+
const targetIsDirectHex = Boolean(options.target && isHex32(options.target));
|
|
675
|
+
const matchedInManifest = ctx.manifest ? matchManifestEntries(ctx.manifest, ctx.workspaceDir, ctx.cwd, options.target) : [];
|
|
676
|
+
if (targetIsDirectHex && matchedInManifest.length === 0) {
|
|
677
|
+
const pulled = await client.pullSource(options.target.toLowerCase());
|
|
678
|
+
if (options.stdout) {
|
|
679
|
+
process.stdout.write(pulled.source);
|
|
680
|
+
return [
|
|
681
|
+
{ alias: slugify(pulled.name), scriptId: pulled.scriptId, file: "<stdout>", version: pulled.version }
|
|
682
|
+
];
|
|
683
|
+
}
|
|
684
|
+
const relOut = options.out ?? `${slugify(pulled.name)}.luau`;
|
|
685
|
+
const absOut = resolve2(ctx.cwd, relOut);
|
|
686
|
+
mkdirSync2(dirname2(absOut), { recursive: true });
|
|
687
|
+
writeFileSync2(absOut, pulled.source, "utf8");
|
|
688
|
+
log(`${c.green("\u2B07")} \u0E14\u0E36\u0E07\u0E0B\u0E2D\u0E23\u0E4C\u0E2A ${c.bold(pulled.name)} (v${pulled.version}) \u2192 ${relOut}`);
|
|
689
|
+
const out = [
|
|
690
|
+
{ alias: slugify(pulled.name), scriptId: pulled.scriptId, file: relOut, version: pulled.version }
|
|
691
|
+
];
|
|
692
|
+
if (options.json) writeJson(out);
|
|
693
|
+
return out;
|
|
694
|
+
}
|
|
695
|
+
if (!ctx.manifest) {
|
|
696
|
+
throw new Error(`\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E44\u0E1F\u0E25\u0E4C ${MANIFEST_FILE} \u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E31\u0E19 \`luaward init\` \u0E2B\u0E23\u0E37\u0E2D\u0E23\u0E30\u0E1A\u0E38 script ID 32 \u0E2B\u0E25\u0E31\u0E01`);
|
|
697
|
+
}
|
|
698
|
+
if (matchedInManifest.length === 0) {
|
|
699
|
+
throw new Error(`\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C "${options.target}" \u0E43\u0E19 ${MANIFEST_FILE}`);
|
|
700
|
+
}
|
|
701
|
+
let manifestDirty = false;
|
|
702
|
+
const results = [];
|
|
703
|
+
for (const [alias, item] of matchedInManifest) {
|
|
704
|
+
if (!item.id) {
|
|
705
|
+
if (options.target) {
|
|
706
|
+
throw new Error(`\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C "${alias}" \u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35 id \u0E1A\u0E19\u0E40\u0E0B\u0E34\u0E23\u0E4C\u0E1F\u0E40\u0E27\u0E2D\u0E23\u0E4C - \u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E31\u0E19 \`luaward push ${alias}\` \u0E01\u0E48\u0E2D\u0E19`);
|
|
707
|
+
}
|
|
708
|
+
log(`${c.yellow("!")} \u0E02\u0E49\u0E32\u0E21 "${alias}" \u0E40\u0E19\u0E37\u0E48\u0E2D\u0E07\u0E08\u0E32\u0E01\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35 id \u0E1A\u0E19\u0E40\u0E0B\u0E34\u0E23\u0E4C\u0E1F\u0E40\u0E27\u0E2D\u0E23\u0E4C (\u0E23\u0E31\u0E19 push \u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E2A\u0E23\u0E49\u0E32\u0E07\u0E01\u0E48\u0E2D\u0E19)`);
|
|
709
|
+
continue;
|
|
710
|
+
}
|
|
711
|
+
const pulled = await client.pullSource(item.id);
|
|
712
|
+
if (item.name !== pulled.name || item.preset !== pulled.preset) {
|
|
713
|
+
item.name = pulled.name;
|
|
714
|
+
item.preset = pulled.preset;
|
|
715
|
+
manifestDirty = true;
|
|
716
|
+
}
|
|
717
|
+
if (options.stdout && matchedInManifest.length === 1) {
|
|
718
|
+
process.stdout.write(pulled.source);
|
|
719
|
+
results.push({ alias, scriptId: pulled.scriptId, file: "<stdout>", version: pulled.version });
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
const outFile = options.out && matchedInManifest.length === 1 ? resolve2(ctx.cwd, options.out) : resolve2(ctx.workspaceDir, item.file);
|
|
723
|
+
mkdirSync2(dirname2(outFile), { recursive: true });
|
|
724
|
+
writeFileSync2(outFile, pulled.source, "utf8");
|
|
725
|
+
const displayPath = options.out && matchedInManifest.length === 1 ? options.out : item.file;
|
|
726
|
+
log(`${c.green("\u2B07")} \u0E14\u0E36\u0E07\u0E0B\u0E2D\u0E23\u0E4C\u0E2A ${c.bold(pulled.name)} (v${pulled.version}) \u2192 ${displayPath}`);
|
|
727
|
+
results.push({ alias, scriptId: pulled.scriptId, file: displayPath, version: pulled.version });
|
|
728
|
+
}
|
|
729
|
+
if (manifestDirty) {
|
|
730
|
+
writeManifest(ctx.manifest, ctx.workspaceDir);
|
|
731
|
+
}
|
|
732
|
+
if (options.json) {
|
|
733
|
+
writeJson(results);
|
|
734
|
+
}
|
|
735
|
+
return results;
|
|
736
|
+
}
|
|
737
|
+
async function cmdPush(options = {}) {
|
|
738
|
+
if (options.preset !== void 0 && !isValidPreset(options.preset)) {
|
|
739
|
+
throw new Error(`\u0E42\u0E2B\u0E21\u0E14\u0E1B\u0E49\u0E2D\u0E07\u0E01\u0E31\u0E19 "${options.preset}" \u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07 (\u0E23\u0E2D\u0E07\u0E23\u0E31\u0E1A\u0E40\u0E09\u0E1E\u0E32\u0E30 fast, balanced, max)`);
|
|
740
|
+
}
|
|
741
|
+
const ctx = getWorkspaceContext(options.cwd);
|
|
742
|
+
const { log, writeJson } = makeOutput(options);
|
|
743
|
+
const wait = options.wait ?? true;
|
|
744
|
+
const pollIntervalMs = options.pollIntervalMs ?? 1200;
|
|
745
|
+
const timeoutMs = options.timeoutMs ?? 12e4;
|
|
746
|
+
const client = getAuthenticatedClient(ctx.cwd, options);
|
|
747
|
+
if (options.script || options.isNew) {
|
|
748
|
+
if (!options.target) {
|
|
749
|
+
throw new Error("\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E44\u0E1F\u0E25\u0E4C .luau/.lua \u0E17\u0E35\u0E48\u0E15\u0E49\u0E2D\u0E07\u0E01\u0E32\u0E23 deploy");
|
|
750
|
+
}
|
|
751
|
+
const absFile = resolve2(ctx.cwd, options.target);
|
|
752
|
+
if (!existsSync2(absFile)) {
|
|
753
|
+
throw new Error(`\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E44\u0E1F\u0E25\u0E4C ${options.target}`);
|
|
754
|
+
}
|
|
755
|
+
const source = readFileSync2(absFile, "utf8");
|
|
756
|
+
const preset = options.preset;
|
|
757
|
+
let res;
|
|
758
|
+
if (options.isNew) {
|
|
759
|
+
const projectId = await resolveProjectId(client, ctx.manifest, options.project);
|
|
760
|
+
const scriptName = options.name?.trim() || basename(absFile, ".luau").replace(/\.lua$/i, "");
|
|
761
|
+
log(`${c.blue("\u2B06")} \u0E01\u0E33\u0E25\u0E31\u0E07\u0E2A\u0E23\u0E49\u0E32\u0E07\u0E41\u0E25\u0E30\u0E2D\u0E31\u0E1B\u0E42\u0E2B\u0E25\u0E14 ${c.bold(scriptName)} (${options.target})\u2026`);
|
|
762
|
+
res = await client.deployScript({
|
|
763
|
+
projectId,
|
|
764
|
+
name: scriptName,
|
|
765
|
+
source,
|
|
766
|
+
preset: preset ?? "balanced",
|
|
767
|
+
storeSource: options.storeSource
|
|
768
|
+
});
|
|
769
|
+
} else {
|
|
770
|
+
const resolved = await resolveScriptTarget(client, ctx, options.script);
|
|
771
|
+
log(`${c.blue("\u2B06")} \u0E01\u0E33\u0E25\u0E31\u0E07\u0E2D\u0E31\u0E1B\u0E42\u0E2B\u0E25\u0E14 ${c.bold(resolved.name)} (${options.target})\u2026`);
|
|
772
|
+
res = await client.deployScript({
|
|
773
|
+
scriptId: resolved.id,
|
|
774
|
+
source,
|
|
775
|
+
preset,
|
|
776
|
+
storeSource: options.storeSource
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
let finalStatus = res.status;
|
|
780
|
+
let finalVersion = res.version;
|
|
781
|
+
let sizeBytes = null;
|
|
782
|
+
if (wait) {
|
|
783
|
+
const built = await waitForBuildReady(client, res.scriptId, res.buildId, res.name, {
|
|
784
|
+
timeoutMs,
|
|
785
|
+
pollIntervalMs,
|
|
786
|
+
log
|
|
787
|
+
});
|
|
788
|
+
finalStatus = built.status;
|
|
789
|
+
finalVersion = built.version;
|
|
790
|
+
sizeBytes = built.sizeBytes;
|
|
791
|
+
} else {
|
|
792
|
+
log(`${c.green("\u2713")} \u0E40\u0E02\u0E49\u0E32\u0E04\u0E34\u0E27 Build ${c.bold(res.name)} v${res.version} (buildId=${res.buildId})`);
|
|
793
|
+
}
|
|
794
|
+
const single = [
|
|
795
|
+
{
|
|
796
|
+
alias: slugify(res.name),
|
|
797
|
+
scriptId: res.scriptId,
|
|
798
|
+
name: res.name,
|
|
799
|
+
version: finalVersion,
|
|
800
|
+
buildId: res.buildId,
|
|
801
|
+
status: finalStatus,
|
|
802
|
+
sizeBytes
|
|
803
|
+
}
|
|
804
|
+
];
|
|
805
|
+
if (options.json) writeJson(single);
|
|
806
|
+
return single;
|
|
807
|
+
}
|
|
808
|
+
if (!ctx.manifest) {
|
|
809
|
+
throw new Error(`\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E44\u0E1F\u0E25\u0E4C ${MANIFEST_FILE} \u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E31\u0E19 \`luaward init\` \u0E2B\u0E23\u0E37\u0E2D\u0E23\u0E30\u0E1A\u0E38 --script <id> / --new`);
|
|
810
|
+
}
|
|
811
|
+
const entries = matchManifestEntries(ctx.manifest, ctx.workspaceDir, ctx.cwd, options.target);
|
|
812
|
+
if (entries.length === 0) {
|
|
813
|
+
throw new Error(`\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C "${options.target}" \u0E43\u0E19 ${MANIFEST_FILE}`);
|
|
814
|
+
}
|
|
815
|
+
let manifestUpdated = false;
|
|
816
|
+
const deployedList = [];
|
|
817
|
+
for (const [alias, item] of entries) {
|
|
818
|
+
const absFile = resolve2(ctx.workspaceDir, item.file);
|
|
819
|
+
if (!existsSync2(absFile)) {
|
|
820
|
+
throw new Error(`\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E44\u0E1F\u0E25\u0E4C\u0E0B\u0E2D\u0E23\u0E4C\u0E2A\u0E42\u0E04\u0E49\u0E14 ${item.file} \u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C "${alias}"`);
|
|
821
|
+
}
|
|
822
|
+
const source = readFileSync2(absFile, "utf8");
|
|
823
|
+
const preset = options.preset ?? item.preset ?? "balanced";
|
|
824
|
+
const name = item.name ?? alias;
|
|
825
|
+
log(`${c.blue("\u2B06")} \u0E01\u0E33\u0E25\u0E31\u0E07\u0E2D\u0E31\u0E1B\u0E42\u0E2B\u0E25\u0E14 ${c.bold(name)} (${item.file}) \xB7 \u0E42\u0E2B\u0E21\u0E14 ${preset.toUpperCase()}\u2026`);
|
|
826
|
+
const res = await client.deployScript({
|
|
827
|
+
scriptId: item.id,
|
|
828
|
+
projectId: item.id ? void 0 : ctx.manifest.projectId,
|
|
829
|
+
name,
|
|
830
|
+
source,
|
|
831
|
+
preset,
|
|
832
|
+
storeSource: options.storeSource
|
|
833
|
+
});
|
|
834
|
+
if (!item.id || item.name !== res.name || options.preset && item.preset !== options.preset) {
|
|
835
|
+
item.id = res.scriptId;
|
|
836
|
+
item.name = res.name;
|
|
837
|
+
item.preset = res.preset;
|
|
838
|
+
manifestUpdated = true;
|
|
839
|
+
}
|
|
840
|
+
let finalStatus = res.status;
|
|
841
|
+
let finalVersion = res.version;
|
|
842
|
+
let sizeBytes = null;
|
|
843
|
+
if (wait) {
|
|
844
|
+
const built = await waitForBuildReady(client, res.scriptId, res.buildId, res.name, {
|
|
845
|
+
timeoutMs,
|
|
846
|
+
pollIntervalMs,
|
|
847
|
+
log
|
|
848
|
+
});
|
|
849
|
+
finalStatus = built.status;
|
|
850
|
+
finalVersion = built.version;
|
|
851
|
+
sizeBytes = built.sizeBytes;
|
|
852
|
+
} else {
|
|
853
|
+
log(`${c.green("\u2713")} \u0E40\u0E02\u0E49\u0E32\u0E04\u0E34\u0E27 Build ${c.bold(res.name)} v${res.version} (buildId=${res.buildId})`);
|
|
854
|
+
}
|
|
855
|
+
deployedList.push({
|
|
856
|
+
alias,
|
|
857
|
+
scriptId: res.scriptId,
|
|
858
|
+
name: res.name,
|
|
859
|
+
version: finalVersion,
|
|
860
|
+
buildId: res.buildId,
|
|
861
|
+
status: finalStatus,
|
|
862
|
+
sizeBytes
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
if (manifestUpdated) {
|
|
866
|
+
writeManifest(ctx.manifest, ctx.workspaceDir);
|
|
867
|
+
}
|
|
868
|
+
if (options.json) {
|
|
869
|
+
writeJson(deployedList);
|
|
870
|
+
}
|
|
871
|
+
return deployedList;
|
|
872
|
+
}
|
|
873
|
+
async function cmdScripts(options = {}) {
|
|
874
|
+
const ctx = getWorkspaceContext(options.cwd);
|
|
875
|
+
const { log, writeJson } = makeOutput(options);
|
|
876
|
+
const client = getAuthenticatedClient(ctx.cwd, options);
|
|
877
|
+
const ws = await client.workspace();
|
|
878
|
+
let scripts = ws.scripts;
|
|
879
|
+
if (options.project) {
|
|
880
|
+
const proj = selectProject(ws.projects, options.project);
|
|
881
|
+
scripts = scripts.filter((s) => s.projectId === proj.id);
|
|
882
|
+
}
|
|
883
|
+
if (options.json) {
|
|
884
|
+
writeJson(scripts);
|
|
885
|
+
return scripts;
|
|
886
|
+
}
|
|
887
|
+
if (scripts.length === 0) {
|
|
888
|
+
log("\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C\u0E43\u0E19\u0E40\u0E27\u0E34\u0E23\u0E4C\u0E01\u0E2A\u0E40\u0E1B\u0E0B\u0E19\u0E35\u0E49");
|
|
889
|
+
return scripts;
|
|
890
|
+
}
|
|
891
|
+
for (const s of scripts) {
|
|
892
|
+
const state = s.enabled ? c.green("ENABLED") : c.yellow("PAUSED");
|
|
893
|
+
const bStatus = s.buildStatus ? `build=${s.buildStatus}` : "no-build";
|
|
894
|
+
const kb = s.sizeBytes ? ` \xB7 ${(s.sizeBytes / 1024).toFixed(1)} KB` : "";
|
|
895
|
+
log(`- ${c.bold(s.name)} [${state}] v${s.version} (${s.preset}, ${bStatus}${kb})`);
|
|
896
|
+
log(` id=${c.dim(s.id)} \xB7 \u0E42\u0E1B\u0E23\u0E40\u0E08\u0E01\u0E15\u0E4C ${s.projectName}`);
|
|
897
|
+
}
|
|
898
|
+
return scripts;
|
|
899
|
+
}
|
|
900
|
+
async function cmdToggle(options = {}) {
|
|
901
|
+
if (options.preset !== void 0 && !isValidPreset(options.preset)) {
|
|
902
|
+
throw new Error(`\u0E42\u0E2B\u0E21\u0E14\u0E1B\u0E49\u0E2D\u0E07\u0E01\u0E31\u0E19 "${options.preset}" \u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07 (\u0E23\u0E2D\u0E07\u0E23\u0E31\u0E1A\u0E40\u0E09\u0E1E\u0E32\u0E30 fast, balanced, max)`);
|
|
903
|
+
}
|
|
904
|
+
if (options.enabled === void 0 && options.preset === void 0) {
|
|
905
|
+
throw new Error("\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E2D\u0E22\u0E48\u0E32\u0E07\u0E19\u0E49\u0E2D\u0E22\u0E2B\u0E19\u0E36\u0E48\u0E07\u0E2D\u0E22\u0E48\u0E32\u0E07: --enable, --disable \u0E2B\u0E23\u0E37\u0E2D --preset fast|balanced|max");
|
|
906
|
+
}
|
|
907
|
+
const ctx = getWorkspaceContext(options.cwd);
|
|
908
|
+
const { log, writeJson } = makeOutput(options);
|
|
909
|
+
const client = getAuthenticatedClient(ctx.cwd, options);
|
|
910
|
+
const target = await resolveScriptTarget(client, ctx, options.target);
|
|
911
|
+
const res = await client.toggleScript({
|
|
912
|
+
scriptId: target.id,
|
|
913
|
+
enabled: options.enabled,
|
|
914
|
+
preset: options.preset
|
|
915
|
+
});
|
|
916
|
+
if (ctx.manifest && target.alias && ctx.manifest.scripts[target.alias]) {
|
|
917
|
+
const item = ctx.manifest.scripts[target.alias];
|
|
918
|
+
if (item.preset !== res.preset) {
|
|
919
|
+
item.preset = res.preset;
|
|
920
|
+
writeManifest(ctx.manifest, ctx.workspaceDir);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
const stateLabel = res.enabled ? c.green("ENABLED") : c.yellow("PAUSED");
|
|
924
|
+
log(`${c.green("\u2713")} \u0E2D\u0E31\u0E1B\u0E40\u0E14\u0E15 ${c.bold(target.name)}: ${stateLabel} \xB7 preset=${res.preset} (v${res.version})`);
|
|
925
|
+
if (res.buildId && options.wait !== false) {
|
|
926
|
+
await waitForBuildReady(client, res.scriptId, res.buildId, target.name, {
|
|
927
|
+
timeoutMs: options.timeoutMs,
|
|
928
|
+
pollIntervalMs: options.pollIntervalMs,
|
|
929
|
+
log
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
if (options.json) {
|
|
933
|
+
writeJson(res);
|
|
934
|
+
}
|
|
935
|
+
return res;
|
|
936
|
+
}
|
|
937
|
+
async function cmdSessions(options = {}) {
|
|
938
|
+
const { log, writeJson } = makeOutput(options);
|
|
939
|
+
const client = getAuthenticatedClient(options.cwd, options);
|
|
940
|
+
const ws = await client.workspace();
|
|
941
|
+
if (options.json) {
|
|
942
|
+
writeJson({ liveDebug: ws.org.liveDebug, sessions: ws.sessions });
|
|
943
|
+
return ws.sessions;
|
|
944
|
+
}
|
|
945
|
+
if (!ws.org.liveDebug) {
|
|
946
|
+
log(`${c.yellow("!")} \u0E40\u0E27\u0E34\u0E23\u0E4C\u0E01\u0E2A\u0E40\u0E1B\u0E0B ${ws.org.name} (${ws.org.planName}) \u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E40\u0E1B\u0E34\u0E14\u0E2A\u0E34\u0E17\u0E18\u0E34\u0E4C Test in Game / Live Debug`);
|
|
947
|
+
}
|
|
948
|
+
if (ws.sessions.length === 0) {
|
|
949
|
+
log("\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35\u0E40\u0E01\u0E21 Roblox \u0E17\u0E35\u0E48\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E2D\u0E22\u0E39\u0E48 (\u0E23\u0E31\u0E19 `luaward pair` \u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E14\u0E39\u0E04\u0E33\u0E2A\u0E31\u0E48\u0E07\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21)");
|
|
950
|
+
return ws.sessions;
|
|
951
|
+
}
|
|
952
|
+
for (const s of ws.sessions) {
|
|
953
|
+
log(
|
|
954
|
+
`${c.green("\u25CF")} ${c.bold(s.game)} (@${s.user}) \xB7 ${s.executor} \xB7 v${s.ver} \xB7 placeId=${s.placeId} \xB7 sid=${c.dim(s.sid)}`
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
return ws.sessions;
|
|
958
|
+
}
|
|
959
|
+
async function cmdPair(options = {}) {
|
|
960
|
+
const { log, writeJson } = makeOutput(options);
|
|
961
|
+
const client = getAuthenticatedClient(options.cwd, options);
|
|
962
|
+
const res = await client.ensurePairCommand();
|
|
963
|
+
if (options.json) {
|
|
964
|
+
writeJson(res);
|
|
965
|
+
} else {
|
|
966
|
+
log(`${c.bold("\u0E27\u0E32\u0E07\u0E04\u0E33\u0E2A\u0E31\u0E48\u0E07\u0E19\u0E35\u0E49\u0E43\u0E19 Roblox Executor \u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21 Test in Game:")}
|
|
967
|
+
`);
|
|
968
|
+
log(` ${c.blue(res.command)}`);
|
|
969
|
+
}
|
|
970
|
+
return res;
|
|
971
|
+
}
|
|
972
|
+
async function cmdExec(options = {}) {
|
|
973
|
+
if (!options.code?.trim()) {
|
|
974
|
+
throw new Error('\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E42\u0E04\u0E49\u0E14 Luau \u0E2B\u0E23\u0E37\u0E2D @path/to/file.luau \u0E40\u0E0A\u0E48\u0E19 `luaward exec "print(game.PlaceId)"`');
|
|
975
|
+
}
|
|
976
|
+
const ctx = getWorkspaceContext(options.cwd);
|
|
977
|
+
const { log, writeJson } = makeOutput(options);
|
|
978
|
+
const client = getAuthenticatedClient(ctx.cwd, options);
|
|
979
|
+
let code = options.code;
|
|
980
|
+
if (code.startsWith("@")) {
|
|
981
|
+
const fileRef = code.slice(1);
|
|
982
|
+
const abs = resolve2(ctx.cwd, fileRef);
|
|
983
|
+
if (!existsSync2(abs)) {
|
|
984
|
+
throw new Error(`\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E44\u0E1F\u0E25\u0E4C ${fileRef}`);
|
|
985
|
+
}
|
|
986
|
+
code = readFileSync2(abs, "utf8");
|
|
987
|
+
}
|
|
988
|
+
const ws = await client.workspace();
|
|
989
|
+
const session = resolveSession(ws, options.sid);
|
|
990
|
+
const prePoll = await client.pollDebug({ sid: session.sid });
|
|
991
|
+
const { cmd } = await client.execSnippet(session.sid, code);
|
|
992
|
+
log(`${c.red("\u26A1")} \u0E2A\u0E48\u0E07\u0E04\u0E33\u0E2A\u0E31\u0E48\u0E07\u0E44\u0E1B\u0E22\u0E31\u0E07 ${c.bold(session.game)} (cmd=${c.dim(cmd)})`);
|
|
993
|
+
let cursor = prePoll.cursor;
|
|
994
|
+
const collected = [];
|
|
995
|
+
if (options.wait !== false) {
|
|
996
|
+
const waitMs = options.waitMs ?? 3e3;
|
|
997
|
+
const interval = options.pollIntervalMs ?? 400;
|
|
998
|
+
const deadline = Date.now() + waitMs;
|
|
999
|
+
while (Date.now() < deadline) {
|
|
1000
|
+
await new Promise((r) => setTimeout(r, interval));
|
|
1001
|
+
const polled = await client.pollDebug({ sid: session.sid, after: cursor });
|
|
1002
|
+
if (polled.cursor) cursor = polled.cursor;
|
|
1003
|
+
const matching = polled.lines.filter((l) => l.cmd === cmd || l.cmd === null);
|
|
1004
|
+
if (matching.length > 0) {
|
|
1005
|
+
collected.push(...matching);
|
|
1006
|
+
printConsoleLines(matching, log);
|
|
1007
|
+
if (matching.some((l) => l.lv === "error" || l.m.includes("[Luaward]"))) break;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
if (options.json) {
|
|
1012
|
+
writeJson({ sid: session.sid, cmd, lines: collected });
|
|
1013
|
+
}
|
|
1014
|
+
return { sid: session.sid, cmd, lines: collected };
|
|
1015
|
+
}
|
|
1016
|
+
async function cmdStop(options = {}) {
|
|
1017
|
+
const { log, writeJson } = makeOutput(options);
|
|
1018
|
+
const client = getAuthenticatedClient(options.cwd, options);
|
|
1019
|
+
const ws = await client.workspace();
|
|
1020
|
+
const session = resolveSession(ws, options.sid);
|
|
1021
|
+
const res = await client.stopDebug(session.sid);
|
|
1022
|
+
if (options.json) {
|
|
1023
|
+
writeJson({ sid: session.sid, cmd: res.cmd });
|
|
1024
|
+
} else {
|
|
1025
|
+
log(`${c.yellow("\u25A0")} \u0E2A\u0E48\u0E07\u0E04\u0E33\u0E2A\u0E31\u0E48\u0E07\u0E2B\u0E22\u0E38\u0E14\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C\u0E43\u0E19 ${c.bold(session.game)} (cmd=${c.dim(res.cmd)})`);
|
|
1026
|
+
}
|
|
1027
|
+
return { sid: session.sid, cmd: res.cmd };
|
|
1028
|
+
}
|
|
1029
|
+
function formatCodeFrame(source, errorLine) {
|
|
1030
|
+
const lines = source.split("\n");
|
|
1031
|
+
const start = Math.max(1, errorLine - 2);
|
|
1032
|
+
const end = Math.min(lines.length, errorLine + 2);
|
|
1033
|
+
const out = [];
|
|
1034
|
+
for (let ln = start; ln <= end; ln++) {
|
|
1035
|
+
const marker = ln === errorLine ? c.red("\u276F") : " ";
|
|
1036
|
+
const num = String(ln).padStart(4, " ");
|
|
1037
|
+
out.push(` ${marker} ${c.dim(`${num} |`)} ${lines[ln - 1] ?? ""}`);
|
|
1038
|
+
}
|
|
1039
|
+
return out.join("\n");
|
|
1040
|
+
}
|
|
1041
|
+
function printConsoleLines(lines, log) {
|
|
1042
|
+
for (const l of lines) {
|
|
1043
|
+
const t = l.at ? new Date(l.at).toTimeString().slice(0, 8) : "";
|
|
1044
|
+
const tag = l.lv === "error" ? c.red("[ERR]") : l.lv === "warn" ? c.yellow("[WRN]") : l.lv === "agent" ? c.blue("[SYS]") : c.dim("[OUT]");
|
|
1045
|
+
log(` ${c.dim(t)} ${tag} ${l.m}`);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
async function runSingleDevExecution(options) {
|
|
1049
|
+
if (!options.scriptId) {
|
|
1050
|
+
throw new Error(
|
|
1051
|
+
"\u0E15\u0E49\u0E2D\u0E07\u0E23\u0E30\u0E1A\u0E38\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C\u0E40\u0E1B\u0E49\u0E32\u0E2B\u0E21\u0E32\u0E22\u0E01\u0E48\u0E2D\u0E19\u0E23\u0E31\u0E19\u0E43\u0E19\u0E40\u0E01\u0E21 (\u0E43\u0E0A\u0E49 --script <alias-or-id> \u0E2B\u0E23\u0E37\u0E2D\u0E1C\u0E39\u0E01\u0E44\u0E1F\u0E25\u0E4C\u0E43\u0E19 luaward.json \u0E14\u0E49\u0E27\u0E22 `luaward init`)"
|
|
1052
|
+
);
|
|
1053
|
+
}
|
|
1054
|
+
const log = options.log ?? console.log;
|
|
1055
|
+
const source = readFileSync2(options.filePath, "utf8");
|
|
1056
|
+
const fileName = basename(options.filePath);
|
|
1057
|
+
const observe = options.observeSeconds ?? 8;
|
|
1058
|
+
if (!Number.isInteger(observe) || observe < 1 || observe > 30) {
|
|
1059
|
+
throw new Error(`--observe \u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E47\u0E19\u0E08\u0E33\u0E19\u0E27\u0E19\u0E40\u0E15\u0E47\u0E21 1\u201330 \u0E27\u0E34\u0E19\u0E32\u0E17\u0E35 (\u0E44\u0E14\u0E49\u0E23\u0E31\u0E1A ${String(observe)})`);
|
|
1060
|
+
}
|
|
1061
|
+
const pollIntervalMs = options.pollIntervalMs ?? 500;
|
|
1062
|
+
const maxPolls = options.maxPolls ?? Math.max(30, Math.ceil((observe + 15) * 1e3 / pollIntervalMs));
|
|
1063
|
+
log(`${c.red("\u25B6")} \u0E2A\u0E48\u0E07\u0E44\u0E1F\u0E25\u0E4C ${c.bold(fileName)} \u0E40\u0E02\u0E49\u0E32\u0E40\u0E01\u0E21\u0E2A\u0E14 (\u0E42\u0E2B\u0E21\u0E14\u0E44\u0E21\u0E48\u0E17\u0E31\u0E1A\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C\u0E25\u0E39\u0E01\u0E04\u0E49\u0E32 \xB7 \u0E40\u0E1D\u0E49\u0E32\u0E14\u0E39 ${observe}s)\u2026`);
|
|
1064
|
+
const started = await options.client.runLocal({
|
|
1065
|
+
sid: options.sid,
|
|
1066
|
+
source,
|
|
1067
|
+
scriptId: options.scriptId,
|
|
1068
|
+
fileName,
|
|
1069
|
+
observe
|
|
1070
|
+
});
|
|
1071
|
+
let cursor = started.cursor;
|
|
1072
|
+
for (let i = 0; i < maxPolls; i++) {
|
|
1073
|
+
await new Promise((r) => setTimeout(r, pollIntervalMs));
|
|
1074
|
+
const polled = await options.client.pollDebug({
|
|
1075
|
+
sid: options.sid,
|
|
1076
|
+
cmd: started.cmd,
|
|
1077
|
+
after: cursor
|
|
1078
|
+
});
|
|
1079
|
+
if (polled.cursor) cursor = polled.cursor;
|
|
1080
|
+
if (polled.lines.length > 0) {
|
|
1081
|
+
printConsoleLines(polled.lines, log);
|
|
1082
|
+
}
|
|
1083
|
+
if (polled.run && polled.run.status !== "running") {
|
|
1084
|
+
const r = polled.run;
|
|
1085
|
+
if (r.status === "pass") {
|
|
1086
|
+
log(
|
|
1087
|
+
`${c.green("\u2713 \u0E1C\u0E48\u0E32\u0E19\u0E04\u0E23\u0E1A 3 \u0E02\u0E31\u0E49\u0E19")} (Load \u2192 Start \u2192 Observe ${r.observeS}s)${r.totalMs != null ? ` \u0E43\u0E19 ${r.totalMs}ms` : ""}`
|
|
1088
|
+
);
|
|
1089
|
+
} else if (r.status === "fail") {
|
|
1090
|
+
log(
|
|
1091
|
+
`${c.red("\u2715 \u0E1E\u0E31\u0E07\u0E17\u0E35\u0E48\u0E02\u0E31\u0E49\u0E19")} ${c.bold(r.failStage ?? "runtime")}${r.errorLine ? ` (\u0E1A\u0E23\u0E23\u0E17\u0E31\u0E14\u0E17\u0E35\u0E48 ${r.errorLine})` : ""}: ${r.error ?? ""}`
|
|
1092
|
+
);
|
|
1093
|
+
if (r.errorLine) {
|
|
1094
|
+
log(formatCodeFrame(source, r.errorLine));
|
|
1095
|
+
}
|
|
1096
|
+
if (r.hint) {
|
|
1097
|
+
log(` ${c.yellow(`\u{1F4A1} \u0E04\u0E33\u0E41\u0E19\u0E30\u0E19\u0E33: ${r.hint}`)}`);
|
|
1098
|
+
}
|
|
1099
|
+
} else {
|
|
1100
|
+
log(`${c.yellow("!")} \u0E01\u0E32\u0E23\u0E23\u0E31\u0E19\u0E08\u0E1A\u0E14\u0E49\u0E27\u0E22\u0E2A\u0E16\u0E32\u0E19\u0E30 ${r.status}`);
|
|
1101
|
+
}
|
|
1102
|
+
return {
|
|
1103
|
+
status: r.status,
|
|
1104
|
+
errorLine: r.errorLine,
|
|
1105
|
+
error: r.error,
|
|
1106
|
+
hint: r.hint
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
log(`${c.yellow("!")} \u0E2B\u0E21\u0E14\u0E40\u0E27\u0E25\u0E32\u0E23\u0E2D\u0E1C\u0E25\u0E17\u0E14\u0E2A\u0E2D\u0E1A\u0E43\u0E19\u0E40\u0E17\u0E2D\u0E23\u0E4C\u0E21\u0E34\u0E19\u0E31\u0E25 (\u0E2A\u0E16\u0E32\u0E19\u0E30\u0E25\u0E48\u0E32\u0E2A\u0E38\u0E14\u0E22\u0E31\u0E07\u0E40\u0E1B\u0E47\u0E19 running)`);
|
|
1111
|
+
return { status: "running", errorLine: null, error: null, hint: null };
|
|
1112
|
+
}
|
|
1113
|
+
async function cmdDev(options = {}) {
|
|
1114
|
+
const ctx = getWorkspaceContext(options.cwd);
|
|
1115
|
+
const { log, writeJson } = makeOutput(options);
|
|
1116
|
+
const client = getAuthenticatedClient(ctx.cwd, options);
|
|
1117
|
+
const ws = await client.workspace();
|
|
1118
|
+
const session = resolveSession(ws, options.sid);
|
|
1119
|
+
let targetFile;
|
|
1120
|
+
let scriptId;
|
|
1121
|
+
if (options.target && existsSync2(resolve2(ctx.cwd, options.target))) {
|
|
1122
|
+
targetFile = resolve2(ctx.cwd, options.target);
|
|
1123
|
+
if (options.script) {
|
|
1124
|
+
scriptId = (await resolveScriptTarget(client, ctx, options.script)).id;
|
|
1125
|
+
} else if (ctx.manifest) {
|
|
1126
|
+
const match = Object.values(ctx.manifest.scripts).find(
|
|
1127
|
+
(s) => resolve2(ctx.workspaceDir, s.file) === targetFile
|
|
1128
|
+
);
|
|
1129
|
+
scriptId = match?.id;
|
|
1130
|
+
}
|
|
1131
|
+
} else if (ctx.manifest) {
|
|
1132
|
+
const entries = matchManifestEntries(ctx.manifest, ctx.workspaceDir, ctx.cwd, options.target);
|
|
1133
|
+
const entry = entries[0]?.[1];
|
|
1134
|
+
if (!entry) {
|
|
1135
|
+
throw new Error(`\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C "${options.target ?? ""}" \u0E43\u0E19 ${MANIFEST_FILE}`);
|
|
1136
|
+
}
|
|
1137
|
+
targetFile = resolve2(ctx.workspaceDir, entry.file);
|
|
1138
|
+
scriptId = options.script ? (await resolveScriptTarget(client, ctx, options.script)).id : entry.id;
|
|
1139
|
+
} else {
|
|
1140
|
+
throw new Error("\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E44\u0E1F\u0E25\u0E4C .luau/.lua \u0E2B\u0E23\u0E37\u0E2D\u0E2A\u0E23\u0E49\u0E32\u0E07\u0E44\u0E1F\u0E25\u0E4C luaward.json \u0E14\u0E49\u0E27\u0E22 `luaward init`");
|
|
1141
|
+
}
|
|
1142
|
+
if (!existsSync2(targetFile)) {
|
|
1143
|
+
throw new Error(`\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E44\u0E1F\u0E25\u0E4C ${targetFile}`);
|
|
1144
|
+
}
|
|
1145
|
+
if (!scriptId) {
|
|
1146
|
+
throw new Error(
|
|
1147
|
+
`\u0E44\u0E1F\u0E25\u0E4C ${basename(targetFile)} \u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E44\u0E14\u0E49\u0E1C\u0E39\u0E01\u0E01\u0E31\u0E1A\u0E2A\u0E04\u0E23\u0E34\u0E1B\u0E15\u0E4C\u0E43\u0E19 Luaward - \u0E43\u0E0A\u0E49 \`--script <alias-or-id>\` \u0E2B\u0E23\u0E37\u0E2D\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E1C\u0E48\u0E32\u0E19 ${MANIFEST_FILE}`
|
|
1148
|
+
);
|
|
1149
|
+
}
|
|
1150
|
+
log(`${c.green("\u25CF")} \u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E01\u0E31\u0E1A\u0E40\u0E01\u0E21 ${c.bold(session.game)} (@${session.user} \xB7 ${session.executor})`);
|
|
1151
|
+
const firstResult = await runSingleDevExecution({
|
|
1152
|
+
client,
|
|
1153
|
+
sid: session.sid,
|
|
1154
|
+
filePath: targetFile,
|
|
1155
|
+
scriptId,
|
|
1156
|
+
observeSeconds: options.observe,
|
|
1157
|
+
log
|
|
1158
|
+
});
|
|
1159
|
+
if (options.watch === false) {
|
|
1160
|
+
if (options.json) writeJson(firstResult);
|
|
1161
|
+
return firstResult;
|
|
1162
|
+
}
|
|
1163
|
+
const targetDir = dirname2(targetFile);
|
|
1164
|
+
const targetName = basename(targetFile);
|
|
1165
|
+
log(
|
|
1166
|
+
`
|
|
1167
|
+
${c.blue("\u{1F440} \u0E42\u0E2B\u0E21\u0E14 Hot Reload (--watch)")} \u0E01\u0E33\u0E25\u0E31\u0E07\u0E40\u0E1D\u0E49\u0E32\u0E14\u0E39\u0E44\u0E1F\u0E25\u0E4C ${c.bold(targetName)} - \u0E01\u0E14 Save \u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E2A\u0E48\u0E07\u0E40\u0E02\u0E49\u0E32\u0E40\u0E01\u0E21\u0E17\u0E31\u0E19\u0E17\u0E35 (Ctrl+C \u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E2D\u0E2D\u0E01)`
|
|
1168
|
+
);
|
|
1169
|
+
let debounceTimer = null;
|
|
1170
|
+
let running = false;
|
|
1171
|
+
let pendingRerun = false;
|
|
1172
|
+
const triggerRun = async () => {
|
|
1173
|
+
if (running) {
|
|
1174
|
+
pendingRerun = true;
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
running = true;
|
|
1178
|
+
try {
|
|
1179
|
+
await runSingleDevExecution({
|
|
1180
|
+
client,
|
|
1181
|
+
sid: session.sid,
|
|
1182
|
+
filePath: targetFile,
|
|
1183
|
+
scriptId,
|
|
1184
|
+
observeSeconds: options.observe,
|
|
1185
|
+
log
|
|
1186
|
+
});
|
|
1187
|
+
} catch (err) {
|
|
1188
|
+
log(`${c.red("\u2715")} ${err instanceof Error ? err.message : String(err)}`);
|
|
1189
|
+
} finally {
|
|
1190
|
+
running = false;
|
|
1191
|
+
if (pendingRerun) {
|
|
1192
|
+
pendingRerun = false;
|
|
1193
|
+
void triggerRun();
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
};
|
|
1197
|
+
const watcher = watch(targetDir, (_eventType, filename) => {
|
|
1198
|
+
if (filename && filename.toString() !== targetName) return;
|
|
1199
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
1200
|
+
debounceTimer = setTimeout(() => {
|
|
1201
|
+
void triggerRun();
|
|
1202
|
+
}, 180);
|
|
1203
|
+
});
|
|
1204
|
+
await new Promise((resolveStop) => {
|
|
1205
|
+
const shutdown = () => {
|
|
1206
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
1207
|
+
watcher.close();
|
|
1208
|
+
process.off("SIGINT", shutdown);
|
|
1209
|
+
process.off("SIGTERM", shutdown);
|
|
1210
|
+
if (options.stopOnExit) {
|
|
1211
|
+
void client.stopDebug(session.sid).catch(() => {
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
log(`
|
|
1215
|
+
${c.dim("\u0E2B\u0E22\u0E38\u0E14\u0E42\u0E2B\u0E21\u0E14 Hot Reload \u0E41\u0E25\u0E49\u0E27")}`);
|
|
1216
|
+
resolveStop();
|
|
1217
|
+
};
|
|
1218
|
+
process.on("SIGINT", shutdown);
|
|
1219
|
+
process.on("SIGTERM", shutdown);
|
|
1220
|
+
});
|
|
1221
|
+
return firstResult;
|
|
1222
|
+
}
|
|
1223
|
+
async function cmdKeysList(options = {}) {
|
|
1224
|
+
const ctx = getWorkspaceContext(options.cwd);
|
|
1225
|
+
const { log, writeJson } = makeOutput(options);
|
|
1226
|
+
const client = getAuthenticatedClient(ctx.cwd, options);
|
|
1227
|
+
const projectId = await resolveProjectId(client, ctx.manifest, options.project);
|
|
1228
|
+
const limit = options.limit ?? 10;
|
|
1229
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 50) {
|
|
1230
|
+
throw new Error("--limit \u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E47\u0E19\u0E08\u0E33\u0E19\u0E27\u0E19\u0E40\u0E15\u0E47\u0E21 1\u201350");
|
|
1231
|
+
}
|
|
1232
|
+
const { rows } = await client.recentKeys(projectId, limit);
|
|
1233
|
+
if (options.json) {
|
|
1234
|
+
writeJson(rows);
|
|
1235
|
+
return rows;
|
|
1236
|
+
}
|
|
1237
|
+
if (rows.length === 0) {
|
|
1238
|
+
log("\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35 License Key \u0E43\u0E19\u0E42\u0E1B\u0E23\u0E40\u0E08\u0E01\u0E15\u0E4C\u0E19\u0E35\u0E49");
|
|
1239
|
+
return rows;
|
|
1240
|
+
}
|
|
1241
|
+
for (const r of rows) {
|
|
1242
|
+
const status = r.banned ? c.red("BANNED") : c.green(r.status.toUpperCase());
|
|
1243
|
+
const days = r.keyDays ? `${r.keyDays}d` : "lifetime";
|
|
1244
|
+
const meta = [
|
|
1245
|
+
days,
|
|
1246
|
+
`resets=${r.totalResets}`,
|
|
1247
|
+
r.discordId ? `discord=${r.discordId}` : null,
|
|
1248
|
+
r.note ? `note="${r.note}"` : null
|
|
1249
|
+
].filter(Boolean).join(" \xB7 ");
|
|
1250
|
+
log(`- ${c.bold(r.key)} [${status}] \xB7 ${c.dim(meta)}`);
|
|
1251
|
+
}
|
|
1252
|
+
return rows;
|
|
1253
|
+
}
|
|
1254
|
+
async function cmdKeysCreate(options = {}) {
|
|
1255
|
+
const ctx = getWorkspaceContext(options.cwd);
|
|
1256
|
+
const { writeJson } = makeOutput(options);
|
|
1257
|
+
const client = getAuthenticatedClient(ctx.cwd, options);
|
|
1258
|
+
const projectId = await resolveProjectId(client, ctx.manifest, options.project);
|
|
1259
|
+
if (options.days !== void 0 && options.days !== null) {
|
|
1260
|
+
if (!Number.isInteger(options.days) || options.days < 1 || options.days > 36500) {
|
|
1261
|
+
throw new Error("--days \u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E47\u0E19\u0E08\u0E33\u0E19\u0E27\u0E19\u0E40\u0E15\u0E47\u0E21 1\u201336500");
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
if (options.discordId !== void 0 && options.discordId !== null && !isValidDiscordId(options.discordId)) {
|
|
1265
|
+
throw new Error("--discord \u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E47\u0E19 Discord user ID (\u0E15\u0E31\u0E27\u0E40\u0E25\u0E02 15\u201322 \u0E2B\u0E25\u0E31\u0E01)");
|
|
1266
|
+
}
|
|
1267
|
+
const created = await client.createQuickKey({
|
|
1268
|
+
projectId,
|
|
1269
|
+
days: options.days ?? null,
|
|
1270
|
+
note: options.note ?? null,
|
|
1271
|
+
discordId: options.discordId?.trim() ?? null
|
|
1272
|
+
});
|
|
1273
|
+
if (options.json) {
|
|
1274
|
+
writeJson(created);
|
|
1275
|
+
} else {
|
|
1276
|
+
console.log(created.key);
|
|
1277
|
+
}
|
|
1278
|
+
return created;
|
|
1279
|
+
}
|
|
1280
|
+
async function cmdKeysResetHwid(options = {}) {
|
|
1281
|
+
if (!options.keyOrId?.trim()) {
|
|
1282
|
+
throw new Error("\u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E30\u0E1A\u0E38\u0E04\u0E35\u0E22\u0E4C\u0E2B\u0E23\u0E37\u0E2D Discord ID \u0E17\u0E35\u0E48\u0E15\u0E49\u0E2D\u0E07\u0E01\u0E32\u0E23\u0E23\u0E35\u0E40\u0E0B\u0E47\u0E15 HWID");
|
|
1283
|
+
}
|
|
1284
|
+
const ctx = getWorkspaceContext(options.cwd);
|
|
1285
|
+
const { log, writeJson } = makeOutput(options);
|
|
1286
|
+
const client = getAuthenticatedClient(ctx.cwd, options);
|
|
1287
|
+
const projectId = options.project || ctx.manifest?.projectId ? await resolveProjectId(client, ctx.manifest, options.project) : void 0;
|
|
1288
|
+
const res = await client.resetHwid(options.keyOrId.trim(), projectId);
|
|
1289
|
+
if (options.json) {
|
|
1290
|
+
writeJson(res);
|
|
1291
|
+
} else {
|
|
1292
|
+
log(`${c.green("\u2713")} \u0E23\u0E35\u0E40\u0E0B\u0E47\u0E15 HWID \u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08: ${res.key} (\u0E23\u0E27\u0E21 ${res.totalResets} \u0E04\u0E23\u0E31\u0E49\u0E07)`);
|
|
1293
|
+
}
|
|
1294
|
+
return res;
|
|
1295
|
+
}
|
|
1296
|
+
async function cmdErrors(options = {}) {
|
|
1297
|
+
const ctx = getWorkspaceContext(options.cwd);
|
|
1298
|
+
const { log, writeJson } = makeOutput(options);
|
|
1299
|
+
const client = getAuthenticatedClient(ctx.cwd, options);
|
|
1300
|
+
if (options.resolveId) {
|
|
1301
|
+
const nextStatus = options.resolveStatus ?? "resolved";
|
|
1302
|
+
const res = await client.resolveError(options.resolveId, nextStatus);
|
|
1303
|
+
if (options.json) {
|
|
1304
|
+
writeJson(res);
|
|
1305
|
+
} else {
|
|
1306
|
+
log(`${c.green("\u2713")} \u0E2D\u0E31\u0E1B\u0E40\u0E14\u0E15 Error ${options.resolveId} \u0E40\u0E1B\u0E47\u0E19\u0E2A\u0E16\u0E32\u0E19\u0E30 ${nextStatus}`);
|
|
1307
|
+
}
|
|
1308
|
+
return res;
|
|
1309
|
+
}
|
|
1310
|
+
const target = await resolveScriptTarget(client, ctx, options.target);
|
|
1311
|
+
const status = options.status ?? "open";
|
|
1312
|
+
const { rows } = await client.listErrors(target.id, status);
|
|
1313
|
+
if (options.json) {
|
|
1314
|
+
writeJson(rows);
|
|
1315
|
+
return rows;
|
|
1316
|
+
}
|
|
1317
|
+
if (rows.length === 0) {
|
|
1318
|
+
log(`\u{1F389} \u0E44\u0E21\u0E48\u0E21\u0E35 Error \u0E2A\u0E16\u0E32\u0E19\u0E30 "${status}" \u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A ${target.name}`);
|
|
1319
|
+
} else {
|
|
1320
|
+
for (const r of rows) {
|
|
1321
|
+
log(`[\xD7${r.count}] (${r.id}) [${r.status}] ${r.message}${r.hint ? `
|
|
1322
|
+
\u{1F4A1} ${r.hint}` : ""}`);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
return rows;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
// src/cli.ts
|
|
1329
|
+
var BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
|
|
1330
|
+
"help",
|
|
1331
|
+
"version",
|
|
1332
|
+
"json",
|
|
1333
|
+
"force",
|
|
1334
|
+
"merge",
|
|
1335
|
+
"pull",
|
|
1336
|
+
"stdout",
|
|
1337
|
+
"no-wait",
|
|
1338
|
+
"wait",
|
|
1339
|
+
"watch",
|
|
1340
|
+
"no-watch",
|
|
1341
|
+
"new",
|
|
1342
|
+
"enable",
|
|
1343
|
+
"disable",
|
|
1344
|
+
"stop-on-exit",
|
|
1345
|
+
"store-source",
|
|
1346
|
+
"no-store-source"
|
|
1347
|
+
]);
|
|
1348
|
+
function expandShortFlag(arg) {
|
|
1349
|
+
if (arg === "-h") return "--help";
|
|
1350
|
+
if (arg === "-v" || arg === "-V") return "--version";
|
|
1351
|
+
if (arg === "-j") return "--json";
|
|
1352
|
+
return arg;
|
|
1353
|
+
}
|
|
1354
|
+
function parseFlags(argv) {
|
|
1355
|
+
const positional = [];
|
|
1356
|
+
const flags = {};
|
|
1357
|
+
let afterSeparator = false;
|
|
1358
|
+
for (let i = 0; i < argv.length; i++) {
|
|
1359
|
+
const raw = argv[i];
|
|
1360
|
+
if (afterSeparator) {
|
|
1361
|
+
positional.push(raw);
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1364
|
+
if (raw === "--") {
|
|
1365
|
+
afterSeparator = true;
|
|
1366
|
+
continue;
|
|
1367
|
+
}
|
|
1368
|
+
const arg = expandShortFlag(raw);
|
|
1369
|
+
if (arg.startsWith("--")) {
|
|
1370
|
+
const eqIdx = arg.indexOf("=");
|
|
1371
|
+
if (eqIdx !== -1) {
|
|
1372
|
+
const key = arg.slice(2, eqIdx);
|
|
1373
|
+
flags[key] = arg.slice(eqIdx + 1);
|
|
1374
|
+
} else {
|
|
1375
|
+
const key = arg.slice(2);
|
|
1376
|
+
if (BOOLEAN_FLAGS.has(key)) {
|
|
1377
|
+
flags[key] = true;
|
|
1378
|
+
} else {
|
|
1379
|
+
const next = argv[i + 1];
|
|
1380
|
+
if (next === void 0 || next.startsWith("--") && next !== "--") {
|
|
1381
|
+
throw new Error(`\u0E41\u0E1F\u0E25\u0E47\u0E01 --${key} \u0E15\u0E49\u0E2D\u0E07\u0E23\u0E30\u0E1A\u0E38\u0E04\u0E48\u0E32`);
|
|
1382
|
+
}
|
|
1383
|
+
flags[key] = next;
|
|
1384
|
+
i++;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
} else {
|
|
1388
|
+
positional.push(arg);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
return { positional, flags };
|
|
1392
|
+
}
|
|
1393
|
+
function stringFlag(flags, name) {
|
|
1394
|
+
const v = flags[name];
|
|
1395
|
+
return typeof v === "string" ? v : void 0;
|
|
1396
|
+
}
|
|
1397
|
+
function intFlag(flags, name) {
|
|
1398
|
+
const raw = stringFlag(flags, name);
|
|
1399
|
+
if (raw === void 0) return void 0;
|
|
1400
|
+
const n = Number(raw);
|
|
1401
|
+
if (!Number.isInteger(n)) {
|
|
1402
|
+
throw new Error(`\u0E41\u0E1F\u0E25\u0E47\u0E01 --${name} \u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E47\u0E19\u0E08\u0E33\u0E19\u0E27\u0E19\u0E40\u0E15\u0E47\u0E21 (\u0E44\u0E14\u0E49\u0E23\u0E31\u0E1A "${raw}")`);
|
|
1403
|
+
}
|
|
1404
|
+
return n;
|
|
1405
|
+
}
|
|
1406
|
+
function formatHelpText() {
|
|
1407
|
+
return `Luaward CLI (v${CLI_VERSION}) - Luau Protection & Live Game Companion
|
|
1408
|
+
|
|
1409
|
+
Usage:
|
|
1410
|
+
luaward login [--token lwm_\u2026] [--url https://luaward.com]
|
|
1411
|
+
luaward logout
|
|
1412
|
+
luaward status
|
|
1413
|
+
luaward init [--project <id-or-name>] [--merge|--force] [--pull]
|
|
1414
|
+
luaward scripts [--project <id-or-name>]
|
|
1415
|
+
luaward pull [alias-or-script-id] [--out <file>] [--stdout]
|
|
1416
|
+
luaward push [alias-or-file] [--preset fast|balanced|max] [--script <id-or-alias>] [--new --project <id> --name <name>] [--store-source|--no-store-source] [--no-wait] [--timeout <sec>]
|
|
1417
|
+
luaward toggle <alias-or-script-id> [--enable|--disable] [--preset fast|balanced|max] [--no-wait]
|
|
1418
|
+
luaward sessions
|
|
1419
|
+
luaward pair
|
|
1420
|
+
luaward dev [alias-or-file] [--script <id-or-alias>] [--watch|--no-watch] [--session <sid>] [--observe <1-30>] [--stop-on-exit]
|
|
1421
|
+
luaward exec <luau-code|@file.luau> [--session <sid>] [--no-wait] [--timeout <sec>]
|
|
1422
|
+
luaward stop [--session <sid>]
|
|
1423
|
+
luaward keys list [--project <id-or-name>] [--limit <1-50>]
|
|
1424
|
+
luaward keys create [--project <id-or-name>] [--days <N>] [--note <text>] [--discord <id>]
|
|
1425
|
+
luaward keys reset-hwid <key-or-discord-id> [--project <id-or-name>]
|
|
1426
|
+
luaward errors [alias-or-script-id] [--status open|resolved|ignored|all]
|
|
1427
|
+
luaward errors [--resolve <error-id> | --ignore <error-id> | --reopen <error-id>]
|
|
1428
|
+
|
|
1429
|
+
Global options:
|
|
1430
|
+
--token <lwm_\u2026> Personal Luaward token (or LUAWARD_TOKEN)
|
|
1431
|
+
--url <origin> Base origin (default: https://luaward.com)
|
|
1432
|
+
--json, -j Output machine-readable JSON
|
|
1433
|
+
--version, -v Print CLI version
|
|
1434
|
+
--help, -h Show help
|
|
1435
|
+
`;
|
|
1436
|
+
}
|
|
1437
|
+
async function runCli(argv) {
|
|
1438
|
+
const { positional, flags } = parseFlags(argv);
|
|
1439
|
+
const sub = positional[0];
|
|
1440
|
+
const token = stringFlag(flags, "token");
|
|
1441
|
+
const apiUrl = stringFlag(flags, "url");
|
|
1442
|
+
const json = flags.json === true;
|
|
1443
|
+
if (flags.version === true || sub === "version") {
|
|
1444
|
+
console.log(json ? JSON.stringify({ version: CLI_VERSION }) : `luaward/${CLI_VERSION}`);
|
|
1445
|
+
return 0;
|
|
1446
|
+
}
|
|
1447
|
+
if (!sub || sub === "help" || flags.help === true) {
|
|
1448
|
+
console.log(formatHelpText());
|
|
1449
|
+
return 0;
|
|
1450
|
+
}
|
|
1451
|
+
const base = { token, apiUrl, json };
|
|
1452
|
+
switch (sub) {
|
|
1453
|
+
case "login":
|
|
1454
|
+
await cmdLogin(base);
|
|
1455
|
+
return 0;
|
|
1456
|
+
case "logout":
|
|
1457
|
+
cmdLogout({ json });
|
|
1458
|
+
return 0;
|
|
1459
|
+
case "status":
|
|
1460
|
+
case "whoami":
|
|
1461
|
+
await cmdStatus(base);
|
|
1462
|
+
return 0;
|
|
1463
|
+
case "init":
|
|
1464
|
+
await cmdInit({
|
|
1465
|
+
...base,
|
|
1466
|
+
project: stringFlag(flags, "project") ?? positional[1],
|
|
1467
|
+
force: flags.force === true,
|
|
1468
|
+
merge: flags.merge === true,
|
|
1469
|
+
pull: flags.pull === true
|
|
1470
|
+
});
|
|
1471
|
+
return 0;
|
|
1472
|
+
case "scripts":
|
|
1473
|
+
await cmdScripts({
|
|
1474
|
+
...base,
|
|
1475
|
+
project: stringFlag(flags, "project")
|
|
1476
|
+
});
|
|
1477
|
+
return 0;
|
|
1478
|
+
case "pull":
|
|
1479
|
+
await cmdPull({
|
|
1480
|
+
...base,
|
|
1481
|
+
target: positional[1],
|
|
1482
|
+
out: stringFlag(flags, "out"),
|
|
1483
|
+
stdout: flags.stdout === true
|
|
1484
|
+
});
|
|
1485
|
+
return 0;
|
|
1486
|
+
case "push":
|
|
1487
|
+
case "deploy": {
|
|
1488
|
+
if (flags["store-source"] === true && flags["no-store-source"] === true) {
|
|
1489
|
+
throw new Error("\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E43\u0E0A\u0E49 --store-source \u0E41\u0E25\u0E30 --no-store-source \u0E1E\u0E23\u0E49\u0E2D\u0E21\u0E01\u0E31\u0E19\u0E44\u0E14\u0E49");
|
|
1490
|
+
}
|
|
1491
|
+
const storeSource = flags["store-source"] === true ? true : flags["no-store-source"] === true ? false : void 0;
|
|
1492
|
+
const timeoutSec = intFlag(flags, "timeout");
|
|
1493
|
+
await cmdPush({
|
|
1494
|
+
...base,
|
|
1495
|
+
target: positional[1],
|
|
1496
|
+
script: stringFlag(flags, "script"),
|
|
1497
|
+
project: stringFlag(flags, "project"),
|
|
1498
|
+
name: stringFlag(flags, "name"),
|
|
1499
|
+
isNew: flags.new === true,
|
|
1500
|
+
preset: stringFlag(flags, "preset"),
|
|
1501
|
+
storeSource,
|
|
1502
|
+
wait: flags["no-wait"] !== true,
|
|
1503
|
+
timeoutMs: timeoutSec !== void 0 ? timeoutSec * 1e3 : void 0
|
|
1504
|
+
});
|
|
1505
|
+
return 0;
|
|
1506
|
+
}
|
|
1507
|
+
case "toggle": {
|
|
1508
|
+
const enabled = flags.enable === true ? true : flags.disable === true ? false : void 0;
|
|
1509
|
+
if (flags.enable === true && flags.disable === true) {
|
|
1510
|
+
throw new Error("\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E43\u0E0A\u0E49 --enable \u0E41\u0E25\u0E30 --disable \u0E1E\u0E23\u0E49\u0E2D\u0E21\u0E01\u0E31\u0E19\u0E44\u0E14\u0E49");
|
|
1511
|
+
}
|
|
1512
|
+
const timeoutSec = intFlag(flags, "timeout");
|
|
1513
|
+
await cmdToggle({
|
|
1514
|
+
...base,
|
|
1515
|
+
target: positional[1],
|
|
1516
|
+
enabled,
|
|
1517
|
+
preset: stringFlag(flags, "preset"),
|
|
1518
|
+
wait: flags["no-wait"] !== true,
|
|
1519
|
+
timeoutMs: timeoutSec !== void 0 ? timeoutSec * 1e3 : void 0
|
|
1520
|
+
});
|
|
1521
|
+
return 0;
|
|
1522
|
+
}
|
|
1523
|
+
case "sessions":
|
|
1524
|
+
await cmdSessions(base);
|
|
1525
|
+
return 0;
|
|
1526
|
+
case "pair":
|
|
1527
|
+
await cmdPair(base);
|
|
1528
|
+
return 0;
|
|
1529
|
+
case "dev":
|
|
1530
|
+
await cmdDev({
|
|
1531
|
+
...base,
|
|
1532
|
+
target: positional[1],
|
|
1533
|
+
script: stringFlag(flags, "script"),
|
|
1534
|
+
watch: flags["no-watch"] !== true,
|
|
1535
|
+
sid: stringFlag(flags, "session"),
|
|
1536
|
+
observe: intFlag(flags, "observe"),
|
|
1537
|
+
stopOnExit: flags["stop-on-exit"] === true
|
|
1538
|
+
});
|
|
1539
|
+
return 0;
|
|
1540
|
+
case "exec": {
|
|
1541
|
+
const timeoutSec = intFlag(flags, "timeout");
|
|
1542
|
+
await cmdExec({
|
|
1543
|
+
...base,
|
|
1544
|
+
code: positional.slice(1).join(" ") || void 0,
|
|
1545
|
+
sid: stringFlag(flags, "session"),
|
|
1546
|
+
wait: flags["no-wait"] !== true,
|
|
1547
|
+
waitMs: timeoutSec !== void 0 ? timeoutSec * 1e3 : void 0
|
|
1548
|
+
});
|
|
1549
|
+
return 0;
|
|
1550
|
+
}
|
|
1551
|
+
case "stop":
|
|
1552
|
+
await cmdStop({
|
|
1553
|
+
...base,
|
|
1554
|
+
sid: stringFlag(flags, "session") ?? positional[1]
|
|
1555
|
+
});
|
|
1556
|
+
return 0;
|
|
1557
|
+
case "keys": {
|
|
1558
|
+
const action = positional[1];
|
|
1559
|
+
if (action === "list" || action === "ls") {
|
|
1560
|
+
await cmdKeysList({
|
|
1561
|
+
...base,
|
|
1562
|
+
project: stringFlag(flags, "project"),
|
|
1563
|
+
limit: intFlag(flags, "limit")
|
|
1564
|
+
});
|
|
1565
|
+
return 0;
|
|
1566
|
+
}
|
|
1567
|
+
if (action === "create") {
|
|
1568
|
+
await cmdKeysCreate({
|
|
1569
|
+
...base,
|
|
1570
|
+
project: stringFlag(flags, "project"),
|
|
1571
|
+
days: intFlag(flags, "days") ?? null,
|
|
1572
|
+
note: stringFlag(flags, "note") ?? null,
|
|
1573
|
+
discordId: stringFlag(flags, "discord") ?? null
|
|
1574
|
+
});
|
|
1575
|
+
return 0;
|
|
1576
|
+
}
|
|
1577
|
+
if (action === "reset-hwid") {
|
|
1578
|
+
await cmdKeysResetHwid({
|
|
1579
|
+
...base,
|
|
1580
|
+
keyOrId: positional[2],
|
|
1581
|
+
project: stringFlag(flags, "project")
|
|
1582
|
+
});
|
|
1583
|
+
return 0;
|
|
1584
|
+
}
|
|
1585
|
+
throw new Error(
|
|
1586
|
+
"\u0E04\u0E33\u0E2A\u0E31\u0E48\u0E07\u0E17\u0E35\u0E48\u0E23\u0E2D\u0E07\u0E23\u0E31\u0E1A: `luaward keys list`, `luaward keys create` \u0E2B\u0E23\u0E37\u0E2D `luaward keys reset-hwid <key>`"
|
|
1587
|
+
);
|
|
1588
|
+
}
|
|
1589
|
+
case "errors": {
|
|
1590
|
+
const resolveId = stringFlag(flags, "resolve") ?? stringFlag(flags, "ignore") ?? stringFlag(flags, "reopen");
|
|
1591
|
+
const resolveStatus = stringFlag(flags, "ignore") ? "ignored" : stringFlag(flags, "reopen") ? "open" : "resolved";
|
|
1592
|
+
const statusRaw = stringFlag(flags, "status");
|
|
1593
|
+
if (statusRaw && !["open", "resolved", "ignored", "all"].includes(statusRaw)) {
|
|
1594
|
+
throw new Error(`--status "${statusRaw}" \u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07 (\u0E23\u0E2D\u0E07\u0E23\u0E31\u0E1A open, resolved, ignored, all)`);
|
|
1595
|
+
}
|
|
1596
|
+
await cmdErrors({
|
|
1597
|
+
...base,
|
|
1598
|
+
target: positional[1],
|
|
1599
|
+
status: statusRaw,
|
|
1600
|
+
resolveId,
|
|
1601
|
+
resolveStatus
|
|
1602
|
+
});
|
|
1603
|
+
return 0;
|
|
1604
|
+
}
|
|
1605
|
+
default:
|
|
1606
|
+
console.log(formatHelpText());
|
|
1607
|
+
return 1;
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
var entryArg = typeof process !== "undefined" && Array.isArray(process.argv) ? process.argv[1] : void 0;
|
|
1611
|
+
var isEntrypoint = Boolean(
|
|
1612
|
+
entryArg && !entryArg.includes("vitest") && (entryArg.endsWith("/cli.js") || entryArg.endsWith("\\cli.js") || entryArg.endsWith("/cli.ts") || entryArg.endsWith("\\cli.ts") || /(?:^|[/\\])luaward(?:\.cmd|\.ps1)?$/i.test(entryArg))
|
|
1613
|
+
);
|
|
1614
|
+
if (isEntrypoint) {
|
|
1615
|
+
runCli(process.argv.slice(2)).then((code) => {
|
|
1616
|
+
if (code !== 0) process.exitCode = code;
|
|
1617
|
+
}).catch((err) => {
|
|
1618
|
+
const wantJson = process.argv.includes("--json") || process.argv.includes("-j");
|
|
1619
|
+
if (wantJson) {
|
|
1620
|
+
const payload = err && typeof err === "object" && "status" in err && "code" in err ? {
|
|
1621
|
+
ok: false,
|
|
1622
|
+
status: err.status,
|
|
1623
|
+
code: err.code,
|
|
1624
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1625
|
+
} : {
|
|
1626
|
+
ok: false,
|
|
1627
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1628
|
+
};
|
|
1629
|
+
console.error(JSON.stringify(payload, null, 2));
|
|
1630
|
+
} else {
|
|
1631
|
+
console.error(`\u2715 ${err instanceof Error ? err.message : String(err)}`);
|
|
1632
|
+
}
|
|
1633
|
+
process.exitCode = 1;
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
export {
|
|
1637
|
+
formatHelpText,
|
|
1638
|
+
parseFlags,
|
|
1639
|
+
runCli
|
|
1640
|
+
};
|
|
1641
|
+
//# sourceMappingURL=cli.js.map
|