0.2.0 ⢠Published 7 months ago
@bastards/bcs-data-localfs v0.2.0
@bastards/bcs-data-localfs š¾
A local filesystem implementation of the BCS data layer that provides simple and efficient content storage using JSON files in your project directory.
Features š
Simple File Storage š
- Store content as JSON files
- Automatic file organization by schema
- Easy version control integration
- Direct file system access
Type-Safe Content š”ļø
- Full TypeScript support
- Schema-based type generation
- Runtime type validation
- Strongly typed content access
Developer Friendly š»
- Zero configuration needed
- Instant setup
- Easy content inspection
- Human-readable storage format
Media Management š¼ļø
- Local media file storage
- Automatic file organization
- Public URL generation
- Media metadata handling
Installation š¦
npm install @bastards/bcs-data-localfs
# or
pnpm add @bastards/bcs-data-localfs
# or
yarn add @bastards/bcs-data-localfsUsage š
- Configure the content endpoints in your
bcs.config.ts:
import { defineConfig } from '@bastards/bcs';
export default defineConfig({
admin: {
// ... other admin config
data: {
content: '/api/bcs/content', // Content endpoint
media: '/api/bcs/media' // Media endpoint
}
},
build: {
adminOutputDir: './static/admin',
typesOutputDir: './src/lib/bcs-types' // Where to generate TypeScript types
}
});- Set up the content API endpoints in your application (example in SvelteKit):
// src/routes/api/bcs/content/+server.ts
import { localFs } from '@bastards/bcs-data-localfs';
export const GET = async ({ url }) => {
const storage = localFs();
return storage.handleContentRequest(url);
};
export const POST = async ({ request }) => {
const storage = localFs();
return storage.handleContentRequest(request);
};
// src/routes/api/bcs/media/+server.ts
import { localFs } from '@bastards/bcs-data-localfs';
export const GET = async ({ url }) => {
const storage = localFs();
return storage.handleMediaRequest(url);
};
export const POST = async ({ request }) => {
const storage = localFs();
return storage.handleMediaRequest(request);
};- Your content will be automatically stored in:
./content/- JSON files for each schema./static/media/- Uploaded media files
Directory Structure š
your-project/
āāā content/
ā āāā Main.json
ā āāā General.json
āāā static/
ā āāā media/
ā ā āāā uploads/
ā āāā admin/
āāā src/
āāā lib/
āāā bcs-types/
āāā schema.d.tsAPI Reference š
The package exports the following:
function localFs(options?: {
contentDir?: string; // Override default content directory
mediaDir?: string; // Override default media directory
}): StorageHandler;
interface StorageHandler {
handleContentRequest(urlOrRequest: URL | Request): Promise<Response>;
handleMediaRequest(urlOrRequest: URL | Request): Promise<Response>;
}Content Format š
Content is stored as JSON files, one per schema:
{
"welcomeSection": {
"title": "Welcome to BCS",
"emoji": "š",
"subtitle": "A modern CMS for modern web development"
}
}Contributing š¤
We welcome contributions! Please see our Contributing Guide for details.
License š
MIT - see the main project repository for details.
Learn More š
For more information about BCS and its features, check out:
- BCS Documentation (Coming soon, still working on it!)
- Main Project README
- Software Bastards
0.2.0
7 months ago