calabasas 0.24.1 → 0.24.2
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/dist/index.js +95 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2262,9 +2262,101 @@ import * as path2 from "path";
|
|
|
2262
2262
|
async function parseConfigFile(configPath) {
|
|
2263
2263
|
const absolutePath = path2.resolve(configPath);
|
|
2264
2264
|
const source = fs2.readFileSync(absolutePath, "utf-8");
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2265
|
+
return parseConfigText(source);
|
|
2266
|
+
}
|
|
2267
|
+
function parseConfigText(source) {
|
|
2268
|
+
const stripped = source.replace(/import\s*\{[^}]*\}\s*from\s*["'][^"']*["'];?/g, "").replace(/export\s+default\s+\(?defineCalabasas(?:\s+as\s+\w+)?\)?\s*\(/, "(").replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "").trim();
|
|
2269
|
+
const start = stripped.indexOf("{");
|
|
2270
|
+
const end = stripped.lastIndexOf("}");
|
|
2271
|
+
if (start === -1 || end === -1 || end <= start) {
|
|
2272
|
+
throw new Error("Could not find defineCalabasas({...}) in config file. Make sure your config uses export default defineCalabasas({...})");
|
|
2273
|
+
}
|
|
2274
|
+
const objectText = stripped.slice(start, end + 1);
|
|
2275
|
+
const json = jsObjectToJson(objectText);
|
|
2276
|
+
try {
|
|
2277
|
+
return JSON.parse(json);
|
|
2278
|
+
} catch (err) {
|
|
2279
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2280
|
+
throw new Error(`Failed to parse config object: ${message}. Check for syntax errors in your config.`);
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
function jsObjectToJson(input) {
|
|
2284
|
+
let result = "";
|
|
2285
|
+
let i = 0;
|
|
2286
|
+
let inString = null;
|
|
2287
|
+
while (i < input.length) {
|
|
2288
|
+
const ch = input[i];
|
|
2289
|
+
if (inString) {
|
|
2290
|
+
if (ch === "\\") {
|
|
2291
|
+
result += ch;
|
|
2292
|
+
i++;
|
|
2293
|
+
if (i < input.length) {
|
|
2294
|
+
result += input[i];
|
|
2295
|
+
i++;
|
|
2296
|
+
}
|
|
2297
|
+
continue;
|
|
2298
|
+
}
|
|
2299
|
+
if (ch === inString) {
|
|
2300
|
+
result += '"';
|
|
2301
|
+
inString = null;
|
|
2302
|
+
i++;
|
|
2303
|
+
continue;
|
|
2304
|
+
}
|
|
2305
|
+
if (inString === "'" && ch === '"') {
|
|
2306
|
+
result += "\\\"";
|
|
2307
|
+
i++;
|
|
2308
|
+
continue;
|
|
2309
|
+
}
|
|
2310
|
+
result += ch;
|
|
2311
|
+
i++;
|
|
2312
|
+
continue;
|
|
2313
|
+
}
|
|
2314
|
+
if (ch === '"' || ch === "'") {
|
|
2315
|
+
inString = ch;
|
|
2316
|
+
result += '"';
|
|
2317
|
+
i++;
|
|
2318
|
+
continue;
|
|
2319
|
+
}
|
|
2320
|
+
if (/[a-zA-Z_$]/.test(ch)) {
|
|
2321
|
+
let ident = "";
|
|
2322
|
+
let j = i;
|
|
2323
|
+
while (j < input.length && /[a-zA-Z_$0-9]/.test(input[j])) {
|
|
2324
|
+
ident += input[j];
|
|
2325
|
+
j++;
|
|
2326
|
+
}
|
|
2327
|
+
let k = j;
|
|
2328
|
+
while (k < input.length && /\s/.test(input[k]))
|
|
2329
|
+
k++;
|
|
2330
|
+
if (k < input.length && input[k] === ":") {
|
|
2331
|
+
result += '"' + ident + '"';
|
|
2332
|
+
i = j;
|
|
2333
|
+
continue;
|
|
2334
|
+
}
|
|
2335
|
+
if (ident === "true" || ident === "false" || ident === "null") {
|
|
2336
|
+
result += ident;
|
|
2337
|
+
i = j;
|
|
2338
|
+
continue;
|
|
2339
|
+
}
|
|
2340
|
+
result += ident;
|
|
2341
|
+
i = j;
|
|
2342
|
+
continue;
|
|
2343
|
+
}
|
|
2344
|
+
if (ch === ",") {
|
|
2345
|
+
let j = i + 1;
|
|
2346
|
+
while (j < input.length && /\s/.test(input[j]))
|
|
2347
|
+
j++;
|
|
2348
|
+
if (j < input.length && (input[j] === "}" || input[j] === "]")) {
|
|
2349
|
+
i++;
|
|
2350
|
+
continue;
|
|
2351
|
+
}
|
|
2352
|
+
result += ch;
|
|
2353
|
+
i++;
|
|
2354
|
+
continue;
|
|
2355
|
+
}
|
|
2356
|
+
result += ch;
|
|
2357
|
+
i++;
|
|
2358
|
+
}
|
|
2359
|
+
return result;
|
|
2268
2360
|
}
|
|
2269
2361
|
|
|
2270
2362
|
// src/lib/intents.ts
|