create-efforge 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +88 -2
- package/dist/addon.js +115 -0
- package/dist/bin.js +13 -0
- package/dist/cli.js +28 -0
- package/dist/commands/add.js +640 -0
- package/dist/commands/create.js +319 -0
- package/dist/commands/list.js +80 -0
- package/dist/diff.js +72 -0
- package/dist/exec.js +33 -0
- package/dist/generate.js +181 -0
- package/dist/manifest.js +14 -0
- package/dist/projectName.js +41 -0
- package/dist/prompts/flow.js +122 -0
- package/dist/prompts/navigable.js +193 -0
- package/dist/routeTree.js +7 -0
- package/dist/rules.js +27 -0
- package/dist/slots.js +116 -0
- package/dist/stack.js +68 -0
- package/dist/transforms/addAlchemyResource.js +71 -0
- package/dist/transforms/addArrayItem.js +31 -0
- package/dist/transforms/addAuthPlugin.js +77 -0
- package/dist/transforms/addDevVar.js +18 -0
- package/dist/transforms/addExport.js +46 -0
- package/dist/transforms/addImport.js +11 -0
- package/dist/transforms/addLayer.js +31 -0
- package/dist/transforms/addServerFnMiddleware.js +62 -0
- package/dist/transforms/addWorkflowSecret.js +43 -0
- package/dist/transforms/addWranglerBinding.js +61 -0
- package/dist/transforms/appendAgentsSection.js +26 -0
- package/dist/transforms/errors.js +7 -0
- package/dist/transforms/index.js +40 -0
- package/dist/transforms/setWranglerValue.js +40 -0
- package/dist/transforms/util.js +219 -0
- package/dist/tree.js +1 -0
- package/dist/versions.js +73 -0
- package/dist/write.js +28 -0
- package/package.json +63 -4
- package/templates/ai/effect-ai-byok/addon.json +619 -0
- package/templates/ai/effect-ai-byok/files/core/llm-crypto.test.ts +52 -0
- package/templates/ai/effect-ai-byok/files/core/llm-crypto.ts +76 -0
- package/templates/ai/effect-ai-byok/files/core/llm-store.ts +21 -0
- package/templates/ai/effect-ai-byok/files/core/llm.ts +32 -0
- package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/migration.sql +9 -0
- package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/snapshot.json +944 -0
- package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/migration.sql +10 -0
- package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/snapshot.json +1232 -0
- package/templates/ai/effect-ai-byok/files/routes/ai.tsx +193 -0
- package/templates/ai/effect-ai-byok/files/schema/d1.ts +16 -0
- package/templates/ai/effect-ai-byok/files/schema/pg.ts +14 -0
- package/templates/ai/effect-ai-byok/files/server/ai-settings.ts +129 -0
- package/templates/ai/effect-ai-byok/files/server/ai.ts +25 -0
- package/templates/ai/effect-ai-byok/files/server/llm-env.ts +48 -0
- package/templates/ai/effect-ai-byok/files/server/llm-orgs.ts +146 -0
- package/templates/ai/effect-ai-byok/files/server/llm-provider.ts +56 -0
- package/templates/ai/effect-ai-byok/files/server/llm-store-drizzle.ts +48 -0
- package/templates/ai/effect-ai-byok/files/server/llm-store-sql-d1.ts +41 -0
- package/templates/ai/effect-ai-byok/files/server/llm-store-sql-pg.ts +41 -0
- package/templates/ai/effect-ai-byok/files/sql/d1.sql +8 -0
- package/templates/ai/effect-ai-byok/files/sql/pg.sql +8 -0
- package/templates/auth/better-auth/addon.json +424 -0
- package/templates/auth/better-auth/files/core/Auth.ts +18 -0
- package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/migration.sql +51 -0
- package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/snapshot.json +522 -0
- package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/migration.sql +51 -0
- package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/snapshot.json +680 -0
- package/templates/auth/better-auth/files/lib/auth-client.ts +4 -0
- package/templates/auth/better-auth/files/routes/app.tsx +54 -0
- package/templates/auth/better-auth/files/schema/d1/auth-schema.ts +86 -0
- package/templates/auth/better-auth/files/schema/pg/auth-schema.ts +73 -0
- package/templates/auth/better-auth/files/server/auth-live.ts +47 -0
- package/templates/auth/better-auth/files/server/session.ts +14 -0
- package/templates/auth/better-auth/files/shared/components/auth-card.tsx +32 -0
- package/templates/auth/better-auth/files/shared/components/user-menu.tsx +44 -0
- package/templates/auth/better-auth/files/shared/drizzle/d1/drizzle.config.ts +7 -0
- package/templates/auth/better-auth/files/shared/drizzle/pg/drizzle.config.ts +10 -0
- package/templates/auth/better-auth/files/shared/lib/form.ts +5 -0
- package/templates/auth/better-auth/files/shared/lib/redirect.ts +6 -0
- package/templates/auth/better-auth/files/shared/routes/app/index.tsx +54 -0
- package/templates/auth/better-auth/files/shared/routes/sign-in.tsx +85 -0
- package/templates/auth/better-auth/files/shared/routes/sign-up.tsx +91 -0
- package/templates/auth/better-auth/files/shared/server/auth-route.ts +15 -0
- package/templates/auth/better-auth/files/shared/server/auth.ts +22 -0
- package/templates/auth/better-auth/files/shared/server/db/d1-drizzle.ts +25 -0
- package/templates/auth/better-auth/files/shared/server/db/d1-effect-sql.ts +17 -0
- package/templates/auth/better-auth/files/shared/server/db/pg-drizzle.ts +32 -0
- package/templates/auth/better-auth/files/shared/server/db/pg-effect-sql.ts +29 -0
- package/templates/auth/better-auth/files/shared/server/require-session.ts +20 -0
- package/templates/auth/better-auth/files/sql/d1/0002_auth.sql +13 -0
- package/templates/auth/better-auth/files/sql/pg/0002_auth.sql +13 -0
- package/templates/auth/better-auth-orgs/addon.json +463 -0
- package/templates/auth/better-auth-orgs/files/components/org-switcher.tsx +65 -0
- package/templates/auth/better-auth-orgs/files/core/Auth.ts +20 -0
- package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/migration.sql +88 -0
- package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/snapshot.json +862 -0
- package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/migration.sql +88 -0
- package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/snapshot.json +1127 -0
- package/templates/auth/better-auth-orgs/files/lib/auth-client.ts +5 -0
- package/templates/auth/better-auth-orgs/files/routes/accept-invite.$id.tsx +68 -0
- package/templates/auth/better-auth-orgs/files/routes/app/settings/index.tsx +27 -0
- package/templates/auth/better-auth-orgs/files/routes/app/settings/members.tsx +202 -0
- package/templates/auth/better-auth-orgs/files/routes/app/settings.tsx +30 -0
- package/templates/auth/better-auth-orgs/files/routes/app.tsx +58 -0
- package/templates/auth/better-auth-orgs/files/routes/onboarding.tsx +66 -0
- package/templates/auth/better-auth-orgs/files/schema/d1/auth-schema.ts +139 -0
- package/templates/auth/better-auth-orgs/files/schema/pg/auth-schema.ts +124 -0
- package/templates/auth/better-auth-orgs/files/server/auth-live.ts +52 -0
- package/templates/auth/better-auth-orgs/files/server/session.ts +44 -0
- package/templates/auth/better-auth-orgs/files/sql/d1/0002_auth.sql +27 -0
- package/templates/auth/better-auth-orgs/files/sql/pg/0002_auth.sql +27 -0
- package/templates/base/addon.json +216 -0
- package/templates/base/files/AGENTS.md +82 -0
- package/templates/base/files/CLAUDE.md +1 -0
- package/templates/base/files/README.md +32 -0
- package/templates/base/files/core/package.json +13 -0
- package/templates/base/files/core/src/index.ts +2 -0
- package/templates/base/files/core/test/core.test.ts +4 -0
- package/templates/base/files/core/tsconfig.json +6 -0
- package/templates/base/files/gitignore +11 -0
- package/templates/base/files/pnpm-workspace.yaml +11 -0
- package/templates/base/files/root/lint/effect-tests.js +45 -0
- package/templates/base/files/root/package.json +16 -0
- package/templates/base/files/root/tsconfig.base.json +19 -0
- package/templates/base/files/root/turbo.json +9 -0
- package/templates/base/files/root/vite.config.ts +86 -0
- package/templates/base/files/web/components.json +21 -0
- package/templates/base/files/web/package.json +17 -0
- package/templates/base/files/web/src/components/theme-provider.tsx +57 -0
- package/templates/base/files/web/src/components/theme-toggle.tsx +34 -0
- package/templates/base/files/web/src/components/ui/avatar.tsx +93 -0
- package/templates/base/files/web/src/components/ui/button.tsx +61 -0
- package/templates/base/files/web/src/components/ui/card.tsx +74 -0
- package/templates/base/files/web/src/components/ui/dialog.tsx +141 -0
- package/templates/base/files/web/src/components/ui/dropdown-menu.tsx +225 -0
- package/templates/base/files/web/src/components/ui/input.tsx +20 -0
- package/templates/base/files/web/src/components/ui/label.tsx +18 -0
- package/templates/base/files/web/src/components/ui/sonner.tsx +45 -0
- package/templates/base/files/web/src/components/widgets.tsx +4 -0
- package/templates/base/files/web/src/lib/utils.ts +6 -0
- package/templates/base/files/web/src/router.tsx +12 -0
- package/templates/base/files/web/src/routes/__root.tsx +42 -0
- package/templates/base/files/web/src/routes/app/index.tsx +27 -0
- package/templates/base/files/web/src/routes/app/settings.tsx +29 -0
- package/templates/base/files/web/src/routes/app.tsx +47 -0
- package/templates/base/files/web/src/routes/index.tsx +51 -0
- package/templates/base/files/web/src/server/greeting.ts +12 -0
- package/templates/base/files/web/src/server/layers.ts +10 -0
- package/templates/base/files/web/src/server/runtime.ts +5 -0
- package/templates/base/files/web/src/styles.css +81 -0
- package/templates/base/files/web/tsconfig.json +11 -0
- package/templates/base/files/web/vite.config.ts +9 -0
- package/templates/database/d1/addon.json +118 -0
- package/templates/database/d1/files/package.json +12 -0
- package/templates/database/d1/files/tsconfig.json +5 -0
- package/templates/database/postgres/addon.json +142 -0
- package/templates/database/postgres/files/docker-compose.yml +21 -0
- package/templates/database/postgres/files/package.json +12 -0
- package/templates/database/postgres/files/runtime.ts +12 -0
- package/templates/database/postgres/files/tsconfig.json +5 -0
- package/templates/extras/browser/addon.json +173 -0
- package/templates/extras/browser/files/BrowserContainer.ts +14 -0
- package/templates/extras/browser/files/app/Dockerfile +15 -0
- package/templates/extras/browser/files/app/dockerignore +1 -0
- package/templates/extras/browser/files/app/package-lock +605 -0
- package/templates/extras/browser/files/app/package.json +9 -0
- package/templates/extras/browser/files/app/src/server.ts +78 -0
- package/templates/extras/browser/files/app/src/url-policy.ts +115 -0
- package/templates/extras/browser/files/app/tsconfig.json +6 -0
- package/templates/extras/browser/files/browser.ts +34 -0
- package/templates/extras/browser/files/core-browser.ts +21 -0
- package/templates/extras/browser/files/run-browser.ts +25 -0
- package/templates/extras/email/addon.json +182 -0
- package/templates/extras/email/files/core-mailer.ts +28 -0
- package/templates/extras/email/files/invitation-email.ts +38 -0
- package/templates/extras/email/files/mailer.ts +58 -0
- package/templates/extras/realtime/addon.json +135 -0
- package/templates/extras/realtime/files/Room.ts +46 -0
- package/templates/extras/realtime/files/core-realtime.ts +19 -0
- package/templates/extras/realtime/files/realtime-demo.tsx +40 -0
- package/templates/extras/realtime/files/realtime-limits.test.ts +32 -0
- package/templates/extras/realtime/files/realtime-limits.ts +35 -0
- package/templates/extras/realtime/files/realtime-route.ts +39 -0
- package/templates/extras/realtime/files/realtime.ts +39 -0
- package/templates/extras/realtime/files/use-room.ts +67 -0
- package/templates/extras/storage/addon.json +132 -0
- package/templates/extras/storage/files/core-storage.ts +64 -0
- package/templates/extras/storage/files/storage-route.ts +50 -0
- package/templates/extras/storage/files/storage-security.test.ts +71 -0
- package/templates/extras/storage/files/storage-security.ts +92 -0
- package/templates/extras/storage/files/storage.ts +84 -0
- package/templates/extras/workflows/addon.json +95 -0
- package/templates/extras/workflows/files/Example.ts +42 -0
- package/templates/extras/workflows/files/core-jobs.ts +45 -0
- package/templates/extras/workflows/files/example-job.ts +36 -0
- package/templates/extras/workflows/files/jobs.ts +34 -0
- package/templates/infra/alchemy/addon.json +37 -0
- package/templates/infra/alchemy/files/README.md +27 -0
- package/templates/infra/alchemy/files/alchemy.run.ts +36 -0
- package/templates/infra/alchemy/files/github/deploy.yml +63 -0
- package/templates/infra/alchemy/files/tsconfig.json +5 -0
- package/templates/infra/alchemy/files/vite.config.ts +30 -0
- package/templates/orm/drizzle/addon.json +188 -0
- package/templates/orm/drizzle/files/d1/Database.ts +7 -0
- package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/migration.sql +10 -0
- package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/snapshot.json +60 -0
- package/templates/orm/drizzle/files/d1/drizzle.config.ts +7 -0
- package/templates/orm/drizzle/files/d1/layer.ts +13 -0
- package/templates/orm/drizzle/files/d1/migrate.ts +37 -0
- package/templates/orm/drizzle/files/d1/schema.ts +15 -0
- package/templates/orm/drizzle/files/pg/Database.ts +7 -0
- package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/migration.sql +10 -0
- package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/snapshot.json +75 -0
- package/templates/orm/drizzle/files/pg/drizzle.config.ts +10 -0
- package/templates/orm/drizzle/files/pg/layer.ts +16 -0
- package/templates/orm/drizzle/files/pg/migrate.ts +24 -0
- package/templates/orm/drizzle/files/pg/schema.ts +11 -0
- package/templates/orm/drizzle/files/shared/index.ts +2 -0
- package/templates/orm/drizzle/files/shared/notes.ts +15 -0
- package/templates/orm/drizzle/files/shared/page.tsx +50 -0
- package/templates/orm/effect-sql/addon.json +124 -0
- package/templates/orm/effect-sql/files/d1/layer.ts +13 -0
- package/templates/orm/effect-sql/files/d1/migrate.ts +20 -0
- package/templates/orm/effect-sql/files/d1/schema.ts +7 -0
- package/templates/orm/effect-sql/files/d1-sql/0001_init.sql +10 -0
- package/templates/orm/effect-sql/files/pg/layer.ts +16 -0
- package/templates/orm/effect-sql/files/pg/migrate.ts +66 -0
- package/templates/orm/effect-sql/files/pg/schema.ts +7 -0
- package/templates/orm/effect-sql/files/pg-sql/0001_init.sql +10 -0
- package/templates/orm/effect-sql/files/shared/Database.ts +7 -0
- package/templates/orm/effect-sql/files/shared/index.ts +2 -0
- package/templates/orm/effect-sql/files/shared/notes.ts +18 -0
- package/templates/orm/effect-sql/files/shared/page.tsx +50 -0
- package/templates/runtime/cloudflare/addon.json +52 -0
- package/templates/runtime/cloudflare/files/cloudflare.ts +10 -0
- package/templates/runtime/cloudflare/files/routes.ts +5 -0
- package/templates/runtime/cloudflare/files/server.ts +22 -0
- package/templates/runtime/cloudflare/files/tsconfig.json +12 -0
- package/templates/runtime/cloudflare/files/vite.config.ts +20 -0
- package/templates/runtime/cloudflare/files/wrangler.jsonc +8 -0
package/dist/generate.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { Effect, FileSystem, Path, Schema } from "effect";
|
|
2
|
+
import { parse, stringify } from "yaml";
|
|
3
|
+
import { addonIdsFor } from "./addon.js";
|
|
4
|
+
import { hash, renderManifest } from "./manifest.js";
|
|
5
|
+
import { applyProjectName } from "./projectName.js";
|
|
6
|
+
import { SlotId, toCommand } from "./stack.js";
|
|
7
|
+
import { runTransform, } from "./transforms/index.js";
|
|
8
|
+
import { efforgeVersion, versions } from "./versions.js";
|
|
9
|
+
export class GenerateError extends Schema.TaggedError()("GenerateError", {
|
|
10
|
+
reason: Schema.Literals([
|
|
11
|
+
"unsafe-path",
|
|
12
|
+
"unpinned",
|
|
13
|
+
"missing-package-json",
|
|
14
|
+
"invalid-json",
|
|
15
|
+
"unknown-addon",
|
|
16
|
+
"io",
|
|
17
|
+
]),
|
|
18
|
+
package: Schema.optionalKey(Schema.String),
|
|
19
|
+
path: Schema.optionalKey(Schema.String),
|
|
20
|
+
message: Schema.String,
|
|
21
|
+
}) {
|
|
22
|
+
}
|
|
23
|
+
/** Every listed slot must match; for `extras`, at least one chosen extra must be listed. */
|
|
24
|
+
export const matches = (when, config) => {
|
|
25
|
+
if (when === undefined)
|
|
26
|
+
return true;
|
|
27
|
+
return SlotId.literals.every((slot) => {
|
|
28
|
+
const allowed = when[slot];
|
|
29
|
+
if (allowed === undefined)
|
|
30
|
+
return true;
|
|
31
|
+
return slot === "extras"
|
|
32
|
+
? config.extras.some((e) => allowed.includes(e))
|
|
33
|
+
: allowed.includes(config[slot]);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
/** `packageManager` goes last, where the formatter (and sort-package-json) puts it. */
|
|
37
|
+
const json = (value) => {
|
|
38
|
+
const { packageManager, ...rest } = value;
|
|
39
|
+
const ordered = packageManager === undefined ? value : { ...rest, packageManager };
|
|
40
|
+
return `${JSON.stringify(ordered, null, 2)}\n`;
|
|
41
|
+
};
|
|
42
|
+
const sortKeys = (o) => Object.fromEntries(Object.entries(o).toSorted(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
43
|
+
const computedNames = new Set(["pnpm-workspace.yaml", ".env.example", "efforge.jsonc"]);
|
|
44
|
+
export const isComputed = (target) => computedNames.has(target) || target === "package.json" || target.endsWith("/package.json");
|
|
45
|
+
/** Packages of the generated monorepo (`@repo/*`) link via `workspace:*`; they have no pinned version. */
|
|
46
|
+
const isWorkspace = (name) => name.startsWith("@repo/");
|
|
47
|
+
const DEFAULT_PACKAGES = ["apps/*", "packages/*"];
|
|
48
|
+
/** Builds the project tree for `config` from the loaded add-ons. Pure apart from reading add-on files. */
|
|
49
|
+
export const generate = (config, addons) => Effect.gen(function* () {
|
|
50
|
+
const fs = yield* FileSystem.FileSystem;
|
|
51
|
+
const path = yield* Path.Path;
|
|
52
|
+
let tree = new Map();
|
|
53
|
+
const overlay = new Set();
|
|
54
|
+
const seams = new Set();
|
|
55
|
+
const used = new Set();
|
|
56
|
+
const env = new Map();
|
|
57
|
+
const seenEnv = new Set();
|
|
58
|
+
const loaded = [];
|
|
59
|
+
for (const id of addonIdsFor(config)) {
|
|
60
|
+
const addon = addons.get(id);
|
|
61
|
+
if (addon === undefined)
|
|
62
|
+
return yield* new GenerateError({
|
|
63
|
+
reason: "unknown-addon",
|
|
64
|
+
message: `add-on "${id}" is not loaded`,
|
|
65
|
+
});
|
|
66
|
+
loaded.push(addon);
|
|
67
|
+
}
|
|
68
|
+
// 1. every overlay, in add-on order, so a later overlay can never clobber an earlier edit
|
|
69
|
+
for (const { manifest, dir } of loaded) {
|
|
70
|
+
for (const f of manifest.files) {
|
|
71
|
+
if (!matches(f.when, config))
|
|
72
|
+
continue;
|
|
73
|
+
const content = yield* fs
|
|
74
|
+
.readFileString(path.join(dir, f.path))
|
|
75
|
+
.pipe(Effect.mapError((e) => new GenerateError({ reason: "io", path: f.path, message: e.message })));
|
|
76
|
+
tree = new Map(tree).set(f.target, content);
|
|
77
|
+
overlay.add(f.target);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// 2. dependencies and env vars
|
|
81
|
+
for (const { manifest } of loaded) {
|
|
82
|
+
const editPackage = (pkgDir, edit) => Effect.gen(function* () {
|
|
83
|
+
const target = pkgDir === "." ? "package.json" : `${pkgDir}/package.json`;
|
|
84
|
+
const text = tree.get(target);
|
|
85
|
+
if (text === undefined)
|
|
86
|
+
return yield* new GenerateError({
|
|
87
|
+
reason: "missing-package-json",
|
|
88
|
+
path: target,
|
|
89
|
+
message: `${manifest.id} adds dependencies or scripts to ${target}, which does not exist`,
|
|
90
|
+
});
|
|
91
|
+
const pkg = yield* Effect.try({
|
|
92
|
+
try: () => JSON.parse(text),
|
|
93
|
+
catch: (e) => new GenerateError({
|
|
94
|
+
reason: "invalid-json",
|
|
95
|
+
path: target,
|
|
96
|
+
message: `${target} is not valid JSON: ${String(e)}`,
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
edit(pkg);
|
|
100
|
+
tree = new Map(tree).set(target, json(pkg));
|
|
101
|
+
});
|
|
102
|
+
for (const [key, section] of [
|
|
103
|
+
["dependencies", manifest.dependencies],
|
|
104
|
+
["devDependencies", manifest.devDependencies],
|
|
105
|
+
]) {
|
|
106
|
+
for (const [pkgDir, names] of Object.entries(section)) {
|
|
107
|
+
const unpinned = names.find((name) => !isWorkspace(name) && versions[name] === undefined);
|
|
108
|
+
if (unpinned !== undefined)
|
|
109
|
+
return yield* new GenerateError({
|
|
110
|
+
reason: "unpinned",
|
|
111
|
+
package: unpinned,
|
|
112
|
+
message: `${manifest.id} uses "${unpinned}", which has no entry in versions.ts`,
|
|
113
|
+
});
|
|
114
|
+
// a Docker build context can't see the root catalog, so such a package pins exact versions
|
|
115
|
+
const standalone = tree.has(`${pkgDir === "." ? "" : `${pkgDir}/`}Dockerfile`);
|
|
116
|
+
yield* editPackage(pkgDir, (pkg) => {
|
|
117
|
+
const deps = { ...pkg[key] };
|
|
118
|
+
for (const name of names) {
|
|
119
|
+
if (isWorkspace(name)) {
|
|
120
|
+
deps[name] = "workspace:*";
|
|
121
|
+
}
|
|
122
|
+
else if (standalone) {
|
|
123
|
+
deps[name] = versions[name];
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
deps[name] = "catalog:";
|
|
127
|
+
used.add(name);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
pkg[key] = sortKeys(deps);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (const [pkgDir, scripts] of Object.entries(manifest.scripts ?? {}))
|
|
135
|
+
yield* editPackage(pkgDir, (pkg) => {
|
|
136
|
+
pkg.scripts = {
|
|
137
|
+
...pkg.scripts,
|
|
138
|
+
...scripts,
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
for (const v of manifest.envVars) {
|
|
142
|
+
if (!matches(v.when, config))
|
|
143
|
+
continue;
|
|
144
|
+
if (seenEnv.has(v.name))
|
|
145
|
+
continue;
|
|
146
|
+
seenEnv.add(v.name);
|
|
147
|
+
const group = env.get(manifest.id) ?? { title: manifest.title, vars: [] };
|
|
148
|
+
group.vars.push(`${v.name}=${v.example}`);
|
|
149
|
+
env.set(manifest.id, group);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// 3. every transform, in add-on order
|
|
153
|
+
for (const { manifest } of loaded) {
|
|
154
|
+
for (const t of manifest.transforms) {
|
|
155
|
+
if (!matches(t.when, config))
|
|
156
|
+
continue;
|
|
157
|
+
const before = tree;
|
|
158
|
+
tree = yield* runTransform(tree, t);
|
|
159
|
+
// seam files are always re-edited by transforms, never hash-checked by `add`
|
|
160
|
+
for (const [file, content] of tree)
|
|
161
|
+
if (before.get(file) !== content)
|
|
162
|
+
seams.add(file);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// Built-in post-step, after transforms and before hashing, so manifest hashes cover the
|
|
166
|
+
// final (named) content and `add` sees an unedited README/wrangler.jsonc as unchanged.
|
|
167
|
+
const out = new Map(applyProjectName(tree, config.name));
|
|
168
|
+
const workspace = out.get("pnpm-workspace.yaml");
|
|
169
|
+
const { packages = DEFAULT_PACKAGES, ...rest } = workspace === undefined ? {} : (parse(workspace) ?? {});
|
|
170
|
+
const catalog = Object.fromEntries([...used].toSorted().map((n) => [n, versions[n]]));
|
|
171
|
+
// keep the template's other keys (e.g. `allowBuilds`); `catalog` is always computed
|
|
172
|
+
out.set("pnpm-workspace.yaml", stringify({ packages, ...rest, catalog }));
|
|
173
|
+
if (env.size > 0)
|
|
174
|
+
out.set(".env.example", `${[...env.values()].map((g) => `# ${g.title}\n${g.vars.join("\n")}`).join("\n\n")}\n`);
|
|
175
|
+
const files = Object.fromEntries([...overlay]
|
|
176
|
+
.filter((t) => !isComputed(t) && !seams.has(t) && out.has(t))
|
|
177
|
+
.toSorted()
|
|
178
|
+
.map((t) => [t, hash(out.get(t))]));
|
|
179
|
+
out.set("efforge.jsonc", renderManifest({ efforgeVersion, stack: config, command: toCommand(config), files }));
|
|
180
|
+
return new Map([...out].toSorted(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
181
|
+
});
|
package/dist/manifest.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
import { StackConfig } from "./stack.js";
|
|
4
|
+
/** sha256 hex, first 16 characters. */
|
|
5
|
+
export const hash = (content) => createHash("sha256").update(content).digest("hex").slice(0, 16);
|
|
6
|
+
export const EfforgeManifest = Schema.Struct({
|
|
7
|
+
efforgeVersion: Schema.String,
|
|
8
|
+
stack: StackConfig,
|
|
9
|
+
command: Schema.String,
|
|
10
|
+
/** overlay target -> hash(content) */
|
|
11
|
+
files: Schema.Record(Schema.String, Schema.String),
|
|
12
|
+
});
|
|
13
|
+
export const manifestHeader = "// Generated by efforge. Used by `efforge add`.\n";
|
|
14
|
+
export const renderManifest = (m) => `${manifestHeader}${JSON.stringify(m, null, 2)}\n`;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { applyEdits, modify, parse } from "jsonc-parser";
|
|
2
|
+
const formattingOptions = { insertSpaces: true, tabSize: 2 };
|
|
3
|
+
const ALCHEMY_RUN = "infra/alchemy.run.ts";
|
|
4
|
+
/** Stack names end up in Cloudflare resource names: lowercase letters, digits and dashes. */
|
|
5
|
+
const slug = (name) => name
|
|
6
|
+
.toLowerCase()
|
|
7
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
8
|
+
.replace(/^-+|-+$/g, "") || "app";
|
|
9
|
+
/** The directory name a project is created in: the last segment of a scoped name. */
|
|
10
|
+
export const projectDirName = (name) => name.split("/").pop() ?? name;
|
|
11
|
+
/**
|
|
12
|
+
* Built-in post-step: names the generated project. Sets the root `package.json` (`<name>-monorepo`, so it can never clash with a workspace package called `<name>`) and
|
|
13
|
+
* `wrangler.jsonc` `name`, the Alchemy stack name and the README's first heading. Files that are absent, or lack
|
|
14
|
+
* the field, are left alone; running it twice changes nothing.
|
|
15
|
+
*/
|
|
16
|
+
export const applyProjectName = (tree, name) => {
|
|
17
|
+
const out = new Map(tree);
|
|
18
|
+
const dir = projectDirName(name);
|
|
19
|
+
const pkg = out.get("package.json");
|
|
20
|
+
if (pkg !== undefined) {
|
|
21
|
+
try {
|
|
22
|
+
const parsed = JSON.parse(pkg);
|
|
23
|
+
out.set("package.json", `${JSON.stringify({ ...parsed, name: `${dir}-monorepo` }, null, 2)}\n`);
|
|
24
|
+
}
|
|
25
|
+
catch { }
|
|
26
|
+
}
|
|
27
|
+
const wrangler = out.get("wrangler.jsonc");
|
|
28
|
+
if (wrangler !== undefined) {
|
|
29
|
+
const errors = [];
|
|
30
|
+
const doc = parse(wrangler, errors, { allowTrailingComma: true });
|
|
31
|
+
if (errors.length === 0 && typeof doc?.name === "string")
|
|
32
|
+
out.set("wrangler.jsonc", applyEdits(wrangler, modify(wrangler, ["name"], dir, { formattingOptions })));
|
|
33
|
+
}
|
|
34
|
+
const readme = out.get("README.md");
|
|
35
|
+
if (readme !== undefined)
|
|
36
|
+
out.set("README.md", readme.replace(/^# .*$/m, `# ${dir}`));
|
|
37
|
+
const alchemy = out.get(ALCHEMY_RUN);
|
|
38
|
+
if (alchemy !== undefined)
|
|
39
|
+
out.set(ALCHEMY_RUN, alchemy.replace(/(Alchemy\.Stack\(\s*)"[^"]*"/, `$1"${slug(dir)}"`));
|
|
40
|
+
return out;
|
|
41
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { IncompatibleStack, validate } from "../rules.js";
|
|
3
|
+
import { available, slots, whyUnavailable } from "../slots.js";
|
|
4
|
+
import { ProjectName } from "../stack.js";
|
|
5
|
+
import { GoBack } from "./navigable.js";
|
|
6
|
+
export class InvalidProjectName extends Schema.TaggedError()("InvalidProjectName", { name: Schema.String, message: Schema.String }) {
|
|
7
|
+
}
|
|
8
|
+
export const DEFAULT_NAME = "my-app";
|
|
9
|
+
/** Names npm refuses, or that would shadow a well-known directory. */
|
|
10
|
+
const reserved = new Set(["node_modules", "favicon.ico", "test", "tests", "src", "dist"]);
|
|
11
|
+
const nameError = (name) => {
|
|
12
|
+
if (name.length > 214)
|
|
13
|
+
return `the name is ${name.length} characters; npm allows 214`;
|
|
14
|
+
if (reserved.has(name))
|
|
15
|
+
return `"${name}" is a reserved or confusing package name; pick another`;
|
|
16
|
+
const r = Schema.decodeUnknownExit(ProjectName)(name);
|
|
17
|
+
return r._tag === "Success"
|
|
18
|
+
? undefined
|
|
19
|
+
: name.includes("/") && !name.startsWith("@")
|
|
20
|
+
? `"${name}" is a path; run efforge from the parent directory and pass just the name`
|
|
21
|
+
: `"${name}" isn't a valid npm package name: use lowercase letters, digits, - . _ ~ (optionally @scope/name)`;
|
|
22
|
+
};
|
|
23
|
+
const defaultFor = (slot, options) => {
|
|
24
|
+
if (slot.multi)
|
|
25
|
+
return [];
|
|
26
|
+
const wanted = slot.default;
|
|
27
|
+
return options.some((o) => o.id === wanted) ? wanted : (options[0]?.id ?? wanted);
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Walks the slots in order. Flags skip their prompt but are validated against the
|
|
31
|
+
* answers so far; a slot with a single available option is chosen silently.
|
|
32
|
+
* `GoBack` returns to the previous slot that was actually prompted.
|
|
33
|
+
*/
|
|
34
|
+
export const askStack = (flags, io, opts = {}) => Effect.gen(function* () {
|
|
35
|
+
// 1. name
|
|
36
|
+
let name = flags.name;
|
|
37
|
+
if (name === undefined) {
|
|
38
|
+
if (opts.yes)
|
|
39
|
+
name = DEFAULT_NAME;
|
|
40
|
+
else {
|
|
41
|
+
const answer = yield* io.text({
|
|
42
|
+
id: "name",
|
|
43
|
+
message: "Project name",
|
|
44
|
+
placeholder: DEFAULT_NAME,
|
|
45
|
+
defaultValue: DEFAULT_NAME,
|
|
46
|
+
validate: (n) => nameError(n) ?? opts.checkName?.(n),
|
|
47
|
+
});
|
|
48
|
+
name = answer === GoBack ? DEFAULT_NAME : answer;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const invalid = nameError(name);
|
|
52
|
+
if (invalid !== undefined)
|
|
53
|
+
return yield* new InvalidProjectName({ name, message: invalid });
|
|
54
|
+
// 2. slots
|
|
55
|
+
const draft = {};
|
|
56
|
+
const previous = {};
|
|
57
|
+
const history = [];
|
|
58
|
+
let section;
|
|
59
|
+
let i = 0;
|
|
60
|
+
while (i < slots.length) {
|
|
61
|
+
const slot = slots[i];
|
|
62
|
+
const options = available(slot.id, draft);
|
|
63
|
+
const ids = options.map((o) => o.id);
|
|
64
|
+
const flag = flags[slot.id];
|
|
65
|
+
if (flag !== undefined) {
|
|
66
|
+
const values = typeof flag === "string" ? [flag] : flag;
|
|
67
|
+
for (const value of values) {
|
|
68
|
+
if (!ids.includes(value)) {
|
|
69
|
+
const reason = whyUnavailable(slot.id, value, draft);
|
|
70
|
+
return yield* new IncompatibleStack(reason === undefined
|
|
71
|
+
? { slot: slot.id, value, allowed: ids }
|
|
72
|
+
: { slot: slot.id, value, allowed: ids, reason });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
draft[slot.id] = slot.multi ? [...new Set(values)] : flag;
|
|
76
|
+
i++;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (opts.yes || (!slot.multi && options.length <= 1)) {
|
|
80
|
+
draft[slot.id] = defaultFor(slot, options);
|
|
81
|
+
i++;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (section !== slot.section) {
|
|
85
|
+
section = slot.section;
|
|
86
|
+
yield* io.section(slot.section);
|
|
87
|
+
}
|
|
88
|
+
const choices = options.map((o) => ({ value: o.id, label: o.label, hint: o.hint }));
|
|
89
|
+
const canGoBack = history.length > 0;
|
|
90
|
+
const prev = previous[slot.id];
|
|
91
|
+
const answer = slot.multi
|
|
92
|
+
? yield* io.multiselect({
|
|
93
|
+
id: slot.id,
|
|
94
|
+
message: slot.title,
|
|
95
|
+
options: choices,
|
|
96
|
+
initial: prev ?? slot.default,
|
|
97
|
+
canGoBack,
|
|
98
|
+
})
|
|
99
|
+
: yield* io.select({
|
|
100
|
+
id: slot.id,
|
|
101
|
+
message: slot.title,
|
|
102
|
+
options: choices,
|
|
103
|
+
initial: prev ?? defaultFor(slot, options),
|
|
104
|
+
canGoBack,
|
|
105
|
+
});
|
|
106
|
+
if (answer === GoBack) {
|
|
107
|
+
const back = history.pop();
|
|
108
|
+
if (back === undefined)
|
|
109
|
+
continue; // cannot happen: first prompt has no Back; re-ask
|
|
110
|
+
for (let j = back; j < slots.length; j++)
|
|
111
|
+
delete draft[slots[j].id];
|
|
112
|
+
section = undefined;
|
|
113
|
+
i = back;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
draft[slot.id] = answer;
|
|
117
|
+
previous[slot.id] = answer;
|
|
118
|
+
history.push(i);
|
|
119
|
+
i++;
|
|
120
|
+
}
|
|
121
|
+
return yield* validate({ name, ...draft });
|
|
122
|
+
});
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { stripVTControlCharacters } from "node:util";
|
|
2
|
+
import * as p from "@clack/prompts";
|
|
3
|
+
import { Cause, Context, Effect, Layer, Schema } from "effect";
|
|
4
|
+
import pc from "picocolors";
|
|
5
|
+
/** Returned by a prompt when the user picked "Back". */
|
|
6
|
+
export const GoBack = Symbol.for("efforge/GoBack");
|
|
7
|
+
export class Cancelled extends Schema.TaggedError()("Cancelled", {}) {
|
|
8
|
+
}
|
|
9
|
+
/** A prompt was needed but stdin is not a terminal (CI, pipes): fail fast instead of hanging. */
|
|
10
|
+
export class NeedsInput extends Schema.TaggedError()("NeedsInput", {
|
|
11
|
+
id: Schema.String,
|
|
12
|
+
options: Schema.Array(Schema.String),
|
|
13
|
+
}) {
|
|
14
|
+
}
|
|
15
|
+
export class PromptIO extends Context.Service()("efforge/PromptIO") {
|
|
16
|
+
}
|
|
17
|
+
const BACK = "\u0000back";
|
|
18
|
+
const backChoice = { value: BACK, label: pc.dim("← Back") };
|
|
19
|
+
const ask = (id, options, run) => process.stdin.isTTY
|
|
20
|
+
? Effect.promise(run).pipe(Effect.flatMap((v) => p.isCancel(v) ? Effect.fail(new Cancelled()) : Effect.succeed(v)))
|
|
21
|
+
: Effect.fail(new NeedsInput({ id, options }));
|
|
22
|
+
const interactive = () => process.stdout.isTTY && !p.isCI();
|
|
23
|
+
/** Elapsed time, shown only once it's worth reading (`always` for installs). */
|
|
24
|
+
const seconds = (start, always = false) => {
|
|
25
|
+
const s = (performance.now() - start) / 1000;
|
|
26
|
+
return always || s >= 1 ? ` ${pc.dim(`${s.toFixed(1)}s`)}` : "";
|
|
27
|
+
};
|
|
28
|
+
/** Keeps the streamed lines readable: no colour codes, no carriage-return progress redraws. */
|
|
29
|
+
const clean = (line) => stripVTControlCharacters(line.split("\r").pop() ?? "").trimEnd();
|
|
30
|
+
const toOption = (c) => (c.hint === undefined
|
|
31
|
+
? { value: c.value, label: c.label }
|
|
32
|
+
: { value: c.value, label: c.label, hint: c.hint });
|
|
33
|
+
/**
|
|
34
|
+
* clack 1.8.1 has no back/escape signal, so "go back" is a synthetic "← Back"
|
|
35
|
+
* entry: last in a select, and in a multiselect (picking it alone goes back).
|
|
36
|
+
*/
|
|
37
|
+
export const livePromptIO = {
|
|
38
|
+
select: (o) => ask(o.id, o.options.map((c) => c.value), () => p.select({
|
|
39
|
+
message: o.message,
|
|
40
|
+
options: [...o.options.map(toOption), ...(o.canGoBack ? [backChoice] : [])],
|
|
41
|
+
...(o.initial === undefined ? {} : { initialValue: o.initial }),
|
|
42
|
+
})).pipe(Effect.map((v) => (v === BACK ? GoBack : v))),
|
|
43
|
+
multiselect: (o) => ask(o.id, o.options.map((c) => c.value), () => p.multiselect({
|
|
44
|
+
message: o.canGoBack
|
|
45
|
+
? `${o.message} ${pc.dim("(select Back alone to go back)")}`
|
|
46
|
+
: o.message,
|
|
47
|
+
options: [...o.options.map(toOption), ...(o.canGoBack ? [backChoice] : [])],
|
|
48
|
+
initialValues: [...(o.initial ?? [])],
|
|
49
|
+
required: false,
|
|
50
|
+
})).pipe(Effect.map((v) => v.includes(BACK) && v.length === 1 ? GoBack : v.filter((x) => x !== BACK))),
|
|
51
|
+
text: (o) => ask(o.id, [], () => p.text({
|
|
52
|
+
message: o.message,
|
|
53
|
+
...(o.placeholder === undefined ? {} : { placeholder: o.placeholder }),
|
|
54
|
+
...(o.defaultValue === undefined ? {} : { defaultValue: o.defaultValue }),
|
|
55
|
+
...(o.validate === undefined
|
|
56
|
+
? {}
|
|
57
|
+
: {
|
|
58
|
+
// an emptied field submits "" (not undefined) after an error; both mean the default
|
|
59
|
+
validate: (v) => o.validate?.(v === undefined || v === "" ? (o.defaultValue ?? "") : v),
|
|
60
|
+
}),
|
|
61
|
+
})),
|
|
62
|
+
confirm: (o) => ask(o.id, [], () => p.confirm({
|
|
63
|
+
message: o.message,
|
|
64
|
+
...(o.initial === undefined ? {} : { initialValue: o.initial }),
|
|
65
|
+
})),
|
|
66
|
+
intro: (title) => Effect.sync(() => p.intro(title)),
|
|
67
|
+
section: (title) => Effect.sync(() => p.log.step(pc.bold(title))),
|
|
68
|
+
info: (message) => Effect.sync(() => p.log.info(message)),
|
|
69
|
+
note: (body, title) => Effect.sync(() => p.note(body, title)),
|
|
70
|
+
outro: (message) => Effect.sync(() => p.outro(message)),
|
|
71
|
+
warn: (message) => Effect.sync(() => p.log.warn(message)),
|
|
72
|
+
// Spinners redraw the terminal: in CI or a pipe, print one line per step instead.
|
|
73
|
+
step: (label, eff) => run(label, () => eff, false),
|
|
74
|
+
task: (label, eff) => run(label, eff, true),
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* A one-line spinner. Not clack's: that one puts stdin in raw mode and answers Ctrl-C with
|
|
78
|
+
* `process.exit(0)`, which skips cleanup and reports success. Here Ctrl-C stays a SIGINT, so the
|
|
79
|
+
* run is interrupted, child processes stop, and the caller can say what is left to do.
|
|
80
|
+
*/
|
|
81
|
+
const spinner = (label) => {
|
|
82
|
+
const out = process.stdout;
|
|
83
|
+
const frames = ["◒", "◐", "◓", "◑"];
|
|
84
|
+
let text = label;
|
|
85
|
+
let frame = 0;
|
|
86
|
+
// a wrapped line can't be redrawn with \r, so everything is cut to the terminal width
|
|
87
|
+
const fit = (s) => {
|
|
88
|
+
const room = (out.columns || 80) - 4;
|
|
89
|
+
const plain = stripVTControlCharacters(s);
|
|
90
|
+
return plain.length <= room ? s : `${plain.slice(0, room - 1)}…`;
|
|
91
|
+
};
|
|
92
|
+
const render = () => out.write(`\r\u001b[2K${pc.magenta(frames[frame++ % 4] ?? "")} ${fit(text)}`);
|
|
93
|
+
const showCursor = () => out.write("\u001b[?25h");
|
|
94
|
+
out.write(`${pc.gray("│")}\n\u001b[?25l`);
|
|
95
|
+
process.once("exit", showCursor);
|
|
96
|
+
render();
|
|
97
|
+
const timer = setInterval(render, 80);
|
|
98
|
+
return {
|
|
99
|
+
message: (s) => {
|
|
100
|
+
text = s;
|
|
101
|
+
},
|
|
102
|
+
end: (symbol, s) => {
|
|
103
|
+
clearInterval(timer);
|
|
104
|
+
process.off("exit", showCursor);
|
|
105
|
+
out.write(`\r\u001b[2K${symbol} ${fit(s)}\n`);
|
|
106
|
+
showCursor();
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
const run = (label, eff, live) => Effect.suspend(() => {
|
|
111
|
+
const start = performance.now();
|
|
112
|
+
const done = (exit) => {
|
|
113
|
+
const ok = exit._tag === "Success";
|
|
114
|
+
const interrupted = !ok && Cause.hasInterruptsOnly(exit.cause);
|
|
115
|
+
return {
|
|
116
|
+
ok,
|
|
117
|
+
interrupted,
|
|
118
|
+
msg: ok
|
|
119
|
+
? `${pc.green("✓")} ${label}${seconds(start, live)}`
|
|
120
|
+
: interrupted
|
|
121
|
+
? `${label} ${pc.dim("(cancelled)")}`
|
|
122
|
+
: `${label} failed`,
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
if (!interactive()) {
|
|
126
|
+
if (live)
|
|
127
|
+
p.log.message(`${label}…`);
|
|
128
|
+
return eff(() => { }).pipe(Effect.onExit((exit) => Effect.sync(() => {
|
|
129
|
+
const { ok, interrupted, msg } = done(exit);
|
|
130
|
+
(ok ? p.log.message : interrupted ? p.log.warn : p.log.error)(msg);
|
|
131
|
+
})));
|
|
132
|
+
}
|
|
133
|
+
const s = spinner(label);
|
|
134
|
+
return eff((line) => {
|
|
135
|
+
const text = clean(line);
|
|
136
|
+
if (text !== "")
|
|
137
|
+
s.message(`${label} ${pc.dim(text)}`);
|
|
138
|
+
}).pipe(Effect.onExit((exit) => Effect.sync(() => {
|
|
139
|
+
const { ok, interrupted, msg } = done(exit);
|
|
140
|
+
s.end(ok ? pc.green("◇") : interrupted ? pc.red("■") : pc.red("▲"), msg);
|
|
141
|
+
})));
|
|
142
|
+
});
|
|
143
|
+
export const PromptIOLive = Layer.succeed(PromptIO, livePromptIO);
|
|
144
|
+
// --- scripted layer (tests) ---------------------------------------------------
|
|
145
|
+
export const CANCEL = Symbol.for("efforge/Cancel");
|
|
146
|
+
/** Answers are consumed in order; running out of answers is a test bug and dies. */
|
|
147
|
+
export const scriptedPromptIO = (answers) => {
|
|
148
|
+
const shown = [];
|
|
149
|
+
const output = [];
|
|
150
|
+
let next = 0;
|
|
151
|
+
const take = (s) => {
|
|
152
|
+
shown.push(s);
|
|
153
|
+
if (next >= answers.length)
|
|
154
|
+
return Effect.die(`scripted PromptIO: no answer left for "${s.id}"`);
|
|
155
|
+
const a = answers[next++];
|
|
156
|
+
return a === CANCEL ? Effect.fail(new Cancelled()) : Effect.succeed(a);
|
|
157
|
+
};
|
|
158
|
+
const io = {
|
|
159
|
+
select: (o) => take({
|
|
160
|
+
kind: "select",
|
|
161
|
+
id: o.id,
|
|
162
|
+
options: o.options.map((c) => c.value),
|
|
163
|
+
canGoBack: o.canGoBack,
|
|
164
|
+
}),
|
|
165
|
+
multiselect: (o) => take({
|
|
166
|
+
kind: "multiselect",
|
|
167
|
+
id: o.id,
|
|
168
|
+
options: o.options.map((c) => c.value),
|
|
169
|
+
canGoBack: o.canGoBack,
|
|
170
|
+
}),
|
|
171
|
+
// like the live prompt, an answer that fails `validate` is reported and asked again
|
|
172
|
+
text: (o) => {
|
|
173
|
+
const loop = Effect.suspend(() => take({ kind: "text", id: o.id, options: [], canGoBack: false })).pipe(Effect.flatMap((a) => {
|
|
174
|
+
const error = typeof a === "string" ? o.validate?.(a) : undefined;
|
|
175
|
+
if (error === undefined)
|
|
176
|
+
return Effect.succeed(a);
|
|
177
|
+
output.push(`invalid ${o.id}: ${error}`);
|
|
178
|
+
return loop;
|
|
179
|
+
}));
|
|
180
|
+
return loop;
|
|
181
|
+
},
|
|
182
|
+
confirm: (o) => take({ kind: "confirm", id: o.id, options: [], canGoBack: false }),
|
|
183
|
+
intro: (t) => Effect.sync(() => void output.push(`intro: ${t}`)),
|
|
184
|
+
section: (t) => Effect.sync(() => void output.push(`section: ${t}`)),
|
|
185
|
+
info: (m) => Effect.sync(() => void output.push(`info: ${m}`)),
|
|
186
|
+
warn: (m) => Effect.sync(() => void output.push(`warn: ${m}`)),
|
|
187
|
+
note: (b, t) => Effect.sync(() => void output.push(`note ${t}: ${b}`)),
|
|
188
|
+
outro: (m) => Effect.sync(() => void output.push(`outro: ${m}`)),
|
|
189
|
+
step: (label, eff) => Effect.sync(() => void output.push(`step: ${label}`)).pipe(Effect.andThen(eff)),
|
|
190
|
+
task: (label, eff) => Effect.sync(() => void output.push(`step: ${label}`)).pipe(Effect.andThen(eff(() => { }))),
|
|
191
|
+
};
|
|
192
|
+
return { layer: Layer.succeed(PromptIO, io), shown, output };
|
|
193
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { exec } from "./exec.js";
|
|
2
|
+
/** Generated projects don't commit `routeTree.gen.ts`; this writes it (TanStack Router's generator). */
|
|
3
|
+
export const ROUTE_TREE_ARGS = ["--filter", "web", "exec", "tsr", "generate"];
|
|
4
|
+
/** The same command as one shell string, for scripts and the e2e helper. */
|
|
5
|
+
export const ROUTE_TREE_COMMAND = ["pnpm", ...ROUTE_TREE_ARGS].join(" ");
|
|
6
|
+
/** Runs after `pnpm install` (the generator is a dev dependency) and before the first format. */
|
|
7
|
+
export const generateRouteTree = (dir) => exec("pnpm", [...ROUTE_TREE_ARGS], dir);
|
package/dist/rules.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { available, slots, whyUnavailable } from "./slots.js";
|
|
3
|
+
import { SlotId } from "./stack.js";
|
|
4
|
+
export class IncompatibleStack extends Schema.TaggedError()("IncompatibleStack", {
|
|
5
|
+
slot: SlotId,
|
|
6
|
+
value: Schema.String,
|
|
7
|
+
allowed: Schema.Array(Schema.String),
|
|
8
|
+
/** extra explanation (e.g. why `add` can't change a slot) */
|
|
9
|
+
reason: Schema.optionalKey(Schema.String),
|
|
10
|
+
}) {
|
|
11
|
+
}
|
|
12
|
+
/** Checks every slot value against `available` given the other choices. */
|
|
13
|
+
export const validate = (config) => Effect.gen(function* () {
|
|
14
|
+
for (const slot of slots) {
|
|
15
|
+
const allowed = available(slot.id, config).map((o) => o.id);
|
|
16
|
+
const values = slot.id === "extras" ? config.extras : [config[slot.id]];
|
|
17
|
+
for (const value of values) {
|
|
18
|
+
if (!allowed.includes(value)) {
|
|
19
|
+
const reason = whyUnavailable(slot.id, value, config);
|
|
20
|
+
return yield* new IncompatibleStack(reason === undefined
|
|
21
|
+
? { slot: slot.id, value, allowed }
|
|
22
|
+
: { slot: slot.id, value, allowed, reason });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return config;
|
|
27
|
+
});
|