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 +1 -1
- package/src/post-scaffold.test.ts +11 -5
- package/src/post-scaffold.ts +10 -4
- package/src/scaffold.test.ts +6 -6
- package/src/scaffold.ts +2 -10
- package/templates/shared/scripts/dev.ts +9 -4
- package/templates/targets/workers/README.md +4 -3
- package/templates/targets/workers/package.json +1 -1
package/package.json
CHANGED
|
@@ -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("
|
|
42
|
-
test("
|
|
43
|
-
expect(
|
|
44
|
-
|
|
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
|
|
package/src/post-scaffold.ts
CHANGED
|
@@ -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
|
-
|
|
62
|
-
run(
|
|
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
|
|
78
|
-
|
|
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) {
|
package/src/scaffold.test.ts
CHANGED
|
@@ -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()).
|
|
352
|
-
expect(await Bun.file(join(generatedRoot, "scripts", "ensure-local-db.ts")).exists()).
|
|
353
|
-
expect(await Bun.file(join(generatedRoot, "scripts", "local-docker.ts")).exists()).
|
|
354
|
-
expect(await Bun.file(join(generatedRoot, "scripts", "wait-for-db.ts")).exists()).
|
|
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()).
|
|
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"
|
|
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
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|