Skip to content

Commit cb80d81

Browse files
authored
Merge pull request #46 from CarboxyDev/development
Update create-blitzpack CLI UX + Update local testing infra
2 parents 2b32016 + 94b3bc1 commit cb80d81

File tree

6 files changed

+82
-8
lines changed

6 files changed

+82
-8
lines changed

.husky/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pnpm typecheck && pnpm test
1+
pnpm typecheck && pnpm test:unit

apps/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"lint": "eslint \"src/**/*.ts\"",
1313
"lint:fix": "eslint \"src/**/*.ts\" --fix",
1414
"test": "vitest run",
15-
"test:unit": "vitest run src/",
15+
"test:unit": "vitest run --config vitest.unit.config.ts",
1616
"test:integration": "vitest run test/integration/",
1717
"test:watch": "vitest",
1818
"test:coverage": "vitest run --coverage",

apps/api/src/plugins/auth.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
import { betterAuth } from 'better-auth';
22
import { prismaAdapter } from 'better-auth/adapters/prisma';
33
import { admin } from 'better-auth/plugins';
4+
import { createAccessControl } from 'better-auth/plugins/access';
5+
import { adminAc, defaultStatements } from 'better-auth/plugins/admin/access';
46
import type { FastifyPluginAsync, FastifyRequest } from 'fastify';
57
import fp from 'fastify-plugin';
68

79
import { loadEnv } from '@/config/env.js';
810
import { RATE_LIMIT_CONFIG } from '@/config/rate-limit.js';
911
import { type PrismaClient } from '@/generated/client/client.js';
1012

13+
const ac = createAccessControl(defaultStatements);
14+
15+
const adminRole = ac.newRole({
16+
...adminAc.statements,
17+
});
18+
19+
const superAdminRole = ac.newRole({
20+
...adminAc.statements,
21+
});
22+
1123
declare module 'fastify' {
1224
interface FastifyInstance {
1325
auth: ReturnType<typeof betterAuth>;
@@ -91,8 +103,12 @@ const authPlugin: FastifyPluginAsync = async (app) => {
91103
socialProviders,
92104
plugins: [
93105
admin({
106+
ac,
107+
roles: {
108+
admin: adminRole,
109+
super_admin: superAdminRole,
110+
},
94111
defaultRole: 'user',
95-
adminRoles: ['admin', 'super_admin'],
96112
}),
97113
],
98114
});

apps/api/vitest.unit.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import tsconfigPaths from 'vite-tsconfig-paths';
2+
import { defineConfig, mergeConfig } from 'vitest/config';
3+
4+
import { sharedConfig } from '../../vitest.shared';
5+
6+
export default mergeConfig(
7+
sharedConfig,
8+
defineConfig({
9+
test: {
10+
name: '@repo/api-unit',
11+
include: ['src/**/*.spec.ts'],
12+
globals: true,
13+
root: './',
14+
},
15+
plugins: [tsconfigPaths()],
16+
})
17+
);

create-blitzpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-blitzpack",
3-
"version": "0.1.12",
3+
"version": "0.1.13",
44
"description": "Create a new Blitzpack project - full-stack TypeScript monorepo with Next.js and Fastify",
55
"type": "module",
66
"bin": {

create-blitzpack/src/prompts.ts

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,59 @@ export async function getProjectOptions(
8787
}
8888

8989
async function promptFeatureSelection(): Promise<FeatureOptions | null> {
90+
let cancelled = false;
91+
92+
const { setupType } = await prompts(
93+
{
94+
type: 'select',
95+
name: 'setupType',
96+
message: 'Setup type:',
97+
choices: [
98+
{
99+
title: 'Recommended',
100+
description: 'all features included',
101+
value: 'recommended',
102+
},
103+
{
104+
title: 'Customize',
105+
description: 'choose features',
106+
value: 'customize',
107+
},
108+
],
109+
initial: 0,
110+
hint: '- Use arrow-keys, Enter to submit',
111+
},
112+
{
113+
onCancel: () => {
114+
cancelled = true;
115+
},
116+
}
117+
);
118+
119+
if (cancelled) {
120+
return null;
121+
}
122+
123+
if (setupType === 'recommended') {
124+
return {
125+
testing: true,
126+
admin: true,
127+
uploads: true,
128+
};
129+
}
130+
90131
const featureChoices = OPTIONAL_FEATURES.map((feature) => ({
91-
title: `${feature.name} ${chalk.dim(`(${feature.description})`)}`,
132+
title: feature.name,
133+
description: feature.description,
92134
value: feature.key,
93-
selected: true,
135+
selected: false,
94136
}));
95137

96-
let cancelled = false;
97138
const { selectedFeatures } = await prompts(
98139
{
99140
type: 'multiselect',
100141
name: 'selectedFeatures',
101-
message: 'Include optional features:',
142+
message: 'Select features to include:',
102143
choices: featureChoices,
103144
hint: '- Space to toggle, Enter to confirm',
104145
instructions: false,

0 commit comments

Comments
 (0)