Skip to content

Commit ec5a56c

Browse files
committed
chore: wip
1 parent b6dd565 commit ec5a56c

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
lines changed

.stacks/core/actions/src/generate.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { log } from '@stacksjs/logging'
2-
import { migrations } from '@stacksjs/database'
2+
import { readModelsFromFolder } from '@stacksjs/database'
33
import { Action, NpmScript } from '@stacksjs/types'
44
import type { GeneratorOptions } from '@stacksjs/types'
55
import { runNpmScript } from '@stacksjs/utils'
@@ -120,5 +120,6 @@ export async function types(options?: GeneratorOptions) {
120120
}
121121

122122
export async function models(options?: any) {
123-
log.success(migrations)
123+
const test = await readModelsFromFolder(`${projectPath()}/config/models`)
124+
console.log(test)
124125
}

.stacks/core/database/src/migrations/index.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface Model {
1616
}
1717

1818
interface ModelData {
19-
[key: string]: any;
19+
[key: string]: any
2020
}
2121

2222
function generatePrismaSchema(models: Model[], path: string): void {
@@ -69,24 +69,25 @@ generator client {
6969
}
7070

7171
function readModelsFromFolder(folderPath: string): ModelData[] {
72-
const models: ModelData[] = [];
72+
const models: ModelData[] = []
7373

7474
fs.readdirSync(folderPath).forEach((file) => {
7575
if (file.endsWith('.ts')) {
76-
const filePath = `${folderPath}/${file}`;
77-
const fileContents = fs.readFileSync(filePath, 'utf-8');
76+
const filePath = `${folderPath}/${file}`
77+
const fileContents = fs.readFileSync(filePath, 'utf-8')
7878

79-
const regex = /return\s*{([^}]*)}/m;
80-
const match = fileContents.match(regex);
79+
const regex = /return\s*{([^}]*)}/m
80+
const match = fileContents.match(regex)
8181

8282
if (match) {
83-
const modelData = eval(`({${match[1]}})`);
84-
models.push(modelData);
83+
console.log(match[0]);
84+
const modelData = eval(`({${match[1]}})`)
85+
models.push(modelData)
8586
}
8687
}
87-
});
88+
})
8889

89-
return models;
90+
return models
9091
}
9192

9293
export {
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
import { PrismaClient } from '@prisma/client'
1+
// import { PrismaClient } from '@prisma/client'
22
import type { SeedData } from '@stacksjs/types'
33

44
async function seed(modelName: string, data: SeedData[]): Promise<void> {
5-
const prisma = new PrismaClient()
5+
// const prisma = new PrismaClient()
66

7-
try {
8-
const model = prisma[modelName]
9-
const seedPromises = data.map(item => model.create({ data: item }))
10-
await Promise.all(seedPromises)
11-
console.log(`Seeding successful for model "${modelName}"`)
12-
}
13-
catch (error) {
14-
console.error(`Error seeding model "${modelName}": ${error.message}`)
15-
}
16-
finally {
17-
await prisma.$disconnect()
18-
}
7+
// try {
8+
// const model = prisma[modelName]
9+
// const seedPromises = data.map(item => model.create({ data: item }))
10+
// await Promise.all(seedPromises)
11+
// console.log(`Seeding successful for model "${modelName}"`)
12+
// }
13+
// catch (error) {
14+
// console.error(`Error seeding model "${modelName}": ${error.message}`)
15+
// }
16+
// finally {
17+
// await prisma.$disconnect()
18+
// }
19+
console.log('test')
1920
}
2021

2122
export { seed }

config/models/test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function getModelData() {
2+
return {
3+
fields: [
4+
{ name: "id", type: "string" },
5+
{ name: "name", type: "string" }
6+
]
7+
};
8+
}

0 commit comments

Comments
 (0)