@farm.js/create-app 0.1.61 → 0.1.63
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/dist/index.js +35 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -28
- package/dist/index.mjs.map +1 -1
- package/dist/{rolldown-runtime-VH7oDXx4.js → rolldown-runtime-CmQyd0Gu.js} +1 -2
- package/dist/utils.js +3 -4
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +2 -3
- package/dist/utils.mjs.map +1 -1
- package/package.json +1 -1
- package/templates/_renderers/preact/package.json +3 -3
- package/templates/_renderers/solid/package.json +3 -3
- package/templates/_renderers/svelte/package.json +3 -3
- package/templates/_renderers/vue/package.json +3 -3
- package/templates/auth/package.json +4 -4
- package/templates/basic/package.json +3 -3
- package/templates/better-auth/package.json +4 -4
- package/templates/react-compiler/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -173,12 +173,10 @@ Label.displayName = "Label";
|
|
|
173
173
|
`;
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
-
|
|
177
|
-
//#region ../farm-cli/src/ui-registry.ts
|
|
176
|
+
// ../farm-cli/src/ui-registry.ts
|
|
178
177
|
/** Value written into a generated `components.json` as `registries.farm.url`. */
|
|
179
178
|
const UI_REGISTRY_URL_TEMPLATE = "https://farmjs.dev/r/{name}.json";
|
|
180
|
-
|
|
181
|
-
//#region ../farm-cli/src/ui-feature-registry.ts
|
|
179
|
+
// ../farm-cli/src/ui-feature-registry.ts
|
|
182
180
|
async function installUIFeature(input) {
|
|
183
181
|
const feature = input.definition.ui;
|
|
184
182
|
if (!feature) {
|
|
@@ -1760,8 +1758,7 @@ function readObject(value) {
|
|
|
1760
1758
|
function pushResultPath(list, filePath) {
|
|
1761
1759
|
if (!list.includes(filePath)) list.push(filePath);
|
|
1762
1760
|
}
|
|
1763
|
-
|
|
1764
|
-
//#region ../farm-cli/src/add-integration.ts
|
|
1761
|
+
// ../farm-cli/src/add-integration.ts
|
|
1765
1762
|
const PROVIDERS = [
|
|
1766
1763
|
{
|
|
1767
1764
|
provider: "ai",
|
|
@@ -1780,6 +1777,7 @@ const PROVIDERS = [
|
|
|
1780
1777
|
notes: [
|
|
1781
1778
|
"Use @ai-sdk/react useChat with api: \"/api/chat\" on the client.",
|
|
1782
1779
|
"Replace model with any AI SDK provider model or Vercel AI Gateway model id.",
|
|
1780
|
+
"The chat route answers only in development until authorize checks your session: every request spends your AI credits.",
|
|
1783
1781
|
"No farm.config integration wiring is required for this route."
|
|
1784
1782
|
],
|
|
1785
1783
|
ui: aiChatUIFeature(),
|
|
@@ -1788,6 +1786,10 @@ const PROVIDERS = [
|
|
|
1788
1786
|
export const POST = aiChatRoute({
|
|
1789
1787
|
model: "openai/gpt-4o-mini",
|
|
1790
1788
|
system: "You are a helpful assistant.",
|
|
1789
|
+
// Every request spends your AI credits. TODO: check the signed-in user, for
|
|
1790
|
+
// example authorize: async ({ request }) => Boolean(await getSession(request)).
|
|
1791
|
+
// Until then the route answers in development and refuses in production.
|
|
1792
|
+
authorize: () => process.env.NODE_ENV === "development",
|
|
1791
1793
|
});
|
|
1792
1794
|
`
|
|
1793
1795
|
},
|
|
@@ -2135,7 +2137,7 @@ export const autumnIntegration = autumn({
|
|
|
2135
2137
|
"BETTER_AUTH_DATABASE_PATH"
|
|
2136
2138
|
],
|
|
2137
2139
|
dependencies: {
|
|
2138
|
-
"better-auth": "^1.
|
|
2140
|
+
"better-auth": "^1.6.22",
|
|
2139
2141
|
"better-sqlite3": "^12.6.2"
|
|
2140
2142
|
},
|
|
2141
2143
|
devDependencies: { "@types/better-sqlite3": "^7.6.13" },
|
|
@@ -2165,7 +2167,8 @@ await migrations.runMigrations();
|
|
|
2165
2167
|
{
|
|
2166
2168
|
path: ".env.example",
|
|
2167
2169
|
merge: "lines",
|
|
2168
|
-
source: () =>
|
|
2170
|
+
source: () => `# Generate with: openssl rand -base64 32
|
|
2171
|
+
BETTER_AUTH_SECRET=
|
|
2169
2172
|
BETTER_AUTH_URL=http://localhost:3000
|
|
2170
2173
|
BETTER_AUTH_DATABASE_PATH=better-auth.sqlite
|
|
2171
2174
|
`
|
|
@@ -2208,7 +2211,7 @@ export const betterAuthIntegration = betterAuth({
|
|
|
2208
2211
|
"AUTH_GITHUB_ID",
|
|
2209
2212
|
"AUTH_GITHUB_SECRET"
|
|
2210
2213
|
],
|
|
2211
|
-
dependencies: { "@auth/core": "0.
|
|
2214
|
+
dependencies: { "@auth/core": "^0.41.3" },
|
|
2212
2215
|
setupFiles: [{
|
|
2213
2216
|
path: "src/lib/auth.ts",
|
|
2214
2217
|
source: () => `import { Auth } from "@auth/core";
|
|
@@ -2223,6 +2226,8 @@ const config = {
|
|
|
2223
2226
|
],
|
|
2224
2227
|
secret: process.env.AUTH_SECRET,
|
|
2225
2228
|
trustHost: true,
|
|
2229
|
+
// @farm.js/authjs serves Auth.js at /api/auth; Auth.js expects /auth otherwise.
|
|
2230
|
+
basePath: "/api/auth",
|
|
2226
2231
|
};
|
|
2227
2232
|
|
|
2228
2233
|
const handler = (request: Request) => Auth(request, config);
|
|
@@ -2691,8 +2696,7 @@ function toImportPath(relativePath) {
|
|
|
2691
2696
|
function escapeRegExp(input) {
|
|
2692
2697
|
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2693
2698
|
}
|
|
2694
|
-
|
|
2695
|
-
//#region ../farm-cli/src/telemetry-contract.ts
|
|
2699
|
+
// ../farm-cli/src/telemetry-contract.ts
|
|
2696
2700
|
const FARM_CREATE_APP_TELEMETRY_COMMANDS = ["create", "list-templates"];
|
|
2697
2701
|
const FARM_TELEMETRY_TEMPLATES = [
|
|
2698
2702
|
"basic",
|
|
@@ -2728,8 +2732,7 @@ const FARM_TELEMETRY_PACKAGE_MANAGERS = [
|
|
|
2728
2732
|
"yarn",
|
|
2729
2733
|
"bun"
|
|
2730
2734
|
];
|
|
2731
|
-
|
|
2732
|
-
//#region ../farm-cli/src/telemetry.ts
|
|
2735
|
+
// ../farm-cli/src/telemetry.ts
|
|
2733
2736
|
const TELEMETRY_SCHEMA_VERSION = 1;
|
|
2734
2737
|
const DEFAULT_TELEMETRY_ENDPOINT = "https://farmjs.dev/api/telemetry/v1/events";
|
|
2735
2738
|
const TELEMETRY_NOTICE_URL = "https://farmjs.dev/docs/telemetry";
|
|
@@ -3055,8 +3058,7 @@ function normalizePlatform(value) {
|
|
|
3055
3058
|
function normalizeArchitecture(value) {
|
|
3056
3059
|
return value === "arm64" || value === "x64" ? value : "other";
|
|
3057
3060
|
}
|
|
3058
|
-
|
|
3059
|
-
//#region src/index.ts
|
|
3061
|
+
// src/index.ts
|
|
3060
3062
|
const templateDetails = {
|
|
3061
3063
|
basic: {
|
|
3062
3064
|
title: "Basic starter",
|
|
@@ -3071,7 +3073,7 @@ const templateDetails = {
|
|
|
3071
3073
|
auth: {
|
|
3072
3074
|
title: "Auth starter",
|
|
3073
3075
|
description: "Farm.js-native auth with local SQLite, secure sessions, and protected routes",
|
|
3074
|
-
instructions: ["FARMJS Auth uses local SQLite automatically; no auth environment variables are needed locally.", "For production, set FARM_AUTH_URL, FARM_AUTH_SECRET, and DATABASE_URL, then run the auth:migrate script."]
|
|
3076
|
+
instructions: ["FARMJS Auth uses local SQLite automatically and generates a random .farm/auth-secret; no auth environment variables are needed locally.", "For production, set FARM_AUTH_URL, FARM_AUTH_SECRET, and DATABASE_URL, then run the auth:migrate script."]
|
|
3075
3077
|
},
|
|
3076
3078
|
"better-auth": {
|
|
3077
3079
|
title: "Better Auth starter",
|
|
@@ -3344,7 +3346,7 @@ async function createApp(projectName, options = {}) {
|
|
|
3344
3346
|
if (integrationResult) {
|
|
3345
3347
|
const details = templateDetails[template].integration;
|
|
3346
3348
|
logger.info(`Open ${details.route} for the ${details.label} starter.`);
|
|
3347
|
-
if (integrationResult.env.length) logger.info("Copy .env.example to .env.local
|
|
3349
|
+
if (integrationResult.env.length) logger.info("Copy .env.example to .env.local, add your provider credentials, and generate any empty secret with openssl rand -base64 32.");
|
|
3348
3350
|
for (const note of integrationResult.notes) logger.info(note);
|
|
3349
3351
|
}
|
|
3350
3352
|
trackFarmProjectCreated({
|
|
@@ -3475,14 +3477,20 @@ async function writeEnvironmentExample(projectPath, keys) {
|
|
|
3475
3477
|
current = await fs.readFile(envPath, "utf8");
|
|
3476
3478
|
} catch {}
|
|
3477
3479
|
const existingKeys = new Set(current.split(/\r?\n/).map((line) => line.match(/^([A-Z][A-Z0-9_]*)=/)?.[1]).filter((key) => Boolean(key)));
|
|
3478
|
-
const additions = keys.filter((key) => !existingKeys.has(key)).
|
|
3480
|
+
const additions = keys.filter((key) => !existingKeys.has(key)).flatMap((key) => environmentExampleLines(key));
|
|
3479
3481
|
if (additions.length > 0) await fs.writeFile(envPath, `${current.trimEnd()}${current.trim() ? "\n" : ""}${additions.join("\n")}\n`, "utf8");
|
|
3480
3482
|
}
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3483
|
+
const GENERATED_SECRET_KEYS = /* @__PURE__ */ new Set([
|
|
3484
|
+
"AUTH_SECRET",
|
|
3485
|
+
"AUTH0_SECRET",
|
|
3486
|
+
"BETTER_AUTH_SECRET",
|
|
3487
|
+
"WORKOS_COOKIE_PASSWORD"
|
|
3488
|
+
]);
|
|
3489
|
+
function environmentExampleLines(key) {
|
|
3490
|
+
if (GENERATED_SECRET_KEYS.has(key)) return ["# Generate with: openssl rand -base64 32", `${key}=`];
|
|
3491
|
+
if (key === "APP_BASE_URL") return [`${key}=http://localhost:3000`];
|
|
3492
|
+
if (key === "UNKEY_BASE_URL") return [`${key}=https://api.unkey.com`];
|
|
3493
|
+
return [`${key}=`];
|
|
3486
3494
|
}
|
|
3487
3495
|
async function writeIntegrationHomePage(projectPath, integration, hasEnvironment) {
|
|
3488
3496
|
const commandRows = [...hasEnvironment ? ["cp .env.example .env.local"] : [], "pnpm dev"].map((command, index) => ` <div className="command-row">
|
|
@@ -3522,8 +3530,8 @@ ${commandRows}
|
|
|
3522
3530
|
await fs.writeFile(path.join(projectPath, "src", "app", "page.tsx"), source, "utf8");
|
|
3523
3531
|
}
|
|
3524
3532
|
async function writeIntegrationReadme(projectPath, integration, env) {
|
|
3525
|
-
const environmentSetup = env.length ? `cp .env.example .env.local\n# Add values for: ${env.join(", ")}\n` : "";
|
|
3526
|
-
const wiring = integration.provider === "ai" ? "The AI route lives in `src/app/api/chat/route.ts` and its local UI lives under `src/components/farm`." : "The provider wiring lives in `src/lib/integrations` and is registered from `farm.config.ts`.";
|
|
3533
|
+
const environmentSetup = env.length ? `cp .env.example .env.local\n# Add values for: ${env.join(", ")}\n# Generate secrets with: openssl rand -base64 32\n` : "";
|
|
3534
|
+
const wiring = integration.provider === "ai" ? "The AI route lives in `src/app/api/chat/route.ts` and its local UI lives under `src/components/farm`. Every request spends your AI credits, so the route answers only in development until its `authorize` checks a signed-in user." : "The provider wiring lives in `src/lib/integrations` and is registered from `farm.config.ts`.";
|
|
3527
3535
|
const source = `# FARMJS ${integration.label} Starter
|
|
3528
3536
|
|
|
3529
3537
|
## Getting started
|
|
@@ -3616,8 +3624,7 @@ function detectPackageManager(userAgent = process.env.npm_config_user_agent) {
|
|
|
3616
3624
|
function installDependencies(projectPath, packageManager) {
|
|
3617
3625
|
return new Promise((resolve, reject) => {
|
|
3618
3626
|
const isWindows = process.platform === "win32";
|
|
3619
|
-
const
|
|
3620
|
-
const child = spawn(command, ["install"], {
|
|
3627
|
+
const child = spawn(packageManager.name, ["install"], {
|
|
3621
3628
|
cwd: projectPath,
|
|
3622
3629
|
env: process.env,
|
|
3623
3630
|
stdio: "inherit",
|
|
@@ -3667,7 +3674,6 @@ async function updatePackageManagerInstructions(projectPath, packageManager) {
|
|
|
3667
3674
|
}
|
|
3668
3675
|
}));
|
|
3669
3676
|
}
|
|
3670
|
-
//#endregion
|
|
3671
3677
|
export { createApp, detectPackageManager, installDependencies };
|
|
3672
3678
|
|
|
3673
3679
|
//# sourceMappingURL=index.mjs.map
|