create-svc 0.1.37 → 0.1.38

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": "create-svc",
3
- "version": "0.1.37",
3
+ "version": "0.1.38",
4
4
  "description": "Local microservice bootstrap CLI for Cloud Run and Workers services with Neon-backed data.",
5
5
  "module": "index.ts",
6
6
  "type": "module",
@@ -2,13 +2,12 @@ import { expect, test } from "bun:test";
2
2
  import { mkdtemp, mkdir, writeFile } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  import { tmpdir } from "node:os";
5
- import { findGeneratedServiceRoot, generatedDependenciesInstalled, normalizeScaffoldArgs } from "./service";
5
+ import { findGeneratedServiceRoot, formatOutsideServiceCommandError, generatedDependenciesInstalled, normalizeScaffoldArgs } from "./service";
6
6
 
7
- test("normalizeScaffoldArgs treats service create as the scaffold command outside a service repo", () => {
7
+ test("normalizeScaffoldArgs treats explicit scaffold commands as generator commands", () => {
8
8
  expect(normalizeScaffoldArgs(["create", "launch-api", "--yes"])).toEqual(["launch-api", "--yes"]);
9
9
  expect(normalizeScaffoldArgs(["new", "launch-api"])).toEqual(["launch-api"]);
10
10
  expect(normalizeScaffoldArgs(["init", "launch-api"])).toEqual(["launch-api"]);
11
- expect(normalizeScaffoldArgs(["launch-api", "--yes"])).toEqual(["launch-api", "--yes"]);
12
11
  });
13
12
 
14
13
  test("normalizeScaffoldArgs maps service help to generator help outside a service repo", () => {
@@ -16,6 +15,17 @@ test("normalizeScaffoldArgs maps service help to generator help outside a servic
16
15
  expect(normalizeScaffoldArgs(["help", "--verbose"])).toEqual(["--help", "--verbose"]);
17
16
  });
18
17
 
18
+ test("formatOutsideServiceCommandError rejects repo-local commands outside generated services", () => {
19
+ expect(formatOutsideServiceCommandError("destroy")).toContain("service destroy must be run inside a generated service repo");
20
+ expect(formatOutsideServiceCommandError("deploy")).toContain("No service.jsonc was found");
21
+ });
22
+
23
+ test("formatOutsideServiceCommandError does not treat positional names as scaffold commands", () => {
24
+ const message = formatOutsideServiceCommandError("launch-api");
25
+ expect(message).toContain("Unknown command: launch-api");
26
+ expect(message).toContain("service create <service_id>");
27
+ });
28
+
19
29
  test("findGeneratedServiceRoot detects generated service context from nested directories", async () => {
20
30
  const root = await mkdtemp(join(tmpdir(), "create-svc-service-root-"));
21
31
  const serviceRoot = join(root, "generated-api");
package/src/service.ts CHANGED
@@ -1,9 +1,22 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
- import { run as runScaffoldCli } from "./cli";
3
+ import { formatScaffoldHelp, run as runScaffoldCli } from "./cli";
4
4
  import { parseJsonc } from "./jsonc";
5
5
 
6
6
  const SCAFFOLD_COMMANDS = new Set(["create", "new", "init"]);
7
+ const GENERATED_SERVICE_COMMANDS = new Set([
8
+ "auth",
9
+ "create",
10
+ "dashboards",
11
+ "deploy",
12
+ "destroy",
13
+ "dev",
14
+ "dns",
15
+ "doctor",
16
+ "migrate",
17
+ "sdk",
18
+ "seed",
19
+ ]);
7
20
 
8
21
  export async function runServiceCommand(argv: string[], cwd = process.cwd()) {
9
22
  const serviceRoot = findGeneratedServiceRoot(cwd);
@@ -12,7 +25,19 @@ export async function runServiceCommand(argv: string[], cwd = process.cwd()) {
12
25
  return;
13
26
  }
14
27
 
15
- await runScaffoldCli(normalizeScaffoldArgs(argv));
28
+ const [command] = argv;
29
+ if (!command || command === "--help" || command === "-h" || command === "help") {
30
+ console.log(formatScaffoldHelp());
31
+ return;
32
+ }
33
+
34
+ if (SCAFFOLD_COMMANDS.has(command)) {
35
+ await runScaffoldCli(normalizeScaffoldArgs(argv));
36
+ return;
37
+ }
38
+
39
+ console.error(formatOutsideServiceCommandError(command));
40
+ process.exit(1);
16
41
  }
17
42
 
18
43
  export function normalizeScaffoldArgs(argv: string[]) {
@@ -26,6 +51,20 @@ export function normalizeScaffoldArgs(argv: string[]) {
26
51
  return argv;
27
52
  }
28
53
 
54
+ export function formatOutsideServiceCommandError(command: string) {
55
+ if (GENERATED_SERVICE_COMMANDS.has(command)) {
56
+ return [
57
+ `service ${command} must be run inside a generated service repo.`,
58
+ "",
59
+ "No service.jsonc was found in this directory or its parents.",
60
+ "To create a new service, run:",
61
+ " service create <service_id>",
62
+ ].join("\n");
63
+ }
64
+
65
+ return [`Unknown command: ${command}`, "", formatScaffoldHelp()].join("\n");
66
+ }
67
+
29
68
  export function findGeneratedServiceRoot(start: string): string | undefined {
30
69
  let current = start;
31
70
  while (true) {