kofi-stack-template-generator 2.0.15 → 2.0.16

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.
@@ -1,9 +1,9 @@
1
1
 
2
- > kofi-stack-template-generator@2.0.15 build /Users/theodenanyoh/Documents/Krumalabs/create-kofi-stack-v2/packages/template-generator
2
+ > kofi-stack-template-generator@2.0.16 build /Users/theodenanyoh/Documents/Krumalabs/create-kofi-stack-v2/packages/template-generator
3
3
  > pnpm run prebuild && tsup src/index.ts --format esm --dts
4
4
 
5
5
 
6
- > kofi-stack-template-generator@2.0.15 prebuild /Users/theodenanyoh/Documents/Krumalabs/create-kofi-stack-v2/packages/template-generator
6
+ > kofi-stack-template-generator@2.0.16 prebuild /Users/theodenanyoh/Documents/Krumalabs/create-kofi-stack-v2/packages/template-generator
7
7
  > node scripts/generate-templates.js
8
8
 
9
9
  Generating templates.generated.ts...
@@ -13,8 +13,8 @@ CLI Using tsconfig: tsconfig.json
13
13
  CLI tsup v8.5.1
14
14
  CLI Target: es2022
15
15
  ESM Build start
16
- ESM dist/index.js 75.40 KB
17
- ESM ⚡️ Build success in 14ms
16
+ ESM dist/index.js 76.64 KB
17
+ ESM ⚡️ Build success in 15ms
18
18
  DTS Build start
19
- DTS ⚡️ Build success in 442ms
19
+ DTS ⚡️ Build success in 467ms
20
20
  DTS dist/index.d.ts 2.96 KB
