File Systems
Understand how to manage and organize files efficiently within the Plasma ecosystem.
Project Structure
Plasma follows a well-organized file structure that promotes maintainability and scalability:
plasma.config.js
package.json
tsconfig.json
File Management
Creating Files Programmatically
Use Plasma's file API to create and manage files:
import { fileSystem } from 'plasma';
// Create a new file
await fileSystem.create('src/components/NewComponent.tsx', {
template: 'react-component',
props: { name: 'NewComponent' },
});
// Create directory structure
await fileSystem.createDirectory('src/features/auth');
File Watching
Monitor file changes in real-time:
import { fileWatcher } from 'plasma';
fileWatcher.watch('src/**/*.{ts,tsx}', {
onChange: (filePath) => {
console.log(`File changed: ${filePath}`);
// Trigger rebuild or hot reload
},
onAdd: (filePath) => {
console.log(`File added: ${filePath}`);
},
});
File Operations
Common file operations:
// Read file content
const content = await fileSystem.read('src/config.ts');
// Write file content
await fileSystem.write('dist/bundle.js', compiledCode);
// Copy files
await fileSystem.copy('src/assets', 'dist/assets');
// Delete files
await fileSystem.delete('temp/cache.json');
Configuration Files
Main Configuration
The plasma.config.js
file is the heart of your project configuration:
export default {
// File system settings
fileSystem: {
watchPatterns: ['src/**/*'],
ignorePatterns: ['node_modules/**', 'dist/**'],
outputDir: 'dist',
},
// Build settings
build: {
target: 'es2020',
format: 'esm',
sourcemap: true,
},
};
TypeScript Configuration
Configure TypeScript for optimal development:
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@/*": ["./src/*"],
"@components/*": ["./src/components/*"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
Package Configuration
Set up your package.json with Plasma scripts:
{
"scripts": {
"dev": "plasma dev",
"build": "plasma build",
"preview": "plasma preview",
"lint": "plasma lint"
}
}
File Templates
Plasma supports file templates for consistent code generation:
File System API
Prop | Type | Default |
---|---|---|
create | (path: string, options?: CreateOptions) => Promise<void> | - |
read | (path: string) => Promise<string> | - |
write | (path: string, content: string) => Promise<void> | - |
delete | (path: string) => Promise<void> | - |
exists | (path: string) => Promise<boolean> | - |
Best Practices
Important: Always use absolute paths or configure path aliases for better maintainability.
- Use descriptive file and folder names
- Group related files in logical directories
- Keep configuration files in the project root
- Use templates for consistent file structure
- Implement proper file watching for development