File Systems
Project Structure
Section titled “Project Structure”Plasma follows a well-organized file structure that promotes maintainability and scalability:
plasma-project/├── src/│ ├── components/│ │ ├── Button.tsx│ │ ├── Modal.tsx│ │ └── index.ts│ ├── pages/│ │ ├── home.tsx│ │ └── about.tsx│ ├── utils/│ │ ├── helpers.ts│ │ └── api.ts│ └── styles/│ ├── globals.css│ └── components.css├── public/│ ├── favicon.ico│ └── logo.svg├── docs/│ ├── README.md│ └── api.md├── plasma.config.js├── package.json└── tsconfig.jsonFile Management
Section titled “File Management”Creating Files Programmatically
Section titled “Creating Files Programmatically”Use Plasma’s file API to create and manage files:
import { fileSystem } from 'plasma';
// Create a new fileawait fileSystem.create('src/components/NewComponent.tsx', { template: 'react-component', props: { name: 'NewComponent' },});
// Create directory structureawait fileSystem.createDirectory('src/features/auth');File Watching
Section titled “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
Section titled “File Operations”Common file operations:
// Read file contentconst content = await fileSystem.read('src/config.ts');
// Write file contentawait fileSystem.write('dist/bundle.js', compiledCode);
// Copy filesawait fileSystem.copy('src/assets', 'dist/assets');
// Delete filesawait fileSystem.delete('temp/cache.json');Configuration Files
Section titled “Configuration Files”1. Main Configuration
Section titled “1. 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, },};2. TypeScript Configuration
Section titled “2. 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"]}3. Package Configuration
Section titled “3. 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
Section titled “File Templates”Plasma supports file templates for consistent code generation:
Component Template
Section titled “Component Template”import React from 'react';
interface {{name}}Props {// Define your props here}
export const {{name}}: React.FC<{{name}}Props> = (props) => { return ( <div className="{{kebabCase name}}"> {/* Component content */} </div> );};
export default {{name}};Page Template
Section titled “Page Template”import React from 'react';import { Metadata } from 'plasma';
export const metadata: Metadata = { title: '{{title}}', description: '{{description}}'};
export default function {{name}}Page() { return ( <div className="page-{{kebabCase name}}"> <h1>{{title}}</h1> {/* Page content */} </div> );}Hook Template
Section titled “Hook Template”import { useState, useEffect } from 'react';
export function use{{name}}() { const [state, setState] = useState(null);
useEffect(() => {// Hook logic}, []);
return {state,setState};}File System API
Section titled “File System API”| Method | Type | Description |
|---|---|---|
| create | (path: string, options?: CreateOptions) => Promise<void> | Create a new file with optional template |
| read | (path: string) => Promise<string> | Read file content as string |
| write | (path: string, content: string) => Promise<void> | Write content to file |
| delete | (path: string) => Promise<void> | Delete a file or directory |
| exists | (path: string) => Promise<boolean> | Check if file exists |
Best Practices
Section titled “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