package/dist/index.js CHANGED
@@ -843,19 +843,21 @@ async function postProcess(vfs, config) {
843
843
  function generateDevScript(vfs, scriptsPath, config) {
844
844
  const isMonorepo = config.structure === "monorepo";
845
845
  const webAppDir = isMonorepo ? "apps/web" : ".";
846
+ const backendDir = isMonorepo ? "packages/backend" : ".";
846
847
  const devScript = `#!/usr/bin/env node
847
848
  /**
848
849
  * Dev Script - Starts Next.js and Convex dev servers
849
850
  */
850
851
 
851
852
  import { spawn, execSync } from 'child_process'
852
- import { existsSync, readFileSync } from 'fs'
853
+ import { existsSync, readFileSync, writeFileSync } from 'fs'
853
854
  import { resolve, dirname } from 'path'
854
855
  import { fileURLToPath } from 'url'
855
856
 
856
857
  const __dirname = dirname(fileURLToPath(import.meta.url))
857
858
  const rootDir = resolve(__dirname, '..')
858
859
  const webAppDir = resolve(rootDir, '${webAppDir}')
860
+ const backendDir = resolve(rootDir, '${backendDir}')
859
861
 
860
862
  function loadEnvFile(dir) {
861
863
  const envPath = resolve(dir, '.env.local')
@@ -880,6 +882,33 @@ function loadEnvFile(dir) {
880
882
  return env
881
883
  }
882
884
 
885
+ function syncEnvToWebApp() {
886
+ // In monorepo, Convex creates .env.local in backend package
887
+ // Web app needs NEXT_PUBLIC_CONVEX_URL to connect to Convex
888
+ const backendEnv = loadEnvFile(backendDir)
889
+ const webEnvPath = resolve(webAppDir, '.env.local')
890
+
891
+ if (backendEnv.NEXT_PUBLIC_CONVEX_URL) {
892
+ const webEnv = loadEnvFile(webAppDir)
893
+
894
+ // Only sync if web app doesn't have the URL or it's different
895
+ if (webEnv.NEXT_PUBLIC_CONVEX_URL !== backendEnv.NEXT_PUBLIC_CONVEX_URL) {
896
+ let content = ''
897
+ if (existsSync(webEnvPath)) {
898
+ content = readFileSync(webEnvPath, 'utf-8')
899
+ // Remove existing NEXT_PUBLIC_CONVEX_URL line if present
900
+ content = content.split('\\n').filter(line => !line.startsWith('NEXT_PUBLIC_CONVEX_URL=')).join('\\n')
901
+ if (content && !content.endsWith('\\n')) content += '\\n'
902
+ }
903
+ content += \`NEXT_PUBLIC_CONVEX_URL=\${backendEnv.NEXT_PUBLIC_CONVEX_URL}\\n\`
904
+ writeFileSync(webEnvPath, content)
905
+ console.log('\u2713 Synced NEXT_PUBLIC_CONVEX_URL to web app\\n')
906
+ }
907
+ }
908
+
909
+ return backendEnv
910
+ }
911
+
883
912
  async function checkAndInstall() {
884
913
  if (!existsSync(resolve(rootDir, 'node_modules'))) {
885
914
  console.log('\u{1F4E6} Installing dependencies...\\n')
@@ -888,9 +917,9 @@ async function checkAndInstall() {
888
917
  }
889
918
 
890
919
  function startDevServers() {
891
- const localEnv = loadEnvFile(webAppDir)
920
+ ${isMonorepo ? "const backendEnv = syncEnvToWebApp()" : "const backendEnv = loadEnvFile(webAppDir)"}
892
921
 
893
- if (!localEnv.CONVEX_DEPLOYMENT) {
922
+ if (!backendEnv.CONVEX_DEPLOYMENT) {
894
923
  console.log('\u26A0\uFE0F Convex not configured. Run: pnpm dev:setup\\n')
895
924
  console.log('Starting Next.js only...\\n')
896
925
  spawn('pnpm', ['${isMonorepo ? "dev:web" : "dev:next"}'], {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kofi-stack-template-generator",
3
- "version": "2.0.15",
3
+ "version": "2.0.16",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/src/generator.ts CHANGED
@@ -208,6 +208,7 @@ function generateDevScript(
208
208
  ): void {
209
209
  const isMonorepo = config.structure === 'monorepo'
210
210
  const webAppDir = isMonorepo ? 'apps/web' : '.'
211
+ const backendDir = isMonorepo ? 'packages/backend' : '.'
211
212
 
212
213
  const devScript = `#!/usr/bin/env node
213
214
  /**
@@ -215,13 +216,14 @@ function generateDevScript(
215
216
  */
216
217
 
217
218
  import { spawn, execSync } from 'child_process'
218
- import { existsSync, readFileSync } from 'fs'
219
+ import { existsSync, readFileSync, writeFileSync } from 'fs'
219
220
  import { resolve, dirname } from 'path'
220
221
  import { fileURLToPath } from 'url'
221
222
 
222
223
  const __dirname = dirname(fileURLToPath(import.meta.url))
223
224
  const rootDir = resolve(__dirname, '..')
224
225
  const webAppDir = resolve(rootDir, '${webAppDir}')
226
+ const backendDir = resolve(rootDir, '${backendDir}')
225
227
 
226
228
  function loadEnvFile(dir) {
227
229
  const envPath = resolve(dir, '.env.local')
@@ -246,6 +248,33 @@ function loadEnvFile(dir) {
246
248
  return env
247
249
  }
248
250
 
251
+ function syncEnvToWebApp() {
252
+ // In monorepo, Convex creates .env.local in backend package
253
+ // Web app needs NEXT_PUBLIC_CONVEX_URL to connect to Convex
254
+ const backendEnv = loadEnvFile(backendDir)
255
+ const webEnvPath = resolve(webAppDir, '.env.local')
256
+
257
+ if (backendEnv.NEXT_PUBLIC_CONVEX_URL) {
258
+ const webEnv = loadEnvFile(webAppDir)
259
+
260
+ // Only sync if web app doesn't have the URL or it's different
261
+ if (webEnv.NEXT_PUBLIC_CONVEX_URL !== backendEnv.NEXT_PUBLIC_CONVEX_URL) {
262
+ let content = ''
263
+ if (existsSync(webEnvPath)) {
264
+ content = readFileSync(webEnvPath, 'utf-8')
265
+ // Remove existing NEXT_PUBLIC_CONVEX_URL line if present
266
+ content = content.split('\\n').filter(line => !line.startsWith('NEXT_PUBLIC_CONVEX_URL=')).join('\\n')
267
+ if (content && !content.endsWith('\\n')) content += '\\n'
268
+ }
269
+ content += \`NEXT_PUBLIC_CONVEX_URL=\${backendEnv.NEXT_PUBLIC_CONVEX_URL}\\n\`
270
+ writeFileSync(webEnvPath, content)
271
+ console.log('✓ Synced NEXT_PUBLIC_CONVEX_URL to web app\\n')
272
+ }
273
+ }
274
+
275
+ return backendEnv
276
+ }
277
+
249
278
  async function checkAndInstall() {
250
279
  if (!existsSync(resolve(rootDir, 'node_modules'))) {
251
280
  console.log('📦 Installing dependencies...\\n')
@@ -254,9 +283,9 @@ async function checkAndInstall() {
254
283
  }
255
284
 
256
285
  function startDevServers() {
257
- const localEnv = loadEnvFile(webAppDir)
286
+ ${isMonorepo ? 'const backendEnv = syncEnvToWebApp()' : 'const backendEnv = loadEnvFile(webAppDir)'}
258
287
 
259
- if (!localEnv.CONVEX_DEPLOYMENT) {
288
+ if (!backendEnv.CONVEX_DEPLOYMENT) {
260
289
  console.log('⚠️ Convex not configured. Run: pnpm dev:setup\\n')
261
290
  console.log('Starting Next.js only...\\n')
262
291
  spawn('pnpm', ['${isMonorepo ? 'dev:web' : 'dev:next'}'], {
@@ -1,6 +1,6 @@
1
1
  // Auto-generated file. Do not edit manually.
2
2
  // Run 'pnpm prebuild' to regenerate.
3
- // Generated: 2026-01-13T23:44:13.187Z
3
+ // Generated: 2026-01-13T23:52:13.846Z
4
4
  // Template count: 78
5
5
 
6
6
  export const EMBEDDED_TEMPLATES: Record<string, string> = {