@bastards/bcs-data-localfs
v0.2.0
Published
Local filesystem implementation of the BCS CMS datalayer
Readme
@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
