create-svc 0.1.47 → 0.1.48

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.48",
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"');
@@ -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);
@@ -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",