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.
Files changed (239) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -2
  3. package/dist/addon.js +115 -0
  4. package/dist/bin.js +13 -0
  5. package/dist/cli.js +28 -0
  6. package/dist/commands/add.js +640 -0
  7. package/dist/commands/create.js +319 -0
  8. package/dist/commands/list.js +80 -0
  9. package/dist/diff.js +72 -0
  10. package/dist/exec.js +33 -0
  11. package/dist/generate.js +181 -0
  12. package/dist/manifest.js +14 -0
  13. package/dist/projectName.js +41 -0
  14. package/dist/prompts/flow.js +122 -0
  15. package/dist/prompts/navigable.js +193 -0
  16. package/dist/routeTree.js +7 -0
  17. package/dist/rules.js +27 -0
  18. package/dist/slots.js +116 -0
  19. package/dist/stack.js +68 -0
  20. package/dist/transforms/addAlchemyResource.js +71 -0
  21. package/dist/transforms/addArrayItem.js +31 -0
  22. package/dist/transforms/addAuthPlugin.js +77 -0
  23. package/dist/transforms/addDevVar.js +18 -0
  24. package/dist/transforms/addExport.js +46 -0
  25. package/dist/transforms/addImport.js +11 -0
  26. package/dist/transforms/addLayer.js +31 -0
  27. package/dist/transforms/addServerFnMiddleware.js +62 -0
  28. package/dist/transforms/addWorkflowSecret.js +43 -0
  29. package/dist/transforms/addWranglerBinding.js +61 -0
  30. package/dist/transforms/appendAgentsSection.js +26 -0
  31. package/dist/transforms/errors.js +7 -0
  32. package/dist/transforms/index.js +40 -0
  33. package/dist/transforms/setWranglerValue.js +40 -0
  34. package/dist/transforms/util.js +219 -0
  35. package/dist/tree.js +1 -0
  36. package/dist/versions.js +73 -0
  37. package/dist/write.js +28 -0
  38. package/package.json +63 -4
  39. package/templates/ai/effect-ai-byok/addon.json +619 -0
  40. package/templates/ai/effect-ai-byok/files/core/llm-crypto.test.ts +52 -0
  41. package/templates/ai/effect-ai-byok/files/core/llm-crypto.ts +76 -0
  42. package/templates/ai/effect-ai-byok/files/core/llm-store.ts +21 -0
  43. package/templates/ai/effect-ai-byok/files/core/llm.ts +32 -0
  44. package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/migration.sql +9 -0
  45. package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/snapshot.json +944 -0
  46. package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/migration.sql +10 -0
  47. package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/snapshot.json +1232 -0
  48. package/templates/ai/effect-ai-byok/files/routes/ai.tsx +193 -0
  49. package/templates/ai/effect-ai-byok/files/schema/d1.ts +16 -0
  50. package/templates/ai/effect-ai-byok/files/schema/pg.ts +14 -0
  51. package/templates/ai/effect-ai-byok/files/server/ai-settings.ts +129 -0
  52. package/templates/ai/effect-ai-byok/files/server/ai.ts +25 -0
  53. package/templates/ai/effect-ai-byok/files/server/llm-env.ts +48 -0
  54. package/templates/ai/effect-ai-byok/files/server/llm-orgs.ts +146 -0
  55. package/templates/ai/effect-ai-byok/files/server/llm-provider.ts +56 -0
  56. package/templates/ai/effect-ai-byok/files/server/llm-store-drizzle.ts +48 -0
  57. package/templates/ai/effect-ai-byok/files/server/llm-store-sql-d1.ts +41 -0
  58. package/templates/ai/effect-ai-byok/files/server/llm-store-sql-pg.ts +41 -0
  59. package/templates/ai/effect-ai-byok/files/sql/d1.sql +8 -0
  60. package/templates/ai/effect-ai-byok/files/sql/pg.sql +8 -0
  61. package/templates/auth/better-auth/addon.json +424 -0
  62. package/templates/auth/better-auth/files/core/Auth.ts +18 -0
  63. package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/migration.sql +51 -0
  64. package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/snapshot.json +522 -0
  65. package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/migration.sql +51 -0
  66. package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/snapshot.json +680 -0
  67. package/templates/auth/better-auth/files/lib/auth-client.ts +4 -0
  68. package/templates/auth/better-auth/files/routes/app.tsx +54 -0
  69. package/templates/auth/better-auth/files/schema/d1/auth-schema.ts +86 -0
  70. package/templates/auth/better-auth/files/schema/pg/auth-schema.ts +73 -0
  71. package/templates/auth/better-auth/files/server/auth-live.ts +47 -0
  72. package/templates/auth/better-auth/files/server/session.ts +14 -0
  73. package/templates/auth/better-auth/files/shared/components/auth-card.tsx +32 -0
  74. package/templates/auth/better-auth/files/shared/components/user-menu.tsx +44 -0
  75. package/templates/auth/better-auth/files/shared/drizzle/d1/drizzle.config.ts +7 -0
  76. package/templates/auth/better-auth/files/shared/drizzle/pg/drizzle.config.ts +10 -0
  77. package/templates/auth/better-auth/files/shared/lib/form.ts +5 -0
  78. package/templates/auth/better-auth/files/shared/lib/redirect.ts +6 -0
  79. package/templates/auth/better-auth/files/shared/routes/app/index.tsx +54 -0
  80. package/templates/auth/better-auth/files/shared/routes/sign-in.tsx +85 -0
  81. package/templates/auth/better-auth/files/shared/routes/sign-up.tsx +91 -0
  82. package/templates/auth/better-auth/files/shared/server/auth-route.ts +15 -0
  83. package/templates/auth/better-auth/files/shared/server/auth.ts +22 -0
  84. package/templates/auth/better-auth/files/shared/server/db/d1-drizzle.ts +25 -0
  85. package/templates/auth/better-auth/files/shared/server/db/d1-effect-sql.ts +17 -0
  86. package/templates/auth/better-auth/files/shared/server/db/pg-drizzle.ts +32 -0
  87. package/templates/auth/better-auth/files/shared/server/db/pg-effect-sql.ts +29 -0
  88. package/templates/auth/better-auth/files/shared/server/require-session.ts +20 -0
  89. package/templates/auth/better-auth/files/sql/d1/0002_auth.sql +13 -0
  90. package/templates/auth/better-auth/files/sql/pg/0002_auth.sql +13 -0
  91. package/templates/auth/better-auth-orgs/addon.json +463 -0
  92. package/templates/auth/better-auth-orgs/files/components/org-switcher.tsx +65 -0
  93. package/templates/auth/better-auth-orgs/files/core/Auth.ts +20 -0
  94. package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/migration.sql +88 -0
  95. package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/snapshot.json +862 -0
  96. package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/migration.sql +88 -0
  97. package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/snapshot.json +1127 -0
  98. package/templates/auth/better-auth-orgs/files/lib/auth-client.ts +5 -0
  99. package/templates/auth/better-auth-orgs/files/routes/accept-invite.$id.tsx +68 -0
  100. package/templates/auth/better-auth-orgs/files/routes/app/settings/index.tsx +27 -0
  101. package/templates/auth/better-auth-orgs/files/routes/app/settings/members.tsx +202 -0
  102. package/templates/auth/better-auth-orgs/files/routes/app/settings.tsx +30 -0
  103. package/templates/auth/better-auth-orgs/files/routes/app.tsx +58 -0
  104. package/templates/auth/better-auth-orgs/files/routes/onboarding.tsx +66 -0
  105. package/templates/auth/better-auth-orgs/files/schema/d1/auth-schema.ts +139 -0
  106. package/templates/auth/better-auth-orgs/files/schema/pg/auth-schema.ts +124 -0
  107. package/templates/auth/better-auth-orgs/files/server/auth-live.ts +52 -0
  108. package/templates/auth/better-auth-orgs/files/server/session.ts +44 -0
  109. package/templates/auth/better-auth-orgs/files/sql/d1/0002_auth.sql +27 -0
  110. package/templates/auth/better-auth-orgs/files/sql/pg/0002_auth.sql +27 -0
  111. package/templates/base/addon.json +216 -0
  112. package/templates/base/files/AGENTS.md +82 -0
  113. package/templates/base/files/CLAUDE.md +1 -0
  114. package/templates/base/files/README.md +32 -0
  115. package/templates/base/files/core/package.json +13 -0
  116. package/templates/base/files/core/src/index.ts +2 -0
  117. package/templates/base/files/core/test/core.test.ts +4 -0
  118. package/templates/base/files/core/tsconfig.json +6 -0
  119. package/templates/base/files/gitignore +11 -0
  120. package/templates/base/files/pnpm-workspace.yaml +11 -0
  121. package/templates/base/files/root/lint/effect-tests.js +45 -0
  122. package/templates/base/files/root/package.json +16 -0
  123. package/templates/base/files/root/tsconfig.base.json +19 -0
  124. package/templates/base/files/root/turbo.json +9 -0
  125. package/templates/base/files/root/vite.config.ts +86 -0
  126. package/templates/base/files/web/components.json +21 -0
  127. package/templates/base/files/web/package.json +17 -0
  128. package/templates/base/files/web/src/components/theme-provider.tsx +57 -0
  129. package/templates/base/files/web/src/components/theme-toggle.tsx +34 -0
  130. package/templates/base/files/web/src/components/ui/avatar.tsx +93 -0
  131. package/templates/base/files/web/src/components/ui/button.tsx +61 -0
  132. package/templates/base/files/web/src/components/ui/card.tsx +74 -0
  133. package/templates/base/files/web/src/components/ui/dialog.tsx +141 -0
  134. package/templates/base/files/web/src/components/ui/dropdown-menu.tsx +225 -0
  135. package/templates/base/files/web/src/components/ui/input.tsx +20 -0
  136. package/templates/base/files/web/src/components/ui/label.tsx +18 -0
  137. package/templates/base/files/web/src/components/ui/sonner.tsx +45 -0
  138. package/templates/base/files/web/src/components/widgets.tsx +4 -0
  139. package/templates/base/files/web/src/lib/utils.ts +6 -0
  140. package/templates/base/files/web/src/router.tsx +12 -0
  141. package/templates/base/files/web/src/routes/__root.tsx +42 -0
  142. package/templates/base/files/web/src/routes/app/index.tsx +27 -0
  143. package/templates/base/files/web/src/routes/app/settings.tsx +29 -0
  144. package/templates/base/files/web/src/routes/app.tsx +47 -0
  145. package/templates/base/files/web/src/routes/index.tsx +51 -0
  146. package/templates/base/files/web/src/server/greeting.ts +12 -0
  147. package/templates/base/files/web/src/server/layers.ts +10 -0
  148. package/templates/base/files/web/src/server/runtime.ts +5 -0
  149. package/templates/base/files/web/src/styles.css +81 -0
  150. package/templates/base/files/web/tsconfig.json +11 -0
  151. package/templates/base/files/web/vite.config.ts +9 -0
  152. package/templates/database/d1/addon.json +118 -0
  153. package/templates/database/d1/files/package.json +12 -0
  154. package/templates/database/d1/files/tsconfig.json +5 -0
  155. package/templates/database/postgres/addon.json +142 -0
  156. package/templates/database/postgres/files/docker-compose.yml +21 -0
  157. package/templates/database/postgres/files/package.json +12 -0
  158. package/templates/database/postgres/files/runtime.ts +12 -0
  159. package/templates/database/postgres/files/tsconfig.json +5 -0
  160. package/templates/extras/browser/addon.json +173 -0
  161. package/templates/extras/browser/files/BrowserContainer.ts +14 -0
  162. package/templates/extras/browser/files/app/Dockerfile +15 -0
  163. package/templates/extras/browser/files/app/dockerignore +1 -0
  164. package/templates/extras/browser/files/app/package-lock +605 -0
  165. package/templates/extras/browser/files/app/package.json +9 -0
  166. package/templates/extras/browser/files/app/src/server.ts +78 -0
  167. package/templates/extras/browser/files/app/src/url-policy.ts +115 -0
  168. package/templates/extras/browser/files/app/tsconfig.json +6 -0
  169. package/templates/extras/browser/files/browser.ts +34 -0
  170. package/templates/extras/browser/files/core-browser.ts +21 -0
  171. package/templates/extras/browser/files/run-browser.ts +25 -0
  172. package/templates/extras/email/addon.json +182 -0
  173. package/templates/extras/email/files/core-mailer.ts +28 -0
  174. package/templates/extras/email/files/invitation-email.ts +38 -0
  175. package/templates/extras/email/files/mailer.ts +58 -0
  176. package/templates/extras/realtime/addon.json +135 -0
  177. package/templates/extras/realtime/files/Room.ts +46 -0
  178. package/templates/extras/realtime/files/core-realtime.ts +19 -0
  179. package/templates/extras/realtime/files/realtime-demo.tsx +40 -0
  180. package/templates/extras/realtime/files/realtime-limits.test.ts +32 -0
  181. package/templates/extras/realtime/files/realtime-limits.ts +35 -0
  182. package/templates/extras/realtime/files/realtime-route.ts +39 -0
  183. package/templates/extras/realtime/files/realtime.ts +39 -0
  184. package/templates/extras/realtime/files/use-room.ts +67 -0
  185. package/templates/extras/storage/addon.json +132 -0
  186. package/templates/extras/storage/files/core-storage.ts +64 -0
  187. package/templates/extras/storage/files/storage-route.ts +50 -0
  188. package/templates/extras/storage/files/storage-security.test.ts +71 -0
  189. package/templates/extras/storage/files/storage-security.ts +92 -0
  190. package/templates/extras/storage/files/storage.ts +84 -0
  191. package/templates/extras/workflows/addon.json +95 -0
  192. package/templates/extras/workflows/files/Example.ts +42 -0
  193. package/templates/extras/workflows/files/core-jobs.ts +45 -0
  194. package/templates/extras/workflows/files/example-job.ts +36 -0
  195. package/templates/extras/workflows/files/jobs.ts +34 -0
  196. package/templates/infra/alchemy/addon.json +37 -0
  197. package/templates/infra/alchemy/files/README.md +27 -0
  198. package/templates/infra/alchemy/files/alchemy.run.ts +36 -0
  199. package/templates/infra/alchemy/files/github/deploy.yml +63 -0
  200. package/templates/infra/alchemy/files/tsconfig.json +5 -0
  201. package/templates/infra/alchemy/files/vite.config.ts +30 -0
  202. package/templates/orm/drizzle/addon.json +188 -0
  203. package/templates/orm/drizzle/files/d1/Database.ts +7 -0
  204. package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/migration.sql +10 -0
  205. package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/snapshot.json +60 -0
  206. package/templates/orm/drizzle/files/d1/drizzle.config.ts +7 -0
  207. package/templates/orm/drizzle/files/d1/layer.ts +13 -0
  208. package/templates/orm/drizzle/files/d1/migrate.ts +37 -0
  209. package/templates/orm/drizzle/files/d1/schema.ts +15 -0
  210. package/templates/orm/drizzle/files/pg/Database.ts +7 -0
  211. package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/migration.sql +10 -0
  212. package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/snapshot.json +75 -0
  213. package/templates/orm/drizzle/files/pg/drizzle.config.ts +10 -0
  214. package/templates/orm/drizzle/files/pg/layer.ts +16 -0
  215. package/templates/orm/drizzle/files/pg/migrate.ts +24 -0
  216. package/templates/orm/drizzle/files/pg/schema.ts +11 -0
  217. package/templates/orm/drizzle/files/shared/index.ts +2 -0
  218. package/templates/orm/drizzle/files/shared/notes.ts +15 -0
  219. package/templates/orm/drizzle/files/shared/page.tsx +50 -0
  220. package/templates/orm/effect-sql/addon.json +124 -0
  221. package/templates/orm/effect-sql/files/d1/layer.ts +13 -0
  222. package/templates/orm/effect-sql/files/d1/migrate.ts +20 -0
  223. package/templates/orm/effect-sql/files/d1/schema.ts +7 -0
  224. package/templates/orm/effect-sql/files/d1-sql/0001_init.sql +10 -0
  225. package/templates/orm/effect-sql/files/pg/layer.ts +16 -0
  226. package/templates/orm/effect-sql/files/pg/migrate.ts +66 -0
  227. package/templates/orm/effect-sql/files/pg/schema.ts +7 -0
  228. package/templates/orm/effect-sql/files/pg-sql/0001_init.sql +10 -0
  229. package/templates/orm/effect-sql/files/shared/Database.ts +7 -0
  230. package/templates/orm/effect-sql/files/shared/index.ts +2 -0
  231. package/templates/orm/effect-sql/files/shared/notes.ts +18 -0
  232. package/templates/orm/effect-sql/files/shared/page.tsx +50 -0
  233. package/templates/runtime/cloudflare/addon.json +52 -0
  234. package/templates/runtime/cloudflare/files/cloudflare.ts +10 -0
  235. package/templates/runtime/cloudflare/files/routes.ts +5 -0
  236. package/templates/runtime/cloudflare/files/server.ts +22 -0
  237. package/templates/runtime/cloudflare/files/tsconfig.json +12 -0
  238. package/templates/runtime/cloudflare/files/vite.config.ts +20 -0
  239. package/templates/runtime/cloudflare/files/wrangler.jsonc +8 -0
