@lukoweb/apitogo 0.2.44 → 0.2.45

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukoweb/apitogo",
3
- "version": "0.2.44",
3
+ "version": "0.2.45",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "**/*.css",
@@ -463,18 +463,19 @@ async function buildPortal(
463
463
 
464
464
  /**
465
465
  * A managed gateway runs the code in its source folder, and a new project has none. The folder is made (a `.gitkeep`
466
- * keeps it in git) and the user is told it is empty; the full template writes a small Node.js server there instead.
467
- * A folder that has files is left as it is. Returns whether the sample server was written.
466
+ * keeps it in git) and the user is told it is empty; with `writeSample` (the full template's own API) a small Node.js
467
+ * server is written there instead. A folder that has files is left as it is. Returns whether the sample was written.
468
468
  */
469
469
  async function createSourceFolder(
470
470
  context: Context,
471
471
  sourcePath: string,
472
472
  runtime: Runtime,
473
+ writeSample: boolean,
473
474
  ): Promise<boolean> {
474
475
  const folder = path.join(context.dir, sourcePath);
475
476
  const entries = await readdir(folder).catch(() => [] as string[]);
476
477
  if (entries.some((name) => name !== ".gitkeep")) return false;
477
- if (context.options.template === "full" && runtime === FULL_SERVER_RUNTIME) {
478
+ if (writeSample && runtime === FULL_SERVER_RUNTIME) {
478
479
  for (const [file, content] of Object.entries(
479
480
  fullServerFiles(context.resolved.project.name),
480
481
  ))
@@ -495,11 +496,35 @@ async function buildGateway(
495
496
  const { options, dir, resolved } = context;
496
497
  const o = options.gateway ?? {};
497
498
  const ask = options.ask;
498
- // The full template runs a backend of its own, so it asks nothing about the origin.
499
- const full = options.template === "full" && !o.url && o.origin !== "proxy";
499
+ const fullTemplate = options.template === "full";
500
+ // `full`: the platform runs the sample Node.js API in `server/`. That is what a script gets; in a terminal the full
501
+ // template asks first, because the user may have code of their own or an API that already runs somewhere else.
502
+ let full = fullTemplate && !o.url && o.origin !== "proxy";
500
503
  let mode =
501
504
  o.origin ??
502
- (o.url ? "proxy" : o.source || o.runtime || full ? "managed" : undefined);
505
+ (o.url ? "proxy" : o.source || o.runtime ? "managed" : undefined);
506
+ if (fullTemplate && !mode && ask) {
507
+ const answer = await ask.choose("Where is your API?", [
508
+ {
509
+ value: "sample" as const,
510
+ label:
511
+ "I have none yet: create a small Node.js API in server/, ready to deploy",
512
+ },
513
+ {
514
+ value: "own" as const,
515
+ label:
516
+ "My code is in this project (Node.js, Python or .NET): the platform runs it",
517
+ },
518
+ {
519
+ value: "proxy" as const,
520
+ label:
521
+ "It already runs somewhere else: the gateway forwards calls to its https address",
522
+ },
523
+ ]);
524
+ full = answer === "sample";
525
+ mode = answer === "proxy" ? "proxy" : "managed";
526
+ }
527
+ if (!mode && full) mode = "managed";
503
528
  if (!mode && ask) {
504
529
  mode = await ask.choose("How does the gateway reach your API?", [
505
530
  {
@@ -576,7 +601,7 @@ async function buildGateway(
576
601
  );
577
602
  }
578
603
  const sourcePath = insideProject(dir, source, "Source folder");
579
- sampleServer = await createSourceFolder(context, sourcePath, runtime);
604
+ sampleServer = await createSourceFolder(context, sourcePath, runtime, full);
580
605
  origin = {
581
606
  mode,
582
607
  source: sourcePath,
@@ -585,7 +610,7 @@ async function buildGateway(
585
610
  ...(o.exclude?.length ? { exclude: o.exclude } : {}),
586
611
  ...(sampleServer ? { healthPath: FULL_SERVER_HEALTH_PATH } : {}),
587
612
  // A full project's API is hosted by the platform and sleeps when idle; the first call must outlast its start.
588
- ...(full ? { timeoutSeconds: FULL_SERVER_TIMEOUT_SECONDS } : {}),
613
+ ...(fullTemplate ? { timeoutSeconds: FULL_SERVER_TIMEOUT_SECONDS } : {}),
589
614
  };
590
615
  }
591
616