create-svc 0.1.47 → 0.1.49

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.47",
3
+ "version": "0.1.49",
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,9 +2,9 @@ import { describe, expect, test } from "bun:test";
2
2
  import {
3
3
  buildDeploymentVerificationCommands,
4
4
  buildLocalVerificationCommands,
5
+ buildLocalPreparationCommands,
5
6
  buildPostScaffoldCommands,
6
7
  buildPreGitBootstrapCommands,
7
- shouldRunLocalMigrate,
8
8
  } from "./post-scaffold";
9
9
 
10
10
  describe("buildPostScaffoldCommands", () => {
@@ -38,10 +38,16 @@ describe("buildPreGitBootstrapCommands", () => {
38
38
  });
39
39
  });
40
40
 
41
- describe("shouldRunLocalMigrate", () => {
42
- test("skips local migrate before Workers dev", () => {
43
- expect(shouldRunLocalMigrate({ target: "workers" })).toBe(false);
44
- expect(shouldRunLocalMigrate({ target: "cloudrun" })).toBe(true);
41
+ describe("buildLocalPreparationCommands", () => {
42
+ test("starts local Postgres before migrating Workers dev", () => {
43
+ expect(buildLocalPreparationCommands({ target: "workers" })).toEqual([
44
+ { command: "bun", args: ["run", "./scripts/ensure-local-db.ts"] },
45
+ { command: "bun", args: ["run", "migrate"] },
46
+ ]);
47
+ });
48
+
49
+ test("runs migrations directly for Cloud Run dev", () => {
50
+ expect(buildLocalPreparationCommands({ target: "cloudrun" })).toEqual([{ command: "bun", args: ["run", "migrate"] }]);
45
51
  });
46
52
  });
47
53
 
@@ -58,8 +58,8 @@ export function runPreGitBootstrapFlow(config: Pick<ScaffoldConfig, "framework">
58
58
  }
59
59
 
60
60
  async function startLocalDevelopment(config: Pick<ScaffoldConfig, "target">, cwd: string) {
61
- if (shouldRunLocalMigrate(config)) {
62
- run("bun", ["run", "migrate"], { cwd });
61
+ for (const command of buildLocalPreparationCommands(config)) {
62
+ run(command.command, command.args, { cwd });
63
63
  }
64
64
  await mkdir(join(cwd, ".service"), { recursive: true });
65
65
  const child = Bun.spawn(["sh", "-c", "exec bun run dev > .service/local-dev.log 2>&1 < /dev/null"], {
@@ -74,8 +74,14 @@ async function startLocalDevelopment(config: Pick<ScaffoldConfig, "target">, cwd
74
74
  await Bun.write(join(cwd, ".service", "local-dev.pid"), `${child.pid}\n`);
75
75
  }
76
76
 
77
- export function shouldRunLocalMigrate(config: Pick<ScaffoldConfig, "target">) {
78
- return config.target !== "workers";
77
+ export function buildLocalPreparationCommands(config: Pick<ScaffoldConfig, "target">): PostScaffoldCommand[] {
78
+ if (config.target === "workers") {
79
+ return [
80
+ { command: "bun", args: ["run", "./scripts/ensure-local-db.ts"] },
81
+ { command: "bun", args: ["run", "migrate"] },
82
+ ];
83
+ }
84
+ return [{ command: "bun", args: ["run", "migrate"] }];
79
85
  }
80
86
 
81
87
  function runWithRetries(command: PostScaffoldCommand, options: CommandOptions, attempts: number, delayMs: number) {
@@ -307,7 +307,7 @@ test("scaffolds the workers target with wrangler lifecycle commands", async () =
307
307
 
308
308
  const packageJson = await Bun.file(join(generatedRoot, "package.json")).text();
309
309
  expect(packageJson).toContain('"@anmho/authctl": "0.1.1"');
310
- expect(packageJson).toContain('"dev": "wrangler dev"');
310
+ expect(packageJson).toContain('"dev": "bun run ./scripts/dev.ts wrangler dev"');
311
311
  expect(packageJson).toContain('"service": "service"');
312
312
  expect(packageJson).toContain('"auth": "service auth"');
313
313
  expect(packageJson).toContain('"wrangler"');
@@ -348,13 +348,13 @@ test("scaffolds the workers target with wrangler lifecycle commands", async () =
348
348
  expect(await Bun.file(join(generatedRoot, "src", "storage.ts")).exists()).toBeTrue();
349
349
  expect(await Bun.file(join(generatedRoot, "scripts", "workers", "cli.ts")).exists()).toBeFalse();
350
350
  expect(await Bun.file(join(generatedRoot, "scripts", "cloudrun", "cli.ts")).exists()).toBeFalse();
351
- expect(await Bun.file(join(generatedRoot, "scripts", "dev.ts")).exists()).toBeFalse();
352
- expect(await Bun.file(join(generatedRoot, "scripts", "ensure-local-db.ts")).exists()).toBeFalse();
353
- expect(await Bun.file(join(generatedRoot, "scripts", "local-docker.ts")).exists()).toBeFalse();
354
- expect(await Bun.file(join(generatedRoot, "scripts", "wait-for-db.ts")).exists()).toBeFalse();
351
+ expect(await Bun.file(join(generatedRoot, "scripts", "dev.ts")).exists()).toBeTrue();
352
+ expect(await Bun.file(join(generatedRoot, "scripts", "ensure-local-db.ts")).exists()).toBeTrue();
353
+ expect(await Bun.file(join(generatedRoot, "scripts", "local-docker.ts")).exists()).toBeTrue();
354
+ expect(await Bun.file(join(generatedRoot, "scripts", "wait-for-db.ts")).exists()).toBeTrue();
355
355
  expect(await Bun.file(join(generatedRoot, "service.yaml")).exists()).toBeFalse();
356
356
  expect(await Bun.file(join(generatedRoot, "Dockerfile")).exists()).toBeFalse();
357
- expect(await Bun.file(join(generatedRoot, "docker-compose.yml")).exists()).toBeFalse();
357
+ expect(await Bun.file(join(generatedRoot, "docker-compose.yml")).exists()).toBeTrue();
358
358
  expect(await Bun.file(join(generatedRoot, "src", "db", "repository.ts")).exists()).toBeFalse();
359
359
  expect(await Bun.file(join(generatedRoot, "src", "temporal", "worker.ts")).exists()).toBeFalse();
360
360
  expect(await Bun.file(join(generatedRoot, "scripts", "codegen.ts")).exists()).toBeFalse();
package/src/scaffold.ts CHANGED
@@ -90,20 +90,12 @@ function shouldSkipForTarget(target: DeployTarget, templateKind: "shared" | "var
90
90
  return false;
91
91
  }
92
92
 
93
- if (relativePath === "Dockerfile" || relativePath === "docker-compose.yml") {
93
+ if (relativePath === "Dockerfile") {
94
94
  return true;
95
95
  }
96
96
 
97
97
  if (templateKind === "shared") {
98
- return (
99
- relativePath === "service.yaml" ||
100
- relativePath === "scripts/dev.ts" ||
101
- relativePath === "scripts/ensure-local-db.ts" ||
102
- relativePath === "scripts/local-docker.ts" ||
103
- relativePath === "scripts/local-env.ts" ||
104
- relativePath === "scripts/seed.ts" ||
105
- relativePath === "scripts/wait-for-db.ts"
106
- );
98
+ return relativePath === "service.yaml";
107
99
  }
108
100
 
109
101
  return (
@@ -8,15 +8,20 @@ if (command.length === 0) {
8
8
  }
9
9
 
10
10
  await ensureLocalPostgres();
11
+ const localEnv = await readLocalEnv();
12
+ const env = {
13
+ ...Bun.env,
14
+ ...localEnv,
15
+ };
16
+ if (env.DATABASE_URL && !env.CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE) {
17
+ env.CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE = env.DATABASE_URL;
18
+ }
11
19
 
12
20
  const child = Bun.spawn(command, {
13
21
  stdin: "inherit",
14
22
  stdout: "inherit",
15
23
  stderr: "inherit",
16
- env: {
17
- ...Bun.env,
18
- ...(await readLocalEnv()),
19
- },
24
+ env,
20
25
  });
21
26
 
22
27
  process.exit(await child.exited);
@@ -32,9 +32,10 @@ bun install
32
32
  bun run dev
33
33
  ```
34
34
 
35
- The Workers target starts with an HTTP waitlist API. Local unit tests use an
36
- in-memory store. Deployed Workers use the `HYPERDRIVE` binding and create the
37
- small waitlist/trigger schema on first use.
35
+ The Workers target starts with an HTTP waitlist API. Local dev starts Docker
36
+ Compose Postgres and passes it to Wrangler as the local Hyperdrive connection.
37
+ Local unit tests use an in-memory store. Deployed Workers use the `HYPERDRIVE`
38
+ binding and create the small waitlist/trigger schema on first use.
38
39
 
39
40
  ## API
40
41
 
@@ -3,7 +3,7 @@
3
3
  "private": true,
4
4
  "type": "module",
5
5
  "scripts": {
6
- "dev": "wrangler dev",
6
+ "dev": "bun run ./scripts/dev.ts wrangler dev",
7
7
  "service": "service",
8
8
  "migrate": "service migrate",
9
9
  "seed": "service seed",