apiblaze 0.21.30 → 0.21.31
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 +86 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34,7 +34,7 @@ var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__
|
|
|
34
34
|
var version;
|
|
35
35
|
var init_package = __esm({
|
|
36
36
|
"package.json"() {
|
|
37
|
-
version = "0.21.
|
|
37
|
+
version = "0.21.31";
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
|
|
@@ -9234,6 +9234,80 @@ function fromNode(dir, out) {
|
|
|
9234
9234
|
out.configuredPort = portFromScripts(scripts);
|
|
9235
9235
|
out.start = scripts.dev ? "npm run dev" : scripts.start ? "npm start" : void 0;
|
|
9236
9236
|
}
|
|
9237
|
+
var ENTRY_FILES = [
|
|
9238
|
+
"server.js",
|
|
9239
|
+
"app.js",
|
|
9240
|
+
"index.js",
|
|
9241
|
+
"main.js",
|
|
9242
|
+
"server.mjs",
|
|
9243
|
+
"app.mjs",
|
|
9244
|
+
"index.mjs",
|
|
9245
|
+
"server.cjs",
|
|
9246
|
+
"server.ts",
|
|
9247
|
+
"app.ts",
|
|
9248
|
+
"index.ts",
|
|
9249
|
+
"main.ts",
|
|
9250
|
+
"src/server.ts",
|
|
9251
|
+
"src/index.ts",
|
|
9252
|
+
"src/app.ts",
|
|
9253
|
+
"src/main.ts",
|
|
9254
|
+
"src/server.js",
|
|
9255
|
+
"src/index.js",
|
|
9256
|
+
"src/app.js",
|
|
9257
|
+
"main.py",
|
|
9258
|
+
"app.py",
|
|
9259
|
+
"server.py",
|
|
9260
|
+
"main.go",
|
|
9261
|
+
"server.go"
|
|
9262
|
+
];
|
|
9263
|
+
var NODE_MODULE_SERVERS = [
|
|
9264
|
+
[/\b(?:require\(\s*|from\s+)['"]express['"]/, "Express"],
|
|
9265
|
+
[/\b(?:require\(\s*|from\s+)['"]fastify['"]/, "Fastify"],
|
|
9266
|
+
[/\b(?:require\(\s*|from\s+)['"]koa['"]/, "Koa"],
|
|
9267
|
+
[/\b(?:require\(\s*|from\s+)['"]hono['"]/, "Hono"],
|
|
9268
|
+
[/\b(?:require\(\s*|from\s+)['"](?:node:)?https?['"]/, "a Node server"]
|
|
9269
|
+
];
|
|
9270
|
+
function portInSource(text) {
|
|
9271
|
+
const m = /\.listen\(\s*(\d{2,5})\b/.exec(text) ?? /\bPORT\b[^\n]{0,40}?(?:\|\||\?\?|or)\s*['"]?(\d{2,5})\b/.exec(text) ?? /\bport\s*[:=]\s*(\d{2,5})\b/.exec(text) ?? /ListenAndServe\(\s*"[^":]*:(\d{2,5})"/.exec(text) ?? /\.run\([^)]*port\s*=\s*(\d{2,5})/.exec(text);
|
|
9272
|
+
return m ? Number(m[1]) : void 0;
|
|
9273
|
+
}
|
|
9274
|
+
function fromEntryFiles(dir, out) {
|
|
9275
|
+
for (const rel of ENTRY_FILES) {
|
|
9276
|
+
const text = readText(import_path4.default.join(dir, rel));
|
|
9277
|
+
if (!text) continue;
|
|
9278
|
+
let fw;
|
|
9279
|
+
let def;
|
|
9280
|
+
if (/\.(c|m)?[jt]s$/.test(rel)) {
|
|
9281
|
+
if (!/\.listen\(|createServer\(|\bserve\(|export default\s+app\b/.test(text)) continue;
|
|
9282
|
+
fw = NODE_MODULE_SERVERS.find(([re]) => re.test(text))?.[1] ?? "a Node server";
|
|
9283
|
+
def = 3e3;
|
|
9284
|
+
} else if (rel.endsWith(".py")) {
|
|
9285
|
+
if (/\bFastAPI\(/.test(text)) {
|
|
9286
|
+
fw = "FastAPI";
|
|
9287
|
+
def = 8e3;
|
|
9288
|
+
} else if (/\bFlask\(/.test(text)) {
|
|
9289
|
+
fw = "Flask";
|
|
9290
|
+
def = 5e3;
|
|
9291
|
+
} else if (/HTTPServer\(|http\.server/.test(text)) {
|
|
9292
|
+
fw = "a Python server";
|
|
9293
|
+
def = 8e3;
|
|
9294
|
+
} else continue;
|
|
9295
|
+
} else if (rel.endsWith(".go")) {
|
|
9296
|
+
if (!/ListenAndServe\(|\.Run\(|\.Start\(|\.Listen\(/.test(text)) continue;
|
|
9297
|
+
fw = GO_SERVERS.find(([re]) => re.test(text))?.[1] ?? "a Go server";
|
|
9298
|
+
def = 8080;
|
|
9299
|
+
}
|
|
9300
|
+
if (!fw) continue;
|
|
9301
|
+
if (!out.framework) {
|
|
9302
|
+
out.framework = fw;
|
|
9303
|
+
out.source = rel;
|
|
9304
|
+
out.defaultPort = def;
|
|
9305
|
+
}
|
|
9306
|
+
if (!out.configuredPort) out.configuredPort = portInSource(text);
|
|
9307
|
+
if (!out.start && rel.endsWith(".js")) out.start = `node ${rel}`;
|
|
9308
|
+
return;
|
|
9309
|
+
}
|
|
9310
|
+
}
|
|
9237
9311
|
function fromPython(dir, out) {
|
|
9238
9312
|
for (const f of ["requirements.txt", "pyproject.toml", "Pipfile"]) {
|
|
9239
9313
|
const text = readText(import_path4.default.join(dir, f));
|
|
@@ -9307,6 +9381,7 @@ async function detectBackend(dir, opts = {}) {
|
|
|
9307
9381
|
fromNode(dir, out);
|
|
9308
9382
|
if (!out.framework) fromPython(dir, out);
|
|
9309
9383
|
if (!out.framework) fromOthers(dir, out);
|
|
9384
|
+
if (!out.frontendOnly && (!out.framework || !out.configuredPort)) fromEntryFiles(dir, out);
|
|
9310
9385
|
const spec2 = findSpecFile(dir);
|
|
9311
9386
|
if (spec2) {
|
|
9312
9387
|
out.specFile = spec2.file;
|
|
@@ -9914,8 +9989,16 @@ async function runForPerson(found) {
|
|
|
9914
9989
|
return;
|
|
9915
9990
|
}
|
|
9916
9991
|
if (report.ownApi) {
|
|
9917
|
-
|
|
9918
|
-
|
|
9992
|
+
const args = ["dev", "--port", String(port ?? 3e3), ...found.specFile ? ["--openapi", found.specFile] : []];
|
|
9993
|
+
const startHint = found.start ? `, once you start it (${found.start})` : ", once it runs";
|
|
9994
|
+
if (!await ask2(` ${import_chalk25.default.bold("?")} Put it behind ${P} now? It reaches your app on port ${port ?? 3e3}${startHint}. ${import_chalk25.default.dim("(Y/n)")} `)) {
|
|
9995
|
+
console.log(` Any time: ${import_chalk25.default.cyan(`${run2} ${args.join(" ")}`)}`);
|
|
9996
|
+
return;
|
|
9997
|
+
}
|
|
9998
|
+
console.log(import_chalk25.default.dim(` $ ${run2} ${args.join(" ")}`));
|
|
9999
|
+
const { spawnSync: spawnSync4 } = await import("child_process");
|
|
10000
|
+
const r = spawnSync4(process.execPath, [process.argv[1], ...args], { stdio: "inherit" });
|
|
10001
|
+
process.exitCode = r.status ?? 0;
|
|
9919
10002
|
return;
|
|
9920
10003
|
}
|
|
9921
10004
|
if (!await ask2(` ${import_chalk25.default.bold("?")} Create a demo app to try out ${P}? ${import_chalk25.default.dim("(Y/n)")} `)) {
|