Skip to content

Commit f374e79

Browse files
committed
feat(upload-module): enforce storage provider requirement for upload module; update prompts and validation logic; enhance user guidance for storage selection
1 parent 3d3e09f commit f374e79

File tree

7 files changed

+40
-11
lines changed

7 files changed

+40
-11
lines changed

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"Bash(if [ -d test-standard ])",
3232
"Bash(then rm -rf test-standard)",
3333
"Bash(rm:*)",
34-
"Bash(mkdir:*)"
34+
"Bash(mkdir:*)",
35+
"Bash(pnpm --filter create-tbk-app typecheck:*)"
3536
],
3637
"deny": [],
3738
"ask": []

packages/create-tbk-app/src/cli.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,13 @@ async function validateAndAdjustConfig(
314314
throw new Error(`Invalid project name: ${validation.error}`);
315315
}
316316

317+
// Validate upload module requires storage provider
318+
if (config.modules?.includes('upload') && config.storage === 'none') {
319+
throw new Error(
320+
'The upload module requires a storage provider. Please select a storage provider (local, s3, or r2) when using the upload module.',
321+
);
322+
}
323+
317324
return resolveProjectDirectory(config, options, interactive);
318325
}
319326

packages/create-tbk-app/src/prompts.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ export async function collectProjectConfig(
9292
const agentOptions = await collectAgentOptions(defaults);
9393
const moduleOptions = await collectModuleOptions(defaults);
9494

95+
// Check if upload module is selected but storage is 'none'
96+
let storage = customConfig.storage!;
97+
if (moduleOptions.includes('upload') && storage === 'none') {
98+
note(
99+
'The upload module requires a storage provider to function properly.',
100+
'Storage provider required',
101+
);
102+
103+
storage = await promptSelectValue<StorageProvider>({
104+
message: 'Select a storage provider for file uploads',
105+
options: [
106+
{ label: 'Local – Store files on disk', value: 'local' },
107+
{ label: 'AWS S3 – Amazon S3', value: 's3' },
108+
{ label: 'Cloudflare R2 – S3 compatible', value: 'r2' },
109+
],
110+
initialValue: 'local',
111+
});
112+
}
113+
95114
const finalConfig: ProjectConfig = {
96115
projectName,
97116
preset,
@@ -101,7 +120,7 @@ export async function collectProjectConfig(
101120
cache: customConfig.cache!,
102121
queues: customConfig.queues ?? false,
103122
queueDashboard: customConfig.queueDashboard ?? false,
104-
storage: customConfig.storage!,
123+
storage,
105124
email: customConfig.email!,
106125
realtime: customConfig.realtime ?? false,
107126
admin: customConfig.admin ?? false,
@@ -204,7 +223,7 @@ async function collectCustomConfig(
204223
const storage = await promptSelectValue<StorageProvider>({
205224
message: 'File storage provider',
206225
options: [
207-
{ label: 'None – No file uploads', value: 'none' },
226+
{ label: 'None – No file uploads', value: 'none', hint: 'Upload module will not be available' },
208227
{ label: 'Local – Store files on disk', value: 'local' },
209228
{ label: 'AWS S3 – Amazon S3', value: 's3' },
210229
{ label: 'Cloudflare R2 – S3 compatible', value: 'r2' },
@@ -318,7 +337,7 @@ async function collectModuleOptions(
318337
{
319338
label: 'Upload',
320339
value: 'upload',
321-
hint: 'File upload example module',
340+
hint: 'File upload example module (requires storage provider)',
322341
},
323342
{
324343
label: 'Healthcheck',

packages/create-tbk-app/templates/base/src/plugins/lifecycle/index.ts renamed to packages/create-tbk-app/templates/base/src/plugins/lifecycle/index.ts.hbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { ToolkitPlugin, PluginFactory } from '@/plugins/types';
22
import { LifecycleManager, type LifecycleOptions } from './lifecycle-manager';
33
import { disconnectDatabase } from '@/lib/database';
4+
{{#if REALTIME}}
45
import { Server as SocketServer } from 'socket.io';
6+
{{/if}}
57
import { cacheProvider, RedisProvider } from '@/lib/cache';
68
import { closeAllQueues } from '@/lib/queue';
79

@@ -26,8 +28,10 @@ export const lifecyclePlugin: PluginFactory<LifecycleOptions> = (
2628
if (cacheProvider instanceof RedisProvider) {
2729
await cacheProvider.getClient().quit();
2830
}
31+
{{#if REALTIME}}
2932
const io = app.locals?.io as SocketServer | undefined;
3033
io?.disconnectSockets(true);
34+
{{/if}}
3135
});
3236

3337
lifecycle.setupSignalHandlers();

packages/create-tbk-app/templates/base/src/plugins/logger/index.ts.hbs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,7 @@ export const loggerPlugin: PluginFactory<LoggerOptions> = (
211211
// Register HTTP logging middleware
212212
app.use(httpLogger);
213213

214-
logger.debug('Logger plugin registered', {
215-
level: options.level || defaultLogLevel,
216-
pretty: options.pretty !== undefined ? options.pretty : isDevelopment,
217-
redact: options.redact?.length || 0,
218-
});
214+
logger.debug('Logger plugin registered');
219215

220216
return [];
221217
},

packages/create-tbk-app/templates/base/src/routes/routes.ts.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import express from 'express';
33
import authRouter, { AUTH_ROUTER_ROOT } from '../modules/auth/auth.router';
44
import userRouter, { USER_ROUTER_ROOT } from '../modules/user/user.router';
55
{{/if}}
6-
{{#if (or OBSERVABILITY_FULL MODULE_HEALTHCHECK)}}
6+
{{#if (MODULE_HEALTHCHECK)}}
77
import healthCheckRouter, {
88
HEALTH_ROUTER_ROOT,
99
} from '../modules/healthcheck/healthcheck.routes';
1010
{{/if}}
1111

1212
const router = express.Router();
1313

14-
{{#if (or OBSERVABILITY_FULL MODULE_HEALTHCHECK)}}
14+
{{#if (MODULE_HEALTHCHECK)}}
1515
router.use(HEALTH_ROUTER_ROOT, healthCheckRouter);
1616
{{/if}}
1717
{{#if AUTH}}

packages/create-tbk-app/templates/base/src/types.ts.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { Request, Response } from 'express';
2+
{{#if REALTIME}}
23
import type { Server } from 'socket.io';
4+
{{/if}}
35
import type { AnyZodObject, ZodEffects, ZodSchema } from 'zod';
46
{{#if AUTH_JWT}}
57
import type { JwtPayload } from '@/utils/jwt.utils';

0 commit comments

Comments
 (0)