rm file
This commit is contained in:
parent
24586855cb
commit
514ed87818
47
lol.js
47
lol.js
@ -1,47 +0,0 @@
|
|||||||
const fs = require('fs/promises');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
function toPascalCase(str) {
|
|
||||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function transformEntities() {
|
|
||||||
const entitiesDir = './src/entities';
|
|
||||||
const baseDir = './src/entities/base';
|
|
||||||
|
|
||||||
// Create base directory if it doesn't exist
|
|
||||||
await fs.mkdir(baseDir, { recursive: true });
|
|
||||||
|
|
||||||
// Get all .ts files in entities directory
|
|
||||||
const files = await fs.readdir(entitiesDir);
|
|
||||||
const tsFiles = files.filter(file => file.endsWith('.ts') && file !== 'index.ts');
|
|
||||||
|
|
||||||
for (const file of tsFiles) {
|
|
||||||
const filePath = path.join(entitiesDir, file);
|
|
||||||
let content = await fs.readFile(filePath, 'utf-8');
|
|
||||||
|
|
||||||
// Get proper Pascal Case class name
|
|
||||||
const className = toPascalCase(path.basename(file, '.ts'));
|
|
||||||
|
|
||||||
// Create base class content
|
|
||||||
let baseContent = content
|
|
||||||
.replace(/@Entity\(\)/, '') // Remove @Entity decorator
|
|
||||||
.replace(/export class (\w+)/, `export class Base${className}`); // Add Base prefix with proper Pascal Case
|
|
||||||
|
|
||||||
// Create derived class content
|
|
||||||
const derivedContent = `import { Entity } from '@mikro-orm/core'
|
|
||||||
import { Base${className} } from '#entities/base/${file}'
|
|
||||||
|
|
||||||
@Entity()
|
|
||||||
export class ${className} extends Base${className} {}
|
|
||||||
`;
|
|
||||||
|
|
||||||
// Write base class
|
|
||||||
await fs.writeFile(path.join(baseDir, file), baseContent);
|
|
||||||
|
|
||||||
// Write derived class
|
|
||||||
await fs.writeFile(filePath, derivedContent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
transformEntities().catch(console.error);
|
|
Loading…
x
Reference in New Issue
Block a user