@@ -0,0 +1,319 @@
1
+ import { readdirSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { Console, Context, Effect, Option, Path, Schema } from "effect";
5
+ import { Argument, Command, Flag } from "effect/cli";
6
+ import pc from "picocolors";
7
+ import { loadAddons } from "../addon.js";
8
+ import { exec, has } from "../exec.js";
9
+ import { generate } from "../generate.js";
10
+ import { askStack, DEFAULT_NAME } from "../prompts/flow.js";
11
+ import { PromptIO } from "../prompts/navigable.js";
12
+ import { projectDirName } from "../projectName.js";
13
+ import { generateRouteTree } from "../routeTree.js";
14
+ import { slots } from "../slots.js";
15
+ import { toCommand } from "../stack.js";
16
+ import { TargetNotEmpty, writeTree } from "../write.js";
17
+ /** The package's `templates/` dir, resolved relative to this module (same depth in `src/` and `dist/`). */
18
+ export const defaultTemplatesDir = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "templates");
19
+ /** Where add-on templates live; tests point it at fixtures. */
20
+ export const TemplatesDir = Context.Reference("efforge/TemplatesDir", {
21
+ defaultValue: () => defaultTemplatesDir,
22
+ });
23
+ const summary = (stack) => [
24
+ `${pc.dim("name".padEnd(9))} ${stack.name}`,
25
+ ...slots.map((s) => {
26
+ const v = s.id === "extras" ? stack.extras.join(", ") : stack[s.id];
27
+ return `${pc.dim(s.id.padEnd(9))} ${v === "" ? "none" : v}`;
28
+ }),
29
+ ].join("\n");
30
+ const silentIO = (io) => ({
31
+ ...io,
32
+ intro: () => Effect.void,
33
+ section: () => Effect.void,
34
+ info: () => Effect.void,
35
+ warn: () => Effect.void,
36
+ note: () => Effect.void,
37
+ outro: () => Effect.void,
38
+ step: (_label, eff) => eff,
39
+ task: (_label, eff) => eff(() => { }),
40
+ });
41
+ /** Files `vp fmt` can format; the lockfile and dotfiles like .gitignore are left alone. */
42
+ const formattable = /\.(?:tsx?|jsx?|json|jsonc|css|md)$/;
43
+ /** pnpm is required; checked before any prompt so nobody answers everything and then fails. */
44
+ export class PnpmMissing extends Schema.TaggedError()("PnpmMissing", {}) {
45
+ }
46
+ /** A post-write step failed: the files are on disk, `remaining` finishes the setup by hand. */
47
+ export class SetupIncomplete extends Schema.TaggedError()("SetupIncomplete", {
48
+ dir: Schema.String,
49
+ command: Schema.String,
50
+ output: Schema.String,
51
+ remaining: Schema.Array(Schema.String),
52
+ }) {
53
+ }
54
+ /** Node versions Vite+ supports; mirrors `engines` in package.json. */
55
+ const nodeSupported = (version) => {
56
+ const [major = 0, minor = 0] = version.replace(/^v/, "").split(".").map(Number);
57
+ return (major === 24 && minor >= 11) || major >= 26;
58
+ };
59
+ /** What to run after `create`, for this stack. */
60
+ export const nextSteps = (stack, o) => {
61
+ const steps = [];
62
+ if (!o.inPlace)
63
+ steps.push([`cd ${o.dirName}`]);
64
+ if (!o.installed)
65
+ steps.push(["pnpm install"]);
66
+ if (stack.infra === "alchemy") {
67
+ steps.push(["cp .env.example .env", "local values for Alchemy"]);
68
+ // D1 migrations still need wrangler.jsonc under Alchemy (a known v0.1 gap, docs/limits.md)
69
+ if (stack.database === "postgres") {
70
+ steps.push(["docker compose up -d --wait", "local Postgres"]);
71
+ steps.push(["pnpm db:migrate"]);
72
+ }
73
+ steps.push(["pnpm dev", "alchemy dev; deploying: see infra/README.md"]);
74
+ }
75
+ else {
76
+ if (stack.database === "postgres")
77
+ steps.push(["docker compose up -d --wait", "local Postgres"]);
78
+ if (stack.database !== "none")
79
+ steps.push(["pnpm db:migrate", stack.database === "d1" ? "local D1" : undefined]);
80
+ steps.push(["pnpm dev", "http://localhost:5173"]);
81
+ }
82
+ const width = Math.max(...steps.map(([c]) => c.length));
83
+ return steps
84
+ .map(([c, note]) => ` ${pc.cyan(c)}${note === undefined ? "" : ` ${" ".repeat(width - c.length)}${pc.dim(`# ${note}`)}`}`)
85
+ .join("\n");
86
+ };
87
+ /** validate -> generate -> (dry-run | write -> git init -> pnpm install -> route tree -> format -> commit). */
88
+ export const create = (opts) => Effect.gen(function* () {
89
+ const live = yield* PromptIO;
90
+ const path = yield* Path.Path;
91
+ const templatesDir = yield* TemplatesDir;
92
+ // --json must keep stdout machine-readable: it never prompts and prints no chrome.
93
+ const quiet = opts.json;
94
+ const yes = opts.yes || opts.json;
95
+ const io = quiet ? silentIO(live) : live;
96
+ if (!quiet)
97
+ yield* io.intro(`${pc.bgCyan(pc.black(" efforge "))}${pc.dim(" Effect apps on Cloudflare, already wired")}`);
98
+ // `.` scaffolds into the current directory, named after it.
99
+ const inPlace = opts.flags.name === ".";
100
+ const flags = inPlace ? { ...opts.flags, name: path.basename(process.cwd()) } : opts.flags;
101
+ let git = opts.git;
102
+ if (!opts.dryRun) {
103
+ if (!nodeSupported(process.version))
104
+ yield* io.warn(`Node ${process.version} isn't supported by the generated project (Vite+ needs Node 24.11+ or 26+).`);
105
+ if (opts.install && !(yield* has("pnpm", process.cwd())))
106
+ return yield* new PnpmMissing();
107
+ if (git && !(yield* has("git", process.cwd()))) {
108
+ yield* io.warn("git isn't installed: skipping git init and the initial commit.");
109
+ git = false;
110
+ }
111
+ }
112
+ const targetFor = (name) => inPlace ? process.cwd() : path.resolve(projectDirName(name));
113
+ const stack = yield* askStack(flags, io, {
114
+ yes,
115
+ checkName: opts.dryRun
116
+ ? undefined
117
+ : (name) => {
118
+ const dir = targetFor(name);
119
+ return isOccupied(dir)
120
+ ? `${path.relative(process.cwd(), dir) || "."} already exists and isn't empty; pick another name`
121
+ : undefined;
122
+ },
123
+ });
124
+ const command = toCommand(stack);
125
+ const dirName = projectDirName(stack.name);
126
+ const dir = targetFor(stack.name);
127
+ // Fail before generating (and before the confirm prompt) rather than after the user answered everything.
128
+ if (!opts.dryRun && isOccupied(dir))
129
+ return yield* new TargetNotEmpty({ dir });
130
+ const addons = yield* loadAddons(templatesDir);
131
+ const tree = yield* generate(stack, addons);
132
+ const files = [...tree.keys()].toSorted();
133
+ const shownCommand = inPlace ? command.replace(` ${stack.name} --`, " . --") : command;
134
+ if (opts.dryRun) {
135
+ if (!opts.json && isOccupied(dir))
136
+ yield* io.warn(`${inPlace ? "This directory" : `./${dirName}`} isn't empty, so a real run would stop here.`);
137
+ if (opts.json) {
138
+ yield* Console.log(JSON.stringify({ stack, command, files }, null, 2));
139
+ }
140
+ else {
141
+ yield* io.note(summary(stack), "Your stack");
142
+ yield* io.note(files.join("\n"), `${files.length} files`);
143
+ yield* io.outro(`${pc.dim("dry run: nothing written.")} Run it for real:\n ${shownCommand}`);
144
+ }
145
+ return;
146
+ }
147
+ yield* io.note(summary(stack), "Your stack");
148
+ if (!yes) {
149
+ const ok = yield* io.confirm({
150
+ id: "confirm",
151
+ message: `Create it in ${inPlace ? "this directory" : `./${dirName}`}?`,
152
+ initial: true,
153
+ });
154
+ if (ok !== true) {
155
+ yield* io.outro("Nothing written.");
156
+ return;
157
+ }
158
+ }
159
+ const remaining = [];
160
+ let written = false;
161
+ const setup = Effect.gen(function* () {
162
+ yield* io.step(`Writing ${files.length} files`, writeTree(dir, tree));
163
+ written = true;
164
+ // Init before formatting: oxfmt honors .gitignore files up the directory tree, so a project
165
+ // outside any repo would otherwise pick up a parent's ignore rules (a `*` hides every file).
166
+ // A failure here must not fail the scaffold.
167
+ const gitReady = git
168
+ ? yield* io.step("Initializing git", exec("git", ["init"], dir)).pipe(Effect.as(true), Effect.catchTag("CommandFailed", (e) => io
169
+ .info(`git setup skipped: ${e.command} failed. ${e.output.trim().split("\n")[0] ?? ""}`)
170
+ .pipe(Effect.as(false))))
171
+ : false;
172
+ if (opts.install)
173
+ remaining.push("pnpm install", "pnpm format");
174
+ if (gitReady)
175
+ remaining.push("git add -A && git commit -m 'Initial commit'");
176
+ if (opts.install) {
177
+ yield* io.task("Installing dependencies (pnpm install)", (log) => exec("pnpm", ["install"], dir, log));
178
+ remaining.shift();
179
+ // routeTree.gen.ts isn't committed to templates: write it now, so typecheck and format see it.
180
+ yield* io
181
+ .step("Generating the route tree", generateRouteTree(dir))
182
+ .pipe(Effect.catchTag("CommandFailed", (e) => io.info(`route tree skipped: ${e.command} failed. ${e.output.trim().split("\n")[0] ?? ""}; \`pnpm typecheck\` regenerates it`)));
183
+ // Transforms insert code and bindings unformatted, so tidy them now: the first `pnpm check`
184
+ // passes. Without a repo of its own, a parent repo's ignore rules could hide every file, so
185
+ // name the files: explicit paths bypass ignore files. Anything oxfmt can't fix is the user's to see.
186
+ const targets = gitReady ? [] : files.filter((f) => formattable.test(f));
187
+ yield* io
188
+ .step("Formatting", exec("pnpm", ["format", ...targets], dir))
189
+ .pipe(Effect.catchTag("CommandFailed", () => Effect.void));
190
+ remaining.shift();
191
+ }
192
+ if (gitReady) {
193
+ // Plain commit: whatever identity git is configured with.
194
+ yield* io
195
+ .step("Creating the initial commit", Effect.gen(function* () {
196
+ yield* exec("git", ["add", "-A"], dir);
197
+ yield* exec("git", ["commit", "-m", "Initial commit from efforge"], dir);
198
+ }))
199
+ .pipe(Effect.catchTag("CommandFailed", (e) => io.info(`git commit skipped: ${e.command} failed. ${e.output.trim().split("\n")[0] ?? ""}${/identity|user\.(name|email)/i.test(e.output) ? " Set git config user.name and user.email, then commit." : ""}`)));
200
+ remaining.length = 0;
201
+ }
202
+ });
203
+ yield* setup.pipe(Effect.catchTag("CommandFailed", (e) => Effect.fail(new SetupIncomplete({
204
+ dir,
205
+ command: e.command,
206
+ output: e.output,
207
+ remaining: [...remaining],
208
+ }))), Effect.onInterrupt(() => io.warn(!written
209
+ ? `Stopped while writing files. Delete ${inPlace ? "what was written here" : `./${dirName}`} and run efforge again.`
210
+ : remaining.length === 0
211
+ ? `Stopped. ./${dirName} is set up; only the last step was skipped.`
212
+ : `Stopped. ./${dirName} is only partly set up: delete it, or finish with:\n ${remaining.join("\n ")}`)));
213
+ if (opts.json) {
214
+ yield* Console.log(JSON.stringify({ stack, command, files }, null, 2));
215
+ return;
216
+ }
217
+ yield* io.note(nextSteps(stack, { dirName, inPlace, installed: opts.install }), "Next steps");
218
+ yield* io.outro(`${pc.green("Done.")} ${pc.dim("Add more later:")} npx create-efforge list\n ${pc.dim("Same stack again:")} ${command}`);
219
+ });
220
+ /** Exists and has something in it besides `.git` and OS clutter. */
221
+ export const isOccupied = (dir) => {
222
+ try {
223
+ return readdirSync(dir).some((f) => !ignorable.has(f));
224
+ }
225
+ catch {
226
+ return false;
227
+ }
228
+ };
229
+ const ignorable = new Set([".git", ".DS_Store", "Thumbs.db"]);
230
+ // --- CLI -----------------------------------------------------------------------
231
+ const slotFlag = (id) => {
232
+ const slot = slots.find((s) => s.id === id);
233
+ return Flag.String(id).pipe(Flag.withDescription(`${slot.title}: ${slot.options.map((o) => o.id).join(" | ")}${slot.multi ? " (comma-separated)" : ""}`), Flag.optional);
234
+ };
235
+ /** Shared by the root command and the explicit `create` subcommand. */
236
+ export const createConfig = {
237
+ name: Argument.String("name").pipe(Argument.withDescription(`Project name and directory (default prompt: ${DEFAULT_NAME})`), Argument.optional),
238
+ runtime: slotFlag("runtime"),
239
+ database: slotFlag("database"),
240
+ orm: slotFlag("orm"),
241
+ auth: slotFlag("auth"),
242
+ infra: slotFlag("infra"),
243
+ ai: slotFlag("ai"),
244
+ extras: slotFlag("extras"),
245
+ yes: Flag.Boolean("yes").pipe(Flag.withAlias("y"), Flag.withDescription("Accept defaults for anything a flag didn't set"), Flag.withDefault(false)),
246
+ dryRun: Flag.Boolean("dry-run").pipe(Flag.withDescription("Print the files that would be written; write nothing"), Flag.withDefault(false)),
247
+ json: Flag.Boolean("json").pipe(Flag.withDescription("Print only {stack, command, files} as JSON on stdout (implies --yes)"), Flag.withDefault(false)),
248
+ install: Flag.Boolean("install").pipe(Flag.withDescription("Run pnpm install (--no-install to skip)"), Flag.withDefault(true)),
249
+ git: Flag.Boolean("git").pipe(Flag.withDescription("git init + initial commit (--no-git to skip)"), Flag.withDefault(true)),
250
+ };
251
+ const opt = (o) => Option.getOrUndefined(o);
252
+ export const toCreateOptions = (input) => ({
253
+ flags: {
254
+ name: opt(input.name),
255
+ runtime: opt(input.runtime),
256
+ database: opt(input.database),
257
+ orm: opt(input.orm),
258
+ auth: opt(input.auth),
259
+ infra: opt(input.infra),
260
+ ai: opt(input.ai),
261
+ extras: Option.match(input.extras, {
262
+ onNone: () => undefined,
263
+ onSome: (s) => s
264
+ .split(",")
265
+ .map((x) => x.trim())
266
+ .filter((x) => x !== ""),
267
+ }),
268
+ },
269
+ yes: input.yes,
270
+ dryRun: input.dryRun,
271
+ json: input.json,
272
+ install: input.install,
273
+ git: input.git,
274
+ });
275
+ const flagHint = (id, options) => id === "name"
276
+ ? "pass a project name"
277
+ : id === "confirm"
278
+ ? "pass --yes to create without confirming"
279
+ : `pass --${id}=${options.join("|")}${id === "extras" ? " (comma-separated, or --extras= for none)" : ""}`;
280
+ const describe = (e) => {
281
+ switch (e._tag) {
282
+ case "IncompatibleStack": {
283
+ const slot = slots.find((x) => x.id === e.slot);
284
+ const known = slot?.options.some((o) => o.id === e.value) ?? false;
285
+ const allowed = e.allowed.join(", ");
286
+ return known
287
+ ? `--${String(e.slot)}=${String(e.value)} can't be used here${typeof e.reason === "string" ? `: ${e.reason}.` : `. Options: ${allowed}`}`
288
+ : `Unknown --${String(e.slot)}=${String(e.value)}. Options: ${allowed}`;
289
+ }
290
+ case "InvalidProjectName":
291
+ return String(e.message);
292
+ case "TargetNotEmpty":
293
+ return `${String(e.dir)} already exists and isn't empty. Pick another name or remove it.`;
294
+ case "NeedsInput":
295
+ return `No terminal to ask for "${String(e.id)}": ${flagHint(String(e.id), e.options)}, or --yes to accept the defaults.`;
296
+ case "PnpmMissing":
297
+ return "efforge projects use pnpm, and it isn't on your PATH. Install it (corepack enable pnpm, or https://pnpm.io/installation) and re-run, or pass --no-install.";
298
+ case "SetupIncomplete": {
299
+ const rest = e.remaining;
300
+ return `\`${String(e.command)}\` failed. The files are in ${String(e.dir)}${rest.length > 0 ? `; to finish, run there:\n ${rest.join("\n ")}` : "."}\n\n${String(e.output).trim().split("\n").slice(-15).join("\n")}`;
301
+ }
302
+ default:
303
+ return e.message ?? e._tag;
304
+ }
305
+ };
306
+ /** Command handler: one clear error and exit code 1; cancelling exits 130 like any Ctrl-C. */
307
+ export const createHandler = (input) => create(toCreateOptions(input)).pipe(Effect.catch((e) => Effect.gen(function* () {
308
+ const io = yield* PromptIO;
309
+ const cancelled = e._tag === "Cancelled";
310
+ yield* Effect.sync(() => {
311
+ process.exitCode = cancelled ? 130 : 1;
312
+ });
313
+ if (cancelled)
314
+ return yield* io.outro("Cancelled. Nothing written.");
315
+ if (input.json)
316
+ return yield* Console.log(JSON.stringify({ error: { code: e._tag, message: describe(e) } }, null, 2));
317
+ yield* Console.error(pc.red(describe(e)));
318
+ })));
319
+ export const createCommand = Command.make("create", createConfig, createHandler).pipe(Command.withDescription("Create a new app"));
@@ -0,0 +1,80 @@
1
+ import { Console, Effect, Path } from "effect";
2
+ import { Command, Flag } from "effect/cli";
3
+ import pc from "picocolors";
4
+ import { loadAddons } from "../addon.js";
5
+ import { slots } from "../slots.js";
6
+ import { readManifest } from "./add.js";
7
+ import { TemplatesDir } from "./create.js";
8
+ /** Every option of every slot, with its add-on description; `none` and single-option slots are left out. */
9
+ export const listAddons = (cwd) => Effect.gen(function* () {
10
+ const addons = yield* loadAddons(yield* TemplatesDir);
11
+ // outside a project, list everything; a --cwd that doesn't exist is a mistake worth reporting
12
+ const stack = yield* readManifest(cwd).pipe(Effect.map((m) => m.stack), Effect.catchTag("NotAnEfforgeProject", (e) => e.reason === "efforge.jsonc not found" ? Effect.succeed(undefined) : Effect.fail(e)));
13
+ const out = [];
14
+ for (const slot of slots) {
15
+ if (slot.options.length <= 1)
16
+ continue;
17
+ for (const o of slot.options) {
18
+ if (o.id === "none")
19
+ continue;
20
+ const id = `${slot.id}/${o.id}`;
21
+ const m = addons.get(id)?.manifest;
22
+ const installed = stack === undefined
23
+ ? undefined
24
+ : slot.id === "extras"
25
+ ? stack.extras.includes(o.id)
26
+ : stack[slot.id] === o.id;
27
+ out.push({
28
+ id,
29
+ slot: slot.id,
30
+ option: o.id,
31
+ title: m?.title ?? o.label,
32
+ description: m?.description ?? o.hint ?? "",
33
+ ...(installed === undefined ? {} : { installed }),
34
+ });
35
+ }
36
+ }
37
+ return { project: stack !== undefined, addons: out };
38
+ });
39
+ /** First clause of a description, cut to fit the terminal. */
40
+ const short = (s, room) => {
41
+ const clause = s.split(/[:;]\s|\.(?:\s|$)/)[0] ?? s;
42
+ return clause.length <= room ? clause : `${clause.slice(0, Math.max(10, room - 1)).trimEnd()}…`;
43
+ };
44
+ export const listCommand = Command.make("list", {
45
+ json: Flag.Boolean("json").pipe(Flag.withDescription("Print the add-ons as JSON on stdout"), Flag.withDefault(false)),
46
+ cwd: Flag.String("cwd").pipe(Flag.withDescription("Mark what this efforge project already has (default: current directory)"), Flag.withDefault(".")),
47
+ }, (input) => Effect.gen(function* () {
48
+ const path = yield* Path.Path;
49
+ const { project, addons } = yield* listAddons(path.resolve(input.cwd));
50
+ if (input.json)
51
+ return yield* Console.log(JSON.stringify(addons, null, 2));
52
+ const width = Math.max(...addons.map((a) => a.id.length));
53
+ // cut descriptions to the terminal; piped output keeps them whole, a very narrow one drops them
54
+ const room = process.stdout.isTTY ? (process.stdout.columns || 80) - width - 6 : undefined;
55
+ const lines = [];
56
+ let slot = "";
57
+ for (const a of addons) {
58
+ if (a.slot !== slot) {
59
+ slot = a.slot;
60
+ const def = slots.find((s) => s.id === slot);
61
+ lines.push("", pc.bold(def?.title ?? slot));
62
+ }
63
+ const mark = a.installed === true ? pc.green("✓") : " ";
64
+ if (room !== undefined && room < 20) {
65
+ lines.push(`${mark} ${a.installed === true ? pc.dim(a.id) : pc.cyan(a.id)}`);
66
+ continue;
67
+ }
68
+ lines.push(`${mark} ${a.installed === true ? pc.dim(a.id.padEnd(width)) : pc.cyan(a.id.padEnd(width))} ${pc.dim(room === undefined ? a.description : short(a.description, room))}`);
69
+ }
70
+ lines.push("", pc.dim(project
71
+ ? "✓ already in this project. Add one with: npx create-efforge add <id>"
72
+ : "Pick them in npm create efforge, or add one later with: npx create-efforge add <id>"));
73
+ yield* Console.log(lines.join("\n").replace(/^\n/, ""));
74
+ }).pipe(Effect.catch((e) => Effect.gen(function* () {
75
+ const err = e;
76
+ yield* Console.error(pc.red(err.message ?? err._tag));
77
+ yield* Effect.sync(() => {
78
+ process.exitCode = 1;
79
+ });
80
+ })))).pipe(Command.withDescription("List the add-ons you can pick or add later"));
package/dist/diff.js ADDED
@@ -0,0 +1,72 @@
1
+ const CONTEXT = 3;
2
+ const lines = (text) => {
3
+ if (text === "")
4
+ return [];
5
+ const parts = text.split("\n");
6
+ if (parts.at(-1) === "")
7
+ parts.pop();
8
+ return parts;
9
+ };
10
+ /** Line-level edit script via a longest-common-subsequence table (files here are small). */
11
+ const script = (a, b) => {
12
+ const n = a.length;
13
+ const m = b.length;
14
+ const table = Array.from({ length: n + 1 }, () => Array.from({ length: m + 1 }).fill(0));
15
+ for (let i = n - 1; i >= 0; i--)
16
+ for (let j = m - 1; j >= 0; j--)
17
+ table[i][j] =
18
+ a[i] === b[j]
19
+ ? table[i + 1][j + 1] + 1
20
+ : Math.max(table[i + 1][j], table[i][j + 1]);
21
+ const ops = [];
22
+ let i = 0;
23
+ let j = 0;
24
+ while (i < n && j < m) {
25
+ if (a[i] === b[j]) {
26
+ ops.push({ kind: " ", line: a[i] });
27
+ i++;
28
+ j++;
29
+ }
30
+ else if (table[i + 1][j] >= table[i][j + 1]) {
31
+ ops.push({ kind: "-", line: a[i++] });
32
+ }
33
+ else {
34
+ ops.push({ kind: "+", line: b[j++] });
35
+ }
36
+ }
37
+ while (i < n)
38
+ ops.push({ kind: "-", line: a[i++] });
39
+ while (j < m)
40
+ ops.push({ kind: "+", line: b[j++] });
41
+ return ops;
42
+ };
43
+ /** Unified diff of `before` -> `after` with 3 lines of context; empty string when equal. */
44
+ export const unifiedDiff = (file, before, after, labels = { before: "on disk", after: "efforge" }) => {
45
+ const ops = script(lines(before), lines(after));
46
+ const changed = ops.flatMap((op, i) => (op.kind === " " ? [] : [i]));
47
+ if (changed.length === 0)
48
+ return "";
49
+ // group changes whose context windows touch into hunks
50
+ const ranges = [];
51
+ for (const idx of changed) {
52
+ const start = Math.max(0, idx - CONTEXT);
53
+ const end = Math.min(ops.length, idx + CONTEXT + 1);
54
+ const last = ranges.at(-1);
55
+ if (last !== undefined && start <= last[1])
56
+ last[1] = Math.max(last[1], end);
57
+ else
58
+ ranges.push([start, end]);
59
+ }
60
+ const out = [`--- ${file} (${labels.before})`, `+++ ${file} (${labels.after})`];
61
+ for (const [start, end] of ranges) {
62
+ const slice = ops.slice(start, end);
63
+ const before0 = ops.slice(0, start).filter((o) => o.kind !== "+").length;
64
+ const after0 = ops.slice(0, start).filter((o) => o.kind !== "-").length;
65
+ const bCount = slice.filter((o) => o.kind !== "+").length;
66
+ const aCount = slice.filter((o) => o.kind !== "-").length;
67
+ out.push(`@@ -${bCount === 0 ? before0 : before0 + 1},${bCount} +${aCount === 0 ? after0 : after0 + 1},${aCount} @@`);
68
+ for (const op of slice)
69
+ out.push(`${op.kind}${op.line}`);
70
+ }
71
+ return `${out.join("\n")}\n`;
72
+ };
package/dist/exec.js ADDED
@@ -0,0 +1,33 @@
1
+ import { Effect, Schema, Stream } from "effect";
2
+ import { ChildProcess, ChildProcessSpawner } from "effect/process";
3
+ export class CommandFailed extends Schema.TaggedError()("CommandFailed", {
4
+ command: Schema.String,
5
+ exitCode: Schema.optionalKey(Schema.Number),
6
+ output: Schema.String,
7
+ }) {
8
+ }
9
+ /**
10
+ * Runs `cmd args` in `cwd`, returning combined output; a non-zero exit fails with `CommandFailed`.
11
+ * `onLine` sees each output line as it arrives (for live progress).
12
+ */
13
+ export const exec = (cmd, args, cwd, onLine) => {
14
+ const command = [cmd, ...args].join(" ");
15
+ return Effect.gen(function* () {
16
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
17
+ const handle = yield* spawner.spawn(ChildProcess.make(cmd, [...args], { cwd }));
18
+ const lines = [];
19
+ const [, code] = yield* Effect.all([
20
+ handle.all.pipe(Stream.decodeText(), Stream.splitLines, Stream.runForEach((line) => Effect.sync(() => {
21
+ lines.push(line);
22
+ onLine?.(line);
23
+ }))),
24
+ handle.exitCode,
25
+ ], { concurrency: 2 });
26
+ const output = lines.join("\n");
27
+ if (code !== 0)
28
+ return yield* new CommandFailed({ command, exitCode: code, output });
29
+ return output;
30
+ }).pipe(Effect.scoped, Effect.catchTag("PlatformError", (e) => new CommandFailed({ command, output: e.message })));
31
+ };
32
+ /** True when `cmd --version` runs; used to check for pnpm and git before writing anything. */
33
+ export const has = (cmd, cwd) => exec(cmd, ["--version"], cwd).pipe(Effect.as(true), Effect.catchTag("CommandFailed", () => Effect.succeed(false)));