fixed package.json executing seeding script

This commit is contained in:
2025-11-05 15:22:29 +01:00
parent eec9ea92d0
commit ec86290d72
2 changed files with 33 additions and 6 deletions

View File

@@ -4,9 +4,9 @@
"type": "module",
"scripts": {
"dev": "npm run build && npx tsx src/server.ts",
"dev:single": "cross-env NODE_ENV=development TRUST_PROXY_ENABLED=false npx tsx src/server.ts",
"seed:test-data": "node --loader ts-node/esm src/scripts/seedTestData.ts",
"dev:all": "concurrently \"npm run dev:single\" \"npm run seed:test-data\"",
"dev:single": "cross-env NODE_ENV=development TRUST_PROXY_ENABLED=false SEED_TEST_DATA=true npx tsx src/server.ts",
"seed:test-data": "npx tsx src/scripts/seedTestData.ts",
"dev:all": "npm run dev:single",
"build": "tsc",
"start": "node dist/server.js",
"prestart": "npm run build",

View File

@@ -85,11 +85,30 @@ export async function seedTestData(): Promise<void> {
try {
console.log('🌱 Starting test data seeding...');
// Read test.json file
const testDataPath = path.resolve(__dirname, '../../test.json');
// Read test.json file - adjust path to be relative to project root
const testDataPath = path.resolve(process.cwd(), 'test.json');
console.log('🔍 Looking for test.json at:', testDataPath);
if (!fs.existsSync(testDataPath)) {
console.log('❌ test.json file not found at:', testDataPath);
// Try alternative paths
const alternativePaths = [
path.resolve(__dirname, '../../../test.json'),
path.resolve(process.cwd(), '../test.json'),
path.resolve(__dirname, '../../test.json')
];
for (const altPath of alternativePaths) {
console.log('🔍 Trying alternative path:', altPath);
if (fs.existsSync(altPath)) {
console.log('✅ Found test.json at:', altPath);
// Continue with the found path
break;
}
}
return;
}
@@ -314,5 +333,13 @@ export async function seedTestData(): Promise<void> {
// Run if called directly
if (import.meta.url === `file://${process.argv[1]}`) {
seedTestData().catch(console.error);
seedTestData()
.then(() => {
console.log('✅ Seed script completed');
process.exit(0);
})
.catch((error) => {
console.error('❌ Seed script failed:', error);
process.exit(1);
});
}